]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
perf stat: Avoid buffer overflow to the aggregation map
authorIan Rogers <irogers@google.com>
Sat, 19 Jul 2025 03:05:04 +0000 (20:05 -0700)
committerNamhyung Kim <namhyung@kernel.org>
Thu, 24 Jul 2025 20:41:34 +0000 (13:41 -0700)
CPUs may be created and passed to perf_stat__get_aggr (via
config->aggr_get_id), such as in the stat display
should_skip_zero_counter. There may be no such aggr_id, for example,
if running with a thread. Add a missing bound check and just create
IDs for these cases.

Reviewed-by: Thomas Falcon <thomas.falcon@intel.com>
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: James Clark <james.clark@linaro.org>
Link: https://lore.kernel.org/r/20250719030517.1990983-3-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/builtin-stat.c

index 77e2248fa7fc2360778600540a4c3ffa32e16557..73b4521ab8af2afc3bb76244382ad9c9bc8d6c11 100644 (file)
@@ -1365,7 +1365,7 @@ static struct aggr_cpu_id perf_stat__get_aggr(struct perf_stat_config *config,
        struct aggr_cpu_id id;
 
        /* per-process mode - should use global aggr mode */
-       if (cpu.cpu == -1)
+       if (cpu.cpu == -1 || cpu.cpu >= config->cpus_aggr_map->nr)
                return get_id(config, cpu);
 
        if (aggr_cpu_id__is_empty(&config->cpus_aggr_map->map[cpu.cpu]))