]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
perf tools: Fix int16_t truncation of max_cpu_num in set_max_cpu_num()
authorArnaldo Carvalho de Melo <acme@redhat.com>
Sat, 6 Jun 2026 14:25:40 +0000 (11:25 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Sat, 6 Jun 2026 17:42:19 +0000 (14:42 -0300)
commit33fa2bf5608fc36bc25231592145f4738f14f11b
tree807ce00d95a4bd33b69181127ec677ea1128a619
parente2496db45bfd8dfb6154ec415798fee330f1cc0a
perf tools: Fix int16_t truncation of max_cpu_num in set_max_cpu_num()

set_max_cpu_num() assigns the sysfs "possible" CPU count to
max_cpu_num.cpu which is int16_t (struct perf_cpu).  On systems
with >32767 possible CPUs the value silently truncates, potentially
wrapping negative.  This causes cpunode_map to be underallocated
and subsequent cpu__get_node() calls to read out of bounds.

The matching check for max_present_cpu_num was added by commit
c760174401f6 ("perf cpumap: Reduce cpu size from int to int16_t")
but max_cpu_num was missed.  Add the same INT16_MAX guard.

Fixes: c760174401f605cf ("perf cpumap: Reduce cpu size from int to int16_t")
Reported-by: sashiko-bot <sashiko-bot@kernel.org>
Cc: Ian Rogers <irogers@google.com>
Assisted-by: Claude:claude-opus-4.6
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/cpumap.c