From: Ian Rogers Date: Wed, 20 May 2026 19:05:33 +0000 (-0700) Subject: perf kmem: Add bounds checks to tracepoint read values X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1bd2c9403ec5fe42bc2828b52c253e7cfed101e8;p=thirdparty%2Fkernel%2Flinux.git 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 Acked-by: Namhyung Kim Cc: Adrian Hunter Cc: Albert Ou Cc: Alexander Shishkin Cc: Alexandre Ghiti Cc: Andi Kleen Cc: Andrew Jones Cc: Anup Patel Cc: Athira Rajeev Cc: Blake Jones Cc: Chen Ni Cc: Chun-Tse Shao Cc: Dapeng Mi Cc: Derek Foreman Cc: Dmitriy Vyukov Cc: Dr. David Alan Gilbert Cc: Howard Chu Cc: Hrishikesh Suresh Cc: Ingo Molnar Cc: James Clark Cc: Jiri Olsa Cc: Krzysztof Ɓopatowski Cc: Leo Yan Cc: Palmer Dabbelt Cc: Paul Walmsley Cc: Peter Zijlstra Cc: Quan Zhou Cc: Ravi Bangoria Cc: Swapnil Sapkal Cc: Thomas Falcon Cc: Tianyou Li Cc: Yujie Liu Cc: tanze Signed-off-by: Arnaldo Carvalho de Melo --- diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index daf2272c73372..33585e353efe5 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