linux-stable/tools/lib/perf
Ian Rogers d0e2f7ae04 libperf evlist: Avoid out-of-bounds access
[ Upstream commit 1947b92464 ]

Parallel testing appears to show a race between allocating and setting
evsel ids. As there is a bounds check on the xyarray it yields a segv
like:

```
AddressSanitizer:DEADLYSIGNAL

=================================================================

==484408==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000010

==484408==The signal is caused by a WRITE memory access.

==484408==Hint: address points to the zero page.

    #0 0x55cef5d4eff4 in perf_evlist__id_hash tools/lib/perf/evlist.c:256
    #1 0x55cef5d4f132 in perf_evlist__id_add tools/lib/perf/evlist.c:274
    #2 0x55cef5d4f545 in perf_evlist__id_add_fd tools/lib/perf/evlist.c:315
    #3 0x55cef5a1923f in store_evsel_ids util/evsel.c:3130
    #4 0x55cef5a19400 in evsel__store_ids util/evsel.c:3147
    #5 0x55cef5888204 in __run_perf_stat tools/perf/builtin-stat.c:832
    #6 0x55cef5888c06 in run_perf_stat tools/perf/builtin-stat.c:960
    #7 0x55cef58932db in cmd_stat tools/perf/builtin-stat.c:2878
...
```

Avoid this crash by early exiting the perf_evlist__id_add_fd and
perf_evlist__id_add is the access is out-of-bounds.

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Yang Jihong <yangjihong1@huawei.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20240229070757.796244-1-irogers@google.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-04-13 13:07:36 +02:00
..
Documentation libperf: Add API for allocating new thread map array 2022-02-23 14:40:23 -03:00
include libperf evlist: Avoid out-of-bounds access 2024-04-13 13:07:36 +02:00
tests libperf: Add a test case for read formats 2022-08-19 15:56:44 -03:00
Build libperf: Change tests to single static and shared binaries 2021-07-07 11:41:58 -03:00
Makefile perf cpumap: Add reference count checking 2023-04-17 16:50:02 -03:00
core.c
cpumap.c libperf cpumap: Add "any CPU"/dummy test function 2023-05-27 09:37:13 -03:00
evlist.c libperf evlist: Avoid out-of-bounds access 2024-04-13 13:07:36 +02:00
evsel.c perf tools: Remove special handling of system-wide evsel 2022-10-06 08:03:53 -03:00
internal.h
lib.c libperf: Add preadn() 2022-05-23 10:11:12 -03:00
libperf.map libperf: Add API for allocating new thread map array 2022-02-23 14:40:23 -03:00
libperf.pc.template
mmap.c libperf: Implement riscv mmap support 2023-08-16 08:52:47 -03:00
threadmap.c libperf: Add API for allocating new thread map array 2022-02-23 14:40:23 -03:00
xyarray.c