mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git
synced 2026-11-02 23:54:33 +01: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 <[email protected]> Cc: Ian Rogers <[email protected]> Assisted-by: Claude Code:claude-opus-4-6 Signed-off-by: Arnaldo Carvalho de Melo <[email protected]> Signed-off-by: Namhyung Kim <[email protected]>
This commit is contained in:
1 parent
4ba223016b
commit
a881fc5603
1 file changed
+12
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user