summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2026-05-20 12:05:33 -0700
committerArnaldo Carvalho de Melo <acme@redhat.com>2026-05-20 16:39:40 -0300
commit1bd2c9403ec5fe42bc2828b52c253e7cfed101e8 (patch)
tree6ede0415f365a370b187e9fbaf01930cb2fe559d
parente454fef5d2c6e3fc89bd87a2da491dae3977a9ed (diff)
perf kmem: Add bounds checks to tracepoint read values
Sanitize order and migrate_type values from tracepoint payloads before using them as array indexes. When processing page_alloc_event and page_free_event, verify that 'order' is less than MAX_PAGE_ORDER and 'migrate_type' is less than MAX_MIGRATE_TYPES. This guarantees that indexing into order_stats[MAX_PAGE_ORDER][MAX_MIGRATE_TYPES] remains strictly within bounds, avoiding out-of-bound heap or static segment accesses. Signed-off-by: Ian Rogers <irogers@google.com> Acked-by: Namhyung Kim <namhyung@kernel.org> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Albert Ou <aou@eecs.berkeley.edu> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Alexandre Ghiti <alex@ghiti.fr> Cc: Andi Kleen <ak@linux.intel.com> Cc: Andrew Jones <ajones@ventanamicro.com> Cc: Anup Patel <anup@brainfault.org> Cc: Athira Rajeev <atrajeev@linux.ibm.com> Cc: Blake Jones <blakejones@google.com> Cc: Chen Ni <nichen@iscas.ac.cn> Cc: Chun-Tse Shao <ctshao@google.com> Cc: Dapeng Mi <dapeng1.mi@linux.intel.com> Cc: Derek Foreman <derek.foreman@collabora.com> Cc: Dmitriy Vyukov <dvyukov@google.com> Cc: Dr. David Alan Gilbert <linux@treblig.org> Cc: Howard Chu <howardchu95@gmail.com> Cc: Hrishikesh Suresh <hrishikesh123s@gmail.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@linaro.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Krzysztof Ɓopatowski <krzysztof.m.lopatowski@gmail.com> Cc: Leo Yan <leo.yan@arm.com> Cc: Palmer Dabbelt <palmer@dabbelt.com> Cc: Paul Walmsley <pjw@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Quan Zhou <zhouquan@iscas.ac.cn> Cc: Ravi Bangoria <ravi.bangoria@amd.com> Cc: Swapnil Sapkal <swapnil.sapkal@amd.com> Cc: Thomas Falcon <thomas.falcon@intel.com> Cc: Tianyou Li <tianyou.li@intel.com> Cc: Yujie Liu <yujie.liu@intel.com> Cc: tanze <tanze@kylinos.cn> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/builtin-kmem.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index daf2272c7337..33585e353efe 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -826,6 +826,16 @@ static int evsel__process_page_alloc_event(struct perf_sample *sample)
.migrate_type = migrate_type,
};
+ if (order >= MAX_PAGE_ORDER) {
+ pr_debug("Out-of-bounds order %u\n", order);
+ return -1;
+ }
+
+ if (migrate_type >= MAX_MIGRATE_TYPES) {
+ pr_debug("Out-of-bounds migratetype %u\n", migrate_type);
+ return -1;
+ }
+
if (use_pfn)
page = perf_sample__intval(sample, "pfn");
else
@@ -892,6 +902,11 @@ static int evsel__process_page_free_event(struct perf_sample *sample)
.order = order,
};
+ if (order >= MAX_PAGE_ORDER) {
+ pr_debug("Out-of-bounds order %u\n", order);
+ return -1;
+ }
+
if (use_pfn)
page = perf_sample__intval(sample, "pfn");
else