Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1406624

[PATCH v5 1/8] perf tools: Check 'base' pointer before checking refcnt when put a mmap

From Wang Nan <wangnan0@huawei.com>
Newsgroups linux.kernel
Subject [PATCH v5 1/8] perf tools: Check 'base' pointer before checking refcnt when put a mmap
Date 2016-05-25 07:10 +0200
Message-ID <rCzeW-5mD-11@gated-at.bofh.it> (permalink)
References <rCzeV-5mD-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


evlist->mmap[i]->refcnt could be 0 if an evlist has no evsel or all
evsels don't match the evlist during mmap. For example, when all evsels
are overwritable but the evlist itself is normal. To avoid crashing,
perf should check 'base' pointer before checking refcnt, and raise bug
only when base is not NULL.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.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
---
 tools/perf/util/evlist.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index fbd0d47..f916d25 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -857,9 +857,11 @@ static void perf_evlist__mmap_get(struct perf_evlist *evlist, int idx)
 
 static void perf_evlist__mmap_put(struct perf_evlist *evlist, int idx)
 {
-	BUG_ON(atomic_read(&evlist->mmap[idx].refcnt) == 0);
+	struct perf_mmap *mmap = &evlist->mmap[idx];
 
-	if (atomic_dec_and_test(&evlist->mmap[idx].refcnt))
+	BUG_ON(mmap->base && atomic_read(&mmap->refcnt) == 0);
+
+	if (atomic_dec_and_test(&mmap->refcnt))
 		__perf_evlist__munmap(evlist, idx);
 }
 
-- 
1.8.3.4

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v5 0/8] perf tools: Support overwritable ring buffer Wang Nan <wangnan0@huawei.com> - 2016-05-25 07:10 +0200
  [PATCH v5 4/8] perf record: Introduce rec->overwrite_evlist for overwritable events Wang Nan <wangnan0@huawei.com> - 2016-05-25 07:10 +0200
    Re: [PATCH v5 4/8] perf record: Introduce rec->overwrite_evlist for  overwritable events "Wangnan (F)" <wangnan0@huawei.com> - 2016-05-25 12:20 +0200
      Re: [PATCH v5 4/8] perf record: Introduce rec->overwrite_evlist for  overwritable events "Wangnan (F)" <wangnan0@huawei.com> - 2016-05-25 15:50 +0200
        Re: [PATCH v5 4/8] perf record: Introduce rec->overwrite_evlist for  overwritable events Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-25 16:20 +0200
  [PATCH v5 1/8] perf tools: Check 'base' pointer before checking refcnt when put a mmap Wang Nan <wangnan0@huawei.com> - 2016-05-25 07:10 +0200
  [PATCH v5 2/8] perf tools: Choose correct reading direction according to evlist->backward Wang Nan <wangnan0@huawei.com> - 2016-05-25 07:10 +0200
  [PATCH v5 3/8] perf tests: Add testcase for auxiliary evlist Wang Nan <wangnan0@huawei.com> - 2016-05-25 07:10 +0200
  [PATCH v5 7/8] perf tools: Don't warn about out of order event if write_backward is used Wang Nan <wangnan0@huawei.com> - 2016-05-25 07:10 +0200
  [PATCH v5 6/8] perf tools: Enable overwrite settings Wang Nan <wangnan0@huawei.com> - 2016-05-25 07:10 +0200

csiph-web