aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorWang Nan <wangnan0@huawei.com>2016-05-23 03:13:39 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-05-23 17:22:46 -0400
commit2d11c65071d489e20b3a811167507939dd8c2eac (patch)
tree48068295866612fb8c24d4adedf3fe1d284bd493 /tools
parent65aea2338765da1a58cc26eeb84d72308492ecb5 (diff)
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@huawei.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Zefan Li <lizefan@huawei.com> Cc: pi3orama@163.com Link: http://lkml.kernel.org/r/1463987628-163563-3-git-send-email-wangnan0@huawei.com Signed-off-by: He Kuang <hekuang@huawei.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/builtin-record.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index f3679c44d3f3..f302cc937ca5 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -40,6 +40,7 @@
40#include <unistd.h> 40#include <unistd.h>
41#include <sched.h> 41#include <sched.h>
42#include <sys/mman.h> 42#include <sys/mman.h>
43#include <asm/bug.h>
43 44
44 45
45struct record { 46struct record {
@@ -98,6 +99,13 @@ static int record__mmap_read(struct record *rec, int idx)
98 rec->samples++; 99 rec->samples++;
99 100
100 size = head - old; 101 size = head - old;
102 if (size > (unsigned long)(md->mask) + 1) {
103 WARN_ONCE(1, "failed to keep up with mmap data. (warn only once)\n");
104
105 md->prev = head;
106 perf_evlist__mmap_consume(rec->evlist, idx);
107 return 0;
108 }
101 109
102 if ((old & md->mask) + size != (head & md->mask)) { 110 if ((old & md->mask) + size != (head & md->mask)) {
103 buf = &data[old & md->mask]; 111 buf = &data[old & md->mask];