]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
perf tools: Add bounds check to cpu__get_node()
authorArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 4 Jun 2026 21:14:23 +0000 (18:14 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 4 Jun 2026 22:17:36 +0000 (19:17 -0300)
commit1e7921d7227de5da0dfc167943092c823ec7e49b
treee2146ac625b1c6aee3434d0231d1a62179e444c0
parent7ccd2e6cecd5bb02a5a15f0dd7199d1e81380bda
perf tools: Add bounds check to cpu__get_node()

cpu__get_node() accesses cpunode_map[cpu.cpu] without checking against
max_cpu_num, the allocation size of cpunode_map.  Callers such as
builtin-kmem.c:evsel__process_alloc_event() pass sample->cpu from
perf.data events, which may exceed the host's CPU count when analyzing
cross-machine recordings.

Add a bounds check against max_cpu_num before indexing, returning -1
for out-of-range values.  This is a central fix that protects all
callers.

Fixes: 86895b480a2f ("perf stat: Add --per-node agregation support")
Reported-by: sashiko-bot <sashiko-bot@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Assisted-by: Claude:claude-opus-4.6
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/cpumap.c