From: Kan Liang Date: Mon, 26 Mar 2018 13:42:09 +0000 (-0400) Subject: perf mmap: Fix accessing unmapped mmap in perf_mmap__read_done() X-Git-Url: http://git.cdn.openwrt.org/?a=commitdiff_plain;h=f58385f629c87a9e210108b39c1f4950d0363ad2;p=openwrt%2Fstaging%2Fblogic.git perf mmap: Fix accessing unmapped mmap in perf_mmap__read_done() There is a segmentation fault when running 'perf trace'. For example: [root@jouet e]# perf trace -e *chdir -o /tmp/bla perf report --ignore-vmlinux -i ../perf.data The perf_mmap__consume() could unmap the mmap. It needs to check the refcnt in perf_mmap__read_done(). Reported-by: Arnaldo Carvalho de Melo Signed-off-by: Kan Liang Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Fixes: ee023de05f35 ("perf mmap: Introduce perf_mmap__read_done()") Link: http://lkml.kernel.org/r/1522071729-16776-1-git-send-email-kan.liang@linux.intel.com Signed-off-by: Arnaldo Carvalho de Melo --- diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c index 38ca3ffb9d61..f6cfc52ff1fe 100644 --- a/tools/perf/util/mmap.c +++ b/tools/perf/util/mmap.c @@ -317,5 +317,11 @@ out: */ void perf_mmap__read_done(struct perf_mmap *map) { + /* + * Check if event was unmapped due to a POLLHUP/POLLERR. + */ + if (!refcount_read(&map->refcnt)) + return; + map->prev = perf_mmap__read_head(map); }