]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
perf kmem: Add bounds checks to tracepoint read values
authorIan Rogers <irogers@google.com>
Wed, 20 May 2026 19:05:33 +0000 (12:05 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 20 May 2026 19:39:40 +0000 (16:39 -0300)
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>
tools/perf/builtin-kmem.c

index daf2272c733729800803f91b4e40c7bc14b46350..33585e353efe56cc4f4c9ecd8efe38e311566baa 100644 (file)
@@ -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