linux/tools/lib/perf
Adrian Hunter a668cc07f9 perf tools: Fix segfault accessing sample_id xyarray
perf_evsel::sample_id is an xyarray which can cause a segfault when
accessed beyond its size. e.g.

  # perf record -e intel_pt// -C 1 sleep 1
  Segmentation fault (core dumped)
  #

That is happening because a dummy event is opened to capture text poke
events accross all CPUs, however the mmap logic is allocating according
to the number of user_requested_cpus.

In general, perf sometimes uses the evsel cpus to open events, and
sometimes the evlist user_requested_cpus. However, it is not necessary
to determine which case is which because the opened event file
descriptors are also in an xyarray, the size of whch can be used
to correctly allocate the size of the sample_id xyarray, because there
is one ID per file descriptor.

Note, in the affected code path, perf_evsel fd array is subsequently
used to get the file descriptor for the mmap, so it makes sense for the
xyarrays to be the same size there.

Fixes: d1a177595b ("libperf: Adopt perf_evlist__mmap()/munmap() from tools/perf")
Fixes: 246eba8e90 ("perf tools: Add support for PERF_RECORD_TEXT_POKE")
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Acked-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: stable@vger.kernel.org # 5.5+
Link: https://lore.kernel.org/r/20220413114232.26914-1-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-04-13 22:23:02 -03:00
..
Documentation libperf: Add API for allocating new thread map array 2022-02-23 14:40:23 -03:00
include perf cpumap: Add is_subset function 2022-04-01 16:19:35 -03:00
tests libperf tests: Fix typo in perf_evlist__open() failure error messages 2022-03-26 10:55:57 -03:00
Build libperf: Change tests to single static and shared binaries 2021-07-07 11:41:58 -03:00
core.c
cpumap.c perf cpumap: More cpu map reuse by merge. 2022-04-01 16:19:35 -03:00
evlist.c perf tools: Fix segfault accessing sample_id xyarray 2022-04-13 22:23:02 -03:00
evsel.c perf cpumap: Migrate to libperf cpumap api 2022-01-22 17:08:42 -03:00
internal.h
lib.c
libperf.map libperf: Add API for allocating new thread map array 2022-02-23 14:40:23 -03:00
libperf.pc.template
Makefile kbuild: replace $(if A,A,B) with $(or A,B) 2022-02-15 12:25:56 +09:00
mmap.c libperf: Add arm64 support to perf_mmap__read_self() 2022-02-06 09:14:27 -03:00
threadmap.c libperf: Add API for allocating new thread map array 2022-02-23 14:40:23 -03:00
xyarray.c