WSL2-Linux-Kernel/tools/lib/perf
Adrian Hunter 3876c574e4 perf tools: Fix segfault accessing sample_id xyarray
commit a668cc07f9 upstream.

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-04-27 14:38:50 +02:00
..
Documentation libperf: Add evsel mmap support 2021-04-15 16:38:51 -03:00
include libperf tests: Fix verbose printing 2021-08-24 15:05:35 -03:00
tests libperf tests: Fix test_stat_cpu 2021-10-14 15:41:35 -03:00
Build libperf: Change tests to single static and shared binaries 2021-07-07 11:41:58 -03:00
Makefile libperf: Change tests to single static and shared binaries 2021-07-07 11:41:58 -03:00
core.c libperf: Move to tools/lib/perf 2020-01-06 11:46:09 -03:00
cpumap.c libperf cpumap: Take into advantage it is sorted to optimize perf_cpu_map__max() 2021-08-31 16:17:02 -03:00
evlist.c perf tools: Fix segfault accessing sample_id xyarray 2022-04-27 14:38:50 +02:00
evsel.c libperf evsel: Make use of FD robust. 2021-09-18 17:43:06 -03:00
internal.h libperf: Move to tools/lib/perf 2020-01-06 11:46:09 -03:00
lib.c libperf: Move to tools/lib/perf 2020-01-06 11:46:09 -03:00
libperf.map libperf: Adopt evlist__set_leader() from tools/perf as perf_evlist__set_leader() 2021-07-09 14:04:32 -03:00
libperf.pc.template libperf: Move to tools/lib/perf 2020-01-06 11:46:09 -03:00
mmap.c libperf: Add support for user space counter access 2021-04-20 08:10:45 -03:00
threadmap.c libperf: Move to tools/lib/perf 2020-01-06 11:46:09 -03:00
xyarray.c libperf: Move to tools/lib/perf 2020-01-06 11:46:09 -03:00