Skip to content

Commit a881fc5

Browse files
acmelnamhyung
authored andcommitted
perf header: Sanity check HEADER_MEM_TOPOLOGY
Add validation to process_mem_topology() to harden against malformed perf.data files: - Upper bound check on nr_nodes (reuses MAX_NUMA_NODES, 4096) - Minimum section size check before allocating This is particularly important here since nr is u64, making unbounded values especially dangerous. Cc: Jiri Olsa <jolsa@kernel.org> 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 4ba2230 commit a881fc5

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
@@ -3308,6 +3308,18 @@ static int process_mem_topology(struct feat_fd *ff,
33083308
if (do_read_u64(ff, &nr))
33093309
return -1;
33103310

3311+
if (nr > MAX_NUMA_NODES) {
3312+
pr_err("Invalid HEADER_MEM_TOPOLOGY: nr_nodes (%llu) > %u\n",
3313+
(unsigned long long)nr, MAX_NUMA_NODES);
3314+
return -1;
3315+
}
3316+
3317+
if (ff->size < 3 * sizeof(u64) + nr * 2 * sizeof(u64)) {
3318+
pr_err("Invalid HEADER_MEM_TOPOLOGY: section too small (%zu) for %llu nodes\n",
3319+
ff->size, (unsigned long long)nr);
3320+
return -1;
3321+
}
3322+
33113323
nodes = calloc(nr, sizeof(*nodes));
33123324
if (!nodes)
33133325
return -1;

0 commit comments

Comments
 (0)