diff options
author | Ian Rogers <irogers@google.com> | 2025-07-18 20:05:04 -0700 |
---|---|---|
committer | Namhyung Kim <namhyung@kernel.org> | 2025-07-24 13:41:34 -0700 |
commit | 848e7a06fea9be249c5b788b3f498196925e4d7e (patch) | |
tree | f76944984c57fbfc7500da25163397c8a4121df2 | |
parent | 62f4512238f5541d864a783cbcd8d95d067a17b3 (diff) |
perf stat: Avoid buffer overflow to the aggregation map
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>
-rw-r--r-- | tools/perf/builtin-stat.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 77e2248fa7fc..73b4521ab8af 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -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])) |