Skip to content

Commit 47c68eb

Browse files
acmelnamhyung
authored andcommitted
perf header: Sanity check HEADER_HYBRID_TOPOLOGY
Add upper bound check on nr_nodes in process_hybrid_topology() to harden against malformed perf.data files (reuses MAX_PMU_MAPPINGS, 4096). Cc: Ian Rogers <irogers@google.com> Assisted-by: Claude Code:claude-opus-4-6 Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
1 parent 110a661 commit 47c68eb

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

tools/perf/util/header.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3450,6 +3450,18 @@ static int process_hybrid_topology(struct feat_fd *ff,
34503450
if (do_read_u32(ff, &nr))
34513451
return -1;
34523452

3453+
if (nr > MAX_PMU_MAPPINGS) {
3454+
pr_err("Invalid HEADER_HYBRID_TOPOLOGY: nr_nodes (%u) > %u\n",
3455+
nr, MAX_PMU_MAPPINGS);
3456+
return -1;
3457+
}
3458+
3459+
if (ff->size < sizeof(u32) + nr * 2 * sizeof(u32)) {
3460+
pr_err("Invalid HEADER_HYBRID_TOPOLOGY: section too small (%zu) for %u nodes\n",
3461+
ff->size, nr);
3462+
return -1;
3463+
}
3464+
34533465
nodes = calloc(nr, sizeof(*nodes));
34543466
if (!nodes)
34553467
return -ENOMEM;

0 commit comments

Comments
 (0)