perf mmap: Fix accessing unmapped mmap in perf_mmap__read_done()
authorKan Liang <kan.liang@linux.intel.com>
Mon, 26 Mar 2018 13:42:09 +0000 (09:42 -0400)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 27 Mar 2018 16:13:38 +0000 (13:13 -0300)
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 <acme@redhat.com>
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
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 <acme@redhat.com>
tools/perf/util/mmap.c

index 38ca3ffb9d6146e64d1317bbbfc5e772c934bcfc..f6cfc52ff1fe91c773953983a660a218a179d6a8 100644 (file)
@@ -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);
 }