mirror of
https://github.com/torvalds/linux.git
synced 2026-05-12 16:18:45 +02:00
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>
This commit is contained in:
parent
4ba223016b
commit
a881fc5603
|
|
@ -3308,6 +3308,18 @@ static int process_mem_topology(struct feat_fd *ff,
|
|||
if (do_read_u64(ff, &nr))
|
||||
return -1;
|
||||
|
||||
if (nr > MAX_NUMA_NODES) {
|
||||
pr_err("Invalid HEADER_MEM_TOPOLOGY: nr_nodes (%llu) > %u\n",
|
||||
(unsigned long long)nr, MAX_NUMA_NODES);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ff->size < 3 * sizeof(u64) + nr * 2 * sizeof(u64)) {
|
||||
pr_err("Invalid HEADER_MEM_TOPOLOGY: section too small (%zu) for %llu nodes\n",
|
||||
ff->size, (unsigned long long)nr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
nodes = calloc(nr, sizeof(*nodes));
|
||||
if (!nodes)
|
||||
return -1;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user