Skip to content

Commit 4ba2230

Browse files
acmelnamhyung
authored andcommitted
perf header: Sanity check HEADER_NUMA_TOPOLOGY
Add validation to process_numa_topology() to harden against malformed perf.data files: - Upper bound check on nr_nodes (max 4096) - Minimum section size check before allocating 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 22a2e2b commit 4ba2230

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

tools/perf/util/header.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
#include <event-parse.h>
6464
#endif
6565

66+
#define MAX_NUMA_NODES 4096
6667
#define MAX_SCHED_DOMAINS 64
6768

6869
/*
@@ -3005,6 +3006,18 @@ static int process_numa_topology(struct feat_fd *ff, void *data __maybe_unused)
30053006
if (do_read_u32(ff, &nr))
30063007
return -1;
30073008

3009+
if (nr > MAX_NUMA_NODES) {
3010+
pr_err("Invalid HEADER_NUMA_TOPOLOGY: nr_nodes (%u) > %u\n",
3011+
nr, MAX_NUMA_NODES);
3012+
return -1;
3013+
}
3014+
3015+
if (ff->size < sizeof(u32) + nr * (sizeof(u32) + 2 * sizeof(u64))) {
3016+
pr_err("Invalid HEADER_NUMA_TOPOLOGY: section too small (%zu) for %u nodes\n",
3017+
ff->size, nr);
3018+
return -1;
3019+
}
3020+
30083021
nodes = calloc(nr, sizeof(*nodes));
30093022
if (!nodes)
30103023
return -ENOMEM;

0 commit comments

Comments
 (0)