Skip to content

Commit

Permalink
perf record: Prevent reading invalid data in record__mmap_read
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Wang Nan authored and Arnaldo Carvalho de Melo committed May 23, 2016
1 parent 65aea23 commit 2d11c65
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tools/perf/builtin-record.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <unistd.h>
#include <sched.h>
#include <sys/mman.h>
#include <asm/bug.h>


struct record {
Expand Down Expand Up @@ -98,6 +99,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];
Expand Down

0 comments on commit 2d11c65

Please sign in to comment.