]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
perf stat: Introduce perf_env__get_cpu_topology() to guard NULL env->cpu
authorArnaldo Carvalho de Melo <acme@redhat.com>
Sat, 6 Jun 2026 14:17:45 +0000 (11:17 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Sat, 6 Jun 2026 16:44:46 +0000 (13:44 -0300)
commitafa4363a91a19dff65dceb7fbce7bba689bbc854
tree0ef7ab6677a992222a06edb7f0d0f7c1a7ca8702
parent25627346b10e6a564610ea2c49dc6dd54812226d
perf stat: Introduce perf_env__get_cpu_topology() to guard NULL env->cpu

process_cpu_topology() in header.c frees env->cpu on old-format
perf.data files that predate topology information, but leaves
nr_cpus_avail set.  The six perf_env__get_*_aggr_by_cpu() functions
in builtin-stat.c pass the bounds check but dereference a NULL
env->cpu pointer, crashing on old recordings.

Introduce perf_env__get_cpu_topology() as a safe accessor that
validates env->cpu, cpu.cpu >= 0, and cpu.cpu < nr_cpus_avail in
one place, returning a struct cpu_topology_map pointer or NULL.
Convert all six topology aggregation callbacks to use it.

Fixes: 88031a0de7d68d13 ("perf stat: Switch to cpu version of cpu_map__get()")
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/builtin-stat.c
tools/perf/util/env.h