]> Git Repo - linux.git/commit
perf tools: Fix segfault accessing sample_id xyarray
authorAdrian Hunter <[email protected]>
Wed, 13 Apr 2022 11:42:32 +0000 (14:42 +0300)
committerArnaldo Carvalho de Melo <[email protected]>
Thu, 14 Apr 2022 01:23:02 +0000 (22:23 -0300)
commita668cc07f990d2ed19424d5c1a529521a9d1cee1
treed6724be7a31d8b51816f932a9a63f165a13c08de
parentd73f5d14e0cdd1f39764379250f26163913d7155
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: d1a177595b3a824c ("libperf: Adopt perf_evlist__mmap()/munmap() from tools/perf")
Fixes: 246eba8e9041c477 ("perf tools: Add support for PERF_RECORD_TEXT_POKE")
Signed-off-by: Adrian Hunter <[email protected]>
Acked-by: Ian Rogers <[email protected]>
Cc: Adrian Hunter <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: [email protected] # 5.5+
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
tools/lib/perf/evlist.c
This page took 0.043403 seconds and 4 git commands to generate.