[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1456132275-98875-33-git-send-email-wangnan0@huawei.com>
Date: Mon, 22 Feb 2016 09:10:59 +0000
From: Wang Nan <wangnan0@...wei.com>
To: Alexei Starovoitov <ast@...nel.org>,
Arnaldo Carvalho de Melo <acme@...hat.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>,
Brendan Gregg <brendan.d.gregg@...il.com>
CC: Adrian Hunter <adrian.hunter@...el.com>,
Cody P Schafer <dev@...yps.com>,
"David S. Miller" <davem@...emloft.net>,
He Kuang <hekuang@...wei.com>,
Jérémie Galarneau
<jeremie.galarneau@...icios.com>, Jiri Olsa <jolsa@...nel.org>,
Kirill Smelkov <kirr@...edi.com>,
Li Zefan <lizefan@...wei.com>,
Masami Hiramatsu <masami.hiramatsu.pt@...achi.com>,
Namhyung Kim <namhyung@...nel.org>,
Peter Zijlstra <peterz@...radead.org>, <pi3orama@....com>,
Wang Nan <wangnan0@...wei.com>, <linux-kernel@...r.kernel.org>
Subject: [PATCH 32/48] perf record: Prevent reading invalid data in record__mmap_read
When record__mmap_read() requires data more than the size of ring
buffer, drop those data to avoid accessing invalid memory.
This can happen when reading from overwritable ring buffer, which
should be avoided. However, check this for robustness.
Signed-off-by: Wang Nan <wangnan0@...wei.com>
Signed-off-by: He Kuang <hekuang@...wei.com>
Cc: Arnaldo Carvalho de Melo <acme@...hat.com>
Cc: Jiri Olsa <jolsa@...nel.org>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@...achi.com>
Cc: Namhyung Kim <namhyung@...nel.org>
Cc: Zefan Li <lizefan@...wei.com>
Cc: pi3orama@....com
---
tools/perf/builtin-record.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 310e290..3a7de24 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -37,6 +37,7 @@
#include <unistd.h>
#include <sched.h>
#include <sys/mman.h>
+#include <asm/bug.h>
struct record {
@@ -95,6 +96,13 @@ static int record__mmap_read(struct record *rec, int idx)
rec->samples++;
size = head - old;
+ if (size > (unsigned long)(md->mask) + 1) {
+ WARN_ONCE(1, "failed to keep up with mmap data. (warn only once)\n");
+
+ md->prev = head;
+ perf_evlist__mmap_consume(rec->evlist, idx);
+ return 0;
+ }
if ((old & md->mask) + size != (head & md->mask)) {
buf = &data[old & md->mask];
--
1.8.3.4
Powered by blists - more mailing lists