Skip to content

Commit f613a6d

Browse files
acmelnamhyung
authored andcommitted
perf header: Sanity check HEADER_PMU_MAPPINGS
Add upper bound check on pmu_num in process_pmu_mappings() to harden against malformed perf.data files (max 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 a881fc5 commit f613a6d

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
@@ -64,6 +64,7 @@
6464
#endif
6565

6666
#define MAX_NUMA_NODES 4096
67+
#define MAX_PMU_MAPPINGS 4096
6768
#define MAX_SCHED_DOMAINS 64
6869

6970
/*
@@ -3069,6 +3070,18 @@ static int process_pmu_mappings(struct feat_fd *ff, void *data __maybe_unused)
30693070
return 0;
30703071
}
30713072

3073+
if (pmu_num > MAX_PMU_MAPPINGS) {
3074+
pr_err("Invalid HEADER_PMU_MAPPINGS: pmu_num (%u) > %u\n",
3075+
pmu_num, MAX_PMU_MAPPINGS);
3076+
return -1;
3077+
}
3078+
3079+
if (ff->size < sizeof(u32) + pmu_num * 2 * sizeof(u32)) {
3080+
pr_err("Invalid HEADER_PMU_MAPPINGS: section too small (%zu) for %u PMUs\n",
3081+
ff->size, pmu_num);
3082+
return -1;
3083+
}
3084+
30723085
env->nr_pmu_mappings = pmu_num;
30733086
if (strbuf_init(&sb, 128) < 0)
30743087
return -1;

0 commit comments

Comments
 (0)