| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/11/18 03:28 | flow | patch-triage |
25mArgs:null Results: {
"EnableConfigs": [
"STACKDEPOT",
"STACKDEPOT_ALWAYS_INIT",
"SLUB_DEBUG",
"PAGE_OWNER",
"DEBUG_KMEMLEAK"
],
"FocusSymbols": [
"stack_depot_fetch_into",
"stack_depot_snprint",
"stack_depot_print",
"read_page_owner",
"stack_print",
"__kmem_obj_info"
],
"KMSANReasoning": "The patch series implements 32-bit frame compression for stack depot records on x86_64 and arm64, transitions the fetch API from stack_depot_fetch() returning internal pointers to stack_depot_fetch_into() writing into caller-provided buffers, and adds stack_depot_snprint().\n\nFrom an uninitialized memory perspective:\n1. Internal stack depot data structures: All fields in `struct stack_record` (including `size`, `flags`, and `compressed_entries`/`entries`) are completely written upon allocation in depot_alloc_stack(), followed by explicit kmsan_unpoison_memory(stack, record_size) annotations.\n2. Caller-provided buffers: In depot_copy_entries(), the copied frames are explicitly unpoisoned via kmsan_unpoison_memory(). All updated callers (kmemleak, page_owner, slub, kmsan report) strictly iterate up to the returned frame count `nr_entries`, avoiding any reads of trailing uninitialized buffer elements.\n3. User info-leaks: Stack depot data structures and stack frames are purely kernel-internal diagnostic data and are not copied to user space.\n4. KASAN vs KMSAN: Any potential issues arising from frame compression, index bounds, or array limits are out-of-bounds/corruption risks that are detected by standard KASAN and KUnit tests. There is no uninitialized memory risk uniquely detectable by KMSAN.",
"NeedsKMSAN": false,
"Reasoning": "The patch introduces stack trace frame compression to the stack depot core subsystem (specifically compressing 64-bit kernel text addresses into 32-bit payloads on x86_64 and arm64), modifies struct stack_record, replaces stack_depot_fetch() with stack_depot_fetch_into() introducing new bounds and validation checks (WARN_ON_ONCE), and rewrites stack_depot_snprint() and stack_depot_print() to decode compressed frames. These code paths are fully reachable in virtualized environments. Ubiquitous allocation hot-paths (such as stack_depot_save, which executes on every allocation under KASAN) are excluded from FocusSymbols to avoid diluting fuzzing focus.",
"WorthFuzzing": true
} |
| 1/1 | 2026/11/18 03:28 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit 1904c3d1184586d2fb69893d04ebf95da88c8ff0\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Wed Nov 18 03:28:09 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/arch/arm64/include/asm/stackdepot.h b/arch/arm64/include/asm/stackdepot.h\nnew file mode 100644\nindex 00000000000000..72053527ab219f\n--- /dev/null\n+++ b/arch/arm64/include/asm/stackdepot.h\n@@ -0,0 +1,37 @@\n+/* SPDX-License-Identifier: GPL-2.0 */\n+#ifndef __ASM_STACKDEPOT_H\n+#define __ASM_STACKDEPOT_H\n+\n+#include \u003clinux/types.h\u003e\n+#include \u003casm/sections.h\u003e\n+\n+/*\n+ * Modules are allocated inside a 2 GB relocation window containing the\n+ * kernel image. Store a signed 32-bit offset from _text so compression is\n+ * independent of 4 GB high-bit boundaries crossed by that window.\n+ */\n+static inline unsigned long arch_stack_depot_frame_from_payload(u32 payload)\n+{\n+\treturn (unsigned long)_text + (s64)(s32)payload;\n+}\n+\n+static inline bool\n+arch_stack_depot_frame_try_compress(unsigned long frame, u32 *payload)\n+{\n+\tu32 candidate;\n+\n+\tcandidate = (u32)(frame - (unsigned long)_text);\n+\tif (arch_stack_depot_frame_from_payload(candidate) != frame)\n+\t\treturn false;\n+\n+\t*payload = candidate;\n+\treturn true;\n+}\n+\n+static inline void\n+arch_stack_depot_frame_decompress(u32 payload, unsigned long *frame)\n+{\n+\t*frame = arch_stack_depot_frame_from_payload(payload);\n+}\n+\n+#endif /* __ASM_STACKDEPOT_H */\ndiff --git a/arch/um/include/asm/Kbuild b/arch/um/include/asm/Kbuild\nindex 8fdc0bd9ab6fbc..14778d2457d790 100644\n--- a/arch/um/include/asm/Kbuild\n+++ b/arch/um/include/asm/Kbuild\n@@ -21,6 +21,7 @@ generic-y += preempt.h\n generic-y += ring_buffer.h\n generic-y += runtime-const.h\n generic-y += softirq_stack.h\n+generic-y += stackdepot.h\n generic-y += switch_to.h\n generic-y += topology.h\n generic-y += trace_clock.h\ndiff --git a/arch/x86/include/asm/stackdepot.h b/arch/x86/include/asm/stackdepot.h\nnew file mode 100644\nindex 00000000000000..9a8d04fa8c1c88\n--- /dev/null\n+++ b/arch/x86/include/asm/stackdepot.h\n@@ -0,0 +1,37 @@\n+/* SPDX-License-Identifier: GPL-2.0 */\n+#ifndef _ASM_X86_STACKDEPOT_H\n+#define _ASM_X86_STACKDEPOT_H\n+\n+#include \u003clinux/types.h\u003e\n+\n+#ifdef CONFIG_X86_64\n+/*\n+ * Compress canonical kernel text/module addresses whose upper 32 bits are all\n+ * ones. Other kernel virtual addresses stay raw, so decompression reconstructs\n+ * the original frame by restoring this prefix.\n+ */\n+#define STACK_DEPOT_X86_64_FRAME_PREFIX\t0xffffffff00000000UL\n+#define STACK_DEPOT_X86_64_FRAME_LOW_MASK\t0x00000000ffffffffUL\n+\n+static inline bool\n+arch_stack_depot_frame_try_compress(unsigned long frame, u32 *low)\n+{\n+\tif ((frame \u0026 ~STACK_DEPOT_X86_64_FRAME_LOW_MASK) !=\n+\t STACK_DEPOT_X86_64_FRAME_PREFIX)\n+\t\treturn false;\n+\n+\t*low = (u32)frame;\n+\treturn true;\n+}\n+\n+static inline void\n+arch_stack_depot_frame_decompress(u32 low, unsigned long *frame)\n+{\n+\t*frame = STACK_DEPOT_X86_64_FRAME_PREFIX | low;\n+}\n+\n+#else\n+#include \u003casm-generic/stackdepot.h\u003e\n+#endif /* CONFIG_X86_64 */\n+\n+#endif /* _ASM_X86_STACKDEPOT_H */\ndiff --git a/drivers/gpu/drm/drm_modeset_lock.c b/drivers/gpu/drm/drm_modeset_lock.c\nindex e14814c30d8c06..f48b02379b711c 100644\n--- a/drivers/gpu/drm/drm_modeset_lock.c\n+++ b/drivers/gpu/drm/drm_modeset_lock.c\n@@ -94,16 +94,13 @@ static noinline depot_stack_handle_t __drm_stack_depot_save(void)\n static void __drm_stack_depot_print(depot_stack_handle_t stack_depot)\n {\n \tstruct drm_printer p = drm_dbg_printer(NULL, DRM_UT_KMS, \"drm_modeset_lock\");\n-\tunsigned long *entries;\n-\tunsigned int nr_entries;\n \tchar *buf;\n \n \tbuf = kmalloc(PAGE_SIZE, GFP_NOWAIT | __GFP_NOWARN);\n \tif (!buf)\n \t\treturn;\n \n-\tnr_entries = stack_depot_fetch(stack_depot, \u0026entries);\n-\tstack_trace_snprint(buf, PAGE_SIZE, entries, nr_entries, 2);\n+\tstack_depot_snprint(stack_depot, buf, PAGE_SIZE, 2);\n \n \tdrm_printf(\u0026p, \"attempting to lock a contended lock without backoff:\\n%s\", buf);\n \ndiff --git a/include/asm-generic/Kbuild b/include/asm-generic/Kbuild\nindex b7a388bef6ea0a..76d4792a325af7 100644\n--- a/include/asm-generic/Kbuild\n+++ b/include/asm-generic/Kbuild\n@@ -55,6 +55,7 @@ mandatory-y += serial.h\n mandatory-y += shmparam.h\n mandatory-y += simd.h\n mandatory-y += softirq_stack.h\n+mandatory-y += stackdepot.h\n mandatory-y += switch_to.h\n mandatory-y += timex.h\n mandatory-y += tlbflush.h\ndiff --git a/include/asm-generic/stackdepot.h b/include/asm-generic/stackdepot.h\nnew file mode 100644\nindex 00000000000000..846975767bdd42\n--- /dev/null\n+++ b/include/asm-generic/stackdepot.h\n@@ -0,0 +1,19 @@\n+/* SPDX-License-Identifier: GPL-2.0 */\n+#ifndef __ASM_GENERIC_STACKDEPOT_H\n+#define __ASM_GENERIC_STACKDEPOT_H\n+\n+#include \u003clinux/types.h\u003e\n+\n+static inline bool\n+arch_stack_depot_frame_try_compress(unsigned long frame, u32 *low)\n+{\n+\treturn false;\n+}\n+\n+static inline void\n+arch_stack_depot_frame_decompress(u32 low, unsigned long *frame)\n+{\n+\t/* Generic code never compresses frames, so this hook is unreachable. */\n+}\n+\n+#endif /* __ASM_GENERIC_STACKDEPOT_H */\ndiff --git a/include/linux/stackdepot.h b/include/linux/stackdepot.h\nindex 2cc21ffcdaf9e4..de42f6540266ae 100644\n--- a/include/linux/stackdepot.h\n+++ b/include/linux/stackdepot.h\n@@ -20,6 +20,7 @@\n #ifndef _LINUX_STACKDEPOT_H\n #define _LINUX_STACKDEPOT_H\n \n+#include \u003clinux/bits.h\u003e\n #include \u003clinux/gfp.h\u003e\n \n typedef u32 depot_stack_handle_t;\n@@ -50,14 +51,19 @@ union handle_parts {\n \t};\n };\n \n+/* Frames are compressed into @compressed_entries; see asm/stackdepot.h. */\n+#define STACK_RECORD_COMPRESSED\tBIT(0)\n+\n struct stack_record {\n \tstruct list_head hash_list;\t/* Links in the hash table */\n \tu32 hash;\t\t\t/* Hash in hash table */\n-\tu32 size;\t\t\t/* Number of stored frames */\n+\tu16 size;\t\t\t/* Number of stored frames */\n+\tu16 flags;\t\t\t/* STACK_RECORD_* */\n \tunion handle_parts handle;\t/* Constant after initialization */\n \trefcount_t count;\n \tunion {\n \t\tunsigned long entries[CONFIG_STACKDEPOT_MAX_FRAMES];\t/* Frames */\n+\t\tu32 compressed_entries[CONFIG_STACKDEPOT_MAX_FRAMES];\n \t\tstruct {\n \t\t\t/*\n \t\t\t * An important invariant of the implementation is to\n@@ -189,15 +195,40 @@ depot_stack_handle_t stack_depot_save(unsigned long *entries,\n struct stack_record *__stack_depot_get_stack_record(depot_stack_handle_t handle);\n \n /**\n- * stack_depot_fetch - Fetch a stack trace from stack depot\n+ * stack_depot_fetch_into - Fetch a stack trace into caller-owned storage\n *\n- * @handle:\tStack depot handle returned from stack_depot_save()\n- * @entries:\tPointer to store the address of the stack trace\n+ * @handle:\tStack depot handle\n+ * @entries:\tCaller-owned buffer to copy the stack trace into\n+ * @max_entries:\tNumber of frames that fit in @entries\n+ *\n+ * Copies the stored frames into caller-owned @entries. If fewer frames are\n+ * stored than @max_entries, only the stored frames are written and their count\n+ * is returned. If more frames are stored than @max_entries, the copy is skipped\n+ * entirely and 0 is returned.\n+ *\n+ * Passing a NULL @entries buffer or zero @max_entries for a valid @handle is\n+ * invalid. Callers must provide storage for @max_entries frames.\n+ *\n+ * Callers should size @entries to match the save-side stack depth cap (for\n+ * example, %CONFIG_STACKDEPOT_MAX_FRAMES or the local stack_trace_save() limit)\n+ * when losing diagnostics on an undersized buffer would be surprising.\n+ *\n+ * A non-zero invalid @handle, including a post-put handle, may WARN. Its return\n+ * value and copied contents are undefined because the record may have been\n+ * reused for another stack.\n+ *\n+ * Callers must ensure @handle remains valid for the duration of this call.\n+ * Persistent handles saved without %STACK_DEPOT_FLAG_GET require no extra\n+ * reference; handles saved with %STACK_DEPOT_FLAG_GET require a held reference.\n+ * Callers must not call stack_depot_put() on persistent handles.\n+ * Racing this helper with stack_depot_put() on the same handle is invalid.\n *\n- * Return: Number of frames for the fetched stack\n+ * Return: Number of frames copied, 0 if @handle is 0, stack depot is disabled,\n+ * or @max_entries is less than the number of stored frames.\n */\n-unsigned int stack_depot_fetch(depot_stack_handle_t handle,\n-\t\t\t unsigned long **entries);\n+unsigned int stack_depot_fetch_into(depot_stack_handle_t handle,\n+\t\t\t\t unsigned long *entries,\n+\t\t\t\t unsigned int max_entries);\n \n /**\n * stack_depot_print - Print a stack trace from stack depot\ndiff --git a/lib/Kconfig.debug b/lib/Kconfig.debug\nindex 2d22638ec13a63..861d0caf939130 100644\n--- a/lib/Kconfig.debug\n+++ b/lib/Kconfig.debug\n@@ -2818,6 +2818,22 @@ config RESOURCE_KUNIT_TEST\n \n \t If unsure, say N.\n \n+config STACKDEPOT_KUNIT_TEST\n+\tbool \"KUnit test for stack depot\" if !KUNIT_ALL_TESTS\n+\tdepends on KUNIT=y \u0026\u0026 STACKDEPOT\n+\tdepends on STACKDEPOT_MAX_FRAMES \u003e= 3\n+\tdefault KUNIT_ALL_TESTS\n+\thelp\n+\t Enable this option to test stack depot API behavior at boot.\n+\t This test is built in, so KUNIT must also be built in.\n+\n+\t KUnit tests run during boot and output the results to the debug log\n+\t in TAP format (https://testanything.org/). Only useful for kernel\n+\t developers running the KUnit test harness, and not intended for\n+\t inclusion into a production build.\n+\n+\t If unsure, say N.\n+\n config SYSCTL_KUNIT_TEST\n \ttristate \"KUnit test for sysctl\" if !KUNIT_ALL_TESTS\n \tdepends on KUNIT\ndiff --git a/lib/stackdepot.c b/lib/stackdepot.c\nindex 90c52f2e0d3f42..f323f1e97e1295 100644\n--- a/lib/stackdepot.c\n+++ b/lib/stackdepot.c\n@@ -36,6 +36,8 @@\n #include \u003clinux/memblock.h\u003e\n #include \u003clinux/kasan-enabled.h\u003e\n \n+#include \u003casm/stackdepot.h\u003e\n+\n /*\n * The pool_index is offset by 1 so the first record does not have a 0 handle.\n */\n@@ -94,6 +96,7 @@ static const char *const counter_names[] = {\n \t[DEPOT_COUNTER_PERSIST_BYTES]\t= \"persistent_bytes\",\n };\n static_assert(ARRAY_SIZE(counter_names) == DEPOT_COUNTER_COUNT);\n+static_assert(CONFIG_STACKDEPOT_MAX_FRAMES \u003c= U16_MAX);\n \n static int __init disable_stack_depot(char *str)\n {\n@@ -419,9 +422,37 @@ static struct stack_record *depot_pop_free(void)\n \treturn stack;\n }\n \n-static inline size_t depot_stack_record_size(struct stack_record *s, unsigned int nr_entries)\n+/* Check whether every frame of a stack can be stored in 32 bits. */\n+static bool depot_entries_compressible(const unsigned long *entries,\n+\t\t\t\t unsigned int nr_entries)\n+{\n+\tu32 payload;\n+\n+\tfor (unsigned int i = 0; i \u003c nr_entries; i++) {\n+\t\tif (!arch_stack_depot_frame_try_compress(entries[i], \u0026payload))\n+\t\t\treturn false;\n+\t}\n+\treturn true;\n+}\n+\n+static inline unsigned long depot_stack_entry(const struct stack_record *stack,\n+\t\t\t\t\t unsigned int i)\n {\n-\tconst size_t used = flex_array_size(s, entries, nr_entries);\n+\tunsigned long frame;\n+\n+\tif (!(stack-\u003eflags \u0026 STACK_RECORD_COMPRESSED))\n+\t\treturn stack-\u003eentries[i];\n+\tarch_stack_depot_frame_decompress(stack-\u003ecompressed_entries[i], \u0026frame);\n+\treturn frame;\n+}\n+\n+static inline size_t depot_stack_record_size(struct stack_record *s,\n+\t\t\t\t\t unsigned int nr_entries,\n+\t\t\t\t\t bool compressed)\n+{\n+\tconst size_t used = compressed ?\n+\t\tflex_array_size(s, compressed_entries, nr_entries) :\n+\t\tflex_array_size(s, entries, nr_entries);\n \tconst size_t unused = sizeof(s-\u003eentries) - used;\n \n \tWARN_ON_ONCE(sizeof(s-\u003eentries) \u003c used);\n@@ -436,6 +467,7 @@ depot_alloc_stack(unsigned long *entries, unsigned int nr_entries, u32 hash, dep\n {\n \tstruct stack_record *stack = NULL;\n \tsize_t record_size;\n+\tbool compressed = false;\n \n \tlockdep_assert_held(\u0026pool_lock);\n \n@@ -452,10 +484,13 @@ depot_alloc_stack(unsigned long *entries, unsigned int nr_entries, u32 hash, dep\n \t\t * Evictable entries have to allocate the max. size so they may\n \t\t * safely be re-used by differently sized allocations.\n \t\t */\n-\t\trecord_size = depot_stack_record_size(stack, CONFIG_STACKDEPOT_MAX_FRAMES);\n+\t\trecord_size = depot_stack_record_size(stack,\n+\t\t\t\t\t\t CONFIG_STACKDEPOT_MAX_FRAMES,\n+\t\t\t\t\t\t false);\n \t\tstack = depot_pop_free();\n \t} else {\n-\t\trecord_size = depot_stack_record_size(stack, nr_entries);\n+\t\tcompressed = depot_entries_compressible(entries, nr_entries);\n+\t\trecord_size = depot_stack_record_size(stack, nr_entries, compressed);\n \t}\n \n \tif (!stack) {\n@@ -468,7 +503,16 @@ depot_alloc_stack(unsigned long *entries, unsigned int nr_entries, u32 hash, dep\n \tstack-\u003ehash = hash;\n \tstack-\u003esize = nr_entries;\n \t/* stack-\u003ehandle is already filled in by depot_pop_free_pool(). */\n-\tmemcpy(stack-\u003eentries, entries, flex_array_size(stack, entries, nr_entries));\n+\tif (compressed) {\n+\t\tstack-\u003eflags = STACK_RECORD_COMPRESSED;\n+\t\tfor (unsigned int i = 0; i \u003c nr_entries; i++)\n+\t\t\tarch_stack_depot_frame_try_compress(entries[i],\n+\t\t\t\t\t\t\t \u0026stack-\u003ecompressed_entries[i]);\n+\t} else {\n+\t\tstack-\u003eflags = 0;\n+\t\tmemcpy(stack-\u003eentries, entries,\n+\t\t flex_array_size(stack, entries, nr_entries));\n+\t}\n \n \tif (flags \u0026 STACK_DEPOT_FLAG_GET) {\n \t\trefcount_set(\u0026stack-\u003ecount, 1);\n@@ -588,6 +632,20 @@ int stackdepot_memcmp(const unsigned long *u1, const unsigned long *u2,\n \treturn 0;\n }\n \n+static inline bool depot_stack_equal(const struct stack_record *stack,\n+\t\t\t\t const unsigned long *entries,\n+\t\t\t\t unsigned int size)\n+{\n+\tif (!(stack-\u003eflags \u0026 STACK_RECORD_COMPRESSED))\n+\t\treturn !stackdepot_memcmp(entries, stack-\u003eentries, size);\n+\n+\tfor (unsigned int i = 0; i \u003c size; i++) {\n+\t\tif (depot_stack_entry(stack, i) != entries[i])\n+\t\t\treturn false;\n+\t}\n+\treturn true;\n+}\n+\n /* Finds a stack in a bucket of the hash table. */\n static inline struct stack_record *find_stack(struct list_head *bucket,\n \t\t\t\t\t unsigned long *entries, int size,\n@@ -615,7 +673,7 @@ static inline struct stack_record *find_stack(struct list_head *bucket,\n \t\t * management state unioned with @entries. The refcount is zero\n \t\t * in that case and the below refcount_inc_not_zero() will fail.\n \t\t */\n-\t\tif (data_race(stackdepot_memcmp(entries, stack-\u003eentries, size)))\n+\t\tif (!data_race(depot_stack_equal(stack, entries, size)))\n \t\t\tcontinue;\n \n \t\t/*\n@@ -757,33 +815,59 @@ struct stack_record *__stack_depot_get_stack_record(depot_stack_handle_t handle)\n \treturn depot_fetch_stack(handle);\n }\n \n-unsigned int stack_depot_fetch(depot_stack_handle_t handle,\n-\t\t\t unsigned long **entries)\n+/* Copy the first @nr_entries frames of @stack into @entries. */\n+static void depot_copy_entries(const struct stack_record *stack,\n+\t\t\t unsigned long *entries, unsigned int nr_entries)\n+{\n+\tfor (unsigned int i = 0; i \u003c nr_entries; i++)\n+\t\tentries[i] = depot_stack_entry(stack, i);\n+\t/* stackdepot.c is not instrumented; tell KMSAN the copy is initialized. */\n+\tkmsan_unpoison_memory(entries, nr_entries * sizeof(*entries));\n+}\n+\n+unsigned int stack_depot_fetch_into(depot_stack_handle_t handle,\n+\t\t\t\t unsigned long *entries,\n+\t\t\t\t unsigned int max_entries)\n {\n \tstruct stack_record *stack;\n+\tunsigned int nr_entries;\n \n-\t*entries = NULL;\n-\t/*\n-\t * Let KMSAN know *entries is initialized. This shall prevent false\n-\t * positive reports if instrumented code accesses it.\n-\t */\n-\tkmsan_unpoison_memory(entries, sizeof(*entries));\n+\tif (!handle)\n+\t\treturn 0;\n+\tif (stack_depot_disabled)\n+\t\treturn 0;\n+\tif (WARN_ON_ONCE(!entries || !max_entries))\n+\t\treturn 0;\n \n-\tif (!handle || stack_depot_disabled)\n+\tstack = depot_fetch_stack(handle);\n+\tif (!stack)\n \t\treturn 0;\n+\tnr_entries = stack-\u003esize;\n+\tif (WARN_ON_ONCE(!nr_entries))\n+\t\treturn 0;\n+\tif (nr_entries \u003e max_entries)\n+\t\treturn 0;\n+\n+\tdepot_copy_entries(stack, entries, nr_entries);\n+\treturn nr_entries;\n+}\n+EXPORT_SYMBOL_GPL(stack_depot_fetch_into);\n+\n+static struct stack_record *depot_print_fetch(depot_stack_handle_t handle)\n+{\n+\tstruct stack_record *stack;\n+\n+\tif (!handle || stack_depot_disabled)\n+\t\treturn NULL;\n \n \tstack = depot_fetch_stack(handle);\n \t/*\n \t * Should never be NULL, otherwise this is a use-after-put (or just a\n \t * corrupt handle).\n \t */\n-\tif (WARN(!stack, \"corrupt handle or use after stack_depot_put()\"))\n-\t\treturn 0;\n-\n-\t*entries = stack-\u003eentries;\n-\treturn stack-\u003esize;\n+\tWARN(!stack, \"corrupt handle or use after stack_depot_put()\");\n+\treturn stack;\n }\n-EXPORT_SYMBOL_GPL(stack_depot_fetch);\n \n void stack_depot_put(depot_stack_handle_t handle)\n {\n@@ -805,26 +889,42 @@ void stack_depot_put(depot_stack_handle_t handle)\n }\n EXPORT_SYMBOL_GPL(stack_depot_put);\n \n-void stack_depot_print(depot_stack_handle_t stack)\n+void stack_depot_print(depot_stack_handle_t handle)\n {\n-\tunsigned long *entries;\n-\tunsigned int nr_entries;\n+\tstruct stack_record *stack = depot_print_fetch(handle);\n+\tunsigned long frame;\n \n-\tnr_entries = stack_depot_fetch(stack, \u0026entries);\n-\tif (nr_entries \u003e 0)\n-\t\tstack_trace_print(entries, nr_entries, 0);\n+\tif (!stack)\n+\t\treturn;\n+\tfor (unsigned int i = 0; i \u003c stack-\u003esize; i++) {\n+\t\tframe = depot_stack_entry(stack, i);\n+\t\tkmsan_unpoison_memory(\u0026frame, sizeof(frame));\n+\t\tstack_trace_print(\u0026frame, 1, 0);\n+\t}\n }\n EXPORT_SYMBOL_GPL(stack_depot_print);\n \n int stack_depot_snprint(depot_stack_handle_t handle, char *buf, size_t size,\n \t\t int spaces)\n {\n-\tunsigned long *entries;\n-\tunsigned int nr_entries;\n+\tstruct stack_record *stack = depot_print_fetch(handle);\n+\tunsigned int generated, total = 0;\n+\tunsigned long frame;\n \n-\tnr_entries = stack_depot_fetch(handle, \u0026entries);\n-\treturn nr_entries ? stack_trace_snprint(buf, size, entries, nr_entries,\n-\t\t\t\t\t\tspaces) : 0;\n+\tif (!stack)\n+\t\treturn 0;\n+\tfor (unsigned int i = 0; i \u003c stack-\u003esize \u0026\u0026 size; i++) {\n+\t\tframe = depot_stack_entry(stack, i);\n+\t\tkmsan_unpoison_memory(\u0026frame, sizeof(frame));\n+\t\tgenerated = stack_trace_snprint(buf, size, \u0026frame, 1, spaces);\n+\t\ttotal += generated;\n+\t\t/* Stop once @buf is full, as stack_trace_snprint() does. */\n+\t\tif (generated \u003e= size)\n+\t\t\tbreak;\n+\t\tbuf += generated;\n+\t\tsize -= generated;\n+\t}\n+\treturn total;\n }\n EXPORT_SYMBOL_GPL(stack_depot_snprint);\n \ndiff --git a/lib/tests/Makefile b/lib/tests/Makefile\nindex df0537e1b91faf..bc6532d881505f 100644\n--- a/lib/tests/Makefile\n+++ b/lib/tests/Makefile\n@@ -49,6 +49,7 @@ obj-$(CONFIG_RANDSTRUCT_KUNIT_TEST) += randstruct_kunit.o\n obj-$(CONFIG_SCANF_KUNIT_TEST) += scanf_kunit.o\n obj-$(CONFIG_SEQ_BUF_KUNIT_TEST) += seq_buf_kunit.o\n obj-$(CONFIG_SLUB_KUNIT_TEST) += slub_kunit.o\n+obj-$(CONFIG_STACKDEPOT_KUNIT_TEST) += stackdepot_kunit.o\n obj-$(CONFIG_TEST_SORT) += test_sort.o\n CFLAGS_stackinit_kunit.o += $(call cc-disable-warning, switch-unreachable)\n obj-$(CONFIG_STACKINIT_KUNIT_TEST) += stackinit_kunit.o\ndiff --git a/lib/tests/stackdepot_kunit.c b/lib/tests/stackdepot_kunit.c\nnew file mode 100644\nindex 00000000000000..abcc34844125ac\n--- /dev/null\n+++ b/lib/tests/stackdepot_kunit.c\n@@ -0,0 +1,312 @@\n+// SPDX-License-Identifier: GPL-2.0-only\n+\n+#include \u003ckunit/test.h\u003e\n+#include \u003clinux/array_size.h\u003e\n+#include \u003clinux/gfp.h\u003e\n+#include \u003clinux/limits.h\u003e\n+#include \u003clinux/minmax.h\u003e\n+#include \u003clinux/stacktrace.h\u003e\n+#include \u003clinux/stackdepot.h\u003e\n+#include \u003clinux/string.h\u003e\n+\n+#include \u003casm/stackdepot.h\u003e\n+\n+#ifdef CONFIG_ARM64\n+#include \u003casm/sections.h\u003e\n+\n+static inline unsigned long stackdepot_arm64_frame(long offset)\n+{\n+\treturn (unsigned long)((long)_text + offset);\n+}\n+#endif\n+\n+static void stackdepot_fetch_into_roundtrip(struct kunit *test)\n+{\n+\tunsigned long entries[] = {\n+\t\t0x101000UL,\n+\t\t0x102000UL,\n+\t\t0x103000UL,\n+\t};\n+\tunsigned long exact[ARRAY_SIZE(entries)] = {};\n+\tunsigned long fetched[ARRAY_SIZE(entries) + 1] = {\n+\t\t[ARRAY_SIZE(entries)] = 0xa5a5a5a5UL,\n+\t};\n+\tunsigned long expected_tail = fetched[ARRAY_SIZE(entries)];\n+\tdepot_stack_handle_t handle;\n+\tunsigned int nr_entries;\n+\n+\tKUNIT_ASSERT_EQ(test, stack_depot_init(), 0);\n+\n+\thandle = stack_depot_save(entries, ARRAY_SIZE(entries), GFP_KERNEL);\n+\tKUNIT_ASSERT_NE(test, handle, (depot_stack_handle_t)0);\n+\n+\tnr_entries = stack_depot_fetch_into(handle, exact, ARRAY_SIZE(exact));\n+\tKUNIT_EXPECT_EQ(test, nr_entries, (unsigned int)ARRAY_SIZE(entries));\n+\tKUNIT_EXPECT_MEMEQ(test, exact, entries, sizeof(entries));\n+\n+\tnr_entries = stack_depot_fetch_into(handle, fetched, ARRAY_SIZE(fetched));\n+\tKUNIT_EXPECT_EQ(test, nr_entries, (unsigned int)ARRAY_SIZE(entries));\n+\tKUNIT_EXPECT_MEMEQ(test, fetched, entries, sizeof(entries));\n+\tKUNIT_EXPECT_EQ(test, fetched[ARRAY_SIZE(entries)], expected_tail);\n+}\n+\n+static void stackdepot_fetch_into_rejects_missing_or_short_stack(struct kunit *test)\n+{\n+\tunsigned long entries[] = {\n+\t\t0x111000UL,\n+\t\t0x112000UL,\n+\t\t0x113000UL,\n+\t};\n+\tunsigned long fetched[ARRAY_SIZE(entries)] = {\n+\t\t0xa1a1a1a1UL,\n+\t\t0xb2b2b2b2UL,\n+\t\t0xc3c3c3c3UL,\n+\t};\n+\tunsigned long expected[ARRAY_SIZE(fetched)];\n+\tdepot_stack_handle_t handle;\n+\tunsigned int nr_entries;\n+\n+\tKUNIT_ASSERT_EQ(test, stack_depot_init(), 0);\n+\n+\thandle = stack_depot_save(entries, ARRAY_SIZE(entries), GFP_KERNEL);\n+\tKUNIT_ASSERT_NE(test, handle, (depot_stack_handle_t)0);\n+\tmemcpy(expected, fetched, sizeof(expected));\n+\n+\tnr_entries = stack_depot_fetch_into(0, fetched, ARRAY_SIZE(fetched));\n+\tKUNIT_EXPECT_EQ(test, nr_entries, 0U);\n+\tKUNIT_EXPECT_MEMEQ(test, fetched, expected, sizeof(expected));\n+\n+\tnr_entries = stack_depot_fetch_into(0, NULL, 0);\n+\tKUNIT_EXPECT_EQ(test, nr_entries, 0U);\n+\n+\tnr_entries = stack_depot_fetch_into(handle, fetched,\n+\t\t\t\t\t ARRAY_SIZE(fetched) - 1);\n+\tKUNIT_EXPECT_EQ(test, nr_entries, 0U);\n+\tKUNIT_EXPECT_MEMEQ(test, fetched, expected, sizeof(expected));\n+}\n+\n+static void stackdepot_frame_raw_fallback(struct kunit *test)\n+{\n+\tunsigned long frame = 0x1000UL;\n+\tbool compressed;\n+\tu32 payload;\n+\n+#ifdef CONFIG_ARM64\n+\tframe = (unsigned long)_text + (unsigned long)S32_MAX + 1UL;\n+#endif\n+\n+\tcompressed = arch_stack_depot_frame_try_compress(frame, \u0026payload);\n+\tKUNIT_EXPECT_FALSE(test, compressed);\n+}\n+\n+#if defined(CONFIG_X86_64) \u0026\u0026 !defined(CONFIG_UML)\n+static void stackdepot_frame_x86_64(struct kunit *test)\n+{\n+\tunsigned long direct_map = 0xffff888000001000UL;\n+\tunsigned long frame = 0xffffffff81234567UL;\n+\tunsigned long out;\n+\tbool compressed;\n+\tu32 low;\n+\n+\tcompressed = arch_stack_depot_frame_try_compress(frame, \u0026low);\n+\tKUNIT_EXPECT_TRUE(test, compressed);\n+\tKUNIT_EXPECT_EQ(test, low, (u32)0x81234567);\n+\tarch_stack_depot_frame_decompress(low, \u0026out);\n+\tKUNIT_EXPECT_EQ(test, out, frame);\n+\n+\tcompressed = arch_stack_depot_frame_try_compress(direct_map, \u0026low);\n+\tKUNIT_EXPECT_FALSE(test, compressed);\n+}\n+#endif /* CONFIG_X86_64 \u0026\u0026 !CONFIG_UML */\n+\n+#ifdef CONFIG_ARM64\n+static void stackdepot_frame_arm64(struct kunit *test)\n+{\n+\tlong negative_offset = S32_MIN;\n+\tlong positive_offset = S32_MAX;\n+\tlong offset = 0x123456;\n+\tunsigned long frame = stackdepot_arm64_frame(offset);\n+\tunsigned long out;\n+\tbool compressed;\n+\tu32 payload;\n+\n+\tcompressed = arch_stack_depot_frame_try_compress(frame, \u0026payload);\n+\tKUNIT_EXPECT_TRUE(test, compressed);\n+\tKUNIT_EXPECT_EQ(test, payload, (u32)(s32)offset);\n+\tarch_stack_depot_frame_decompress(payload, \u0026out);\n+\tKUNIT_EXPECT_EQ(test, out, frame);\n+\n+\tframe = stackdepot_arm64_frame(negative_offset);\n+\tcompressed = arch_stack_depot_frame_try_compress(frame, \u0026payload);\n+\tKUNIT_EXPECT_TRUE(test, compressed);\n+\tKUNIT_EXPECT_EQ(test, payload, (u32)(s32)negative_offset);\n+\tarch_stack_depot_frame_decompress(payload, \u0026out);\n+\tKUNIT_EXPECT_EQ(test, out, frame);\n+\n+\tframe = stackdepot_arm64_frame(positive_offset);\n+\tcompressed = arch_stack_depot_frame_try_compress(frame, \u0026payload);\n+\tKUNIT_EXPECT_TRUE(test, compressed);\n+\tKUNIT_EXPECT_EQ(test, payload, (u32)(s32)positive_offset);\n+\tarch_stack_depot_frame_decompress(payload, \u0026out);\n+\tKUNIT_EXPECT_EQ(test, out, frame);\n+}\n+#endif /* CONFIG_ARM64 */\n+\n+#if (defined(CONFIG_X86_64) \u0026\u0026 !defined(CONFIG_UML)) || defined(CONFIG_ARM64)\n+#define STACKDEPOT_TEST_COMPRESSED\n+\n+/* Return a distinct compressible frame for each @i. */\n+static unsigned long stackdepot_compressible_frame(unsigned int i)\n+{\n+#ifdef CONFIG_ARM64\n+\treturn stackdepot_arm64_frame(0x1000L * (i + 1));\n+#else\n+\treturn 0xffffffff81000000UL + 0x1000UL * (i + 1);\n+#endif\n+}\n+\n+/* Return a frame that cannot be compressed but has the same 32-bit payload. */\n+static unsigned long stackdepot_raw_frame(unsigned int i)\n+{\n+#ifdef CONFIG_ARM64\n+\treturn stackdepot_compressible_frame(i) + BIT_ULL(32);\n+#else\n+\treturn stackdepot_compressible_frame(i) \u0026 U32_MAX;\n+#endif\n+}\n+\n+static void stackdepot_compressed_frames(struct kunit *test)\n+{\n+\tunsigned long compressible[3], mixed[3], fetched[3];\n+\tdepot_stack_handle_t compressed_handle, mixed_handle;\n+\tstruct stack_record *record;\n+\tunsigned int i;\n+\n+\tfor (i = 0; i \u003c ARRAY_SIZE(compressible); i++)\n+\t\tcompressible[i] = stackdepot_compressible_frame(0x100 + i);\n+\tmemcpy(mixed, compressible, sizeof(mixed));\n+\tmixed[1] = stackdepot_raw_frame(0x101);\n+\n+\tKUNIT_ASSERT_EQ(test, stack_depot_init(), 0);\n+\n+\tcompressed_handle = stack_depot_save(compressible,\n+\t\t\t\t\t ARRAY_SIZE(compressible), GFP_KERNEL);\n+\tKUNIT_ASSERT_NE(test, compressed_handle, (depot_stack_handle_t)0);\n+\tmixed_handle = stack_depot_save(mixed, ARRAY_SIZE(mixed), GFP_KERNEL);\n+\tKUNIT_ASSERT_NE(test, mixed_handle, (depot_stack_handle_t)0);\n+\t/* Equal payloads must not make different stacks compare equal. */\n+\tKUNIT_EXPECT_NE(test, compressed_handle, mixed_handle);\n+\tKUNIT_EXPECT_EQ(test, stack_depot_save(compressible, ARRAY_SIZE(compressible),\n+\t\t\t\t\t GFP_KERNEL), compressed_handle);\n+\n+\trecord = __stack_depot_get_stack_record(compressed_handle);\n+\tKUNIT_ASSERT_NOT_NULL(test, record);\n+\tKUNIT_EXPECT_TRUE(test, record-\u003eflags \u0026 STACK_RECORD_COMPRESSED);\n+\trecord = __stack_depot_get_stack_record(mixed_handle);\n+\tKUNIT_ASSERT_NOT_NULL(test, record);\n+\tKUNIT_EXPECT_FALSE(test, record-\u003eflags \u0026 STACK_RECORD_COMPRESSED);\n+\n+\tKUNIT_EXPECT_EQ(test, stack_depot_fetch_into(compressed_handle, fetched,\n+\t\t\t\t\t\t ARRAY_SIZE(fetched)),\n+\t\t\t(unsigned int)ARRAY_SIZE(compressible));\n+\tKUNIT_EXPECT_MEMEQ(test, fetched, compressible, sizeof(compressible));\n+\tKUNIT_EXPECT_EQ(test, stack_depot_fetch_into(mixed_handle, fetched,\n+\t\t\t\t\t\t ARRAY_SIZE(fetched)),\n+\t\t\t(unsigned int)ARRAY_SIZE(mixed));\n+\tKUNIT_EXPECT_MEMEQ(test, fetched, mixed, sizeof(mixed));\n+}\n+\n+/* Evictable records are max-size, so their frames are not compressed. */\n+static void stackdepot_get_record_not_compressed(struct kunit *test)\n+{\n+\tunsigned long entries[3], fetched[3];\n+\tdepot_stack_handle_t handle;\n+\tstruct stack_record *record;\n+\tunsigned int i;\n+\n+\tfor (i = 0; i \u003c ARRAY_SIZE(entries); i++)\n+\t\tentries[i] = stackdepot_compressible_frame(0x200 + i);\n+\n+\tKUNIT_ASSERT_EQ(test, stack_depot_init(), 0);\n+\n+\thandle = stack_depot_save_flags(entries, ARRAY_SIZE(entries), GFP_KERNEL,\n+\t\t\t\t\tSTACK_DEPOT_FLAG_CAN_ALLOC |\n+\t\t\t\t\tSTACK_DEPOT_FLAG_GET);\n+\tKUNIT_ASSERT_NE(test, handle, (depot_stack_handle_t)0);\n+\trecord = __stack_depot_get_stack_record(handle);\n+\tKUNIT_ASSERT_NOT_NULL(test, record);\n+\tKUNIT_EXPECT_FALSE(test, record-\u003eflags \u0026 STACK_RECORD_COMPRESSED);\n+\tKUNIT_EXPECT_EQ(test, stack_depot_fetch_into(handle, fetched,\n+\t\t\t\t\t\t ARRAY_SIZE(fetched)),\n+\t\t\t(unsigned int)ARRAY_SIZE(entries));\n+\tKUNIT_EXPECT_MEMEQ(test, fetched, entries, sizeof(entries));\n+\tstack_depot_put(handle);\n+}\n+#endif\n+\n+/* stack_depot_snprint() must match stack_trace_snprint(), with truncation. */\n+static void stackdepot_snprint_matches_stack_trace(struct kunit *test)\n+{\n+\tconst unsigned int nr = min(40, CONFIG_STACKDEPOT_MAX_FRAMES);\n+\tconst size_t size = 4096;\n+\tunsigned long entries[40];\n+\tdepot_stack_handle_t handle;\n+\tchar *got, *want;\n+\tunsigned int i;\n+\n+\tfor (i = 0; i \u003c nr; i++) {\n+#ifdef STACKDEPOT_TEST_COMPRESSED\n+\t\tentries[i] = stackdepot_compressible_frame(0x300 + i);\n+#else\n+\t\tentries[i] = 0x301000UL + 0x1000UL * i;\n+#endif\n+\t}\n+\tgot = kunit_kzalloc(test, size, GFP_KERNEL);\n+\twant = kunit_kzalloc(test, size, GFP_KERNEL);\n+\tKUNIT_ASSERT_NOT_NULL(test, got);\n+\tKUNIT_ASSERT_NOT_NULL(test, want);\n+\n+\tKUNIT_ASSERT_EQ(test, stack_depot_init(), 0);\n+\thandle = stack_depot_save(entries, nr, GFP_KERNEL);\n+\tKUNIT_ASSERT_NE(test, handle, (depot_stack_handle_t)0);\n+\n+\tKUNIT_EXPECT_EQ(test, stack_depot_snprint(handle, got, size, 2),\n+\t\t\tstack_trace_snprint(want, size, entries, nr, 2));\n+\tKUNIT_EXPECT_STREQ(test, got, want);\n+\n+\t/* Truncate part-way through the trace. */\n+\tmemset(got, 0, size);\n+\tmemset(want, 0, size);\n+\tKUNIT_EXPECT_EQ(test, stack_depot_snprint(handle, got, 700, 0),\n+\t\t\tstack_trace_snprint(want, 700, entries, nr, 0));\n+\tKUNIT_EXPECT_STREQ(test, got, want);\n+}\n+\n+static struct kunit_case stackdepot_test_cases[] = {\n+\tKUNIT_CASE(stackdepot_fetch_into_roundtrip),\n+\tKUNIT_CASE(stackdepot_fetch_into_rejects_missing_or_short_stack),\n+\tKUNIT_CASE(stackdepot_snprint_matches_stack_trace),\n+\tKUNIT_CASE(stackdepot_frame_raw_fallback),\n+#if defined(CONFIG_X86_64) \u0026\u0026 !defined(CONFIG_UML)\n+\tKUNIT_CASE(stackdepot_frame_x86_64),\n+#endif\n+#ifdef CONFIG_ARM64\n+\tKUNIT_CASE(stackdepot_frame_arm64),\n+#endif\n+#ifdef STACKDEPOT_TEST_COMPRESSED\n+\tKUNIT_CASE(stackdepot_compressed_frames),\n+\tKUNIT_CASE(stackdepot_get_record_not_compressed),\n+#endif\n+\t{}\n+};\n+\n+static struct kunit_suite stackdepot_test_suite = {\n+\t.name = \"stackdepot\",\n+\t.test_cases = stackdepot_test_cases,\n+};\n+\n+kunit_test_suite(stackdepot_test_suite);\n+\n+MODULE_DESCRIPTION(\"KUnit tests for stack depot\");\n+MODULE_AUTHOR(\"Caleb Kan \u003cckan@cloudflare.com\u003e\");\n+MODULE_LICENSE(\"GPL\");\ndiff --git a/mm/kmemleak.c b/mm/kmemleak.c\nindex 20c0eb41c8730b..61ff4a10ce11e2 100644\n--- a/mm/kmemleak.c\n+++ b/mm/kmemleak.c\n@@ -378,10 +378,10 @@ static void __print_unreferenced(struct seq_file *seq,\n \t\t\t\t bool hex_dump)\n {\n \tint i;\n-\tunsigned long *entries;\n+\tunsigned long entries[MAX_TRACE];\n \tunsigned int nr_entries;\n \n-\tnr_entries = stack_depot_fetch(object-\u003etrace_handle, \u0026entries);\n+\tnr_entries = stack_depot_fetch_into(object-\u003etrace_handle, entries, ARRAY_SIZE(entries));\n \twarn_or_seq_printf(seq, \"unreferenced object%s 0x%08lx (size %zu):\\n\",\n \t\t\t __object_type_str(object),\n \t\t\t object-\u003epointer, object-\u003esize);\ndiff --git a/mm/kmsan/kmsan_test.c b/mm/kmsan/kmsan_test.c\nindex 31f47cc4dab400..7c04e4b21873d9 100644\n--- a/mm/kmsan/kmsan_test.c\n+++ b/mm/kmsan/kmsan_test.c\n@@ -669,7 +669,7 @@ static void test_long_origin_chain(struct kunit *test)\n */\n static void test_stackdepot_roundtrip(struct kunit *test)\n {\n-\tunsigned long src_entries[16], *dst_entries;\n+\tunsigned long src_entries[16], dst_entries[16];\n \tunsigned int src_nentries, dst_nentries;\n \tEXPECTATION_NO_REPORT(expect);\n \tdepot_stack_handle_t handle;\n@@ -680,7 +680,7 @@ static void test_stackdepot_roundtrip(struct kunit *test)\n \t\tstack_trace_save(src_entries, ARRAY_SIZE(src_entries), 1);\n \thandle = stack_depot_save(src_entries, src_nentries, GFP_KERNEL);\n \tstack_depot_print(handle);\n-\tdst_nentries = stack_depot_fetch(handle, \u0026dst_entries);\n+\tdst_nentries = stack_depot_fetch_into(handle, dst_entries, ARRAY_SIZE(dst_entries));\n \tKUNIT_EXPECT_TRUE(test, src_nentries == dst_nentries);\n \n \tkmsan_check_memory((void *)dst_entries,\ndiff --git a/mm/kmsan/report.c b/mm/kmsan/report.c\nindex d6853ce089541d..0770658ba932e5 100644\n--- a/mm/kmsan/report.c\n+++ b/mm/kmsan/report.c\n@@ -83,9 +83,9 @@ static char *pretty_descr(char *descr)\n \treturn report_local_descr;\n }\n \n-void kmsan_print_origin(depot_stack_handle_t origin)\n+static void kmsan_print_origin_with_buf(depot_stack_handle_t origin,\n+\t\t\t\t\tunsigned long *entries)\n {\n-\tunsigned long *entries = NULL, *chained_entries = NULL;\n \tunsigned int nr_entries, chained_nr_entries, skipnr;\n \tvoid *pc1 = NULL, *pc2 = NULL;\n \tdepot_stack_handle_t head;\n@@ -97,7 +97,8 @@ void kmsan_print_origin(depot_stack_handle_t origin)\n \t\treturn;\n \n \twhile (true) {\n-\t\tnr_entries = stack_depot_fetch(origin, \u0026entries);\n+\t\tnr_entries =\n+\t\t\tstack_depot_fetch_into(origin, entries, KMSAN_STACK_DEPTH);\n \t\tdepth = kmsan_depth_from_eb(stack_depot_get_extra_bits(origin));\n \t\tmagic = nr_entries ? entries[0] : 0;\n \t\tif ((nr_entries == 4) \u0026\u0026 (magic == KMSAN_ALLOCA_MAGIC_ORIGIN)) {\n@@ -123,14 +124,10 @@ void kmsan_print_origin(depot_stack_handle_t origin)\n \t\t\torigin = entries[2];\n \t\t\tpr_err(\"Uninit was stored to memory at:\\n\");\n \t\t\tchained_nr_entries =\n-\t\t\t\tstack_depot_fetch(head, \u0026chained_entries);\n-\t\t\tkmsan_internal_unpoison_memory(\n-\t\t\t\tchained_entries,\n-\t\t\t\tchained_nr_entries * sizeof(*chained_entries),\n-\t\t\t\t/*checked*/ false);\n-\t\t\tskipnr = get_stack_skipnr(chained_entries,\n-\t\t\t\t\t\t chained_nr_entries);\n-\t\t\tstack_trace_print(chained_entries + skipnr,\n+\t\t\t\tstack_depot_fetch_into(head, entries,\n+\t\t\t\t\t\t KMSAN_STACK_DEPTH);\n+\t\t\tskipnr = get_stack_skipnr(entries, chained_nr_entries);\n+\t\t\tstack_trace_print(entries + skipnr,\n \t\t\t\t\t chained_nr_entries - skipnr, 0);\n \t\t\tpr_err(\"\\n\");\n \t\t\tcontinue;\n@@ -147,6 +144,13 @@ void kmsan_print_origin(depot_stack_handle_t origin)\n \t}\n }\n \n+void kmsan_print_origin(depot_stack_handle_t origin)\n+{\n+\tunsigned long entries[KMSAN_STACK_DEPTH];\n+\n+\tkmsan_print_origin_with_buf(origin, entries);\n+}\n+\n void kmsan_report(depot_stack_handle_t origin, void *address, int size,\n \t\t int off_first, int off_last, const void __user *user_addr,\n \t\t enum kmsan_bug_reason reason)\n@@ -193,7 +197,7 @@ void kmsan_report(depot_stack_handle_t origin, void *address, int size,\n \t\t\t 0);\n \tpr_err(\"\\n\");\n \n-\tkmsan_print_origin(origin);\n+\tkmsan_print_origin_with_buf(origin, stack_entries);\n \n \tif (size) {\n \t\tpr_err(\"\\n\");\ndiff --git a/mm/page_owner.c b/mm/page_owner.c\nindex cfc31c92d76570..16429e70e00df8 100644\n--- a/mm/page_owner.c\n+++ b/mm/page_owner.c\n@@ -1068,8 +1068,8 @@ static int stack_print(struct seq_file *m, void *v)\n {\n \tint i, nr_base_pages;\n \tstruct stack *stack = v;\n-\tunsigned long *entries;\n-\tunsigned long nr_entries;\n+\tunsigned long entries[PAGE_OWNER_STACK_DEPTH];\n+\tunsigned int nr_entries;\n \tstruct stack_record *stack_record = stack-\u003estack_record;\n \tstruct stack_print_ctx *ctx = m-\u003eprivate;\n \n@@ -1083,8 +1083,8 @@ static int stack_print(struct seq_file *m, void *v)\n \t\treturn 0;\n \n \tif (ctx-\u003eflags \u0026 STACK_PRINT_FLAG_STACK) {\n-\t\tnr_entries = stack_record-\u003esize;\n-\t\tentries = stack_record-\u003eentries;\n+\t\tnr_entries = stack_depot_fetch_into(stack_record-\u003ehandle.handle,\n+\t\t\t\t\t\t entries, ARRAY_SIZE(entries));\n \t\tfor (i = 0; i \u003c nr_entries; i++)\n \t\t\tseq_printf(m, \" %pS\\n\", (void *)entries[i]);\n \t}\ndiff --git a/mm/slub.c b/mm/slub.c\nindex cd671b93471918..32e6597a5c033c 100644\n--- a/mm/slub.c\n+++ b/mm/slub.c\n@@ -8328,12 +8328,12 @@ void __kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct slab *slab)\n #ifdef CONFIG_STACKDEPOT\n \t{\n \t\tdepot_stack_handle_t handle;\n-\t\tunsigned long *entries;\n+\t\tunsigned long entries[TRACK_ADDRS_COUNT];\n \t\tunsigned int nr_entries;\n \n \t\thandle = READ_ONCE(trackp-\u003ehandle);\n \t\tif (handle) {\n-\t\t\tnr_entries = stack_depot_fetch(handle, \u0026entries);\n+\t\t\tnr_entries = stack_depot_fetch_into(handle, entries, ARRAY_SIZE(entries));\n \t\t\tfor (i = 0; i \u003c KS_ADDRS_COUNT \u0026\u0026 i \u003c nr_entries; i++)\n \t\t\t\tkpp-\u003ekp_stack[i] = (void *)entries[i];\n \t\t}\n@@ -8341,7 +8341,7 @@ void __kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct slab *slab)\n \t\ttrackp = get_track(s, objp, TRACK_FREE);\n \t\thandle = READ_ONCE(trackp-\u003ehandle);\n \t\tif (handle) {\n-\t\t\tnr_entries = stack_depot_fetch(handle, \u0026entries);\n+\t\t\tnr_entries = stack_depot_fetch_into(handle, entries, ARRAY_SIZE(entries));\n \t\t\tfor (i = 0; i \u003c KS_ADDRS_COUNT \u0026\u0026 i \u003c nr_entries; i++)\n \t\t\t\tkpp-\u003ekp_free_stack[i] = (void *)entries[i];\n \t\t}\n@@ -10031,12 +10031,14 @@ static int slab_debugfs_show(struct seq_file *seq, void *v)\n #ifdef CONFIG_STACKDEPOT\n \t\t{\n \t\t\tdepot_stack_handle_t handle;\n-\t\t\tunsigned long *entries;\n+\t\t\tunsigned long entries[TRACK_ADDRS_COUNT];\n \t\t\tunsigned int nr_entries, j;\n \n \t\t\thandle = READ_ONCE(l-\u003ehandle);\n \t\t\tif (handle) {\n-\t\t\t\tnr_entries = stack_depot_fetch(handle, \u0026entries);\n+\t\t\t\tnr_entries =\n+\t\t\t\t\tstack_depot_fetch_into(handle, entries,\n+\t\t\t\t\t\t\t ARRAY_SIZE(entries));\n \t\t\t\tseq_puts(seq, \"\\n\");\n \t\t\t\tfor (j = 0; j \u003c nr_entries; j++)\n \t\t\t\t\tseq_printf(seq, \" %pS\\n\", (void *)entries[j]);\ndiff --git a/scripts/gdb/linux/constants.py.in b/scripts/gdb/linux/constants.py.in\nindex dab8b80bed6988..da6b39c3dc13f5 100644\n--- a/scripts/gdb/linux/constants.py.in\n+++ b/scripts/gdb/linux/constants.py.in\n@@ -22,6 +22,7 @@\n #include \u003clinux/radix-tree.h\u003e\n #include \u003clinux/maple_tree.h\u003e\n #include \u003clinux/slab.h\u003e\n+#include \u003clinux/stackdepot.h\u003e\n #include \u003clinux/threads.h\u003e\n #include \u003clinux/vmalloc.h\u003e\n \n@@ -112,6 +113,10 @@ if IS_BUILTIN(CONFIG_PAGE_OWNER):\n LX_GDBPARSED(PAGE_EXT_OWNER)\n LX_GDBPARSED(PAGE_EXT_OWNER_ALLOCATED)\n \n+/* linux/stackdepot.h */\n+if IS_BUILTIN(CONFIG_STACKDEPOT):\n+ LX_GDBPARSED(STACK_RECORD_COMPRESSED)\n+\n /* linux/slab.h */\n LX_GDBPARSED(SLAB_RED_ZONE)\n LX_GDBPARSED(SLAB_POISON)\ndiff --git a/scripts/gdb/linux/stackdepot.py b/scripts/gdb/linux/stackdepot.py\nindex aaa18af25cd121..f689cacb3cb703 100644\n--- a/scripts/gdb/linux/stackdepot.py\n+++ b/scripts/gdb/linux/stackdepot.py\n@@ -20,6 +20,21 @@ def help():\n gdb.write(\"Unrecognized command\\n\")\n raise gdb.GdbError(t)\n \n+def stack_record_entry(stack, i):\n+ if not int(stack['flags']) \u0026 constants.LX_STACK_RECORD_COMPRESSED:\n+ return int(stack['entries'][i])\n+\n+ # Mirror arch_stack_depot_frame_decompress().\n+ payload = int(stack['compressed_entries'][i])\n+ if utils.is_target_arch(\"x86-64\"):\n+ return 0xffffffff00000000 | payload\n+ if utils.is_target_arch(\"aarch64\"):\n+ text = int(gdb.parse_and_eval(\"(unsigned long)_text\"))\n+ if payload \u0026 0x80000000:\n+ payload -= 1 \u003c\u003c 32\n+ return (text + payload) \u0026 0xffffffffffffffff\n+ raise gdb.GdbError(\"compressed stack depot frames are not supported on this architecture\\n\")\n+\n def stack_depot_fetch(handle):\n global DEPOT_STACK_ALIGN\n global stack_record_type\n@@ -40,7 +55,7 @@ def stack_depot_fetch(handle):\n pool_index = parts['pool_index_plus_1'] - 1\n if pool_index \u003e= pools_num:\n gdb.write(\"pool index %d out of bounds (%d) for stack id 0x%08x\\n\" % (pool_index, pools_num, handle))\n- return gdb.Value(0), 0\n+ return [], 0\n \n stack_pools = gdb.parse_and_eval('stack_pools')\n \n@@ -48,10 +63,10 @@ def stack_depot_fetch(handle):\n pool = stack_pools[pool_index]\n stack = (pool + gdb.Value(offset).cast(utils.get_size_t_type())).cast(stack_record_type.get_type().pointer())\n size = int(stack['size'].cast(utils.get_ulong_type()))\n- return stack['entries'], size\n+ return [stack_record_entry(stack, i) for i in range(size)], size\n except Exception as e:\n gdb.write(\"%s\\n\" % e)\n- return gdb.Value(0), 0\n+ return [], 0\n \n def stack_depot_print(handle):\n if not constants.LX_CONFIG_STACKDEPOT:\n@@ -61,7 +76,7 @@ def stack_depot_print(handle):\n if nr_entries \u003e 0:\n for i in range(0, nr_entries):\n try:\n- gdb.execute(\"x /i 0x%x\" % (int(entries[i])))\n+ gdb.execute(\"x /i 0x%x\" % entries[i])\n except Exception as e:\n gdb.write(\"%s\\n\" % e)\n \n"
} |
| 2/1 | 2026/11/18 03:28 | agent | patch-evaluator |
11mModel:core Args: null Results: {
"EnableConfigs": [
"STACKDEPOT",
"STACKDEPOT_ALWAYS_INIT",
"SLUB_DEBUG",
"PAGE_OWNER",
"DEBUG_KMEMLEAK"
],
"FocusSymbols": [
"stack_depot_fetch_into",
"stack_depot_snprint",
"stack_depot_print",
"read_page_owner",
"stack_print",
"__kmem_obj_info"
],
"Reasoning": "The patch introduces stack trace frame compression to the stack depot core subsystem (specifically compressing 64-bit kernel text addresses into 32-bit payloads on x86_64 and arm64), modifies struct stack_record, replaces stack_depot_fetch() with stack_depot_fetch_into() introducing new bounds and validation checks (WARN_ON_ONCE), and rewrites stack_depot_snprint() and stack_depot_print() to decode compressed frames. These code paths are fully reachable in virtualized environments. Ubiquitous allocation hot-paths (such as stack_depot_save, which executes on every allocation under KASAN) are excluded from FocusSymbols to avoid diluting fuzzing focus.",
"WorthFuzzing": true
}Instruction: You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.
IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.
================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.
- REACHABILITY IS THE PRIMARY GATE:
Fuzzing can only discover bugs in code that can actually execute in standard virtualized
environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
regardless of whether it adds assertions or complex logic.
- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
Patch authors routinely label changes as "cleanups", "refactorings", or state
"No functional change intended". Do NOT take these claims at face value.
Code refactorings that rearrange logic, introduce helper functions, or alter state management
in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
If reachable executable code is modified or refactored, it MUST be fuzzed.
- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
Even if the author believes the invariant always holds, fuzzing is essential to verify whether
an unusual sequence of operations can violate it.
================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:
- Non-kernel and non-executable changes:
* Modifications to Documentation/, comments, or spelling fixes.
* User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
that do not affect the compiled kernel image (vmlinux) or kernel modules.
* Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
that do not alter control flow or data structures.
* Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
* Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
* Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
physical PCI hot-unplug or manual sysfs driver unbinding.
* Code paths exclusive to architectures other than the target architecture.
================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
* Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
* Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
* Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
* Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).
================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:
- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
Do NOT list generic, ubiquitous functions called by almost every program in the corpus
(including, but not limited to: general memory allocators and deallocators, page fault
and trap handlers, or core synchronization primitives; this is not an exhaustive list).
Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
which severely dilutes fuzzing effort away from the actual changes.
- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
List functions that specifically implement the logic being added or altered, or direct API entrypoints
for the subsystem feature under review.
- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).
================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit 1904c3d1184586d2fb69893d04ebf95da88c8ff0
Author: syz-cluster <triage@syzkaller.com>
Date: Wed Nov 18 03:28:09 2026 +0000
syz-cluster: applied patch under review
diff --git a/arch/arm64/include/asm/stackdepot.h b/arch/arm64/include/asm/stackdepot.h
new file mode 100644
index 00000000000000..72053527ab219f
--- /dev/null
+++ b/arch/arm64/include/asm/stackdepot.h
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __ASM_STACKDEPOT_H
+#define __ASM_STACKDEPOT_H
+
+#include <linux/types.h>
+#include <asm/sections.h>
+
+/*
+ * Modules are allocated inside a 2 GB relocation window containing the
+ * kernel image. Store a signed 32-bit offset from _text so compression is
+ * independent of 4 GB high-bit boundaries crossed by that window.
+ */
+static inline unsigned long arch_stack_depot_frame_from_payload(u32 payload)
+{
+ return (unsigned long)_text + (s64)(s32)payload;
+}
+
+static inline bool
+arch_stack_depot_frame_try_compress(unsigned long frame, u32 *payload)
+{
+ u32 candidate;
+
+ candidate = (u32)(frame - (unsigned long)_text);
+ if (arch_stack_depot_frame_from_payload(candidate) != frame)
+ return false;
+
+ *payload = candidate;
+ return true;
+}
+
+static inline void
+arch_stack_depot_frame_decompress(u32 payload, unsigned long *frame)
+{
+ *frame = arch_stack_depot_frame_from_payload(payload);
+}
+
+#endif /* __ASM_STACKDEPOT_H */
diff --git a/arch/um/include/asm/Kbuild b/arch/um/include/asm/Kbuild
index 8fdc0bd9ab6fbc..14778d2457d790 100644
--- a/arch/um/include/asm/Kbuild
+++ b/arch/um/include/asm/Kbuild
@@ -21,6 +21,7 @@ generic-y += preempt.h
generic-y += ring_buffer.h
generic-y += runtime-const.h
generic-y += softirq_stack.h
+generic-y += stackdepot.h
generic-y += switch_to.h
generic-y += topology.h
generic-y += trace_clock.h
diff --git a/arch/x86/include/asm/stackdepot.h b/arch/x86/include/asm/stackdepot.h
new file mode 100644
index 00000000000000..9a8d04fa8c1c88
--- /dev/null
+++ b/arch/x86/include/asm/stackdepot.h
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_X86_STACKDEPOT_H
+#define _ASM_X86_STACKDEPOT_H
+
+#include <linux/types.h>
+
+#ifdef CONFIG_X86_64
+/*
+ * Compress canonical kernel text/module addresses whose upper 32 bits are all
+ * ones. Other kernel virtual addresses stay raw, so decompression reconstructs
+ * the original frame by restoring this prefix.
+ */
+#define STACK_DEPOT_X86_64_FRAME_PREFIX 0xffffffff00000000UL
+#define STACK_DEPOT_X86_64_FRAME_LOW_MASK 0x00000000ffffffffUL
+
+static inline bool
+arch_stack_depot_frame_try_compress(unsigned long frame, u32 *low)
+{
+ if ((frame & ~STACK_DEPOT_X86_64_FRAME_LOW_MASK) !=
+ STACK_DEPOT_X86_64_FRAME_PREFIX)
+ return false;
+
+ *low = (u32)frame;
+ return true;
+}
+
+static inline void
+arch_stack_depot_frame_decompress(u32 low, unsigned long *frame)
+{
+ *frame = STACK_DEPOT_X86_64_FRAME_PREFIX | low;
+}
+
+#else
+#include <asm-generic/stackdepot.h>
+#endif /* CONFIG_X86_64 */
+
+#endif /* _ASM_X86_STACKDEPOT_H */
diff --git a/drivers/gpu/drm/drm_modeset_lock.c b/drivers/gpu/drm/drm_modeset_lock.c
index e14814c30d8c06..f48b02379b711c 100644
--- a/drivers/gpu/drm/drm_modeset_lock.c
+++ b/drivers/gpu/drm/drm_modeset_lock.c
@@ -94,16 +94,13 @@ static noinline depot_stack_handle_t __drm_stack_depot_save(void)
static void __drm_stack_depot_print(depot_stack_handle_t stack_depot)
{
struct drm_printer p = drm_dbg_printer(NULL, DRM_UT_KMS, "drm_modeset_lock");
- unsigned long *entries;
- unsigned int nr_entries;
char *buf;
buf = kmalloc(PAGE_SIZE, GFP_NOWAIT | __GFP_NOWARN);
if (!buf)
return;
- nr_entries = stack_depot_fetch(stack_depot, &entries);
- stack_trace_snprint(buf, PAGE_SIZE, entries, nr_entries, 2);
+ stack_depot_snprint(stack_depot, buf, PAGE_SIZE, 2);
drm_printf(&p, "attempting to lock a contended lock without backoff:\n%s", buf);
diff --git a/include/asm-generic/Kbuild b/include/asm-generic/Kbuild
index b7a388bef6ea0a..76d4792a325af7 100644
--- a/include/asm-generic/Kbuild
+++ b/include/asm-generic/Kbuild
@@ -55,6 +55,7 @@ mandatory-y += serial.h
mandatory-y += shmparam.h
mandatory-y += simd.h
mandatory-y += softirq_stack.h
+mandatory-y += stackdepot.h
mandatory-y += switch_to.h
mandatory-y += timex.h
mandatory-y += tlbflush.h
diff --git a/include/asm-generic/stackdepot.h b/include/asm-generic/stackdepot.h
new file mode 100644
index 00000000000000..846975767bdd42
--- /dev/null
+++ b/include/asm-generic/stackdepot.h
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __ASM_GENERIC_STACKDEPOT_H
+#define __ASM_GENERIC_STACKDEPOT_H
+
+#include <linux/types.h>
+
+static inline bool
+arch_stack_depot_frame_try_compress(unsigned long frame, u32 *low)
+{
+ return false;
+}
+
+static inline void
+arch_stack_depot_frame_decompress(u32 low, unsigned long *frame)
+{
+ /* Generic code never compresses frames, so this hook is unreachable. */
+}
+
+#endif /* __ASM_GENERIC_STACKDEPOT_H */
diff --git a/include/linux/stackdepot.h b/include/linux/stackdepot.h
index 2cc21ffcdaf9e4..de42f6540266ae 100644
--- a/include/linux/stackdepot.h
+++ b/include/linux/stackdepot.h
@@ -20,6 +20,7 @@
#ifndef _LINUX_STACKDEPOT_H
#define _LINUX_STACKDEPOT_H
+#include <linux/bits.h>
#include <linux/gfp.h>
typedef u32 depot_stack_handle_t;
@@ -50,14 +51,19 @@ union handle_parts {
};
};
+/* Frames are compressed into @compressed_entries; see asm/stackdepot.h. */
+#define STACK_RECORD_COMPRESSED BIT(0)
+
struct stack_record {
struct list_head hash_list; /* Links in the hash table */
u32 hash; /* Hash in hash table */
- u32 size; /* Number of stored frames */
+ u16 size; /* Number of stored frames */
+ u16 flags; /* STACK_RECORD_* */
union handle_parts handle; /* Constant after initialization */
refcount_t count;
union {
unsigned long entries[CONFIG_STACKDEPOT_MAX_FRAMES]; /* Frames */
+ u32 compressed_entries[CONFIG_STACKDEPOT_MAX_FRAMES];
struct {
/*
* An important invariant of the implementation is to
@@ -189,15 +195,40 @@ depot_stack_handle_t stack_depot_save(unsigned long *entries,
struct stack_record *__stack_depot_get_stack_record(depot_stack_handle_t handle);
/**
- * stack_depot_fetch - Fetch a stack trace from stack depot
+ * stack_depot_fetch_into - Fetch a stack trace into caller-owned storage
*
- * @handle: Stack depot handle returned from stack_depot_save()
- * @entries: Pointer to store the address of the stack trace
+ * @handle: Stack depot handle
+ * @entries: Caller-owned buffer to copy the stack trace into
+ * @max_entries: Number of frames that fit in @entries
+ *
+ * Copies the stored frames into caller-owned @entries. If fewer frames are
+ * stored than @max_entries, only the stored frames are written and their count
+ * is returned. If more frames are stored than @max_entries, the copy is skipped
+ * entirely and 0 is returned.
+ *
+ * Passing a NULL @entries buffer or zero @max_entries for a valid @handle is
+ * invalid. Callers must provide storage for @max_entries frames.
+ *
+ * Callers should size @entries to match the save-side stack depth cap (for
+ * example, %CONFIG_STACKDEPOT_MAX_FRAMES or the local stack_trace_save() limit)
+ * when losing diagnostics on an undersized buffer would be surprising.
+ *
+ * A non-zero invalid @handle, including a post-put handle, may WARN. Its return
+ * value and copied contents are undefined because the record may have been
+ * reused for another stack.
+ *
+ * Callers must ensure @handle remains valid for the duration of this call.
+ * Persistent handles saved without %STACK_DEPOT_FLAG_GET require no extra
+ * reference; handles saved with %STACK_DEPOT_FLAG_GET require a held reference.
+ * Callers must not call stack_depot_put() on persistent handles.
+ * Racing this helper with stack_depot_put() on the same handle is invalid.
*
- * Return: Number of frames for the fetched stack
+ * Return: Number of frames copied, 0 if @handle is 0, stack depot is disabled,
+ * or @max_entries is less than the number of stored frames.
*/
-unsigned int stack_depot_fetch(depot_stack_handle_t handle,
- unsigned long **entries);
+unsigned int stack_depot_fetch_into(depot_stack_handle_t handle,
+ unsigned long *entries,
+ unsigned int max_entries);
/**
* stack_depot_print - Print a stack trace from stack depot
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 2d22638ec13a63..861d0caf939130 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -2818,6 +2818,22 @@ config RESOURCE_KUNIT_TEST
If unsure, say N.
+config STACKDEPOT_KUNIT_TEST
+ bool "KUnit test for stack depot" if !KUNIT_ALL_TESTS
+ depends on KUNIT=y && STACKDEPOT
+ depends on STACKDEPOT_MAX_FRAMES >= 3
+ default KUNIT_ALL_TESTS
+ help
+ Enable this option to test stack depot API behavior at boot.
+ This test is built in, so KUNIT must also be built in.
+
+ KUnit tests run during boot and output the results to the debug log
+ in TAP format (https://testanything.org/). Only useful for kernel
+ developers running the KUnit test harness, and not intended for
+ inclusion into a production build.
+
+ If unsure, say N.
+
config SYSCTL_KUNIT_TEST
tristate "KUnit test for sysctl" if !KUNIT_ALL_TESTS
depends on KUNIT
diff --git a/lib/stackdepot.c b/lib/stackdepot.c
index 90c52f2e0d3f42..f323f1e97e1295 100644
--- a/lib/stackdepot.c
+++ b/lib/stackdepot.c
@@ -36,6 +36,8 @@
#include <linux/memblock.h>
#include <linux/kasan-enabled.h>
+#include <asm/stackdepot.h>
+
/*
* The pool_index is offset by 1 so the first record does not have a 0 handle.
*/
@@ -94,6 +96,7 @@ static const char *const counter_names[] = {
[DEPOT_COUNTER_PERSIST_BYTES] = "persistent_bytes",
};
static_assert(ARRAY_SIZE(counter_names) == DEPOT_COUNTER_COUNT);
+static_assert(CONFIG_STACKDEPOT_MAX_FRAMES <= U16_MAX);
static int __init disable_stack_depot(char *str)
{
@@ -419,9 +422,37 @@ static struct stack_record *depot_pop_free(void)
return stack;
}
-static inline size_t depot_stack_record_size(struct stack_record *s, unsigned int nr_entries)
+/* Check whether every frame of a stack can be stored in 32 bits. */
+static bool depot_entries_compressible(const unsigned long *entries,
+ unsigned int nr_entries)
+{
+ u32 payload;
+
+ for (unsigned int i = 0; i < nr_entries; i++) {
+ if (!arch_stack_depot_frame_try_compress(entries[i], &payload))
+ return false;
+ }
+ return true;
+}
+
+static inline unsigned long depot_stack_entry(const struct stack_record *stack,
+ unsigned int i)
{
- const size_t used = flex_array_size(s, entries, nr_entries);
+ unsigned long frame;
+
+ if (!(stack->flags & STACK_RECORD_COMPRESSED))
+ return stack->entries[i];
+ arch_stack_depot_frame_decompress(stack->compressed_entries[i], &frame);
+ return frame;
+}
+
+static inline size_t depot_stack_record_size(struct stack_record *s,
+ unsigned int nr_entries,
+ bool compressed)
+{
+ const size_t used = compressed ?
+ flex_array_size(s, compressed_entries, nr_entries) :
+ flex_array_size(s, entries, nr_entries);
const size_t unused = sizeof(s->entries) - used;
WARN_ON_ONCE(sizeof(s->entries) < used);
@@ -436,6 +467,7 @@ depot_alloc_stack(unsigned long *entries, unsigned int nr_entries, u32 hash, dep
{
struct stack_record *stack = NULL;
size_t record_size;
+ bool compressed = false;
lockdep_assert_held(&pool_lock);
@@ -452,10 +484,13 @@ depot_alloc_stack(unsigned long *entries, unsigned int nr_entries, u32 hash, dep
* Evictable entries have to allocate the max. size so they may
* safely be re-used by differently sized allocations.
*/
- record_size = depot_stack_record_size(stack, CONFIG_STACKDEPOT_MAX_FRAMES);
+ record_size = depot_stack_record_size(stack,
+ CONFIG_STACKDEPOT_MAX_FRAMES,
+ false);
stack = depot_pop_free();
} else {
- record_size = depot_stack_record_size(stack, nr_entries);
+ compressed = depot_entries_compressible(entries, nr_entries);
+ record_size = depot_stack_record_size(stack, nr_entries, compressed);
}
if (!stack) {
@@ -468,7 +503,16 @@ depot_alloc_stack(unsigned long *entries, unsigned int nr_entries, u32 hash, dep
stack->hash = hash;
stack->size = nr_entries;
/* stack->handle is already filled in by depot_pop_free_pool(). */
- memcpy(stack->entries, entries, flex_array_size(stack, entries, nr_entries));
+ if (compressed) {
+ stack->flags = STACK_RECORD_COMPRESSED;
+ for (unsigned int i = 0; i < nr_entries; i++)
+ arch_stack_depot_frame_try_compress(entries[i],
+ &stack->compressed_entries[i]);
+ } else {
+ stack->flags = 0;
+ memcpy(stack->entries, entries,
+ flex_array_size(stack, entries, nr_entries));
+ }
if (flags & STACK_DEPOT_FLAG_GET) {
refcount_set(&stack->count, 1);
@@ -588,6 +632,20 @@ int stackdepot_memcmp(const unsigned long *u1, const unsigned long *u2,
return 0;
}
+static inline bool depot_stack_equal(const struct stack_record *stack,
+ const unsigned long *entries,
+ unsigned int size)
+{
+ if (!(stack->flags & STACK_RECORD_COMPRESSED))
+ return !stackdepot_memcmp(entries, stack->entries, size);
+
+ for (unsigned int i = 0; i < size; i++) {
+ if (depot_stack_entry(stack, i) != entries[i])
+ return false;
+ }
+ return true;
+}
+
/* Finds a stack in a bucket of the hash table. */
static inline struct stack_record *find_stack(struct list_head *bucket,
unsigned long *entries, int size,
@@ -615,7 +673,7 @@ static inline struct stack_record *find_stack(struct list_head *bucket,
* management state unioned with @entries. The refcount is zero
* in that case and the below refcount_inc_not_zero() will fail.
*/
- if (data_race(stackdepot_memcmp(entries, stack->entries, size)))
+ if (!data_race(depot_stack_equal(stack, entries, size)))
continue;
/*
@@ -757,33 +815,59 @@ struct stack_record *__stack_depot_get_stack_record(depot_stack_handle_t handle)
return depot_fetch_stack(handle);
}
-unsigned int stack_depot_fetch(depot_stack_handle_t handle,
- unsigned long **entries)
+/* Copy the first @nr_entries frames of @stack into @entries. */
+static void depot_copy_entries(const struct stack_record *stack,
+ unsigned long *entries, unsigned int nr_entries)
+{
+ for (unsigned int i = 0; i < nr_entries; i++)
+ entries[i] = depot_stack_entry(stack, i);
+ /* stackdepot.c is not instrumented; tell KMSAN the copy is initialized. */
+ kmsan_unpoison_memory(entries, nr_entries * sizeof(*entries));
+}
+
+unsigned int stack_depot_fetch_into(depot_stack_handle_t handle,
+ unsigned long *entries,
+ unsigned int max_entries)
{
struct stack_record *stack;
+ unsigned int nr_entries;
- *entries = NULL;
- /*
- * Let KMSAN know *entries is initialized. This shall prevent false
- * positive reports if instrumented code accesses it.
- */
- kmsan_unpoison_memory(entries, sizeof(*entries));
+ if (!handle)
+ return 0;
+ if (stack_depot_disabled)
+ return 0;
+ if (WARN_ON_ONCE(!entries || !max_entries))
+ return 0;
- if (!handle || stack_depot_disabled)
+ stack = depot_fetch_stack(handle);
+ if (!stack)
return 0;
+ nr_entries = stack->size;
+ if (WARN_ON_ONCE(!nr_entries))
+ return 0;
+ if (nr_entries > max_entries)
+ return 0;
+
+ depot_copy_entries(stack, entries, nr_entries);
+ return nr_entries;
+}
+EXPORT_SYMBOL_GPL(stack_depot_fetch_into);
+
+static struct stack_record *depot_print_fetch(depot_stack_handle_t handle)
+{
+ struct stack_record *stack;
+
+ if (!handle || stack_depot_disabled)
+ return NULL;
stack = depot_fetch_stack(handle);
/*
* Should never be NULL, otherwise this is a use-after-put (or just a
* corrupt handle).
*/
- if (WARN(!stack, "corrupt handle or use after stack_depot_put()"))
- return 0;
-
- *entries = stack->entries;
- return stack->size;
+ WARN(!stack, "corrupt handle or use after stack_depot_put()");
+ return stack;
}
-EXPORT_SYMBOL_GPL(stack_depot_fetch);
void stack_depot_put(depot_stack_handle_t handle)
{
@@ -805,26 +889,42 @@ void stack_depot_put(depot_stack_handle_t handle)
}
EXPORT_SYMBOL_GPL(stack_depot_put);
-void stack_depot_print(depot_stack_handle_t stack)
+void stack_depot_print(depot_stack_handle_t handle)
{
- unsigned long *entries;
- unsigned int nr_entries;
+ struct stack_record *stack = depot_print_fetch(handle);
+ unsigned long frame;
- nr_entries = stack_depot_fetch(stack, &entries);
- if (nr_entries > 0)
- stack_trace_print(entries, nr_entries, 0);
+ if (!stack)
+ return;
+ for (unsigned int i = 0; i < stack->size; i++) {
+ frame = depot_stack_entry(stack, i);
+ kmsan_unpoison_memory(&frame, sizeof(frame));
+ stack_trace_print(&frame, 1, 0);
+ }
}
EXPORT_SYMBOL_GPL(stack_depot_print);
int stack_depot_snprint(depot_stack_handle_t handle, char *buf, size_t size,
int spaces)
{
- unsigned long *entries;
- unsigned int nr_entries;
+ struct stack_record *stack = depot_print_fetch(handle);
+ unsigned int generated, total = 0;
+ unsigned long frame;
- nr_entries = stack_depot_fetch(handle, &entries);
- return nr_entries ? stack_trace_snprint(buf, size, entries, nr_entries,
- spaces) : 0;
+ if (!stack)
+ return 0;
+ for (unsigned int i = 0; i < stack->size && size; i++) {
+ frame = depot_stack_entry(stack, i);
+ kmsan_unpoison_memory(&frame, sizeof(frame));
+ generated = stack_trace_snprint(buf, size, &frame, 1, spaces);
+ total += generated;
+ /* Stop once @buf is full, as stack_trace_snprint() does. */
+ if (generated >= size)
+ break;
+ buf += generated;
+ size -= generated;
+ }
+ return total;
}
EXPORT_SYMBOL_GPL(stack_depot_snprint);
diff --git a/lib/tests/Makefile b/lib/tests/Makefile
index df0537e1b91faf..bc6532d881505f 100644
--- a/lib/tests/Makefile
+++ b/lib/tests/Makefile
@@ -49,6 +49,7 @@ obj-$(CONFIG_RANDSTRUCT_KUNIT_TEST) += randstruct_kunit.o
obj-$(CONFIG_SCANF_KUNIT_TEST) += scanf_kunit.o
obj-$(CONFIG_SEQ_BUF_KUNIT_TEST) += seq_buf_kunit.o
obj-$(CONFIG_SLUB_KUNIT_TEST) += slub_kunit.o
+obj-$(CONFIG_STACKDEPOT_KUNIT_TEST) += stackdepot_kunit.o
obj-$(CONFIG_TEST_SORT) += test_sort.o
CFLAGS_stackinit_kunit.o += $(call cc-disable-warning, switch-unreachable)
obj-$(CONFIG_STACKINIT_KUNIT_TEST) += stackinit_kunit.o
diff --git a/lib/tests/stackdepot_kunit.c b/lib/tests/stackdepot_kunit.c
new file mode 100644
index 00000000000000..abcc34844125ac
--- /dev/null
+++ b/lib/tests/stackdepot_kunit.c
@@ -0,0 +1,312 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <kunit/test.h>
+#include <linux/array_size.h>
+#include <linux/gfp.h>
+#include <linux/limits.h>
+#include <linux/minmax.h>
+#include <linux/stacktrace.h>
+#include <linux/stackdepot.h>
+#include <linux/string.h>
+
+#include <asm/stackdepot.h>
+
+#ifdef CONFIG_ARM64
+#include <asm/sections.h>
+
+static inline unsigned long stackdepot_arm64_frame(long offset)
+{
+ return (unsigned long)((long)_text + offset);
+}
+#endif
+
+static void stackdepot_fetch_into_roundtrip(struct kunit *test)
+{
+ unsigned long entries[] = {
+ 0x101000UL,
+ 0x102000UL,
+ 0x103000UL,
+ };
+ unsigned long exact[ARRAY_SIZE(entries)] = {};
+ unsigned long fetched[ARRAY_SIZE(entries) + 1] = {
+ [ARRAY_SIZE(entries)] = 0xa5a5a5a5UL,
+ };
+ unsigned long expected_tail = fetched[ARRAY_SIZE(entries)];
+ depot_stack_handle_t handle;
+ unsigned int nr_entries;
+
+ KUNIT_ASSERT_EQ(test, stack_depot_init(), 0);
+
+ handle = stack_depot_save(entries, ARRAY_SIZE(entries), GFP_KERNEL);
+ KUNIT_ASSERT_NE(test, handle, (depot_stack_handle_t)0);
+
+ nr_entries = stack_depot_fetch_into(handle, exact, ARRAY_SIZE(exact));
+ KUNIT_EXPECT_EQ(test, nr_entries, (unsigned int)ARRAY_SIZE(entries));
+ KUNIT_EXPECT_MEMEQ(test, exact, entries, sizeof(entries));
+
+ nr_entries = stack_depot_fetch_into(handle, fetched, ARRAY_SIZE(fetched));
+ KUNIT_EXPECT_EQ(test, nr_entries, (unsigned int)ARRAY_SIZE(entries));
+ KUNIT_EXPECT_MEMEQ(test, fetched, entries, sizeof(entries));
+ KUNIT_EXPECT_EQ(test, fetched[ARRAY_SIZE(entries)], expected_tail);
+}
+
+static void stackdepot_fetch_into_rejects_missing_or_short_stack(struct kunit *test)
+{
+ unsigned long entries[] = {
+ 0x111000UL,
+ 0x112000UL,
+ 0x113000UL,
+ };
+ unsigned long fetched[ARRAY_SIZE(entries)] = {
+ 0xa1a1a1a1UL,
+ 0xb2b2b2b2UL,
+ 0xc3c3c3c3UL,
+ };
+ unsigned long expected[ARRAY_SIZE(fetched)];
+ depot_stack_handle_t handle;
+ unsigned int nr_entries;
+
+ KUNIT_ASSERT_EQ(test, stack_depot_init(), 0);
+
+ handle = stack_depot_save(entries, ARRAY_SIZE(entries), GFP_KERNEL);
+ KUNIT_ASSERT_NE(test, handle, (depot_stack_handle_t)0);
+ memcpy(expected, fetched, sizeof(expected));
+
+ nr_entries = stack_depot_fetch_into(0, fetched, ARRAY_SIZE(fetched));
+ KUNIT_EXPECT_EQ(test, nr_entries, 0U);
+ KUNIT_EXPECT_MEMEQ(test, fetched, expected, sizeof(expected));
+
+ nr_entries = stack_depot_fetch_into(0, NULL, 0);
+ KUNIT_EXPECT_EQ(test, nr_entries, 0U);
+
+ nr_entries = stack_depot_fetch_into(handle, fetched,
+ ARRAY_SIZE(fetched) - 1);
+ KUNIT_EXPECT_EQ(test, nr_entries, 0U);
+ KUNIT_EXPECT_MEMEQ(test, fetched, expected, sizeof(expected));
+}
+
+static void stackdepot_frame_raw_fallback(struct kunit *test)
+{
+ unsigned long frame = 0x1000UL;
+ bool compressed;
+ u32 payload;
+
+#ifdef CONFIG_ARM64
+ frame = (unsigned long)_text + (unsigned long)S32_MAX + 1UL;
+#endif
+
+ compressed = arch_stack_depot_frame_try_compress(frame, &payload);
+ KUNIT_EXPECT_FALSE(test, compressed);
+}
+
+#if defined(CONFIG_X86_64) && !defined(CONFIG_UML)
+static void stackdepot_frame_x86_64(struct kunit *test)
+{
+ unsigned long direct_map = 0xffff888000001000UL;
+ unsigned long frame = 0xffffffff81234567UL;
+ unsigned long out;
+ bool compressed;
+ u32 low;
+
+ compressed = arch_stack_depot_frame_try_compress(frame, &low);
+ KUNIT_EXPECT_TRUE(test, compressed);
+ KUNIT_EXPECT_EQ(test, low, (u32)0x81234567);
+ arch_stack_depot_frame_decompress(low, &out);
+ KUNIT_EXPECT_EQ(test, out, frame);
+
+ compressed = arch_stack_depot_frame_try_compress(direct_map, &low);
+ KUNIT_EXPECT_FALSE(test, compressed);
+}
+#endif /* CONFIG_X86_64 && !CONFIG_UML */
+
+#ifdef CONFIG_ARM64
+static void stackdepot_frame_arm64(struct kunit *test)
+{
+ long negative_offset = S32_MIN;
+ long positive_offset = S32_MAX;
+ long offset = 0x123456;
+ unsigned long frame = stackdepot_arm64_frame(offset);
+ unsigned long out;
+ bool compressed;
+ u32 payload;
+
+ compressed = arch_stack_depot_frame_try_compress(frame, &payload);
+ KUNIT_EXPECT_TRUE(test, compressed);
+ KUNIT_EXPECT_EQ(test, payload, (u32)(s32)offset);
+ arch_stack_depot_frame_decompress(payload, &out);
+ KUNIT_EXPECT_EQ(test, out, frame);
+
+ frame = stackdepot_arm64_frame(negative_offset);
+ compressed = arch_stack_depot_frame_try_compress(frame, &payload);
+ KUNIT_EXPECT_TRUE(test, compressed);
+ KUNIT_EXPECT_EQ(test, payload, (u32)(s32)negative_offset);
+ arch_stack_depot_frame_decompress(payload, &out);
+ KUNIT_EXPECT_EQ(test, out, frame);
+
+ frame = stackdepot_arm64_frame(positive_offset);
+ compressed = arch_stack_depot_frame_try_compress(frame, &payload);
+ KUNIT_EXPECT_TRUE(test, compressed);
+ KUNIT_EXPECT_EQ(test, payload, (u32)(s32)positive_offset);
+ arch_stack_depot_frame_decompress(payload, &out);
+ KUNIT_EXPECT_EQ(test, out, frame);
+}
+#endif /* CONFIG_ARM64 */
+
+#if (defined(CONFIG_X86_64) && !defined(CONFIG_UML)) || defined(CONFIG_ARM64)
+#define STACKDEPOT_TEST_COMPRESSED
+
+/* Return a distinct compressible frame for each @i. */
+static unsigned long stackdepot_compressible_frame(unsigned int i)
+{
+#ifdef CONFIG_ARM64
+ return stackdepot_arm64_frame(0x1000L * (i + 1));
+#else
+ return 0xffffffff81000000UL + 0x1000UL * (i + 1);
+#endif
+}
+
+/* Return a frame that cannot be compressed but has the same 32-bit payload. */
+static unsigned long stackdepot_raw_frame(unsigned int i)
+{
+#ifdef CONFIG_ARM64
+ return stackdepot_compressible_frame(i) + BIT_ULL(32);
+#else
+ return stackdepot_compressible_frame(i) & U32_MAX;
+#endif
+}
+
+static void stackdepot_compressed_frames(struct kunit *test)
+{
+ unsigned long compressible[3], mixed[3], fetched[3];
+ depot_stack_handle_t compressed_handle, mixed_handle;
+ struct stack_record *record;
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_SIZE(compressible); i++)
+ compressible[i] = stackdepot_compressible_frame(0x100 + i);
+ memcpy(mixed, compressible, sizeof(mixed));
+ mixed[1] = stackdepot_raw_frame(0x101);
+
+ KUNIT_ASSERT_EQ(test, stack_depot_init(), 0);
+
+ compressed_handle = stack_depot_save(compressible,
+ ARRAY_SIZE(compressible), GFP_KERNEL);
+ KUNIT_ASSERT_NE(test, compressed_handle, (depot_stack_handle_t)0);
+ mixed_handle = stack_depot_save(mixed, ARRAY_SIZE(mixed), GFP_KERNEL);
+ KUNIT_ASSERT_NE(test, mixed_handle, (depot_stack_handle_t)0);
+ /* Equal payloads must not make different stacks compare equal. */
+ KUNIT_EXPECT_NE(test, compressed_handle, mixed_handle);
+ KUNIT_EXPECT_EQ(test, stack_depot_save(compressible, ARRAY_SIZE(compressible),
+ GFP_KERNEL), compressed_handle);
+
+ record = __stack_depot_get_stack_record(compressed_handle);
+ KUNIT_ASSERT_NOT_NULL(test, record);
+ KUNIT_EXPECT_TRUE(test, record->flags & STACK_RECORD_COMPRESSED);
+ record = __stack_depot_get_stack_record(mixed_handle);
+ KUNIT_ASSERT_NOT_NULL(test, record);
+ KUNIT_EXPECT_FALSE(test, record->flags & STACK_RECORD_COMPRESSED);
+
+ KUNIT_EXPECT_EQ(test, stack_depot_fetch_into(compressed_handle, fetched,
+ ARRAY_SIZE(fetched)),
+ (unsigned int)ARRAY_SIZE(compressible));
+ KUNIT_EXPECT_MEMEQ(test, fetched, compressible, sizeof(compressible));
+ KUNIT_EXPECT_EQ(test, stack_depot_fetch_into(mixed_handle, fetched,
+ ARRAY_SIZE(fetched)),
+ (unsigned int)ARRAY_SIZE(mixed));
+ KUNIT_EXPECT_MEMEQ(test, fetched, mixed, sizeof(mixed));
+}
+
+/* Evictable records are max-size, so their frames are not compressed. */
+static void stackdepot_get_record_not_compressed(struct kunit *test)
+{
+ unsigned long entries[3], fetched[3];
+ depot_stack_handle_t handle;
+ struct stack_record *record;
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_SIZE(entries); i++)
+ entries[i] = stackdepot_compressible_frame(0x200 + i);
+
+ KUNIT_ASSERT_EQ(test, stack_depot_init(), 0);
+
+ handle = stack_depot_save_flags(entries, ARRAY_SIZE(entries), GFP_KERNEL,
+ STACK_DEPOT_FLAG_CAN_ALLOC |
+ STACK_DEPOT_FLAG_GET);
+ KUNIT_ASSERT_NE(test, handle, (depot_stack_handle_t)0);
+ record = __stack_depot_get_stack_record(handle);
+ KUNIT_ASSERT_NOT_NULL(test, record);
+ KUNIT_EXPECT_FALSE(test, record->flags & STACK_RECORD_COMPRESSED);
+ KUNIT_EXPECT_EQ(test, stack_depot_fetch_into(handle, fetched,
+ ARRAY_SIZE(fetched)),
+ (unsigned int)ARRAY_SIZE(entries));
+ KUNIT_EXPECT_MEMEQ(test, fetched, entries, sizeof(entries));
+ stack_depot_put(handle);
+}
+#endif
+
+/* stack_depot_snprint() must match stack_trace_snprint(), with truncation. */
+static void stackdepot_snprint_matches_stack_trace(struct kunit *test)
+{
+ const unsigned int nr = min(40, CONFIG_STACKDEPOT_MAX_FRAMES);
+ const size_t size = 4096;
+ unsigned long entries[40];
+ depot_stack_handle_t handle;
+ char *got, *want;
+ unsigned int i;
+
+ for (i = 0; i < nr; i++) {
+#ifdef STACKDEPOT_TEST_COMPRESSED
+ entries[i] = stackdepot_compressible_frame(0x300 + i);
+#else
+ entries[i] = 0x301000UL + 0x1000UL * i;
+#endif
+ }
+ got = kunit_kzalloc(test, size, GFP_KERNEL);
+ want = kunit_kzalloc(test, size, GFP_KERNEL);
+ KUNIT_ASSERT_NOT_NULL(test, got);
+ KUNIT_ASSERT_NOT_NULL(test, want);
+
+ KUNIT_ASSERT_EQ(test, stack_depot_init(), 0);
+ handle = stack_depot_save(entries, nr, GFP_KERNEL);
+ KUNIT_ASSERT_NE(test, handle, (depot_stack_handle_t)0);
+
+ KUNIT_EXPECT_EQ(test, stack_depot_snprint(handle, got, size, 2),
+ stack_trace_snprint(want, size, entries, nr, 2));
+ KUNIT_EXPECT_STREQ(test, got, want);
+
+ /* Truncate part-way through the trace. */
+ memset(got, 0, size);
+ memset(want, 0, size);
+ KUNIT_EXPECT_EQ(test, stack_depot_snprint(handle, got, 700, 0),
+ stack_trace_snprint(want, 700, entries, nr, 0));
+ KUNIT_EXPECT_STREQ(test, got, want);
+}
+
+static struct kunit_case stackdepot_test_cases[] = {
+ KUNIT_CASE(stackdepot_fetch_into_roundtrip),
+ KUNIT_CASE(stackdepot_fetch_into_rejects_missing_or_short_stack),
+ KUNIT_CASE(stackdepot_snprint_matches_stack_trace),
+ KUNIT_CASE(stackdepot_frame_raw_fallback),
+#if defined(CONFIG_X86_64) && !defined(CONFIG_UML)
+ KUNIT_CASE(stackdepot_frame_x86_64),
+#endif
+#ifdef CONFIG_ARM64
+ KUNIT_CASE(stackdepot_frame_arm64),
+#endif
+#ifdef STACKDEPOT_TEST_COMPRESSED
+ KUNIT_CASE(stackdepot_compressed_frames),
+ KUNIT_CASE(stackdepot_get_record_not_compressed),
+#endif
+ {}
+};
+
+static struct kunit_suite stackdepot_test_suite = {
+ .name = "stackdepot",
+ .test_cases = stackdepot_test_cases,
+};
+
+kunit_test_suite(stackdepot_test_suite);
+
+MODULE_DESCRIPTION("KUnit tests for stack depot");
+MODULE_AUTHOR("Caleb Kan <ckan@cloudflare.com>");
+MODULE_LICENSE("GPL");
diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index 20c0eb41c8730b..61ff4a10ce11e2 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -378,10 +378,10 @@ static void __print_unreferenced(struct seq_file *seq,
bool hex_dump)
{
int i;
- unsigned long *entries;
+ unsigned long entries[MAX_TRACE];
unsigned int nr_entries;
- nr_entries = stack_depot_fetch(object->trace_handle, &entries);
+ nr_entries = stack_depot_fetch_into(object->trace_handle, entries, ARRAY_SIZE(entries));
warn_or_seq_printf(seq, "unreferenced object%s 0x%08lx (size %zu):\n",
__object_type_str(object),
object->pointer, object->size);
diff --git a/mm/kmsan/kmsan_test.c b/mm/kmsan/kmsan_test.c
index 31f47cc4dab400..7c04e4b21873d9 100644
--- a/mm/kmsan/kmsan_test.c
+++ b/mm/kmsan/kmsan_test.c
@@ -669,7 +669,7 @@ static void test_long_origin_chain(struct kunit *test)
*/
static void test_stackdepot_roundtrip(struct kunit *test)
{
- unsigned long src_entries[16], *dst_entries;
+ unsigned long src_entries[16], dst_entries[16];
unsigned int src_nentries, dst_nentries;
EXPECTATION_NO_REPORT(expect);
depot_stack_handle_t handle;
@@ -680,7 +680,7 @@ static void test_stackdepot_roundtrip(struct kunit *test)
stack_trace_save(src_entries, ARRAY_SIZE(src_entries), 1);
handle = stack_depot_save(src_entries, src_nentries, GFP_KERNEL);
stack_depot_print(handle);
- dst_nentries = stack_depot_fetch(handle, &dst_entries);
+ dst_nentries = stack_depot_fetch_into(handle, dst_entries, ARRAY_SIZE(dst_entries));
KUNIT_EXPECT_TRUE(test, src_nentries == dst_nentries);
kmsan_check_memory((void *)dst_entries,
diff --git a/mm/kmsan/report.c b/mm/kmsan/report.c
index d6853ce089541d..0770658ba932e5 100644
--- a/mm/kmsan/report.c
+++ b/mm/kmsan/report.c
@@ -83,9 +83,9 @@ static char *pretty_descr(char *descr)
return report_local_descr;
}
-void kmsan_print_origin(depot_stack_handle_t origin)
+static void kmsan_print_origin_with_buf(depot_stack_handle_t origin,
+ unsigned long *entries)
{
- unsigned long *entries = NULL, *chained_entries = NULL;
unsigned int nr_entries, chained_nr_entries, skipnr;
void *pc1 = NULL, *pc2 = NULL;
depot_stack_handle_t head;
@@ -97,7 +97,8 @@ void kmsan_print_origin(depot_stack_handle_t origin)
return;
while (true) {
- nr_entries = stack_depot_fetch(origin, &entries);
+ nr_entries =
+ stack_depot_fetch_into(origin, entries, KMSAN_STACK_DEPTH);
depth = kmsan_depth_from_eb(stack_depot_get_extra_bits(origin));
magic = nr_entries ? entries[0] : 0;
if ((nr_entries == 4) && (magic == KMSAN_ALLOCA_MAGIC_ORIGIN)) {
@@ -123,14 +124,10 @@ void kmsan_print_origin(depot_stack_handle_t origin)
origin = entries[2];
pr_err("Uninit was stored to memory at:\n");
chained_nr_entries =
- stack_depot_fetch(head, &chained_entries);
- kmsan_internal_unpoison_memory(
- chained_entries,
- chained_nr_entries * sizeof(*chained_entries),
- /*checked*/ false);
- skipnr = get_stack_skipnr(chained_entries,
- chained_nr_entries);
- stack_trace_print(chained_entries + skipnr,
+ stack_depot_fetch_into(head, entries,
+ KMSAN_STACK_DEPTH);
+ skipnr = get_stack_skipnr(entries, chained_nr_entries);
+ stack_trace_print(entries + skipnr,
chained_nr_entries - skipnr, 0);
pr_err("\n");
continue;
@@ -147,6 +144,13 @@ void kmsan_print_origin(depot_stack_handle_t origin)
}
}
+void kmsan_print_origin(depot_stack_handle_t origin)
+{
+ unsigned long entries[KMSAN_STACK_DEPTH];
+
+ kmsan_print_origin_with_buf(origin, entries);
+}
+
void kmsan_report(depot_stack_handle_t origin, void *address, int size,
int off_first, int off_last, const void __user *user_addr,
enum kmsan_bug_reason reason)
@@ -193,7 +197,7 @@ void kmsan_report(depot_stack_handle_t origin, void *address, int size,
0);
pr_err("\n");
- kmsan_print_origin(origin);
+ kmsan_print_origin_with_buf(origin, stack_entries);
if (size) {
pr_err("\n");
diff --git a/mm/page_owner.c b/mm/page_owner.c
index cfc31c92d76570..16429e70e00df8 100644
--- a/mm/page_owner.c
+++ b/mm/page_owner.c
@@ -1068,8 +1068,8 @@ static int stack_print(struct seq_file *m, void *v)
{
int i, nr_base_pages;
struct stack *stack = v;
- unsigned long *entries;
- unsigned long nr_entries;
+ unsigned long entries[PAGE_OWNER_STACK_DEPTH];
+ unsigned int nr_entries;
struct stack_record *stack_record = stack->stack_record;
struct stack_print_ctx *ctx = m->private;
@@ -1083,8 +1083,8 @@ static int stack_print(struct seq_file *m, void *v)
return 0;
if (ctx->flags & STACK_PRINT_FLAG_STACK) {
- nr_entries = stack_record->size;
- entries = stack_record->entries;
+ nr_entries = stack_depot_fetch_into(stack_record->handle.handle,
+ entries, ARRAY_SIZE(entries));
for (i = 0; i < nr_entries; i++)
seq_printf(m, " %pS\n", (void *)entries[i]);
}
diff --git a/mm/slub.c b/mm/slub.c
index cd671b93471918..32e6597a5c033c 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -8328,12 +8328,12 @@ void __kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct slab *slab)
#ifdef CONFIG_STACKDEPOT
{
depot_stack_handle_t handle;
- unsigned long *entries;
+ unsigned long entries[TRACK_ADDRS_COUNT];
unsigned int nr_entries;
handle = READ_ONCE(trackp->handle);
if (handle) {
- nr_entries = stack_depot_fetch(handle, &entries);
+ nr_entries = stack_depot_fetch_into(handle, entries, ARRAY_SIZE(entries));
for (i = 0; i < KS_ADDRS_COUNT && i < nr_entries; i++)
kpp->kp_stack[i] = (void *)entries[i];
}
@@ -8341,7 +8341,7 @@ void __kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct slab *slab)
trackp = get_track(s, objp, TRACK_FREE);
handle = READ_ONCE(trackp->handle);
if (handle) {
- nr_entries = stack_depot_fetch(handle, &entries);
+ nr_entries = stack_depot_fetch_into(handle, entries, ARRAY_SIZE(entries));
for (i = 0; i < KS_ADDRS_COUNT && i < nr_entries; i++)
kpp->kp_free_stack[i] = (void *)entries[i];
}
@@ -10031,12 +10031,14 @@ static int slab_debugfs_show(struct seq_file *seq, void *v)
#ifdef CONFIG_STACKDEPOT
{
depot_stack_handle_t handle;
- unsigned long *entries;
+ unsigned long entries[TRACK_ADDRS_COUNT];
unsigned int nr_entries, j;
handle = READ_ONCE(l->handle);
if (handle) {
- nr_entries = stack_depot_fetch(handle, &entries);
+ nr_entries =
+ stack_depot_fetch_into(handle, entries,
+ ARRAY_SIZE(entries));
seq_puts(seq, "\n");
for (j = 0; j < nr_entries; j++)
seq_printf(seq, " %pS\n", (void *)entries[j]);
diff --git a/scripts/gdb/linux/constants.py.in b/scripts/gdb/linux/constants.py.in
index dab8b80bed6988..da6b39c3dc13f5 100644
--- a/scripts/gdb/linux/constants.py.in
+++ b/scripts/gdb/linux/constants.py.in
@@ -22,6 +22,7 @@
#include <linux/radix-tree.h>
#include <linux/maple_tree.h>
#include <linux/slab.h>
+#include <linux/stackdepot.h>
#include <linux/threads.h>
#include <linux/vmalloc.h>
@@ -112,6 +113,10 @@ if IS_BUILTIN(CONFIG_PAGE_OWNER):
LX_GDBPARSED(PAGE_EXT_OWNER)
LX_GDBPARSED(PAGE_EXT_OWNER_ALLOCATED)
+/* linux/stackdepot.h */
+if IS_BUILTIN(CONFIG_STACKDEPOT):
+ LX_GDBPARSED(STACK_RECORD_COMPRESSED)
+
/* linux/slab.h */
LX_GDBPARSED(SLAB_RED_ZONE)
LX_GDBPARSED(SLAB_POISON)
diff --git a/scripts/gdb/linux/stackdepot.py b/scripts/gdb/linux/stackdepot.py
index aaa18af25cd121..f689cacb3cb703 100644
--- a/scripts/gdb/linux/stackdepot.py
+++ b/scripts/gdb/linux/stackdepot.py
@@ -20,6 +20,21 @@ def help():
gdb.write("Unrecognized command\n")
raise gdb.GdbError(t)
+def stack_record_entry(stack, i):
+ if not int(stack['flags']) & constants.LX_STACK_RECORD_COMPRESSED:
+ return int(stack['entries'][i])
+
+ # Mirror arch_stack_depot_frame_decompress().
+ payload = int(stack['compressed_entries'][i])
+ if utils.is_target_arch("x86-64"):
+ return 0xffffffff00000000 | payload
+ if utils.is_target_arch("aarch64"):
+ text = int(gdb.parse_and_eval("(unsigned long)_text"))
+ if payload & 0x80000000:
+ payload -= 1 << 32
+ return (text + payload) & 0xffffffffffffffff
+ raise gdb.GdbError("compressed stack depot frames are not supported on this architecture\n")
+
def stack_depot_fetch(handle):
global DEPOT_STACK_ALIGN
global stack_record_type
@@ -40,7 +55,7 @@ def stack_depot_fetch(handle):
pool_index = parts['pool_index_plus_1'] - 1
if pool_index >= pools_num:
gdb.write("pool index %d out of bounds (%d) for stack id 0x%08x\n" % (pool_index, pools_num, handle))
- return gdb.Value(0), 0
+ return [], 0
stack_pools = gdb.parse_and_eval('stack_pools')
@@ -48,10 +63,10 @@ def stack_depot_fetch(handle):
pool = stack_pools[pool_index]
stack = (pool + gdb.Value(offset).cast(utils.get_size_t_type())).cast(stack_record_type.get_type().pointer())
size = int(stack['size'].cast(utils.get_ulong_type()))
- return stack['entries'], size
+ return [stack_record_entry(stack, i) for i in range(size)], size
except Exception as e:
gdb.write("%s\n" % e)
- return gdb.Value(0), 0
+ return [], 0
def stack_depot_print(handle):
if not constants.LX_CONFIG_STACKDEPOT:
@@ -61,7 +76,7 @@ def stack_depot_print(handle):
if nr_entries > 0:
for i in range(0, nr_entries):
try:
- gdb.execute("x /i 0x%x" % (int(entries[i])))
+ gdb.execute("x /i 0x%x" % entries[i])
except Exception as e:
gdb.write("%s\n" % e)
|
| 3/2 | 2026/11/18 03:28 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 17729 output: 30 thoughts: 1343 Thoughts: **Fuzzing Evaluation: Stack Depot Patch Series** Okay, let's break this down. My goal is to determine if this patch series warrants fuzzing with syzkaller. First, I need to methodically apply the WorthFuzzing criteria, which I know inside and out. The core triage philosophy emphasizes reachability and a healthy dose of skepticism regarding claims of "just refactoring" if reachable code is touched. New or modified assertions are always a red flag that demands fuzzing. My initial assessment is that this series looks promising for fuzzing. It appears to be significantly modifying stack depot, which is used across several crucial kernel subsystems. Looking closely at the code, it's definitely touching core kernel infrastructure. We're talking modifications to `lib/stackdepot.c`, architecture-specific header files (`arch/x86/include/asm/stackdepot.h`), the general `include/linux/stackdepot.h` along with code in memory management (`mm/slub.c`, `mm/kmemleak.c`, `mm/page_owner.c`) and even a driver (`drivers/gpu/drm/drm_modeset_lock.c`). That's a strong indicator. The changes involve compression of stack frames, modification of `struct stack_record`, changes to how entries are allocated, compared, and fetched. This looks like a refactoring and algorithmic change to the stack depot internals. Critically, stack depot is *used* by KASAN, KMSAN, KFENCE, page_owner, kmemleak, SLUB debug tracking, and DRM modeset locking. All of these are relevant to the kernel's integrity and memory management. Thinking through the WorthFuzzing criteria, this clearly hits several positive criteria: changes to a "core subsystem" (lib/ and mm/), and refactoring of "reachable data structures, helper abstractions, or algorithm flows." Any changes to how stack traces are stored and retrieved are relevant here. Therefore, WorthFuzzing=true. Now, I'll need to drill down into the configuration details and relevant symbols. Specifically, I'll need to use my tools to inspect the Kconfig files for `STACKDEPOT` to understand its dependencies and how it's enabled. I'll need to identify any non-standard parent subsystem configs required and note down how to extract the correct configurations. I also need to identify the feature-specific entry points and logic to be fuzzed, as opposed to lifecycle hot-paths. I'll use `grepper` (or similar tools) to find all of the relevant symbols and entry points. |
| 4/2 | 2026/11/18 03:28 | tool | grepper |
0mArgs:{
"Expression": "config STACKDEPOT",
"PathPrefixes": [
"lib/Kconfig"
]
}Results: {
"Output": "lib/Kconfig=551=config ARCH_STACKWALK\n--\nlib/Kconfig-553-\nlib/Kconfig:554:config STACKDEPOT\nlib/Kconfig-555-\tbool\n--\nlib/Kconfig-559-\nlib/Kconfig:560:config STACKDEPOT_ALWAYS_INIT\nlib/Kconfig-561-\tbool\n--\nlib/Kconfig-565-\nlib/Kconfig:566:config STACKDEPOT_MAX_FRAMES\nlib/Kconfig-567-\tint \"Maximum number of frames in trace saved in stack depot\"\n"
} |
| 5/2 | 2026/11/18 03:28 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 19820 output: 32 thoughts: 35 Thoughts: Here's my take on the thought process: **Diving into the Kernel Configuration for Stack Depth Analysis** Okay, time to get my hands dirty. I need to refresh my memory on the stack depth configuration options within the kernel build system. Specifically, I'm thinking about those related to `STACKDEPOT` and its associated parameters. The most efficient way to do this is to jump right into the `Kconfig` file. I'm targeting around line 550, give or take, as that's usually where I've found these types of options in the past. That should get me directly to definitions of `STACKDEPOT`, `STACKDEPOT_MAX_FRAMES`, and any related variables. From there I'll be able to quickly see how they are defined, what dependencies they have, and refresh my knowledge of their interaction with other features within the kernel configuration system. |
| 6/2 | 2026/11/18 03:28 | tool | read-file |
0mArgs:{
"File": "lib/Kconfig",
"FirstLine": 550,
"LineCount": 35
}Results: {
"Contents": " 550:\t# Temporary. Goes away when all archs are cleaned up\n 551:\tconfig ARCH_STACKWALK\n 552:\t bool\n 553:\t\n 554:\tconfig STACKDEPOT\n 555:\t\tbool\n 556:\t\tselect STACKTRACE\n 557:\t\thelp\n 558:\t\t Stack depot: stack trace storage that avoids duplication\n 559:\t\n 560:\tconfig STACKDEPOT_ALWAYS_INIT\n 561:\t\tbool\n 562:\t\tselect STACKDEPOT\n 563:\t\thelp\n 564:\t\t Always initialize stack depot during early boot\n 565:\t\n 566:\tconfig STACKDEPOT_MAX_FRAMES\n 567:\t\tint \"Maximum number of frames in trace saved in stack depot\"\n 568:\t\trange 1 256\n 569:\t\tdefault 64\n 570:\t\tdepends on STACKDEPOT\n 571:\t\n 572:\tconfig REF_TRACKER\n 573:\t\tbool\n 574:\t\tdepends on STACKTRACE_SUPPORT\n 575:\t\tselect STACKDEPOT\n 576:\t\n 577:\tconfig SBITMAP\n 578:\t\tbool\n 579:\t\n 580:\tconfig PARMAN\n 581:\t\ttristate \"parman\" if COMPILE_TEST\n 582:\t\n 583:\tconfig OBJAGG\n 584:\t\ttristate \"objagg\" if COMPILE_TEST\n"
} |
| 7/2 | 2026/11/18 03:28 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 20490 output: 19 thoughts: 30 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience and presented in the first person: **Investigating STACKDEPOT Configuration Dependency** Right, so `config STACKDEPOT`...it's a boolean, and obviously it's being selected by *something* within the Kconfig system. My immediate thought is, "Let's dig into the dependencies." I want to see precisely what other configurations or conditional logic are driving the inclusion of `STACKDEPOT`. Understanding the selection criteria is key to understanding its overall impact and any potential conflicts it might introduce within the larger system. Time to trace the selects and see what's what. |
| 8/2 | 2026/11/18 03:28 | tool | grepper |
0mArgs:{
"Expression": "select STACKDEPOT"
}Results: {
"Output": "drivers/gpu/drm/Kconfig=147=config DRM_DEBUG_DP_MST_TOPOLOGY_REFS\n--\ndrivers/gpu/drm/Kconfig-149-\tdepends on STACKTRACE_SUPPORT\ndrivers/gpu/drm/Kconfig:150: select STACKDEPOT\ndrivers/gpu/drm/Kconfig-151- select DRM_KMS_HELPER\n--\ndrivers/gpu/drm/Kconfig=162=config DRM_DEBUG_MODESET_LOCK\n--\ndrivers/gpu/drm/Kconfig-166-\tdepends on EXPERT\ndrivers/gpu/drm/Kconfig:167:\tselect STACKDEPOT\ndrivers/gpu/drm/Kconfig-168-\tdefault y if DEBUG_WW_MUTEX_SLOWPATH\n--\ndrivers/gpu/drm/Kconfig.debug=39=config DRM_DEBUG_MM\n--\ndrivers/gpu/drm/Kconfig.debug-43-\tdepends on STACKTRACE_SUPPORT\ndrivers/gpu/drm/Kconfig.debug:44:\tselect STACKDEPOT\ndrivers/gpu/drm/Kconfig.debug-45-\thelp\n--\ndrivers/gpu/drm/i915/Kconfig.debug=36=config DRM_I915_DEBUG\n--\ndrivers/gpu/drm/i915/Kconfig.debug-44-\tselect REF_TRACKER\ndrivers/gpu/drm/i915/Kconfig.debug:45:\tselect STACKDEPOT\ndrivers/gpu/drm/i915/Kconfig.debug-46-\tselect STACKTRACE\n--\ndrivers/gpu/drm/i915/Kconfig.debug=178=config DRM_I915_DEBUG_GUC\n--\ndrivers/gpu/drm/i915/Kconfig.debug-180-\tdepends on DRM_I915\ndrivers/gpu/drm/i915/Kconfig.debug:181:\tselect STACKDEPOT\ndrivers/gpu/drm/i915/Kconfig.debug-182-\tdefault n\n--\ndrivers/gpu/drm/i915/Kconfig.debug=263=config DRM_I915_DEBUG_RUNTIME_PM\n--\ndrivers/gpu/drm/i915/Kconfig.debug-267-\tselect REF_TRACKER\ndrivers/gpu/drm/i915/Kconfig.debug:268:\tselect STACKDEPOT\ndrivers/gpu/drm/i915/Kconfig.debug-269-\tselect STACKTRACE\n--\ndrivers/gpu/drm/i915/Kconfig.debug=279=config DRM_I915_DEBUG_WAKEREF\n--\ndrivers/gpu/drm/i915/Kconfig.debug-282-\tselect REF_TRACKER\ndrivers/gpu/drm/i915/Kconfig.debug:283:\tselect STACKDEPOT\ndrivers/gpu/drm/i915/Kconfig.debug-284-\tselect STACKTRACE\n--\ndrivers/gpu/drm/xe/Kconfig.debug=105=config DRM_XE_DEBUG_GUC\n--\ndrivers/gpu/drm/xe/Kconfig.debug-108- default n\ndrivers/gpu/drm/xe/Kconfig.debug:109: select STACKDEPOT\ndrivers/gpu/drm/xe/Kconfig.debug-110- help\n--\nlib/Kconfig=560=config STACKDEPOT_ALWAYS_INIT\nlib/Kconfig-561-\tbool\nlib/Kconfig:562:\tselect STACKDEPOT\nlib/Kconfig-563-\thelp\n--\nlib/Kconfig=572=config REF_TRACKER\n--\nlib/Kconfig-574-\tdepends on STACKTRACE_SUPPORT\nlib/Kconfig:575:\tselect STACKDEPOT\nlib/Kconfig-576-\n--\nlib/Kconfig.kasan=46=menuconfig KASAN\n--\nlib/Kconfig.kasan-52-\tdepends on SYSFS \u0026\u0026 !SLUB_TINY\nlib/Kconfig.kasan:53:\tselect STACKDEPOT_ALWAYS_INIT\nlib/Kconfig.kasan-54-\thelp\n--\nlib/Kconfig.kmsan=8=config KMSAN\n--\nlib/Kconfig.kmsan-12-\tdepends on !PREEMPT_RT\nlib/Kconfig.kmsan:13:\tselect STACKDEPOT\nlib/Kconfig.kmsan:14:\tselect STACKDEPOT_ALWAYS_INIT\nlib/Kconfig.kmsan-15-\thelp\n--\nmm/Kconfig.debug=48=config SLUB_DEBUG\n--\nmm/Kconfig.debug-51-\tdepends on SYSFS \u0026\u0026 !SLUB_TINY\nmm/Kconfig.debug:52:\tselect STACKDEPOT if STACKTRACE_SUPPORT\nmm/Kconfig.debug-53-\thelp\n--\nmm/Kconfig.debug=59=config SLUB_DEBUG_ON\n--\nmm/Kconfig.debug-61-\tdepends on SLUB_DEBUG\nmm/Kconfig.debug:62:\tselect STACKDEPOT_ALWAYS_INIT if STACKTRACE_SUPPORT\nmm/Kconfig.debug-63-\tdefault n\n--\nmm/Kconfig.debug=105=config PAGE_OWNER\n--\nmm/Kconfig.debug-109-\tselect STACKTRACE\nmm/Kconfig.debug:110:\tselect STACKDEPOT\nmm/Kconfig.debug-111-\tselect PAGE_EXTENSION\n--\nmm/Kconfig.debug=201=config DEBUG_KMEMLEAK\n--\nmm/Kconfig.debug-207-\tselect CRC32\nmm/Kconfig.debug:208:\tselect STACKDEPOT\nmm/Kconfig.debug:209:\tselect STACKDEPOT_ALWAYS_INIT if !DEBUG_KMEMLEAK_DEFAULT_OFF\nmm/Kconfig.debug-210-\thelp\n"
} |
| 9/2 | 2026/11/18 03:28 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 22163 output: 28 thoughts: 447 Thoughts: **Analyzing the Stack Depot Configuration** Okay, so I'm diving into this stack depot implementation. My initial observation is that `STACKDEPOT` gets pulled in by a bunch of other configurations: `STACKDEPOT_ALWAYS_INIT`, `KASAN`, `KMSAN`, `PAGE_OWNER`, `DEBUG_KMEMLEAK`, `SLUB_DEBUG`, and even the KUnit test for it, `STACKDEPOT_KUNIT_TEST`. It seems like it's a useful infrastructure, given how many debug and safety features depend on it. Of course, `STACKDEPOT` itself can also be directly selected, or alternatively, you can force it's initialization with `STACKDEPOT_ALWAYS_INIT`. I see that `CONFIG_STACKDEPOT` is defined in `lib/Kconfig`, which makes sense. Looking at the diff, there's a new KUnit test option being introduced: `STACKDEPOT_KUNIT_TEST`. It depends on `KUNIT=y` and `STACKDEPOT` of course. It also needs `STACKDEPOT_MAX_FRAMES` to be at least 3, and it defaults to `KUNIT_ALL_TESTS` if defined. Also, I'm noting the definition in `arch/x86/include/asm/stackdepot.h`. There's an `ifdef` for `CONFIG_X86_64`, which is crucial. It looks like they're doing some address compression specifically for x86-64, with `STACK_DEPOT_X86_64_FRAME_PREFIX` and `STACK_DEPOT_X86_64_FRAME_LOW_MASK`. Since the target is amd64, that `CONFIG_X86_64` will be set, so we can assume this compression is in use. We also know that `CONFIG_STACKDEPOT` must be enabled in the first place, or none of this matters. Here's the critical bit: `STACKDEPOT_ALWAYS_INIT`. This implies that without explicit initialization elsewhere, stack depot may not actually *do* anything if this isn't enabled. So, now I need to figure out when `stack_depot_init()` is called, or if `STACKDEPOT_ALWAYS_INIT` is responsible for its initialization. A quick `grep` for `stack_depot_init` or `CONFIG_STACKDEPOT_ALWAYS_INIT` is in order. I need to understand when and how this crucial component is activated. |
| 10/2 | 2026/11/18 03:29 | tool | grepper |
0mArgs:{
"Expression": "STACKDEPOT_ALWAYS_INIT|stack_depot_init"
}Results: {
"Output": "drivers/gpu/drm/display/drm_dp_mst_topology.c=5739=int drm_dp_mst_topology_mgr_init(struct drm_dp_mst_topology_mgr *mgr,\n--\ndrivers/gpu/drm/display/drm_dp_mst_topology.c-5750-\tmutex_init(\u0026mgr-\u003etopology_ref_history_lock);\ndrivers/gpu/drm/display/drm_dp_mst_topology.c:5751:\tstack_depot_init();\ndrivers/gpu/drm/display/drm_dp_mst_topology.c-5752-#endif\n--\ndrivers/gpu/drm/drm_mm.c=929=void drm_mm_init(struct drm_mm *mm, u64 start, u64 size)\n--\ndrivers/gpu/drm/drm_mm.c-950-#ifdef CONFIG_DRM_DEBUG_MM\ndrivers/gpu/drm/drm_mm.c:951:\tstack_depot_init();\ndrivers/gpu/drm/drm_mm.c-952-#endif\n--\ndrivers/gpu/drm/drm_modeset_lock.c=94=static void __drm_stack_depot_print(depot_stack_handle_t stack_depot)\n--\ndrivers/gpu/drm/drm_modeset_lock.c-109-\ndrivers/gpu/drm/drm_modeset_lock.c:110:static void __drm_stack_depot_init(void)\ndrivers/gpu/drm/drm_modeset_lock.c-111-{\ndrivers/gpu/drm/drm_modeset_lock.c:112:\tstack_depot_init();\ndrivers/gpu/drm/drm_modeset_lock.c-113-}\n--\ndrivers/gpu/drm/drm_modeset_lock.c=119=static void __drm_stack_depot_print(depot_stack_handle_t stack_depot)\n--\ndrivers/gpu/drm/drm_modeset_lock.c-121-}\ndrivers/gpu/drm/drm_modeset_lock.c:122:static void __drm_stack_depot_init(void)\ndrivers/gpu/drm/drm_modeset_lock.c-123-{\n--\ndrivers/gpu/drm/drm_modeset_lock.c=361=void drm_modeset_lock_init(struct drm_modeset_lock *lock)\n--\ndrivers/gpu/drm/drm_modeset_lock.c-364-\tINIT_LIST_HEAD(\u0026lock-\u003ehead);\ndrivers/gpu/drm/drm_modeset_lock.c:365:\t__drm_stack_depot_init();\ndrivers/gpu/drm/drm_modeset_lock.c-366-}\n--\ndrivers/gpu/drm/xe/xe_guc_ct.c=93=static void ct_dead_init(struct xe_guc_ct *ct)\n--\ndrivers/gpu/drm/xe/xe_guc_ct.c-98-#if IS_ENABLED(CONFIG_DRM_XE_DEBUG_GUC)\ndrivers/gpu/drm/xe/xe_guc_ct.c:99:\tstack_depot_init();\ndrivers/gpu/drm/xe/xe_guc_ct.c-100-#endif\n--\ninclude/linux/ref_tracker.h=58=static inline void ref_tracker_dir_init(struct ref_tracker_dir *dir,\n--\ninclude/linux/ref_tracker.h-70-\tref_tracker_dir_debugfs(dir);\ninclude/linux/ref_tracker.h:71:\tstack_depot_init();\ninclude/linux/ref_tracker.h-72-}\n--\ninclude/linux/stackdepot.h=85=typedef u32 depot_flags_t;\n--\ninclude/linux/stackdepot.h-99- *\ninclude/linux/stackdepot.h:100: * 1. Selecting CONFIG_STACKDEPOT_ALWAYS_INIT. This option is suitable in\ninclude/linux/stackdepot.h-101- * scenarios where it's known at compile time that stack depot will be used.\n--\ninclude/linux/stackdepot.h-107- *\ninclude/linux/stackdepot.h:108: * 3. Calling stack_depot_init(). Possible after boot is complete. This option\ninclude/linux/stackdepot.h-109- * is recommended for modules initialized later in the boot process, after\n--\ninclude/linux/stackdepot.h-111- *\ninclude/linux/stackdepot.h:112: * stack_depot_init() and stack_depot_request_early_init() can be called\ninclude/linux/stackdepot.h-113- * regardless of whether CONFIG_STACKDEPOT is enabled and are no-op when this\n--\ninclude/linux/stackdepot.h-118-#ifdef CONFIG_STACKDEPOT\ninclude/linux/stackdepot.h:119:int stack_depot_init(void);\ninclude/linux/stackdepot.h-120-\n--\ninclude/linux/stackdepot.h=124=int __init stack_depot_early_init(void);\ninclude/linux/stackdepot.h-125-#else\ninclude/linux/stackdepot.h:126:static inline int stack_depot_init(void) { return 0; }\ninclude/linux/stackdepot.h-127-\n--\nlib/Kconfig=554=config STACKDEPOT\n--\nlib/Kconfig-559-\nlib/Kconfig:560:config STACKDEPOT_ALWAYS_INIT\nlib/Kconfig-561-\tbool\n--\nlib/Kconfig.kasan=46=menuconfig KASAN\n--\nlib/Kconfig.kasan-52-\tdepends on SYSFS \u0026\u0026 !SLUB_TINY\nlib/Kconfig.kasan:53:\tselect STACKDEPOT_ALWAYS_INIT\nlib/Kconfig.kasan-54-\thelp\n--\nlib/Kconfig.kmsan=8=config KMSAN\n--\nlib/Kconfig.kmsan-13-\tselect STACKDEPOT\nlib/Kconfig.kmsan:14:\tselect STACKDEPOT_ALWAYS_INIT\nlib/Kconfig.kmsan-15-\thelp\n--\nlib/stackdepot.c=47=static bool stack_depot_disabled;\nlib/stackdepot.c:48:static bool __stack_depot_early_init_requested __initdata = IS_ENABLED(CONFIG_STACKDEPOT_ALWAYS_INIT);\nlib/stackdepot.c-49-static bool __stack_depot_early_init_passed __initdata;\n--\nlib/stackdepot.c=153=int __init stack_depot_early_init(void)\n--\nlib/stackdepot.c-163-\t * Print disabled message even if early init has not been requested:\nlib/stackdepot.c:164:\t * stack_depot_init() will not print one.\nlib/stackdepot.c-165-\t */\n--\nlib/stackdepot.c-180-\t * Check if early init has been requested after setting\nlib/stackdepot.c:181:\t * stack_bucket_number_order: stack_depot_init() uses its value.\nlib/stackdepot.c-182-\t */\n--\nlib/stackdepot.c-230-/* Allocates a hash table via kvcalloc. Can be used after boot. */\nlib/stackdepot.c:231:int stack_depot_init(void)\nlib/stackdepot.c-232-{\nlib/stackdepot.c:233:\tstatic DEFINE_MUTEX(stack_depot_init_mutex);\nlib/stackdepot.c-234-\tunsigned long entries;\n--\nlib/stackdepot.c-236-\nlib/stackdepot.c:237:\tmutex_lock(\u0026stack_depot_init_mutex);\nlib/stackdepot.c-238-\n--\nlib/stackdepot.c-286-out_unlock:\nlib/stackdepot.c:287:\tmutex_unlock(\u0026stack_depot_init_mutex);\nlib/stackdepot.c-288-\n--\nlib/stackdepot.c-290-}\nlib/stackdepot.c:291:EXPORT_SYMBOL_GPL(stack_depot_init);\nlib/stackdepot.c-292-\n--\nlib/tests/stackdepot_kunit.c=23=static void stackdepot_fetch_into_roundtrip(struct kunit *test)\n--\nlib/tests/stackdepot_kunit.c-37-\nlib/tests/stackdepot_kunit.c:38:\tKUNIT_ASSERT_EQ(test, stack_depot_init(), 0);\nlib/tests/stackdepot_kunit.c-39-\n--\nlib/tests/stackdepot_kunit.c=53=static void stackdepot_fetch_into_rejects_missing_or_short_stack(struct kunit *test)\n--\nlib/tests/stackdepot_kunit.c-68-\nlib/tests/stackdepot_kunit.c:69:\tKUNIT_ASSERT_EQ(test, stack_depot_init(), 0);\nlib/tests/stackdepot_kunit.c-70-\n--\nlib/tests/stackdepot_kunit.c=178=static void stackdepot_compressed_frames(struct kunit *test)\n--\nlib/tests/stackdepot_kunit.c-189-\nlib/tests/stackdepot_kunit.c:190:\tKUNIT_ASSERT_EQ(test, stack_depot_init(), 0);\nlib/tests/stackdepot_kunit.c-191-\n--\nlib/tests/stackdepot_kunit.c=220=static void stackdepot_get_record_not_compressed(struct kunit *test)\n--\nlib/tests/stackdepot_kunit.c-229-\nlib/tests/stackdepot_kunit.c:230:\tKUNIT_ASSERT_EQ(test, stack_depot_init(), 0);\nlib/tests/stackdepot_kunit.c-231-\n--\nlib/tests/stackdepot_kunit.c=248=static void stackdepot_snprint_matches_stack_trace(struct kunit *test)\n--\nlib/tests/stackdepot_kunit.c-268-\nlib/tests/stackdepot_kunit.c:269:\tKUNIT_ASSERT_EQ(test, stack_depot_init(), 0);\nlib/tests/stackdepot_kunit.c-270-\thandle = stack_depot_save(entries, nr, GFP_KERNEL);\n--\nmm/Kconfig.debug=59=config SLUB_DEBUG_ON\n--\nmm/Kconfig.debug-61-\tdepends on SLUB_DEBUG\nmm/Kconfig.debug:62:\tselect STACKDEPOT_ALWAYS_INIT if STACKTRACE_SUPPORT\nmm/Kconfig.debug-63-\tdefault n\n--\nmm/Kconfig.debug=201=config DEBUG_KMEMLEAK\n--\nmm/Kconfig.debug-208-\tselect STACKDEPOT\nmm/Kconfig.debug:209:\tselect STACKDEPOT_ALWAYS_INIT if !DEBUG_KMEMLEAK_DEFAULT_OFF\nmm/Kconfig.debug-210-\thelp\n--\nmm/mm_init.c=2698=void __init mm_core_init(void)\n--\nmm/mm_init.c-2729-\t * page_owner must be initialized after buddy is ready, and also after\nmm/mm_init.c:2730:\t * slab is ready so that stack_depot_init() works properly\nmm/mm_init.c-2731-\t */\n--\nmm/slab_common.c=318=struct kmem_cache *__kmem_cache_create_args(const char *name,\n--\nmm/slab_common.c-337-\tif (flags \u0026 SLAB_STORE_USER)\nmm/slab_common.c:338:\t\tstack_depot_init();\nmm/slab_common.c-339-#else\n"
} |
| 11/2 | 2026/11/18 03:29 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 26286 output: 27 thoughts: 1301 Thoughts: **Analyzing Stack Depot Configuration for Build Optimization**
Okay, let's dive into how the `stack depot` functionality is configured and used within the kernel build system, given my expertise, I'm thinking about the most efficient ways to use this information.
First, I need to figure out the prerequisites: When `CONFIG_STACKDEPOT` is enabled, the functionality is available. So, let's explore which configuration options trigger `STACKDEPOT`. I see that directly setting `CONFIG_STACKDEPOT=y` enables it, but there are others, like `CONFIG_STACKDEPOT_ALWAYS_INIT`, `CONFIG_KASAN`, `CONFIG_PAGE_OWNER`, and so on.
Now, let me look into the `lib/Kconfig` file and it shows that `STACKDEPOT` itself doesn't have a prompt and is instead selected by other options. Namely: `STACKDEPOT_ALWAYS_INIT`, `KASAN`, `KMSAN`, `PAGE_OWNER`, `DEBUG_KMEMLEAK`, `SLUB_DEBUG`, `REF_TRACKER`, `DRM_DEBUG_MODESET_LOCK`, and indirectly, `STACKDEPOT_KUNIT_TEST`. So, to compile `lib/stackdepot.c`, I'll need one of these selecting configs, like `STACKDEPOT_ALWAYS_INIT`, `KASAN`, or `SLUB_DEBUG`.
The next question: can configuration fragments, like those used by syzkaller, directly enable `STACKDEPOT` or related options? Yes, syzkaller fragments can set `CONFIG_STACKDEPOT_ALWAYS_INIT=y` or `CONFIG_STACKDEPOT=y`. Even though `STACKDEPOT` lacks a prompt, the build system can still handle this. Enabling `STACKDEPOT_ALWAYS_INIT`, or one of the options that select it, like `KASAN`, is definitely valid.
Focusing on the most efficient configurations, I notice that if `STACKDEPOT_ALWAYS_INIT=y` is set, `STACKDEPOT` is automatically selected and initialized – this is worth keeping in mind. And it's true: this option is a simple `bool` without a prompt.
Now, I'll go through which configs that *do* have prompts and select `STACKDEPOT`: `KASAN` ("KASAN: runtime memory debugger"), `KMSAN` ("KMSAN: detector of uninitialized values"), `PAGE_OWNER` ("Track page allocation and release"), `DEBUG_KMEMLEAK` ("Simple memory leak detector"), `SLUB_DEBUG_ON` ("Enable SLUB debugging by default"), `DRM_DEBUG_MODESET_LOCK` ("DRM modeset locking debug"), and `REF_TRACKER` (though it's selected by other configs). `STACKDEPOT_KUNIT_TEST` depends on both `KUNIT` and `STACKDEPOT`.
Importantly, back to syzkaller, can it just set `STACKDEPOT` or `STACKDEPOT_ALWAYS_INIT`? In Kconfig, it seems that if a config without a prompt is selected by another config, then enabling `KASAN`, `SLUB_DEBUG_ON`, `DEBUG_KMEMLEAK`, or `PAGE_OWNER` automatically selects `STACKDEPOT` *and* `STACKDEPOT_ALWAYS_INIT`. Let's confirm:
* `SLUB_DEBUG_ON` selects `STACKDEPOT_ALWAYS_INIT` if `STACKTRACE_SUPPORT` is enabled.
* `DEBUG_KMEMLEAK` selects `STACKDEPOT` and `STACKDEPOT_ALWAYS_INIT` if `DEBUG_KMEMLEAK_DEFAULT_OFF` is not set.
* `KASAN` also selects `STACKDEPOT_ALWAYS_INIT`.
So, syzkaller often enables `KASAN` or `SLUB_DEBUG_ON` or explicitly enables `STACKDEPOT` or `STACKDEPOT_ALWAYS_INIT`. Many tools use `merge_config.sh`, but for Kconfig dependencies, listing `STACKDEPOT` and `STACKDEPOT_ALWAYS_INIT` in the EnableConfigs, along with `KASAN`, `DEBUG_KMEMLEAK`, `PAGE_OWNER`, or `SLUB_DEBUG_ON`, seems accurate.
Finally, remembering the instructions from Section 5: Identify the necessary `CONFIG_` options for building the code. I need to inspect Kconfig files and `#ifdef` guards, check `depends on` lines, and strip the `CONFIG_` prefix.
Now, let's see how `stackdepot.o` is built in `lib/Makefile`.
|
| 12/2 | 2026/11/18 03:29 | tool | grepper |
0mArgs:{
"Expression": "stackdepot",
"PathPrefixes": [
"lib/Makefile"
]
}Results: {
"Output": "lib/Makefile=244=obj-$(CONFIG_IRQ_POLL) += irq_poll.o\nlib/Makefile-245-\nlib/Makefile:246:# stackdepot.c should not be instrumented or call instrumented functions.\nlib/Makefile-247-# Prevent the compiler from calling builtins like memcmp() or bcmp() from this\nlib/Makefile-248-# file.\nlib/Makefile:249:CFLAGS_stackdepot.o += -fno-builtin\nlib/Makefile:250:CONTEXT_ANALYSIS_stackdepot.o := y\nlib/Makefile:251:obj-$(CONFIG_STACKDEPOT) += stackdepot.o\nlib/Makefile:252:KASAN_SANITIZE_stackdepot.o := n\nlib/Makefile:253:# In particular, instrumenting stackdepot.c with KMSAN will result in infinite\nlib/Makefile-254-# recursion.\nlib/Makefile:255:KMSAN_SANITIZE_stackdepot.o := n\nlib/Makefile:256:KCOV_INSTRUMENT_stackdepot.o := n\nlib/Makefile-257-\n"
} |
| 13/2 | 2026/11/18 03:29 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 28916 output: 34 thoughts: 1562 Thoughts: **Fuzzing Decision for stackdepot.o** Okay, let's break this down systematically. I see a patch touching `stackdepot.o`, with associated changes in `arch/x86/include/asm/stackdepot.h` and `lib/stackdepot.c`. Specifically, the Kconfig options `CONFIG_STACKDEPOT`, `CONFIG_STACKDEPOT_MAX_FRAMES`, and `STACKDEPOT_ALWAYS_INIT` are relevant, along with the newly introduced `CONFIG_STACKDEPOT_KUNIT_TEST`. The fact that `STACKDEPOT_KUNIT_TEST` has a dependency chain (`KUNIT=y && STACKDEPOT && STACKDEPOT_MAX_FRAMES >= 3`) tells me something about the likely usage of this feature. Now, that line 256 in `lib/Makefile`: `KCOV_INSTRUMENT_stackdepot.o := n`... that immediately raises a flag! Syzkaller uses KCOV, so *should* this be concerning? Let's not jump to conclusions. The triage instructions are key here. I need to go through the decision criteria. I *must* meticulously re-read the worth-fuzzing decision criteria. Crucially, are KCOV instrumentation overrides explicitly mentioned in the "do not fuzz" section? No! Now, the triage instructions explicitly say: return `WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories`. `KCOV_INSTRUMENT := n` is *not* one of those negative criteria! In other words, the absence of KCOV instrumentation on a specific compilation unit does not automatically exclude it from fuzzing. Further, `stackdepot` is called by KASAN, kmemleak, page_owner, slub, etc. and that code is definitely instrumented! Even without KCOV, there's a good chance syzkaller can uncover issues because this code is used by KASAN/kmemeak etc. And this patch *does* modify potentially reachable, executable code. Specifically, `lib/stackdepot.c` is being altered, including functions like `stack_depot_save`, `stack_depot_fetch_into`, `stack_depot_snprint`, `stack_depot_print`, etc. It's also making changes to `mm/slub.c`, `mm/kmemleak.c`, `mm/page_owner.c`, `drivers/gpu/drm/drm_modeset_lock.c` - so it's not isolated. Plus, there are new assertions within these functions (`WARN_ON_ONCE(!entries || !max_entries)`, `WARN_ON_ONCE(!nr_entries)`, `WARN(!stack, "corrupt handle...")`) that *absolutely* must be fuzzed. The triage instructions state that *any* modification to reachable code is worth fuzzing and modifications or new assertions are especially relevant! Given that all of this code *is* reachable and executable in standard virtualized environments (crucial!), the decision is clear. `WorthFuzzing=true`. Now, I need to choose the best `FocusSymbols` and `EnableConfigs`. Let's dig deeper into the symbol changes and call sites to figure out how best to configure this fuzzer. My next step is to examine the specific function changes in `lib/stackdepot.c` and how those functions are used in the system, and determine if there are useful `FocusSymbols` or `EnableConfigs`. |
| 14/2 | 2026/11/18 03:30 | tool | grepper |
0mArgs:{
"Expression": "EXPORT_SYMBOL.*depot",
"PathPrefixes": [
"lib/stackdepot.c"
]
}Results: {
"Output": "lib/stackdepot.c=231=int stack_depot_init(void)\n--\nlib/stackdepot.c-290-}\nlib/stackdepot.c:291:EXPORT_SYMBOL_GPL(stack_depot_init);\nlib/stackdepot.c-292-\n--\nlib/stackdepot.c=699=depot_stack_handle_t stack_depot_save_flags(unsigned long *entries,\n--\nlib/stackdepot.c-798-}\nlib/stackdepot.c:799:EXPORT_SYMBOL_GPL(stack_depot_save_flags);\nlib/stackdepot.c-800-\nlib/stackdepot.c=801=depot_stack_handle_t stack_depot_save(unsigned long *entries,\n--\nlib/stackdepot.c-807-}\nlib/stackdepot.c:808:EXPORT_SYMBOL_GPL(stack_depot_save);\nlib/stackdepot.c-809-\n--\nlib/stackdepot.c=828=unsigned int stack_depot_fetch_into(depot_stack_handle_t handle,\n--\nlib/stackdepot.c-853-}\nlib/stackdepot.c:854:EXPORT_SYMBOL_GPL(stack_depot_fetch_into);\nlib/stackdepot.c-855-\n--\nlib/stackdepot.c=872=void stack_depot_put(depot_stack_handle_t handle)\n--\nlib/stackdepot.c-889-}\nlib/stackdepot.c:890:EXPORT_SYMBOL_GPL(stack_depot_put);\nlib/stackdepot.c-891-\nlib/stackdepot.c=892=void stack_depot_print(depot_stack_handle_t handle)\n--\nlib/stackdepot.c-904-}\nlib/stackdepot.c:905:EXPORT_SYMBOL_GPL(stack_depot_print);\nlib/stackdepot.c-906-\nlib/stackdepot.c=907=int stack_depot_snprint(depot_stack_handle_t handle, char *buf, size_t size,\n--\nlib/stackdepot.c-928-}\nlib/stackdepot.c:929:EXPORT_SYMBOL_GPL(stack_depot_snprint);\nlib/stackdepot.c-930-\nlib/stackdepot.c=931=depot_stack_handle_t __must_check stack_depot_set_extra_bits(\n--\nlib/stackdepot.c-942-}\nlib/stackdepot.c:943:EXPORT_SYMBOL(stack_depot_set_extra_bits);\nlib/stackdepot.c-944-\nlib/stackdepot.c=945=unsigned int stack_depot_get_extra_bits(depot_stack_handle_t handle)\n--\nlib/stackdepot.c-950-}\nlib/stackdepot.c:951:EXPORT_SYMBOL(stack_depot_get_extra_bits);\nlib/stackdepot.c-952-\n"
} |
| 15/2 | 2026/11/18 03:30 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 32108 output: 21 thoughts: 812 Thoughts: **Analyzing Changes in `lib/stackdepot.c` and Their Implications** Okay, let's break down these changes in `lib/stackdepot.c`. My initial assessment is that we've got a significant update, particularly focusing on how stack traces are handled and stored within the depot. First, I see several key additions and modifications. `stack_depot_fetch_into` is a new function, presumably intended to replace `stack_depot_fetch`. `stack_depot_snprint` and `stack_depot_print` have been reworked to iterate through and decode frames individually using `depot_stack_entry`, incorporating truncation handling in `stack_depot_snprint`. `depot_alloc_stack` now includes compression logic based on `depot_entries_compressible`. `depot_stack_equal` is another new function which compares compressed entries by decompressing each frame. We have also added `depot_copy_entries`, `depot_print_fetch`, `depot_stack_entry`, `depot_entries_compressible` which are used by the other functions. `depot_stack_record_size` has also been modified to include a `compressed` argument. Now, I need to consider the implications of these changes, particularly in the context of fuzzing and code analysis. My immediate question is: what calls `stack_depot_save` and the new `stack_depot_fetch_into` or `stack_depot_snprint`? I need to understand the call graphs to see if we're dealing with ubiquitous functions. This is where things get interesting. I'm recalling the guideline to avoid listing ubiquitous functions, as that dilutes fuzzing efforts. I need to know if `stack_depot_save` is ubiquitous. Hold on… With KASAN (generic or SW tags) enabled, almost every `kmalloc/kfree` calls `kasan_save_stack()` which then calls `stack_depot_save()`. So, yes, `stack_depot_save` is essentially called on every syscall when KASAN is active. This makes it ubiquitous and not a good candidate. But, what about `stack_depot_fetch_into`? *That* seems more targeted. I need to make sure I understand all call points. It looks like it is called only when SLUB debug info is being printed (`slab_debugfs_show`, `__kmem_obj_info`), when kmemleak detects unreferenced objects (`__print_unreferenced`), when page_owner is reading the stack (`stack_print`), and in KMSAN's origin reporting (`kmsan_print_origin_with_buf`). These seem to be specific debugging scenarios or leak detection, not the every-day case. So this one is a good candidate. And what about `stack_depot_snprint`? It is called by `__drm_stack_depot_print` (when a lock contention happens in `drm_modeset_lock`), so I need to make sure I have the full list of callers, so let me do a quick check... |
| 16/2 | 2026/11/18 03:30 | tool | grepper |
0mArgs:{
"Expression": "stack_depot_snprint"
}Results: {
"Output": "drivers/gpu/drm/display/drm_dp_mst_topology.c=1611=__dump_topology_ref_history(struct drm_device *drm,\n--\ndrivers/gpu/drm/display/drm_dp_mst_topology.c-1639-\ndrivers/gpu/drm/display/drm_dp_mst_topology.c:1640:\t\tstack_depot_snprint(entry-\u003ebacktrace, buf, PAGE_SIZE, 4);\ndrivers/gpu/drm/display/drm_dp_mst_topology.c-1641-\n--\ndrivers/gpu/drm/drm_mm.c=119=static void show_leaks(struct drm_mm *mm)\n--\ndrivers/gpu/drm/drm_mm.c-134-\ndrivers/gpu/drm/drm_mm.c:135:\t\tstack_depot_snprint(node-\u003estack, buf, BUFSZ, 0);\ndrivers/gpu/drm/drm_mm.c-136-\t\tDRM_ERROR(\"node [%08llx + %08llx]: inserted at\\n%s\",\n--\ndrivers/gpu/drm/drm_modeset_lock.c=94=static void __drm_stack_depot_print(depot_stack_handle_t stack_depot)\n--\ndrivers/gpu/drm/drm_modeset_lock.c-102-\ndrivers/gpu/drm/drm_modeset_lock.c:103:\tstack_depot_snprint(stack_depot, buf, PAGE_SIZE, 2);\ndrivers/gpu/drm/drm_modeset_lock.c-104-\n--\ndrivers/gpu/drm/i915/gt/uc/intel_guc_ct.c=1002=static bool ct_check_lost_and_found(struct intel_guc_ct *ct, u32 fence)\n--\ndrivers/gpu/drm/i915/gt/uc/intel_guc_ct.c-1016-\t\tbuf = kmalloc(SZ_4K, GFP_NOWAIT);\ndrivers/gpu/drm/i915/gt/uc/intel_guc_ct.c:1017:\t\tif (buf \u0026\u0026 stack_depot_snprint(ct-\u003erequests.lost_and_found[n].stack,\ndrivers/gpu/drm/i915/gt/uc/intel_guc_ct.c-1018-\t\t\t\t\t buf, SZ_4K, 0)) {\n--\ndrivers/gpu/drm/i915/i915_vma.c=77=static void vma_print_allocator(struct i915_vma *vma, const char *reason)\n--\ndrivers/gpu/drm/i915/i915_vma.c-87-\ndrivers/gpu/drm/i915/i915_vma.c:88:\tstack_depot_snprint(vma-\u003enode.stack, buf, sizeof(buf), 0);\ndrivers/gpu/drm/i915/i915_vma.c-89-\tdrm_dbg(vma-\u003eobj-\u003ebase.dev,\n--\ndrivers/gpu/drm/xe/xe_guc_ct.c=115=static void fast_req_dump(struct xe_guc_ct *ct, u16 fence, unsigned int slot)\n--\ndrivers/gpu/drm/xe/xe_guc_ct.c-120-\ndrivers/gpu/drm/xe/xe_guc_ct.c:121:\tif (buf \u0026\u0026 stack_depot_snprint(ct-\u003efast_req[slot].stack, buf, SZ_4K, 0))\ndrivers/gpu/drm/xe/xe_guc_ct.c-122-\t\txe_gt_err(gt, \"Fence 0x%x was used by action %#04x sent at:\\n%s\\n\",\n--\ninclude/linux/stackdepot.h=238=void stack_depot_print(depot_stack_handle_t stack);\n--\ninclude/linux/stackdepot.h-240-/**\ninclude/linux/stackdepot.h:241: * stack_depot_snprint - Print a stack trace from stack depot into a buffer\ninclude/linux/stackdepot.h-242- *\n--\ninclude/linux/stackdepot.h-249- */\ninclude/linux/stackdepot.h:250:int stack_depot_snprint(depot_stack_handle_t handle, char *buf, size_t size,\ninclude/linux/stackdepot.h-251-\t\t int spaces);\n--\nlib/ref_tracker.c=141=__ref_tracker_dir_pr_ostream(struct ref_tracker_dir *dir,\n--\nlib/ref_tracker.c-164-\t\tstack = stats-\u003estacks[i].stack_handle;\nlib/ref_tracker.c:165:\t\tif (sbuf \u0026\u0026 !stack_depot_snprint(stack, sbuf, STACK_BUF_SIZE, 4))\nlib/ref_tracker.c-166-\t\t\tsbuf[0] = 0;\n--\nlib/stackdepot.c=905=EXPORT_SYMBOL_GPL(stack_depot_print);\nlib/stackdepot.c-906-\nlib/stackdepot.c:907:int stack_depot_snprint(depot_stack_handle_t handle, char *buf, size_t size,\nlib/stackdepot.c-908-\t\t int spaces)\n--\nlib/stackdepot.c-928-}\nlib/stackdepot.c:929:EXPORT_SYMBOL_GPL(stack_depot_snprint);\nlib/stackdepot.c-930-\n--\nlib/tests/stackdepot_kunit.c=220=static void stackdepot_get_record_not_compressed(struct kunit *test)\n--\nlib/tests/stackdepot_kunit.c-246-\nlib/tests/stackdepot_kunit.c:247:/* stack_depot_snprint() must match stack_trace_snprint(), with truncation. */\nlib/tests/stackdepot_kunit.c-248-static void stackdepot_snprint_matches_stack_trace(struct kunit *test)\n--\nlib/tests/stackdepot_kunit.c-272-\nlib/tests/stackdepot_kunit.c:273:\tKUNIT_EXPECT_EQ(test, stack_depot_snprint(handle, got, size, 2),\nlib/tests/stackdepot_kunit.c-274-\t\t\tstack_trace_snprint(want, size, entries, nr, 2));\n--\nlib/tests/stackdepot_kunit.c-279-\tmemset(want, 0, size);\nlib/tests/stackdepot_kunit.c:280:\tKUNIT_EXPECT_EQ(test, stack_depot_snprint(handle, got, 700, 0),\nlib/tests/stackdepot_kunit.c-281-\t\t\tstack_trace_snprint(want, 700, entries, nr, 0));\n--\nmm/page_owner.c=603=print_page_owner(char __user *buf, size_t count, unsigned long pfn,\n--\nmm/page_owner.c-637-\tif (print_mode != PAGE_OWNER_PRINT_HANDLE) {\nmm/page_owner.c:638:\t\tret += stack_depot_snprint(handle, kbuf + ret, count - ret, 0);\nmm/page_owner.c-639-\t\tif (ret \u003e= count)\n"
} |
| 17/2 | 2026/11/18 03:30 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 35549 output: 34 thoughts: 2594 Thoughts: **Focusing on Stack Depot: A Deep Dive for Symbol Coverage** Okay, let's break this down. My primary goal here is to identify the most effective symbols to target for fuzzing coverage. The patch I'm examining involves `stack_depot`, so my focus is on understanding the changes and how best to represent them in terms of symbol coverage. Initially, I looked at a list of functions: `stack_depot_snprint`, `stack_depot_fetch_into`, `stack_depot_print`, `depot_alloc_stack`, and `find_stack`. I quickly categorized them based on whether they are non-static, potential target symbols. The key ones in `lib/stackdepot.c` seem to be `stack_depot_fetch_into`, `stack_depot_snprint`, `stack_depot_print`, `stack_depot_save_flags`, and `stack_depot_save`, as they're not static. I also noted `depot_alloc_stack` and `find_stack` as potentially inlined or separate in `vmlinux`. The next step was to verify if `stack_depot_fetch_into`, `stack_depot_snprint`, `stack_depot_print`, `stack_depot_save`, and `stack_depot_save_flags` are exported symbols. They are. Then, I shifted my attention to the callers. I identified several in files modified by the patch: `__drm_stack_depot_print` in `drivers/gpu/drm/drm_modeset_lock.c`, `__kmem_obj_info` and `slab_debugfs_show` in `mm/slub.c`, `__print_unreferenced` in `mm/kmemleak.c`, and several in `mm/page_owner.c`: `stack_print` and `print_page_owner` (the latter calling `stack_depot_snprint`). I also looked at `kmsan_print_origin` and `kmsan_report` in `mm/kmsan/report.c`. The immediate question: is `__drm_stack_depot_print` in `drivers/gpu/drm/drm_modeset_lock.c` reachable in QEMU? DRM modeset locking *is* standard in DRM KMS. A major concern arose regarding `stack_depot_save`. Is this a ubiquitous function? The answer is *yes*, particularly in the presence of KASAN. In KASAN builds, *every* `kasan_record_aux_stack`, every `kasan_save_stack`, and even basic memory allocation calls like `slab_alloc` and `kfree` use `stack_depot_save`. Listing it as a focus symbol would create a serious problem in syzkaller. I then revisited the patch details: the primary change is stack depot compression. The commit compresses kernel text/module addresses, and I had to understand the compression logic within `stack_depot_save`, `depot_alloc_stack`, `find_stack`, `depot_stack_equal`, `stack_depot_fetch_into`, `stack_depot_print` and `stack_depot_snprint`. The analysis of `WARN_ON_ONCE` within `stack_depot_fetch_into` is also critical, and shows the importance of checking the error conditions. Based on this, I concluded that `stack_depot_fetch_into` is not ubiquitous, only called when we inspect or report stack depot traces. `stack_depot_snprint` is only when printing traces to a buffer (e.g., debugfs). Likewise, `stack_depot_print` is for error, warning, or debug printing. The most critical realization: if `stack_depot_save` is included in FocusSymbols, *every* memory allocation in a KASAN-enabled syzkaller instance will hit it! This is a "hot-path" and will effectively nullify the fuzzing effort. Even with page owner or slub debug enabled `stack_depot_save` becomes a very frequent function. So, the focus *must* be on the *specific* features introduced or altered by the patch itself. This leads me to focus on `stack_depot_fetch_into` (which replaces `stack_depot_fetch`), `stack_depot_snprint` (modified for entry-by-entry decompression and formatting), and `stack_depot_print` (modified for entry-by-entry decompression and printing), and the caller functions I previously enumerated. |
| 18/2 | 2026/11/18 03:31 | tool | grepper |
0mArgs:{
"Expression": "depot_alloc_stack",
"PathPrefixes": [
"lib/stackdepot.c"
]
}Results: {
"Output": "lib/stackdepot.c=464=static struct stack_record *\nlib/stackdepot.c:465:depot_alloc_stack(unsigned long *entries, unsigned int nr_entries, u32 hash, depot_flags_t flags, void **prealloc)\nlib/stackdepot.c-466-\t__must_hold(\u0026pool_lock)\n--\nlib/stackdepot.c=699=depot_stack_handle_t stack_depot_save_flags(unsigned long *entries,\n--\nlib/stackdepot.c-763-\t\tstruct stack_record *new =\nlib/stackdepot.c:764:\t\t\tdepot_alloc_stack(entries, nr_entries, hash, depot_flags, \u0026prealloc);\nlib/stackdepot.c-765-\n--\nlib/stackdepot.c-778-\t\t * Either stack depot already contains this stack trace, or\nlib/stackdepot.c:779:\t\t * depot_alloc_stack() did not consume the preallocated memory.\nlib/stackdepot.c-780-\t\t * Try to keep the preallocated memory for future.\n"
} |
| 19/2 | 2026/11/18 03:31 | llm | patch-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 39483 output: 24 thoughts: 279 Thoughts: **Analyzing Stack Depot and Fuzzing Prioritization** Okay, so `depot_alloc_stack` is exclusively called by `stack_depot_save_flags`, and that, in turn, is only called by `stack_depot_save`. That's a pretty narrow chain. My immediate thought is, what if someone's specifically targeting stack depot in a fuzzing campaign? It's a valid concern. This leads me to think about syzkaller and those `FocusSymbols`. They're supposed to prioritize specific kernel symbols during fuzzing – that's the whole point. But if those symbols are as common as `kmalloc`, `page_fault`, or `spin_lock`, then every single program generated matches the criteria, negating any benefit. A critical flaw in prioritization! Now, back to the stack depot. I need to figure out how exploitable this is. Are the key functions here ubiquitous? Let's consider: Is `stack_depot_fetch_into` everywhere? No, definitely not. How about `stack_depot_snprint` and `stack_depot_print`? Again, no. But what about the functions that start this chain, `stack_depot_save_flags` and `stack_depot_save`? That's the real question. Furthermore, if KASAN is disabled in a kernel build, or if we are using SLUB_DEBUG or PAGE_OWNER, when is `stack_depot_save` actually called? I need to know the call paths. I need to understand when this stack depot save occurs, and where the entry points might be. Time to dig into the call graphs. |
| 20/2 | 2026/11/18 03:32 | tool | grepper |
0mArgs:{
"Expression": "stack_depot_save(_flags)?\\("
}Results: {
"Output": "\nFull output is too long, showing 200 out of 236 lines.\nUse more precise expression or PathPrefixes if possible.\n\nNumber of matching lines per file (17 files in total):\ndrivers/gpu/drm/display/drm_dp_mst_topology.c:1\ndrivers/gpu/drm/drm_mm.c:1\ndrivers/gpu/drm/drm_modeset_lock.c:4\ndrivers/gpu/drm/i915/gt/uc/intel_guc_ct.c:1\ndrivers/gpu/drm/xe/xe_guc_ct.c:1\ninclude/linux/stackdepot.h:10\nlib/ref_tracker.c:2\nlib/stackdepot.c:3\nlib/tests/stackdepot_kunit.c:7\nmm/kasan/common.c:1\nmm/kmemleak.c:2\nmm/kmsan/core.c:3\nmm/kmsan/instrumentation.c:2\nmm/kmsan/kmsan_test.c:1\nmm/page_owner.c:3\nmm/slub.c:1\ntools/testing/selftests/mm/ksft_kmemleak_dedup.sh:1\n\ndrivers/gpu/drm/display/drm_dp_mst_topology.c=1543=__topology_ref_save(struct drm_dp_mst_topology_mgr *mgr,\n--\ndrivers/gpu/drm/display/drm_dp_mst_topology.c-1553-\tn = stack_trace_save(stack_entries, ARRAY_SIZE(stack_entries), 1);\ndrivers/gpu/drm/display/drm_dp_mst_topology.c:1554:\tbacktrace = stack_depot_save(stack_entries, n, GFP_KERNEL);\ndrivers/gpu/drm/display/drm_dp_mst_topology.c-1555-\tif (!backtrace)\n--\ndrivers/gpu/drm/drm_mm.c=108=static noinline void save_stack(struct drm_mm_node *node)\n--\ndrivers/gpu/drm/drm_mm.c-115-\t/* May be called under spinlock, so avoid sleeping */\ndrivers/gpu/drm/drm_mm.c:116:\tnode-\u003estack = stack_depot_save(entries, n, GFP_NOWAIT);\ndrivers/gpu/drm/drm_mm.c-117-}\n--\ndrivers/gpu/drm/drm_modeset_lock.c=81=static DEFINE_WW_CLASS(crtc_ww_class);\n--\ndrivers/gpu/drm/drm_modeset_lock.c-83-#if IS_ENABLED(CONFIG_DRM_DEBUG_MODESET_LOCK)\ndrivers/gpu/drm/drm_modeset_lock.c:84:static noinline depot_stack_handle_t __drm_stack_depot_save(void)\ndrivers/gpu/drm/drm_modeset_lock.c-85-{\n--\ndrivers/gpu/drm/drm_modeset_lock.c-90-\ndrivers/gpu/drm/drm_modeset_lock.c:91:\treturn stack_depot_save(entries, n, GFP_NOWAIT | __GFP_NOWARN);\ndrivers/gpu/drm/drm_modeset_lock.c-92-}\n--\ndrivers/gpu/drm/drm_modeset_lock.c=110=static void __drm_stack_depot_init(void)\n--\ndrivers/gpu/drm/drm_modeset_lock.c-114-#else /* CONFIG_DRM_DEBUG_MODESET_LOCK */\ndrivers/gpu/drm/drm_modeset_lock.c:115:static depot_stack_handle_t __drm_stack_depot_save(void)\ndrivers/gpu/drm/drm_modeset_lock.c-116-{\n--\ndrivers/gpu/drm/drm_modeset_lock.c=285=static inline int modeset_lock(struct drm_modeset_lock *lock,\n--\ndrivers/gpu/drm/drm_modeset_lock.c-322-\t\tctx-\u003econtended = lock;\ndrivers/gpu/drm/drm_modeset_lock.c:323:\t\tctx-\u003estack_depot = __drm_stack_depot_save();\ndrivers/gpu/drm/drm_modeset_lock.c-324-\t}\n--\ndrivers/gpu/drm/i915/gt/uc/intel_guc_ct.c=406=static void ct_track_lost_and_found(struct intel_guc_ct *ct, u32 fence, u32 action)\n--\ndrivers/gpu/drm/i915/gt/uc/intel_guc_ct.c-415-\t/* May be called under spinlock, so avoid sleeping */\ndrivers/gpu/drm/i915/gt/uc/intel_guc_ct.c:416:\tct-\u003erequests.lost_and_found[lost].stack = stack_depot_save(entries, n, GFP_NOWAIT);\ndrivers/gpu/drm/i915/gt/uc/intel_guc_ct.c-417-#endif\n--\ndrivers/gpu/drm/xe/xe_guc_ct.c=103=static void fast_req_stack_save(struct xe_guc_ct *ct, unsigned int slot)\n--\ndrivers/gpu/drm/xe/xe_guc_ct.c-110-\t/* May be called under spinlock, so avoid sleeping */\ndrivers/gpu/drm/xe/xe_guc_ct.c:111:\tct-\u003efast_req[slot].stack = stack_depot_save(entries, n, GFP_NOWAIT);\ndrivers/gpu/drm/xe/xe_guc_ct.c-112-#endif\n--\ninclude/linux/stackdepot.h=85=typedef u32 depot_flags_t;\n--\ninclude/linux/stackdepot.h-87-/*\ninclude/linux/stackdepot.h:88: * Flags that can be passed to stack_depot_save_flags(); see the comment next\ninclude/linux/stackdepot.h-89- * to its declaration for more details.\n--\ninclude/linux/stackdepot.h=130=static inline int stack_depot_early_init(void)\t{ return 0; }\n--\ninclude/linux/stackdepot.h-162- */\ninclude/linux/stackdepot.h:163:depot_stack_handle_t stack_depot_save_flags(unsigned long *entries,\ninclude/linux/stackdepot.h-164-\t\t\t\t\t unsigned int nr_entries,\n--\ninclude/linux/stackdepot.h-175- * Does not increment the refcount on the saved stack trace; see\ninclude/linux/stackdepot.h:176: * stack_depot_save_flags() for more details.\ninclude/linux/stackdepot.h-177- *\ninclude/linux/stackdepot.h-178- * Context: Contexts where allocations via alloc_pages() are allowed;\ninclude/linux/stackdepot.h:179: * see stack_depot_save_flags() for more details.\ninclude/linux/stackdepot.h-180- *\n--\ninclude/linux/stackdepot.h-182- */\ninclude/linux/stackdepot.h:183:depot_stack_handle_t stack_depot_save(unsigned long *entries,\ninclude/linux/stackdepot.h-184-\t\t\t\t unsigned int nr_entries, gfp_t alloc_flags);\n--\ninclude/linux/stackdepot.h=229=unsigned int stack_depot_fetch_into(depot_stack_handle_t handle,\n--\ninclude/linux/stackdepot.h-235- *\ninclude/linux/stackdepot.h:236: * @stack:\tStack depot handle returned from stack_depot_save()\ninclude/linux/stackdepot.h-237- */\ninclude/linux/stackdepot.h=238=void stack_depot_print(depot_stack_handle_t stack);\n--\ninclude/linux/stackdepot.h-242- *\ninclude/linux/stackdepot.h:243: * @handle:\tStack depot handle returned from stack_depot_save()\ninclude/linux/stackdepot.h-244- * @buf:\tPointer to the print buffer\n--\ninclude/linux/stackdepot.h=250=int stack_depot_snprint(depot_stack_handle_t handle, char *buf, size_t size,\n--\ninclude/linux/stackdepot.h-255- *\ninclude/linux/stackdepot.h:256: * @handle:\tStack depot handle returned from stack_depot_save()\ninclude/linux/stackdepot.h-257- *\n--\ninclude/linux/stackdepot.h-259- * been dropped (once the number of stack_depot_evict() calls matches the\ninclude/linux/stackdepot.h:260: * number of stack_depot_save_flags() calls with STACK_DEPOT_FLAG_GET set for\ninclude/linux/stackdepot.h-261- * this stack trace).\n--\ninclude/linux/stackdepot.h=263=void stack_depot_put(depot_stack_handle_t handle);\n--\ninclude/linux/stackdepot.h-267- *\ninclude/linux/stackdepot.h:268: * @handle:\tStack depot handle returned from stack_depot_save()\ninclude/linux/stackdepot.h-269- * @extra_bits:\tValue to set the extra bits\n--\nlib/ref_tracker.c=252=int ref_tracker_alloc(struct ref_tracker_dir *dir,\n--\nlib/ref_tracker.c-276-\tnr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 1);\nlib/ref_tracker.c:277:\ttracker-\u003ealloc_stack_handle = stack_depot_save(entries, nr_entries, gfp);\nlib/ref_tracker.c-278-\n--\nlib/ref_tracker.c=286=int ref_tracker_free(struct ref_tracker_dir *dir,\n--\nlib/ref_tracker.c-306-\tnr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 1);\nlib/ref_tracker.c:307:\tstack_handle = stack_depot_save(entries, nr_entries,\nlib/ref_tracker.c-308-\t\t\t\t\tGFP_NOWAIT);\n--\nlib/stackdepot.c=650=static inline struct stack_record *find_stack(struct list_head *bucket,\n--\nlib/stackdepot.c-698-\nlib/stackdepot.c:699:depot_stack_handle_t stack_depot_save_flags(unsigned long *entries,\nlib/stackdepot.c-700-\t\t\t\t\t unsigned int nr_entries,\n--\nlib/stackdepot.c=799=EXPORT_SYMBOL_GPL(stack_depot_save_flags);\nlib/stackdepot.c-800-\nlib/stackdepot.c:801:depot_stack_handle_t stack_depot_save(unsigned long *entries,\nlib/stackdepot.c-802-\t\t\t\t unsigned int nr_entries,\n--\nlib/stackdepot.c-804-{\nlib/stackdepot.c:805:\treturn stack_depot_save_flags(entries, nr_entries, alloc_flags,\nlib/stackdepot.c-806-\t\t\t\t STACK_DEPOT_FLAG_CAN_ALLOC);\n--\nlib/tests/stackdepot_kunit.c=23=static void stackdepot_fetch_into_roundtrip(struct kunit *test)\n--\nlib/tests/stackdepot_kunit.c-39-\nlib/tests/stackdepot_kunit.c:40:\thandle = stack_depot_save(entries, ARRAY_SIZE(entries), GFP_KERNEL);\nlib/tests/stackdepot_kunit.c-41-\tKUNIT_ASSERT_NE(test, handle, (depot_stack_handle_t)0);\n--\nlib/tests/stackdepot_kunit.c=53=static void stackdepot_fetch_into_rejects_missing_or_short_stack(struct kunit *test)\n--\nlib/tests/stackdepot_kunit.c-70-\nlib/tests/stackdepot_kunit.c:71:\thandle = stack_depot_save(entries, ARRAY_SIZE(entries), GFP_KERNEL);\nlib/tests/stackdepot_kunit.c-72-\tKUNIT_ASSERT_NE(test, handle, (depot_stack_handle_t)0);\n--\nlib/tests/stackdepot_kunit.c=178=static void stackdepot_compressed_frames(struct kunit *test)\n--\nlib/tests/stackdepot_kunit.c-191-\nlib/tests/stackdepot_kunit.c:192:\tcompressed_handle = stack_depot_save(compressible,\nlib/tests/stackdepot_kunit.c-193-\t\t\t\t\t ARRAY_SIZE(compressible), GFP_KERNEL);\nlib/tests/stackdepot_kunit.c-194-\tKUNIT_ASSERT_NE(test, compressed_handle, (depot_stack_handle_t)0);\nlib/tests/stackdepot_kunit.c:195:\tmixed_handle = stack_depot_save(mixed, ARRAY_SIZE(mixed), GFP_KERNEL);\nlib/tests/stackdepot_kunit.c-196-\tKUNIT_ASSERT_NE(test, mixed_handle, (depot_stack_handle_t)0);\n--\nlib/tests/stackdepot_kunit.c-198-\tKUNIT_EXPECT_NE(test, compressed_handle, mixed_handle);\nlib/tests/stackdepot_kunit.c:199:\tKUNIT_EXPECT_EQ(test, stack_depot_save(compressible, ARRAY_SIZE(compressible),\nlib/tests/stackdepot_kunit.c-200-\t\t\t\t\t GFP_KERNEL), compressed_handle);\n--\nlib/tests/stackdepot_kunit.c=220=static void stackdepot_get_record_not_compressed(struct kunit *test)\n--\nlib/tests/stackdepot_kunit.c-231-\nlib/tests/stackdepot_kunit.c:232:\thandle = stack_depot_save_flags(entries, ARRAY_SIZE(entries), GFP_KERNEL,\nlib/tests/stackdepot_kunit.c-233-\t\t\t\t\tSTACK_DEPOT_FLAG_CAN_ALLOC |\n--\nlib/tests/stackdepot_kunit.c=248=static void stackdepot_snprint_matches_stack_trace(struct kunit *test)\n--\nlib/tests/stackdepot_kunit.c-269-\tKUNIT_ASSERT_EQ(test, stack_depot_init(), 0);\nlib/tests/stackdepot_kunit.c:270:\thandle = stack_depot_save(entries, nr, GFP_KERNEL);\nlib/tests/stackdepot_kunit.c-271-\tKUNIT_ASSERT_NE(test, handle, (depot_stack_handle_t)0);\n--\nmm/kasan/common.c=52=depot_stack_handle_t kasan_save_stack(gfp_t flags, depot_flags_t depot_flags)\n--\nmm/kasan/common.c-57-\tnr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 0);\nmm/kasan/common.c:58:\treturn stack_depot_save_flags(entries, nr_entries, flags, depot_flags);\nmm/kasan/common.c-59-}\n--\nmm/kmemleak.c=663=static noinline depot_stack_handle_t set_track_prepare(void)\n--\nmm/kmemleak.c-676-\tnr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 3);\nmm/kmemleak.c:677:\ttrace_handle = stack_depot_save(entries, nr_entries, GFP_NOWAIT);\nmm/kmemleak.c-678-\n--\nmm/kmemleak.c=1784=static void dedup_record(struct xarray *dedup, struct kmemleak_object *object,\n--\nmm/kmemleak.c-1791-\t * No stack trace to dedup against: early-boot allocation tracked\nmm/kmemleak.c:1792:\t * before kmemleak_init() set up object_cache, or stack_depot_save()\nmm/kmemleak.c-1793-\t * failure under memory pressure.\n--\nmm/kmsan/core.c=67=depot_stack_handle_t kmsan_save_stack_with_flags(gfp_t flags,\n--\nmm/kmsan/core.c-75-\nmm/kmsan/core.c:76:\thandle = stack_depot_save(entries, nr_entries, flags);\nmm/kmsan/core.c-77-\treturn stack_depot_set_extra_bits(handle, extra);\n--\nmm/kmsan/core.c=146=depot_stack_handle_t kmsan_internal_chain_origin(depot_stack_handle_t id)\n--\nmm/kmsan/core.c-184-\t * know it is initialized. Explicitly unpoison it to avoid false\nmm/kmsan/core.c:185:\t * positives when stack_depot_save() passes it to instrumented code.\nmm/kmsan/core.c-186-\t */\nmm/kmsan/core.c-187-\tkmsan_internal_unpoison_memory(entries, sizeof(entries), false);\nmm/kmsan/core.c:188:\thandle = stack_depot_save(entries, ARRAY_SIZE(entries), __GFP_HIGH);\nmm/kmsan/core.c-189-\treturn stack_depot_set_extra_bits(handle, extra_bits);\n--\nmm/kmsan/instrumentation.c=261=void __msan_poison_alloca(void *address, uintptr_t size, char *descr)\n--\nmm/kmsan/instrumentation.c-283-\nmm/kmsan/instrumentation.c:284:\t/* stack_depot_save() may allocate memory. */\nmm/kmsan/instrumentation.c-285-\tkmsan_enter_runtime();\nmm/kmsan/instrumentation.c:286:\thandle = stack_depot_save(entries, ARRAY_SIZE(entries), __GFP_HIGH);\nmm/kmsan/instrumentation.c-287-\tkmsan_leave_runtime();\n\n"
} |
| 21/2 | 2026/11/18 03:32 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 44899 output: 37 thoughts: 1872 Thoughts: **Analyzing Stack Depot for Fuzzing Focus** Okay, so I need to figure out the best functions to target for fuzzing, specifically related to `stack_depot`. My initial thought was that `stack_depot_save` would be a good candidate, given it seems to be called across multiple memory tracking systems (KASAN, KMSAN, kmemleak, DRM modeset lock, page_owner, slub, ref_tracker). However, I need to be careful, as the guidance explicitly warns against ubiquitous functions. Let me re-read Section 4: "EXTRACTING FocusSymbols (PREVENTING DILUTION)". The goal is to avoid functions called by *almost every* program and focus instead on feature logic or entrypoints. Okay, let's start by looking at the functions that were modified or added in `lib/stackdepot.c`. I see `stack_depot_fetch_into`, `stack_depot_snprint`, and `stack_depot_print`. Now, what about `stack_depot_save_flags` or just plain `stack_depot_save`? A key point is that with KASAN enabled, `stack_depot_save_flags` *and* `stack_depot_save` are called on every memory allocation. That means it’s called everywhere and is *ubiquitous* under KASAN. Even if KASAN isn't enabled, if something like `DEBUG_KMEMLEAK` or `PAGE_OWNER` or stackdepot is tested directly, `stack_depot_save` is called on every slab allocation. Since syzkaller usually runs with KASAN, listing `stack_depot_save` would mean *every* syscall that does a `kmalloc` would be flagged as focused. That's a huge dilution of effort. So, let's drill down. `stack_depot_fetch_into` looks promising. It's newly added, has new validation checks with `WARN_ON_ONCE`, copies entries using `depot_copy_entries`, and calls `depot_stack_entry`, which does frame decompression. `stack_depot_snprint` is modified to iterate and handle a buffer while calling `depot_stack_entry`, `kmsan_unpoison_memory`, and `stack_trace_snprint`. Similarly, `stack_depot_print` does something very similar to `stack_depot_snprint` but for printing! Wait, was `stack_depot_put` changed? No, it's just context! Now, what about callers of these functions? I see that `__kmem_obj_info` and `slab_debugfs_show` in `mm/slub.c` call `stack_depot_fetch_into`. `stack_print` in `mm/page_owner.c` also calls it. `kmsan_print_origin` (and `kmsan_report`) in `mm/kmsan/report.c` eventually calls `stack_depot_fetch_into` too! Back to `stack_depot_save` vs `stack_depot_save_flags`. Could `stack_depot_save_flags` represent feature logic? Thinking about it, `depot_alloc_stack`, `depot_entries_compressible`, and `arch_stack_depot_frame_try_compress` are only called during the *save* operation! Without a save, there's no compression logic to target. So, is `stack_depot_save` ubiquitous? Yes, if KASAN is enabled! So, let's consider `stack_depot_fetch_into`, `stack_depot_snprint`, and `stack_depot_print` as more targeted options. Any other non-static functions in lib/stackdepot.c or callers? Hmm, `depot_alloc_stack` is static! So GCC might inline that into `stack_depot_save_flags`. The real question: how does syzkaller *trigger* this code? `Stack depot` is not a standalone subsystem with syscalls, you can't just `sys_stackdepot()`. The answer is Debugfs! My hypothesis is that, syzkaller calls this code via these debugfs files: 1. Reading `/sys/kernel/debug/page_owner_stacks` or `/sys/kernel/debug/page_owner` 2. Reading `/sys/kernel/debug/slab/...` 3. Reading `/sys/kernel/debug/kmemleak` 4. Reading `/sys/kernel/debug/clear` 5. |
| 22/2 | 2026/11/18 03:33 | tool | grepper |
0mArgs:{
"Expression": "stack_print|print_page_owner",
"PathPrefixes": [
"mm/page_owner.c"
]
}Results: {
"Output": "mm/page_owner.c=46=static DEFINE_SPINLOCK(stack_list_lock);\n--\nmm/page_owner.c-51-\nmm/page_owner.c:52:struct stack_print_ctx {\nmm/page_owner.c-53-\tstruct stack *stack;\n--\nmm/page_owner.c=476=void pagetypeinfo_showmixedcount_print(struct seq_file *m,\n--\nmm/page_owner.c-556- */\nmm/page_owner.c:557:static inline int print_page_owner_memcg(char *kbuf, size_t count, int ret,\nmm/page_owner.c-558-\t\t\t\t\t struct page *page)\n--\nmm/page_owner.c-594-#else\nmm/page_owner.c:595:static inline int print_page_owner_memcg(char *kbuf, size_t count, int ret,\nmm/page_owner.c-596-\t\t\t\t\t struct page *page)\n--\nmm/page_owner.c=602=static ssize_t\nmm/page_owner.c:603:print_page_owner(char __user *buf, size_t count, unsigned long pfn,\nmm/page_owner.c-604-\t\tstruct page *page, struct page_owner *page_owner,\n--\nmm/page_owner.c-655-\nmm/page_owner.c:656:\tret = print_page_owner_memcg(kbuf, count, ret, page);\nmm/page_owner.c-657-\n--\nmm/page_owner.c=729=read_page_owner(struct file *file, char __user *buf, size_t count, loff_t *ppos)\n--\nmm/page_owner.c-827-\t\tpage_ext_put(page_ext);\nmm/page_owner.c:828:\t\treturn print_page_owner(buf, count, pfn, page,\nmm/page_owner.c-829-\t\t\t\t\u0026page_owner_tmp, handle, state);\n--\nmm/page_owner.c=1030=static void *stack_start(struct seq_file *m, loff_t *ppos)\n--\nmm/page_owner.c-1032-\tstruct stack *stack;\nmm/page_owner.c:1033:\tstruct stack_print_ctx *ctx = m-\u003eprivate;\nmm/page_owner.c-1034-\n--\nmm/page_owner.c=1053=static void *stack_next(struct seq_file *m, void *v, loff_t *ppos)\n--\nmm/page_owner.c-1055-\tstruct stack *stack = v;\nmm/page_owner.c:1056:\tstruct stack_print_ctx *ctx = m-\u003eprivate;\nmm/page_owner.c-1057-\n--\nmm/page_owner.c=1065=static unsigned long pages_threshold;\nmm/page_owner.c-1066-\nmm/page_owner.c:1067:static int stack_print(struct seq_file *m, void *v)\nmm/page_owner.c-1068-{\n--\nmm/page_owner.c-1073-\tstruct stack_record *stack_record = stack-\u003estack_record;\nmm/page_owner.c:1074:\tstruct stack_print_ctx *ctx = m-\u003eprivate;\nmm/page_owner.c-1075-\n--\nmm/page_owner.c=1104=static const struct seq_operations stack_op = {\n--\nmm/page_owner.c-1107-\t.stop\t= stack_stop,\nmm/page_owner.c:1108:\t.show\t= stack_print\nmm/page_owner.c-1109-};\n--\nmm/page_owner.c=1111=static int stack_open(struct inode *inode, struct file *file)\n--\nmm/page_owner.c-1113-\tint ret = seq_open_private(file, \u0026stack_op,\nmm/page_owner.c:1114:\t\t\t\t sizeof(struct stack_print_ctx));\nmm/page_owner.c-1115-\n--\nmm/page_owner.c-1117-\t\tstruct seq_file *m = file-\u003eprivate_data;\nmm/page_owner.c:1118:\t\tstruct stack_print_ctx *ctx = m-\u003eprivate;\nmm/page_owner.c-1119-\n"
} |
| 23/2 | 2026/11/18 03:33 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 49002 output: 33 thoughts: 121 Thoughts: **Investigating the Page Owner Debugfs Interaction** Okay, so I'm tracing this `read_page_owner` function. It looks like it triggers a cascade: `print_page_owner` gets called, which in turn hands things off to `stack_depot_snprint`. Interesting. And then, `stack_print` is the key – it's the `.show` function of the `page_owner_stacks` debugfs file. That function is responsible for calling `stack_depot_fetch_into`. I'm starting to get the picture of the data flow. Now, I want to pivot and see if I can draw parallels. Let me look at the slab debugging side. Let's see what's happening in `mm/slub.c`. Ah, there it is: `slab_debugfs_show` - that’s the `.show` function for the debugfs files related to slabs! So the structure is similar, a `.show` function for the debugfs file! I'm going to dig into `mm/slub.c` and zero in on how `slab_debugfs_show` works to see how these connections are made in order to form a full picture. |
| 24/2 | 2026/11/18 03:33 | tool | grepper |
0mArgs:{
"Expression": "slab_debugfs_show",
"PathPrefixes": [
"mm/slub.c"
]
}Results: {
"Output": "mm/slub.c=9985=late_initcall(slab_late_init);\n--\nmm/slub.c-9988-#if defined(CONFIG_SLUB_DEBUG) \u0026\u0026 defined(CONFIG_DEBUG_FS)\nmm/slub.c:9989:static int slab_debugfs_show(struct seq_file *seq, void *v)\nmm/slub.c-9990-{\n--\nmm/slub.c=10088=static const struct seq_operations slab_debugfs_sops = {\n--\nmm/slub.c-10091-\t.stop = slab_debugfs_stop,\nmm/slub.c:10092:\t.show = slab_debugfs_show,\nmm/slub.c-10093-};\n"
} |
| 25/2 | 2026/11/18 03:33 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 49633 output: 33 thoughts: 21 Thoughts: Here's a summary of my thought process, as requested: **Diving into `mm/kmemleak.c` for Analysis** Okay, so we're talking about unreferenced memory leaks, which points us directly to the kmemleak subsystem. My initial instinct is to go straight to the code responsible for printing the reports – specifically, the area around the `__print_unreferenced` function within `mm/kmemleak.c`. That function is likely the central point where the kernel identifies and logs those pesky, unreachable blocks of memory. I want to understand how it's determining what constitutes "unreferenced" and what criteria are being used. Are we looking at specific traversal mechanisms? What checks are in place to determine if the pointer is truly unreachable? Understanding how that function works is key to understanding the leak detection logic. |
| 26/2 | 2026/11/18 03:34 | tool | grepper |
0mArgs:{
"Expression": "__print_unreferenced",
"PathPrefixes": [
"mm/kmemleak.c"
]
}Results: {
"Output": "mm/kmemleak.c=363=static const char *__object_type_str(struct kmemleak_object *object)\n--\nmm/kmemleak.c-375- */\nmm/kmemleak.c:376:static void __print_unreferenced(struct seq_file *seq,\nmm/kmemleak.c-377-\t\t\t\t struct kmemleak_object *object,\n--\nmm/kmemleak.c=400=static void print_unreferenced(struct seq_file *seq,\n--\nmm/kmemleak.c-402-{\nmm/kmemleak.c:403:\t__print_unreferenced(seq, object, true);\nmm/kmemleak.c-404-}\n--\nmm/kmemleak.c=1767=static void print_leak_locked(struct kmemleak_object *object, bool hex_dump)\n--\nmm/kmemleak.c-1769-\traw_spin_lock_irq(\u0026object-\u003elock);\nmm/kmemleak.c:1770:\t__print_unreferenced(NULL, object,\nmm/kmemleak.c-1771-\t\t\t hex_dump \u0026\u0026 (object-\u003eflags \u0026 OBJECT_ALLOCATED));\n"
} |
| 27/2 | 2026/11/18 03:34 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 50180 output: 30 thoughts: 1833 Thoughts: **Focus Symbol Analysis: `stackdepot.c` and KCOV Instrumentation** Okay, so I'm digging into how to best define FocusSymbols for syzkaller, specifically considering the changes related to `stack_depot.c`. My initial thought was to simply include functions like `stack_depot_save` or `stack_depot_save_flags`. But, wait a second, these are likely *ubiquitous lifecycle hot-paths*. Considering a standard syzkaller setup with KASAN, `stack_depot_save` is executed on *every* memory allocation. That means almost every test case would trigger these symbols, making the focus filter completely ineffective, as the documentation warns against. That's a classic mistake I needed to catch. So, I need to focus on the specific logic being added or altered, or API entrypoints. So, that means: * `stack_depot_fetch_into`: This is new and a primary entrypoint. * `stack_depot_snprint`: Altered in this patch and decompresses and prints now frame-by-frame. * `stack_depot_print`: Altered in this patch and decompresses and prints now frame-by-frame. I started to think about other functions in the system that were used, such as `__kmem_obj_info` in `mm/slub.c`, `stack_print` and `print_page_owner` from `mm/page_owner.c`, and even `__print_unreferenced` from `mm/kmemleak.c`. I considered if those static functions would be appropriate as focus symbols. But, I remember that `kmemleak_seq_show` and `kmemleak_write` are called when reading kmemleak debugfs. Then I looked at `drivers/gpu/drm/drm_modeset_lock.c` and remembered, that is drm specific. A crucial point hit me: what about *static* functions within `lib/stackdepot.c`? Can they be FocusSymbols? I started checking the functions, like `depot_alloc_stack`, `find_stack`, and `depot_copy_entries`. I started getting concerned because they were static. But... wait! I need to consider KCOV instrumentation! The key is whether KCOV can *see* these functions. Looking at `lib/Makefile`, I see `KCOV_INSTRUMENT_stackdepot.o := n`. This means that GCC/Clang *does not* instrument functions in `stackdepot.o` with `__sanitizer_cov_trace_pc`! If KCOV doesn't instrument `stackdepot.c`, then KCOV can't record coverage for any symbols within it, period. So, can syzkaller even observe PCs inside functions in `stackdepot.c`? No! Syzkaller uses the coverage PCs to determine FocusSymbols. The callers *of* these functions *in other files* (e.g., in `mm/slub.c`, `mm/page_owner.c`, etc.) ARE instrumented. So, is `stack_depot_fetch_into` (despite being an entrypoint) a valid focus symbol? My conclusion is, no! The focus should be the caller functions, such as those from `mm/slub.c`, `mm/page_owner.c` and `mm/kmemleak.c`. |
| 28/2 | 2026/11/18 03:34 | tool | grepper |
0mArgs:{
"Expression": "KCOV_INSTRUMENT",
"PathPrefixes": [
"mm/Makefile"
]
}Results: {
"Output": "mm/Makefile=18=KCSAN_INSTRUMENT_BARRIERS := y\n--\nmm/Makefile-22-# free pages, or a task is migrated between nodes.\nmm/Makefile:23:KCOV_INSTRUMENT_slab_common.o := n\nmm/Makefile:24:KCOV_INSTRUMENT_slub.o := n\nmm/Makefile:25:KCOV_INSTRUMENT_page_alloc.o := n\nmm/Makefile:26:KCOV_INSTRUMENT_debug-pagealloc.o := n\nmm/Makefile:27:KCOV_INSTRUMENT_kmemleak.o := n\nmm/Makefile:28:KCOV_INSTRUMENT_memcontrol.o := n\nmm/Makefile:29:KCOV_INSTRUMENT_memcontrol-v1.o := n\nmm/Makefile:30:KCOV_INSTRUMENT_mmzone.o := n\nmm/Makefile:31:KCOV_INSTRUMENT_vmstat.o := n\nmm/Makefile:32:KCOV_INSTRUMENT_failslab.o := n\nmm/Makefile-33-\n"
} |
| 29/2 | 2026/11/18 03:34 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 53075 output: 33 thoughts: 645 Thoughts: Here's my thought process, as it stands: **Reviewing KCOV Instrumentation and FocusSymbols** Okay, first things first, I see that `mm/page_owner.o` isn't listed as instrumented, which is a bit surprising since `page_owner.o` *is* instrumented by KCOV. Let me double-check that `page_owner.o` is indeed instrumented. *grep KCOV_INSTRUMENT_page_owner mm/Makefile*... Nope, nothing there. Interesting. And while I'm at it, I noticed that DRM drivers, specifically `drivers/gpu/drm`, *are* instrumented. And what about `stackdepot_kunit.o`? That's in `lib/tests/Makefile` and it isn't disabled. Good. Now, hold on. I need to make sure I understand the requirements of `FocusSymbols`. Should it include `stack_depot_fetch_into`, `stack_depot_snprint`, and `stack_depot_print`? Let's go back and re-read Section 4: *"...List functions that specifically implement the logic being added or altered, or direct API entrypoints for the subsystem feature under review."* Even if `stackdepot.o` itself has KCOV_INSTRUMENT := n, the *direct* API entrypoints for the subsystem feature I'm reviewing are exactly those functions: `stack_depot_fetch_into`, `stack_depot_snprint`, and `stack_depot_print`. The callers are `print_page_owner` (in `mm/page_owner.c`) and `stack_print` (in `mm/page_owner.c`). So, can `stack_depot_fetch_into` be in `FocusSymbols`? Yes! It definitely fits the definition: "List functions that specifically implement the logic being added or altered, or direct API entrypoints for the subsystem feature under review." `stack_depot_fetch_into` is literally a new API entrypoint introduced by this patch. And `stack_depot_snprint`, and `stack_depot_print` are entrypoints altered by this patch. That's settled. Wait, what about `stack_print` and `print_page_owner`? Let me check `mm/page_owner.c`. `stack_print` is static, which is, wait, static functions in .c files appear in the kallsyms symbol table unless discarded. Yes! Now, what about `__drm_stack_depot_print`? It's static in `drm_modeset_lock.c`. Okay, let's change gears. What other non-static functions call `stack_depot_fetch_into` or `stack_depot_snprint`? *grep* time! `kmsan_print_origin` is non-static in `mm/kmsan/report.c`. Same with `kmsan_report`, also in `mm/kmsan/report.c`. And what about `page_owner`? Let me check the non-static functions in `mm/page_owner.c`. |
| 30/2 | 2026/11/18 03:35 | tool | grepper |
0mArgs:{
"Expression": "read_page_owner",
"PathPrefixes": [
"mm/page_owner.c"
]
}Results: {
"Output": "mm/page_owner.c=728=static ssize_t\nmm/page_owner.c:729:read_page_owner(struct file *file, char __user *buf, size_t count, loff_t *ppos)\nmm/page_owner.c-730-{\n--\nmm/page_owner.c=1021=static const struct file_operations page_owner_fops = {\n--\nmm/page_owner.c-1025-\t.write\t\t= page_owner_write,\nmm/page_owner.c:1026:\t.read\t\t= read_page_owner,\nmm/page_owner.c-1027-\t.llseek\t\t= lseek_page_owner,\n"
} |
| 31/2 | 2026/11/18 03:35 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 54638 output: 32 thoughts: 646 Thoughts: **Analyzing the Inclusion of `stack_depot_save` in FocusSymbols** Okay, so I'm digging into how `page_owner` and related debugfs interfaces work. I see that the `read_page_owner` function, triggered when reading `/sys/kernel/debug/page_owner`, eventually calls `stack_depot_snprint`, which in turn, likely relies on `stack_depot_fetch_into` and the exported `stack_depot_print`. The functions are all GPL exported, which is good. I'm also reminded that `stack_print` is the `.show` callback for `/sys/kernel/debug/page_owner_stacks`, and calls `stack_depot_fetch_into`. But then I stop and think about `stack_depot_save`. Should this be included in `FocusSymbols`? Let me re-examine why someone might consider that. Ah, right, `stack_depot_save` is where the stack compression happens via `depot_alloc_stack`, compressing the stack to determine if the stack exists using `depot_stack_equal`. However, that's where the concern lies. Now I'm reminded of Section 4 of the guidelines – "AVOID UBIQUITOUS LIFECYCLE HOT-PATHS." It says to *avoid* including generic functions that are called by nearly everything, like memory allocators and synchronization primitives. Listing those functions dilutes the fuzzing effort. Okay, let's step back and consider: what does Syzkaller *do* with `FocusSymbols`? It tracks coverage. If any program execution touches a `FocusSymbol`, the test case is flagged as "focused." Now, if I include `stack_depot_save`, and the kernel is compiled with KASAN (or SLUB_DEBUG, or PAGE_OWNER), is this a path that is called by almost everything? Does every program call `stack_depot_save`? In the KASAN case, doesn't `kmem_cache_alloc` call `kasan_save_stack`? I need to verify when `kasan_save_stack` is called. It seems possible that including `stack_depot_save` might cause *many* tests to be classified as focused, which would be undesirable. |
| 32/2 | 2026/11/18 03:35 | tool | grepper |
0mArgs:{
"Expression": "kasan_save_stack",
"PathPrefixes": [
"mm/kasan/"
]
}Results: {
"Output": "mm/kasan/common.c=45=struct slab *kasan_addr_to_slab(const void *addr)\n--\nmm/kasan/common.c-51-\nmm/kasan/common.c:52:depot_stack_handle_t kasan_save_stack(gfp_t flags, depot_flags_t depot_flags)\nmm/kasan/common.c-53-{\n--\nmm/kasan/common.c=74=void kasan_save_track(struct kasan_track *track, gfp_t flags)\n--\nmm/kasan/common.c-77-\nmm/kasan/common.c:78:\tstack = kasan_save_stack(flags, STACK_DEPOT_FLAG_CAN_ALLOC);\nmm/kasan/common.c-79-\tkasan_set_track(track, stack);\n--\nmm/kasan/generic.c=539=void kasan_record_aux_stack(void *addr)\n--\nmm/kasan/generic.c-555-\talloc_meta-\u003eaux_stack[1] = alloc_meta-\u003eaux_stack[0];\nmm/kasan/generic.c:556:\talloc_meta-\u003eaux_stack[0] = kasan_save_stack(0, 0);\nmm/kasan/generic.c-557-}\n--\nmm/kasan/kasan.h=394=static inline void kasan_init_object_meta(struct kmem_cache *cache, const void *object) { }\n--\nmm/kasan/kasan.h-396-\nmm/kasan/kasan.h:397:depot_stack_handle_t kasan_save_stack(gfp_t flags, depot_flags_t depot_flags);\nmm/kasan/kasan.h-398-void kasan_set_track(struct kasan_track *track, depot_stack_handle_t stack);\n--\nmm/kasan/tags.c=97=static void save_stack_info(struct kmem_cache *cache, void *object,\n--\nmm/kasan/tags.c-105-\nmm/kasan/tags.c:106:\tstack = kasan_save_stack(gfp_flags,\nmm/kasan/tags.c-107-\t\t\tSTACK_DEPOT_FLAG_CAN_ALLOC | STACK_DEPOT_FLAG_GET);\n"
} |
| 33/2 | 2026/11/18 03:35 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 56422 output: 44 thoughts: 700 Thoughts: **Focusing on the Right Targets for Syzkaller with Stack Depot** Okay, so here's the deal. I'm looking at this KASAN integration with `stack_depot`, and it's screaming a big red flag. `kasan_save_track` is called *every single time* there's a memory allocation – every `kmalloc`, `kmem_cache_alloc`, you name it – when KASAN is enabled. And guess what `kasan_save_track` calls? Yup, `kasan_save_stack`, which then hits `stack_depot_save_flags`. So, in every syzkaller test case on a KASAN kernel, `stack_depot_save` and `stack_depot_save_flags` are executed continuously. That's a massive problem for focusing the fuzzer. It's the textbook example of what *not* to include in `FocusSymbols`: ubiquitous functions called by almost everything, like memory allocators! Listing those generic functions would pollute the results and dilute the fuzzing effort. Therefore, `stack_depot_save` and `stack_depot_save_flags` are immediately *off the list*. Now, what *should* be in `FocusSymbols`? Let's get down to the critical functions: 1. `stack_depot_fetch_into`: This is the new, primary function replacing `stack_depot_fetch` in `lib/stackdepot.c`. This is a clear target. 2. `stack_depot_snprint`: Specifically rewritten to iterate over frames and decompress using `depot_stack_entry()` in `lib/stackdepot.c`. This is important, a rewrite like this should be tested. 3. `stack_depot_print`: Similar to `snprint`, rewritten to iterate and decompress frames. 4. `read_page_owner`: This debugfs handler in `mm/page_owner.c` that reads traces and triggers `stack_depot_snprint`. This is a good entry point. 5. `stack_print`: Another debugfs handler in `mm/page_owner.c` reading traces and triggering `stack_depot_fetch_into`. This is another debugfs entry point to target. 6. `__kmem_obj_info`: The slub debug helper in `mm/slub.c` modified to use `stack_depot_fetch_into`. This is a relevant Slub debug call. Hold on, what about `CONFIG_STACKDEPOT_KUNIT_TEST`? Gotta make sure there aren't test symbols we need to consider. Alright, checking... KUnit tests run at boot or module load. Okay, there's `stackdepot_test_suite` in `lib/tests/stackdepot_kunit.c`. But, those tests aren't syscall targets for syzkaller, so they're not a direct concern. Let's do one final check for any other modified direct callers. Ah, in `drivers/gpu/drm/drm_modeset_lock.c`, there's `__drm_stack_depot_print`. Interesting. I'll need to check if anything actually *calls* `__drm_stack_depot_print`. Okay, back to `drm_modeset_lock.c`... |
| 34/2 | 2026/11/18 03:35 | tool | grepper |
0mArgs:{
"Expression": "__drm_stack_depot_print",
"PathPrefixes": [
"drivers/gpu/drm/drm_modeset_lock.c"
]
}Results: {
"Output": "drivers/gpu/drm/drm_modeset_lock.c=84=static noinline depot_stack_handle_t __drm_stack_depot_save(void)\n--\ndrivers/gpu/drm/drm_modeset_lock.c-93-\ndrivers/gpu/drm/drm_modeset_lock.c:94:static void __drm_stack_depot_print(depot_stack_handle_t stack_depot)\ndrivers/gpu/drm/drm_modeset_lock.c-95-{\n--\ndrivers/gpu/drm/drm_modeset_lock.c=115=static depot_stack_handle_t __drm_stack_depot_save(void)\n--\ndrivers/gpu/drm/drm_modeset_lock.c-118-}\ndrivers/gpu/drm/drm_modeset_lock.c:119:static void __drm_stack_depot_print(depot_stack_handle_t stack_depot)\ndrivers/gpu/drm/drm_modeset_lock.c-120-{\n--\ndrivers/gpu/drm/drm_modeset_lock.c=269=void drm_modeset_drop_locks(struct drm_modeset_acquire_ctx *ctx)\n--\ndrivers/gpu/drm/drm_modeset_lock.c-271-\tif (WARN_ON(ctx-\u003econtended))\ndrivers/gpu/drm/drm_modeset_lock.c:272:\t\t__drm_stack_depot_print(ctx-\u003estack_depot);\ndrivers/gpu/drm/drm_modeset_lock.c-273-\n--\ndrivers/gpu/drm/drm_modeset_lock.c=285=static inline int modeset_lock(struct drm_modeset_lock *lock,\n--\ndrivers/gpu/drm/drm_modeset_lock.c-291-\tif (WARN_ON(ctx-\u003econtended))\ndrivers/gpu/drm/drm_modeset_lock.c:292:\t\t__drm_stack_depot_print(ctx-\u003estack_depot);\ndrivers/gpu/drm/drm_modeset_lock.c-293-\n"
} |
| 35/2 | 2026/11/18 03:35 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 58439 output: 34 thoughts: 274 Thoughts: **My Analysis of DRM Lock Contention Detection** Okay, so I'm looking at this lock contention situation in the DRM modesetting code. `drm_modeset_drop_locks` and `modeset_lock` are calling `__drm_stack_depot_print` when a contended lock is dropped or another lock is acquired without backoff – interesting. I see that `drm_modeset_drop_locks` is actually exported, meaning it's potentially used outside the core DRM code, which is good to keep in mind. And `drm_modeset_lock`, as expected, just calls `modeset_lock`. Now, the important question is: where are these stack depot prints *actually* used? Let's check `kmsan_report.c`. Aha, looks like `kmsan_print_origin` and `kmsan_report` are only triggered in KMSAN error reporting. That provides some context but I need more. Time to look at the relevant kernel configurations. I'm going to check the patch changes to understand the relevant configs. Okay, here's what's relevant. First, `CONFIG_STACKDEPOT` is critical; it's needed just to compile `lib/stackdepot.c` in the first place. That makes sense. Second, `CONFIG_STACKDEPOT_ALWAYS_INIT` is also important; it ensures the stack depot is initialized early. The intent here is to prevent `stack_depot_save` and `stack_depot_fetch_into` from bailing out. Now I'm getting somewhere! Wait a minute, what happens if `stack_depot_init` *isn't* called? Let me go back to `lib/stackdepot.c` and check what happens around the `stack_depot_disabled` flag or the initialization routines. I need to understand the failure path and the implications. |
| 36/2 | 2026/11/18 03:35 | tool | grepper |
0mArgs:{
"Expression": "stack_depot_disabled",
"PathPrefixes": [
"lib/stackdepot.c"
]
}Results: {
"Output": "lib/stackdepot.c=44=static unsigned int stack_max_pools __read_mostly =\n--\nlib/stackdepot.c-46-\nlib/stackdepot.c:47:static bool stack_depot_disabled;\nlib/stackdepot.c-48-static bool __stack_depot_early_init_requested __initdata = IS_ENABLED(CONFIG_STACKDEPOT_ALWAYS_INIT);\n--\nlib/stackdepot.c=101=static int __init disable_stack_depot(char *str)\nlib/stackdepot.c-102-{\nlib/stackdepot.c:103:\treturn kstrtobool(str, \u0026stack_depot_disabled);\nlib/stackdepot.c-104-}\n--\nlib/stackdepot.c=153=int __init stack_depot_early_init(void)\n--\nlib/stackdepot.c-165-\t */\nlib/stackdepot.c:166:\tif (stack_depot_disabled) {\nlib/stackdepot.c-167-\t\tpr_info(\"disabled\\n\");\n--\nlib/stackdepot.c-203-\t\tpr_err(\"hash table allocation failed, disabling\\n\");\nlib/stackdepot.c:204:\t\tstack_depot_disabled = true;\nlib/stackdepot.c-205-\t\treturn -ENOMEM;\n--\nlib/stackdepot.c-222-\t\tmemblock_free(stack_table, entries * sizeof(struct list_head));\nlib/stackdepot.c:223:\t\tstack_depot_disabled = true;\nlib/stackdepot.c-224-\t\treturn -ENOMEM;\n--\nlib/stackdepot.c=231=int stack_depot_init(void)\n--\nlib/stackdepot.c-238-\nlib/stackdepot.c:239:\tif (stack_depot_disabled || stack_table)\nlib/stackdepot.c-240-\t\tgoto out_unlock;\n--\nlib/stackdepot.c-268-\t\tpr_err(\"hash table allocation failed, disabling\\n\");\nlib/stackdepot.c:269:\t\tstack_depot_disabled = true;\nlib/stackdepot.c-270-\t\tret = -ENOMEM;\n--\nlib/stackdepot.c-281-\t\tkvfree(stack_table);\nlib/stackdepot.c:282:\t\tstack_depot_disabled = true;\nlib/stackdepot.c-283-\t\tret = -ENOMEM;\n--\nlib/stackdepot.c=699=depot_stack_handle_t stack_depot_save_flags(unsigned long *entries,\n--\nlib/stackdepot.c-726-\nlib/stackdepot.c:727:\tif (unlikely(nr_entries == 0) || stack_depot_disabled)\nlib/stackdepot.c-728-\t\treturn 0;\n--\nlib/stackdepot.c=828=unsigned int stack_depot_fetch_into(depot_stack_handle_t handle,\n--\nlib/stackdepot.c-836-\t\treturn 0;\nlib/stackdepot.c:837:\tif (stack_depot_disabled)\nlib/stackdepot.c-838-\t\treturn 0;\n--\nlib/stackdepot.c=856=static struct stack_record *depot_print_fetch(depot_stack_handle_t handle)\n--\nlib/stackdepot.c-859-\nlib/stackdepot.c:860:\tif (!handle || stack_depot_disabled)\nlib/stackdepot.c-861-\t\treturn NULL;\n--\nlib/stackdepot.c=872=void stack_depot_put(depot_stack_handle_t handle)\n--\nlib/stackdepot.c-875-\nlib/stackdepot.c:876:\tif (!handle || stack_depot_disabled)\nlib/stackdepot.c-877-\t\treturn;\n--\nlib/stackdepot.c=967=static int depot_debugfs_init(void)\n--\nlib/stackdepot.c-970-\nlib/stackdepot.c:971:\tif (stack_depot_disabled)\nlib/stackdepot.c-972-\t\treturn 0;\n"
} |
| 37/2 | 2026/11/18 03:35 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 60291 output: 34 thoughts: 44 Thoughts: Okay, here's my take on those thoughts, framed as an expert's internal monologue: **Investigating a Potential `NULL` Return** Alright, so the system's behaving as if `depot_fetch_stack` might be returning `NULL`. That's the key signal here. The precondition is a missing allocation for `stack_table`. Let's clarify what's actually happening. I need to dive into the code for `depot_fetch_stack`, specifically within `lib/stackdepot.c`. My instincts tell me there could be an uninitialized table or a failure during allocation within that function. I'll need to trace the execution path and identify any potential `NULL` returns that are triggered under these circumstances. Time to get my hands dirty and start digging into the implementation details. |
| 38/2 | 2026/11/18 03:35 | tool | grepper |
0mArgs:{
"Expression": "depot_fetch_stack",
"PathPrefixes": [
"lib/stackdepot.c"
]
}Results: {
"Output": "lib/stackdepot.c=296=static bool depot_init_pool(void **prealloc)\n--\nlib/stackdepot.c-317-\nlib/stackdepot.c:318:\t/* Save reference to the pool to be used by depot_fetch_stack(). */\nlib/stackdepot.c-319-\tstack_pools[pools_num] = new_pool;\n--\nlib/stackdepot.c-333-\nlib/stackdepot.c:334:\t/* Pairs with concurrent READ_ONCE() in depot_fetch_stack(). */\nlib/stackdepot.c-335-\tWRITE_ONCE(pools_num, pools_num + 1);\n--\nlib/stackdepot.c=465=depot_alloc_stack(unsigned long *entries, unsigned int nr_entries, u32 hash, depot_flags_t flags, void **prealloc)\n--\nlib/stackdepot.c-536-\nlib/stackdepot.c:537:static struct stack_record *depot_fetch_stack(depot_stack_handle_t handle)\nlib/stackdepot.c-538-\t__must_not_hold(\u0026pool_lock)\n--\nlib/stackdepot.c=810=struct stack_record *__stack_depot_get_stack_record(depot_stack_handle_t handle)\n--\nlib/stackdepot.c-814-\nlib/stackdepot.c:815:\treturn depot_fetch_stack(handle);\nlib/stackdepot.c-816-}\n--\nlib/stackdepot.c=828=unsigned int stack_depot_fetch_into(depot_stack_handle_t handle,\n--\nlib/stackdepot.c-841-\nlib/stackdepot.c:842:\tstack = depot_fetch_stack(handle);\nlib/stackdepot.c-843-\tif (!stack)\n--\nlib/stackdepot.c=856=static struct stack_record *depot_print_fetch(depot_stack_handle_t handle)\n--\nlib/stackdepot.c-862-\nlib/stackdepot.c:863:\tstack = depot_fetch_stack(handle);\nlib/stackdepot.c-864-\t/*\n--\nlib/stackdepot.c=872=void stack_depot_put(depot_stack_handle_t handle)\n--\nlib/stackdepot.c-878-\nlib/stackdepot.c:879:\tstack = depot_fetch_stack(handle);\nlib/stackdepot.c-880-\t/*\n"
} |
| 39/2 | 2026/11/18 03:36 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 61219 output: 34 thoughts: 221 Thoughts: **Investigating Stack Depot Initialization** Okay, so I'm digging into how the `stack_depot` functionality is initialized. My immediate thought is, if `stack_table` hasn't been allocated, then `stack_depot_save_flags` is essentially useless; it can't find or allocate stacks unless `stack_depot_init` has been called, or if it was requested to init early, via `CONFIG_STACKDEPOT_ALWAYS_INIT`. I need to figure out what triggers that early initialization. Let's break down the dependencies on `CONFIG_STACKDEPOT_ALWAYS_INIT`. Ah, straightforward, `CONFIG_STACKDEPOT_ALWAYS_INIT` itself will select itself, naturally. But what else? Okay, `CONFIG_PAGE_OWNER`. Wait a second… doesn't `page_owner` call `stack_depot_init` during `mm_core_init`? Yeah, let's confirm that with a quick look at `mm/page_owner.c`. So that's one avenue. And what else? Aha! `CONFIG_SLUB_DEBUG_ON` also selects `STACKDEPOT_ALWAYS_INIT`. Interesting. Debugging flags can lead to early init. And `CONFIG_DEBUG_KMEMLEAK` too. Okay, so that's another trigger. And, unsurprisingly, `CONFIG_KASAN` and `CONFIG_KMSAN` are also selecting it. All of these tools require more bookkeeping to operate correctly, hence the early initialization. Okay, so the picture is becoming clearer: various debugging and memory analysis configurations can force early `stack_depot` initialization. Right, let's confirm that page owner interaction. |
| 40/2 | 2026/11/18 03:36 | tool | grepper |
0mArgs:{
"Expression": "stack_depot_init",
"PathPrefixes": [
"mm/page_owner.c"
]
}Results: {
"Output": "no matches"
} |
| 41/2 | 2026/11/18 03:36 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 61854 output: 28 thoughts: 37 Thoughts: Here's my thought process, as requested: **Debugging the `stack_depot_init` Call** Okay, so I'm trying to trace the initialization of `stack_depot` specifically within the context of `page_owner`. The first question that pops into my head is, *where* exactly is `stack_depot_init` being called for `page_owner`? My instinct tells me the most logical places to look are in either the `mm/page_owner.c` file itself, which would handle `page_owner`-specific initialization, or potentially in the broader memory management initialization file, `mm/mm_init.c`. Both are strong candidates, and I need to check both before proceeding. This'll require a quick code dive. Let's start with those. |
| 42/2 | 2026/11/18 03:36 | tool | grepper |
0mArgs:{
"Expression": "page_owner.*init",
"PathPrefixes": [
"mm/"
]
}Results: {
"Output": "mm/mm_init.c=2698=void __init mm_core_init(void)\n--\nmm/mm_init.c-2728-\t/*\nmm/mm_init.c:2729:\t * page_owner must be initialized after buddy is ready, and also after\nmm/mm_init.c-2730-\t * slab is ready so that stack_depot_init() works properly\n--\nmm/page_alloc.c=5199=unsigned long alloc_pages_bulk_noprof(gfp_t gfp, int preferred_nid,\n--\nmm/page_alloc.c-5244-\t */\nmm/page_alloc.c:5245:\tif (static_branch_unlikely(\u0026page_owner_inited))\nmm/page_alloc.c-5246-\t\tgoto failed;\n--\nmm/page_owner.c=69=struct page_owner_filter_state {\n--\nmm/page_owner.c-74-\nmm/page_owner.c:75:static bool page_owner_enabled __initdata;\nmm/page_owner.c:76:DEFINE_STATIC_KEY_FALSE(page_owner_inited);\nmm/page_owner.c-77-\n--\nmm/page_owner.c=140=static __init void init_page_owner(void)\n--\nmm/page_owner.c-157-\tstack_list = \u0026dummy_stack;\nmm/page_owner.c:158:\tstatic_branch_enable(\u0026page_owner_inited);\nmm/page_owner.c-159-}\n--\nmm/page_owner.c=729=read_page_owner(struct file *file, char __user *buf, size_t count, loff_t *ppos)\n--\nmm/page_owner.c-737-\nmm/page_owner.c:738:\tif (!static_branch_unlikely(\u0026page_owner_inited))\nmm/page_owner.c-739-\t\treturn -EINVAL;\n--\nmm/page_owner.c=1147=static int __init pageowner_init(void)\n--\nmm/page_owner.c-1150-\nmm/page_owner.c:1151:\tif (!static_branch_unlikely(\u0026page_owner_inited)) {\nmm/page_owner.c-1152-\t\tpr_info(\"page_owner is disabled\\n\");\n--\nmm/vmstat.c=1702=static void pagetypeinfo_showmixedcount(struct seq_file *m, pg_data_t *pgdat)\n--\nmm/vmstat.c-1706-\nmm/vmstat.c:1707:\tif (!static_branch_unlikely(\u0026page_owner_inited))\nmm/vmstat.c-1708-\t\treturn;\n"
} |
| 43/2 | 2026/11/18 03:36 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 62817 output: 36 thoughts: 23 Thoughts: Okay, let's dive into this. Here's my take on what's going on, based on that specific line reference: **Analyzing `mm/mm_init.c` at Line 2730** Alright, my brain's going straight to `mm/mm_init.c`, line 2730. *I know this code, so I'm not going to beat around the bush.* I'm immediately thinking, "Okay, initialization phase, memory management... what's being set up right there?". Since it's deep in `mm_init.c`, it's not likely to be a simple variable assignment. This points to something significant, *probably* related to the core of how the memory management system is getting built. It could be mapping virtual memory, allocating crucial kernel data structures, or setting up the page tables for the initial processes. I'm mentally running through the various memory areas—kernel text, data, BSS, vmalloc space, how the physical memory is mapped... This line number is specific enough to trigger that. If it's towards the end of the init, it could be the last steps, maybe setting up the higher-level memory management data structures after the initial mapping is done. I'm expecting something that really affects how the kernel handles allocation. I also think it could have something to do with the heap, and or the stack of something. I need to see the context to be certain, of course, but that line is going to be the lynchpin for setting up a critical phase of memory management during system startup. Without knowing the code, I know its importance. I have to see it. |
| 44/2 | 2026/11/18 03:36 | tool | read-file |
0mArgs:{
"File": "mm/mm_init.c",
"FirstLine": 2725,
"LineCount": 20
}Results: {
"Contents": "2725:\t\tmemblock_free_all();\n2726:\t\tmem_init();\n2727:\t\tkmem_cache_init();\n2728:\t\t/*\n2729:\t\t * page_owner must be initialized after buddy is ready, and also after\n2730:\t\t * slab is ready so that stack_depot_init() works properly\n2731:\t\t */\n2732:\t\tpage_ext_init_flatmem_late();\n2733:\t\tkmemleak_init();\n2734:\t\tptlock_cache_init();\n2735:\t\tpgtable_cache_init();\n2736:\t\tdebug_objects_mem_init();\n2737:\t\tvmalloc_init();\n2738:\t\t/* If no deferred init page_ext now, as vmap is fully initialized */\n2739:\t\tif (!deferred_struct_pages)\n2740:\t\t\tpage_ext_init();\n2741:\t\t/* Should be run before the first non-init thread is created */\n2742:\t\tinit_espfix_bsp();\n2743:\t\t/* Should be run after espfix64 is set up. */\n2744:\t\tpti_init();\n"
} |
| 45/2 | 2026/11/18 03:36 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 63548 output: 35 thoughts: 28 Thoughts: Here's my take on the thought process, as requested: **Tracing the Initialization of `stack_depot` within the `page_owner` context** Alright, let's zero in on this `page_owner` thing. My initial question is: where the heck is `stack_depot_init` getting called from *within* this `page_owner` system? We know the `stack_depot` is critical for memory tracking, so understanding its initialization is paramount. My next step, logically, is to examine the `init_page_owner` function itself. That seems like the most obvious place to start digging for the call to `stack_depot_init`. Let's see what's happening in there. This is likely the entry point for the `page_owner` subsystem's initialization, so it is the most likely spot. Time to look at the code! |
| 46/2 | 2026/11/18 03:37 | tool | read-file |
0mArgs:{
"File": "mm/page_owner.c",
"FirstLine": 140,
"LineCount": 25
}Results: {
"Contents": " 140:\tstatic __init void init_page_owner(void)\n 141:\t{\n 142:\t\tif (!page_owner_enabled)\n 143:\t\t\treturn;\n 144:\t\n 145:\t\tregister_dummy_stack();\n 146:\t\tregister_failure_stack();\n 147:\t\tregister_early_stack();\n 148:\t\tinit_early_allocated_pages();\n 149:\t\t/* Initialize dummy and failure stacks and link them to stack_list */\n 150:\t\tdummy_stack.stack_record = __stack_depot_get_stack_record(dummy_handle);\n 151:\t\tfailure_stack.stack_record = __stack_depot_get_stack_record(failure_handle);\n 152:\t\tif (dummy_stack.stack_record)\n 153:\t\t\trefcount_set(\u0026dummy_stack.stack_record-\u003ecount, 1);\n 154:\t\tif (failure_stack.stack_record)\n 155:\t\t\trefcount_set(\u0026failure_stack.stack_record-\u003ecount, 1);\n 156:\t\tdummy_stack.next = \u0026failure_stack;\n 157:\t\tstack_list = \u0026dummy_stack;\n 158:\t\tstatic_branch_enable(\u0026page_owner_inited);\n 159:\t}\n 160:\t\n 161:\tstruct page_ext_operations page_owner_ops = {\n 162:\t\t.size = sizeof(struct page_owner),\n 163:\t\t.need = need_page_owner,\n 164:\t\t.init = init_page_owner,\n"
} |
| 47/2 | 2026/11/18 03:37 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 64233 output: 33 thoughts: 20 Thoughts: Here's a summary of my immediate thought process: **Tracing the Registration of `dummy_handle`** Okay, so I'm trying to figure out where the `dummy_handle` is registered. Given my expertise, I suspect this is likely a registration within a broader system, perhaps a driver, a library, or some configuration table. My first instinct, based on past experiences, is to investigate the registration logic directly. I need to understand where this `dummy_handle` is being associated with its underlying resources or services. Therefore, my immediate next step, logically, should be to examine the code related to the function or mechanism that seems most likely to handle such registrations. Based on the variable's name, that seems like a strong contender is the function `register_dummy_stack`. Let's start there. |
| 48/2 | 2026/11/18 03:37 | tool | grepper |
0mArgs:{
"Expression": "register_dummy_stack",
"PathPrefixes": [
"mm/page_owner.c"
]
}Results: {
"Output": "mm/page_owner.c=116=static __always_inline depot_stack_handle_t create_dummy_stack(void)\n--\nmm/page_owner.c-124-\nmm/page_owner.c:125:static noinline void register_dummy_stack(void)\nmm/page_owner.c-126-{\n--\nmm/page_owner.c=140=static __init void init_page_owner(void)\n--\nmm/page_owner.c-144-\nmm/page_owner.c:145:\tregister_dummy_stack();\nmm/page_owner.c-146-\tregister_failure_stack();\n"
} |
| 49/2 | 2026/11/18 03:37 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 64638 output: 35 thoughts: 14 Thoughts: Okay, let's dive into this code. **Analyzing the `create_dummy_stack` Function** Right, let me pull up the relevant code for `create_dummy_stack`. I need to understand this function's purpose. Based on the name, I'm expecting it to generate some kind of placeholder stack structure – likely for testing or initialization purposes. Now I need to see what's actually being created within the code block. I'll watch out for what data types it uses, how the stack is populated, and whether there are any configurations which might influence the output of this dummy object. Knowing the expected behaviour will let me move on to the interesting problems, or make effective use of the functionality as designed. |
| 50/2 | 2026/11/18 03:38 | tool | read-file |
0mArgs:{
"File": "mm/page_owner.c",
"FirstLine": 115,
"LineCount": 20
}Results: {
"Contents": " 115:\t\n 116:\tstatic __always_inline depot_stack_handle_t create_dummy_stack(void)\n 117:\t{\n 118:\t\tunsigned long entries[4];\n 119:\t\tunsigned int nr_entries;\n 120:\t\n 121:\t\tnr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 0);\n 122:\t\treturn stack_depot_save(entries, nr_entries, GFP_KERNEL);\n 123:\t}\n 124:\t\n 125:\tstatic noinline void register_dummy_stack(void)\n 126:\t{\n 127:\t\tdummy_handle = create_dummy_stack();\n 128:\t}\n 129:\t\n 130:\tstatic noinline void register_failure_stack(void)\n 131:\t{\n 132:\t\tfailure_handle = create_dummy_stack();\n 133:\t}\n 134:\t\n"
} |
| 51/2 | 2026/11/18 03:38 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 65113 output: 33 thoughts: 20 Thoughts: Okay, here's my interpretation of that thought process, assuming I'm deep in the code: **Checking `need_page_owner`** Alright, so I'm in this part of the code and I've got a variable called `need_page_owner`. The question is, what's going on with it? Time to get down to brass tacks and see what we're dealing with. I need to understand its role in this process. Let's see how `need_page_owner` is being used, where it comes from, and what the implications are if it's true or false. Gotta trace its flow through the logic and ensure it's doing what I expect it to. The devil is always in the details, so let's dig into that `need_page_owner` call and make sure there are no surprises lurking. |
| 52/2 | 2026/11/18 03:38 | tool | grepper |
0mArgs:{
"Expression": "need_page_owner",
"PathPrefixes": [
"mm/page_owner.c"
]
}Results: {
"Output": "mm/page_owner.c=109=early_param(\"page_owner\", early_page_owner_param);\nmm/page_owner.c-110-\nmm/page_owner.c:111:static __init bool need_page_owner(void)\nmm/page_owner.c-112-{\n--\nmm/page_owner.c=161=struct page_ext_operations page_owner_ops = {\nmm/page_owner.c-162-\t.size = sizeof(struct page_owner),\nmm/page_owner.c:163:\t.need = need_page_owner,\nmm/page_owner.c-164-\t.init = init_page_owner,\n"
} |
| 53/2 | 2026/11/18 03:38 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 65541 output: 35 thoughts: 12 Thoughts: Okay, I'm ready to dive into this. Let's see... the `need_page_owner` concept. Here's how I'd break that down: **Considering the Need for a Page Owner** Alright, so the first thing that jumps to mind is the fundamental question: Why do we even need a designated "page owner"? What problem are we trying to solve? Is it about accountability? Ensuring someone has ultimate responsibility for the content's accuracy, relevance, and overall maintenance? Or is it more about governance, making sure changes align with broader organizational goals and standards? Perhaps it's a security issue – someone to vet contributions or control access levels? Then, the specifics become critical. If we *do* need a page owner, what are the *actual* responsibilities? Are we talking about simply approving changes, or actively creating and curating content? Are they expected to proactively monitor the page, or just react to issues? The level of commitment required will heavily influence who's suitable. And that brings me to the next point: what *qualifications* should we demand of this "owner?" Do they need technical expertise, subject matter knowledge, communication skills, or a combination of all three? The answers to these questions are crucial. We have to consider the potential for bottlenecks, too. If this person is the *only* gatekeeper, are we risking slowing down the content publishing process? Is there a contingency plan if they're unavailable? Maybe we need a tiered system – primary owner, secondary reviewer, etc. And how is this "ownership" going to be *enforced*? Is it a formal role within a system, or something more informal? That impacts the necessary tooling and workflows. Finally, let's not forget the user experience. Will the page owner be readily identifiable? Is there a mechanism for providing feedback or raising concerns directly to them? Transparency here is key for building trust. Essentially, a clearly defined role and process is essential to avoid confusion and maintain a smooth workflow. |
| 54/2 | 2026/11/18 03:39 | tool | read-file |
0mArgs:{
"File": "mm/page_owner.c",
"FirstLine": 110,
"LineCount": 10
}Results: {
"Contents": " 110:\t\n 111:\tstatic __init bool need_page_owner(void)\n 112:\t{\n 113:\t\treturn page_owner_enabled;\n 114:\t}\n 115:\t\n 116:\tstatic __always_inline depot_stack_handle_t create_dummy_stack(void)\n 117:\t{\n 118:\t\tunsigned long entries[4];\n 119:\t\tunsigned int nr_entries;\n"
} |
| 55/2 | 2026/11/18 03:39 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 66148 output: 278 thoughts: 1689 Thoughts: **My Analysis of the Stack Depot Patch** Okay, here's the breakdown. This patch introduces significant changes to the kernel's stack depot subsystem. My primary concern, as always, is understanding the implications for testing, fuzzing, and general observability of the kernel. First, let's establish the context. This patch primarily revolves around `lib/stackdepot.c` and associated header files, specifically targeting x86_64, introducing frame compression. We're talking about changes to `struct stack_record`, replacing the core `stack_depot_fetch` with `stack_depot_fetch_into`, and adjustments to `stack_depot_snprint` and `stack_depot_print`. The introduction of assertions using `WARN_ON_ONCE` is also noteworthy. Now, let's identify the key configurations that enable the code paths this patch touches. I need to make sure I am being precise here to ensure good test coverage. We need `STACKDEPOT` for the subsystem itself, `STACKDEPOT_ALWAYS_INIT` to ensure early initialization, `SLUB_DEBUG` to enable the use of `stack_depot_fetch_into` in SLUB, `PAGE_OWNER` to utilize it in `read_page_owner` and `stack_print`, and `DEBUG_KMEMLEAK` to trigger it via kmemleak. I also see that `STACKDEPOT_KUNIT_TEST` and `KUNIT` are needed for the KUnit tests, but I will not include these in the EnableConfigs I provide. The next step is to list the key FocusSymbols. The most relevant symbols to target for analysis are: `stack_depot_fetch_into`, which is the replacement for `stack_depot_fetch` in the depot API, `stack_depot_snprint`, `stack_depot_print`, `read_page_owner`, `stack_print`, and `__kmem_obj_info`. These functions are entry points that will exercise the new code. The changes to these functions warrant investigation. `read_page_owner` and `stack_print` are particularly interesting because they are debugfs entrypoints. I've decided to exclude `stack_depot_save` from the `FocusSymbols` list. It's invoked ubiquitously on memory allocation paths when memory debugging tools like KASAN are active. This is to avoid diluting fuzzing with hot paths that aren't specific to the patch. I also reviewed the static helper functions in `lib/stackdepot.c` to make sure I'm not missing anything. I confirmed that these functions are either `static inline` and inlined into `stackdepot.o` or static, so they are not exported and likely won't require kcov instrumentation, even if the surrounding code does. `stackdepot.o` is also compiled with `KCOV_INSTRUMENT_stackdepot.o := n`. This also impacts testing strategy. Finally, regarding the *reasoning* section: The aim is to concisely explain the core of the patch, the code it modifies, and the conditions under which it's exercised (specifically debugfs entrypoints used by `page_owner.c`, `slub`, and `kmemleak`). The key is to highlight how this enables deeper kernel introspection and debugging. |
| 56/2 | 2026/11/18 03:39 | tool | set-results |
0mArgs:{
"EnableConfigs": [
"STACKDEPOT",
"STACKDEPOT_ALWAYS_INIT",
"SLUB_DEBUG",
"PAGE_OWNER",
"DEBUG_KMEMLEAK"
],
"FocusSymbols": [
"stack_depot_fetch_into",
"stack_depot_snprint",
"stack_depot_print",
"read_page_owner",
"stack_print",
"__kmem_obj_info"
],
"Reasoning": "The patch introduces stack trace frame compression to the stack depot core subsystem (specifically compressing 64-bit kernel text addresses into 32-bit payloads on x86_64 and arm64), modifies struct stack_record, replaces stack_depot_fetch() with stack_depot_fetch_into() introducing new bounds and validation checks (WARN_ON_ONCE), and rewrites stack_depot_snprint() and stack_depot_print() to decode compressed frames. These code paths are fully reachable in virtualized environments. Ubiquitous allocation hot-paths (such as stack_depot_save, which executes on every allocation under KASAN) are excluded from FocusSymbols to avoid diluting fuzzing focus.",
"WorthFuzzing": true
}Results: {
"EnableConfigs": [
"STACKDEPOT",
"STACKDEPOT_ALWAYS_INIT",
"SLUB_DEBUG",
"PAGE_OWNER",
"DEBUG_KMEMLEAK"
],
"FocusSymbols": [
"stack_depot_fetch_into",
"stack_depot_snprint",
"stack_depot_print",
"read_page_owner",
"stack_print",
"__kmem_obj_info"
],
"Reasoning": "The patch introduces stack trace frame compression to the stack depot core subsystem (specifically compressing 64-bit kernel text addresses into 32-bit payloads on x86_64 and arm64), modifies struct stack_record, replaces stack_depot_fetch() with stack_depot_fetch_into() introducing new bounds and validation checks (WARN_ON_ONCE), and rewrites stack_depot_snprint() and stack_depot_print() to decode compressed frames. These code paths are fully reachable in virtualized environments. Ubiquitous allocation hot-paths (such as stack_depot_save, which executes on every allocation under KASAN) are excluded from FocusSymbols to avoid diluting fuzzing focus.",
"WorthFuzzing": true
} |
| 57/1 | 2026/11/18 03:39 | action | If |
14mArgs:{
"WorthFuzzing": true
}Results: null |
| 58/2 | 2026/11/18 03:39 | agent | kmsan-evaluator |
14mModel:core Args: null Results: {
"KMSANReasoning": "The patch series implements 32-bit frame compression for stack depot records on x86_64 and arm64, transitions the fetch API from stack_depot_fetch() returning internal pointers to stack_depot_fetch_into() writing into caller-provided buffers, and adds stack_depot_snprint().\n\nFrom an uninitialized memory perspective:\n1. Internal stack depot data structures: All fields in `struct stack_record` (including `size`, `flags`, and `compressed_entries`/`entries`) are completely written upon allocation in depot_alloc_stack(), followed by explicit kmsan_unpoison_memory(stack, record_size) annotations.\n2. Caller-provided buffers: In depot_copy_entries(), the copied frames are explicitly unpoisoned via kmsan_unpoison_memory(). All updated callers (kmemleak, page_owner, slub, kmsan report) strictly iterate up to the returned frame count `nr_entries`, avoiding any reads of trailing uninitialized buffer elements.\n3. User info-leaks: Stack depot data structures and stack frames are purely kernel-internal diagnostic data and are not copied to user space.\n4. KASAN vs KMSAN: Any potential issues arising from frame compression, index bounds, or array limits are out-of-bounds/corruption risks that are detected by standard KASAN and KUnit tests. There is no uninitialized memory risk uniquely detectable by KMSAN.",
"NeedsKMSAN": false
}Instruction: You are an expert Linux kernel security engineer specializing in kernel memory
error detectors (KASAN and KMSAN). Your job is to review the provided patch series and
determine if the code changes justify spawning a dedicated KMSAN (KernelMemorySanitizer)
fuzzing session in addition to standard KASAN fuzzing.
CRITICAL DISTINCTION BETWEEN KASAN AND KMSAN:
- Standard KASAN kernel builds (upstream-apparmor-kasan.config) already enable
a comprehensive suite of debugging tools and sanitizers, including KASAN
(out-of-bounds accesses, use-after-free, double free, invalid free), LOCKDEP
(locking bugs and deadlocks), UB-sanitizers, and memory corruption checks.
- KMSAN (KernelMemorySanitizer) detects reads of UNINITIALIZED memory (stack, heap,
or page allocations) and kernel-to-user memory info-leaks.
Rule: THERE IS NO SENSE IN RUNNING A KMSAN SESSION IF A BUG CAN BE CAUGHT BY KASAN,
LOCKDEP, OR OTHER STANDARD BUG DETECTORS.
A dedicated KMSAN fuzzing session incurs significant resource costs. You must ONLY
set NeedsKMSAN=true if the code changes introduce or expose UNINITIALIZED MEMORY risks
that are detected ONLY by KMSAN.
Look holistically at the patch series and surrounding code. Even if no direct
uninitialized field accesses or new buffer allocations are added in the diff itself,
a patch may alter control flow, bounds checking, or data length calculations in ways
that change how the rest of the code operates on existing buffers (e.g. allowing
uninitialized stack/heap memory to be read, copied to user space, or used in control
flow). Do not hesitate to use your code access tools to inspect the surrounding code,
called functions, and callers.
Set NeedsKMSAN=true ONLY IF the patch introduces or modifies:
1. Kernel structures sent to user space (via copy_to_user, put_user, netlink skb
attributes, ioctl output arguments, socket options, or BPF buffers) where fields
or structure padding might not be fully initialized/zeroed.
2. Conditional logic or branching that depends on potentially uninitialized variables
or struct fields.
3. Allocation or initialization of complex data structures where uninitialized fields
could be read later in reachable code paths.
4. Bounds checks, lengths, or logic in a way that allows surrounding code to access
uninitialized bytes of existing buffers.
Set NeedsKMSAN=false IF:
- The code changes primarily risk out-of-bounds access, array overflows, NULL pointer
dereferences, locking deadlocks, or use-after-free bugs (these are already caught
by KASAN, LOCKDEP, or standard bug detectors).
- All stack/heap structures touched or introduced by the patch are fully zeroed
or initialized (e.g. using = {0}, memset, kzalloc) before being read or copied.
- The patch does not introduce any risk of uninitialized memory usage or info-leaks.
Use your code access tools to inspect the surrounding code if necessary, then provide
detailed KMSANReasoning contrasting KASAN vs KMSAN applicability for this patch.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit 1904c3d1184586d2fb69893d04ebf95da88c8ff0
Author: syz-cluster <triage@syzkaller.com>
Date: Wed Nov 18 03:28:09 2026 +0000
syz-cluster: applied patch under review
diff --git a/arch/arm64/include/asm/stackdepot.h b/arch/arm64/include/asm/stackdepot.h
new file mode 100644
index 00000000000000..72053527ab219f
--- /dev/null
+++ b/arch/arm64/include/asm/stackdepot.h
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __ASM_STACKDEPOT_H
+#define __ASM_STACKDEPOT_H
+
+#include <linux/types.h>
+#include <asm/sections.h>
+
+/*
+ * Modules are allocated inside a 2 GB relocation window containing the
+ * kernel image. Store a signed 32-bit offset from _text so compression is
+ * independent of 4 GB high-bit boundaries crossed by that window.
+ */
+static inline unsigned long arch_stack_depot_frame_from_payload(u32 payload)
+{
+ return (unsigned long)_text + (s64)(s32)payload;
+}
+
+static inline bool
+arch_stack_depot_frame_try_compress(unsigned long frame, u32 *payload)
+{
+ u32 candidate;
+
+ candidate = (u32)(frame - (unsigned long)_text);
+ if (arch_stack_depot_frame_from_payload(candidate) != frame)
+ return false;
+
+ *payload = candidate;
+ return true;
+}
+
+static inline void
+arch_stack_depot_frame_decompress(u32 payload, unsigned long *frame)
+{
+ *frame = arch_stack_depot_frame_from_payload(payload);
+}
+
+#endif /* __ASM_STACKDEPOT_H */
diff --git a/arch/um/include/asm/Kbuild b/arch/um/include/asm/Kbuild
index 8fdc0bd9ab6fbc..14778d2457d790 100644
--- a/arch/um/include/asm/Kbuild
+++ b/arch/um/include/asm/Kbuild
@@ -21,6 +21,7 @@ generic-y += preempt.h
generic-y += ring_buffer.h
generic-y += runtime-const.h
generic-y += softirq_stack.h
+generic-y += stackdepot.h
generic-y += switch_to.h
generic-y += topology.h
generic-y += trace_clock.h
diff --git a/arch/x86/include/asm/stackdepot.h b/arch/x86/include/asm/stackdepot.h
new file mode 100644
index 00000000000000..9a8d04fa8c1c88
--- /dev/null
+++ b/arch/x86/include/asm/stackdepot.h
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_X86_STACKDEPOT_H
+#define _ASM_X86_STACKDEPOT_H
+
+#include <linux/types.h>
+
+#ifdef CONFIG_X86_64
+/*
+ * Compress canonical kernel text/module addresses whose upper 32 bits are all
+ * ones. Other kernel virtual addresses stay raw, so decompression reconstructs
+ * the original frame by restoring this prefix.
+ */
+#define STACK_DEPOT_X86_64_FRAME_PREFIX 0xffffffff00000000UL
+#define STACK_DEPOT_X86_64_FRAME_LOW_MASK 0x00000000ffffffffUL
+
+static inline bool
+arch_stack_depot_frame_try_compress(unsigned long frame, u32 *low)
+{
+ if ((frame & ~STACK_DEPOT_X86_64_FRAME_LOW_MASK) !=
+ STACK_DEPOT_X86_64_FRAME_PREFIX)
+ return false;
+
+ *low = (u32)frame;
+ return true;
+}
+
+static inline void
+arch_stack_depot_frame_decompress(u32 low, unsigned long *frame)
+{
+ *frame = STACK_DEPOT_X86_64_FRAME_PREFIX | low;
+}
+
+#else
+#include <asm-generic/stackdepot.h>
+#endif /* CONFIG_X86_64 */
+
+#endif /* _ASM_X86_STACKDEPOT_H */
diff --git a/drivers/gpu/drm/drm_modeset_lock.c b/drivers/gpu/drm/drm_modeset_lock.c
index e14814c30d8c06..f48b02379b711c 100644
--- a/drivers/gpu/drm/drm_modeset_lock.c
+++ b/drivers/gpu/drm/drm_modeset_lock.c
@@ -94,16 +94,13 @@ static noinline depot_stack_handle_t __drm_stack_depot_save(void)
static void __drm_stack_depot_print(depot_stack_handle_t stack_depot)
{
struct drm_printer p = drm_dbg_printer(NULL, DRM_UT_KMS, "drm_modeset_lock");
- unsigned long *entries;
- unsigned int nr_entries;
char *buf;
buf = kmalloc(PAGE_SIZE, GFP_NOWAIT | __GFP_NOWARN);
if (!buf)
return;
- nr_entries = stack_depot_fetch(stack_depot, &entries);
- stack_trace_snprint(buf, PAGE_SIZE, entries, nr_entries, 2);
+ stack_depot_snprint(stack_depot, buf, PAGE_SIZE, 2);
drm_printf(&p, "attempting to lock a contended lock without backoff:\n%s", buf);
diff --git a/include/asm-generic/Kbuild b/include/asm-generic/Kbuild
index b7a388bef6ea0a..76d4792a325af7 100644
--- a/include/asm-generic/Kbuild
+++ b/include/asm-generic/Kbuild
@@ -55,6 +55,7 @@ mandatory-y += serial.h
mandatory-y += shmparam.h
mandatory-y += simd.h
mandatory-y += softirq_stack.h
+mandatory-y += stackdepot.h
mandatory-y += switch_to.h
mandatory-y += timex.h
mandatory-y += tlbflush.h
diff --git a/include/asm-generic/stackdepot.h b/include/asm-generic/stackdepot.h
new file mode 100644
index 00000000000000..846975767bdd42
--- /dev/null
+++ b/include/asm-generic/stackdepot.h
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __ASM_GENERIC_STACKDEPOT_H
+#define __ASM_GENERIC_STACKDEPOT_H
+
+#include <linux/types.h>
+
+static inline bool
+arch_stack_depot_frame_try_compress(unsigned long frame, u32 *low)
+{
+ return false;
+}
+
+static inline void
+arch_stack_depot_frame_decompress(u32 low, unsigned long *frame)
+{
+ /* Generic code never compresses frames, so this hook is unreachable. */
+}
+
+#endif /* __ASM_GENERIC_STACKDEPOT_H */
diff --git a/include/linux/stackdepot.h b/include/linux/stackdepot.h
index 2cc21ffcdaf9e4..de42f6540266ae 100644
--- a/include/linux/stackdepot.h
+++ b/include/linux/stackdepot.h
@@ -20,6 +20,7 @@
#ifndef _LINUX_STACKDEPOT_H
#define _LINUX_STACKDEPOT_H
+#include <linux/bits.h>
#include <linux/gfp.h>
typedef u32 depot_stack_handle_t;
@@ -50,14 +51,19 @@ union handle_parts {
};
};
+/* Frames are compressed into @compressed_entries; see asm/stackdepot.h. */
+#define STACK_RECORD_COMPRESSED BIT(0)
+
struct stack_record {
struct list_head hash_list; /* Links in the hash table */
u32 hash; /* Hash in hash table */
- u32 size; /* Number of stored frames */
+ u16 size; /* Number of stored frames */
+ u16 flags; /* STACK_RECORD_* */
union handle_parts handle; /* Constant after initialization */
refcount_t count;
union {
unsigned long entries[CONFIG_STACKDEPOT_MAX_FRAMES]; /* Frames */
+ u32 compressed_entries[CONFIG_STACKDEPOT_MAX_FRAMES];
struct {
/*
* An important invariant of the implementation is to
@@ -189,15 +195,40 @@ depot_stack_handle_t stack_depot_save(unsigned long *entries,
struct stack_record *__stack_depot_get_stack_record(depot_stack_handle_t handle);
/**
- * stack_depot_fetch - Fetch a stack trace from stack depot
+ * stack_depot_fetch_into - Fetch a stack trace into caller-owned storage
*
- * @handle: Stack depot handle returned from stack_depot_save()
- * @entries: Pointer to store the address of the stack trace
+ * @handle: Stack depot handle
+ * @entries: Caller-owned buffer to copy the stack trace into
+ * @max_entries: Number of frames that fit in @entries
+ *
+ * Copies the stored frames into caller-owned @entries. If fewer frames are
+ * stored than @max_entries, only the stored frames are written and their count
+ * is returned. If more frames are stored than @max_entries, the copy is skipped
+ * entirely and 0 is returned.
+ *
+ * Passing a NULL @entries buffer or zero @max_entries for a valid @handle is
+ * invalid. Callers must provide storage for @max_entries frames.
+ *
+ * Callers should size @entries to match the save-side stack depth cap (for
+ * example, %CONFIG_STACKDEPOT_MAX_FRAMES or the local stack_trace_save() limit)
+ * when losing diagnostics on an undersized buffer would be surprising.
+ *
+ * A non-zero invalid @handle, including a post-put handle, may WARN. Its return
+ * value and copied contents are undefined because the record may have been
+ * reused for another stack.
+ *
+ * Callers must ensure @handle remains valid for the duration of this call.
+ * Persistent handles saved without %STACK_DEPOT_FLAG_GET require no extra
+ * reference; handles saved with %STACK_DEPOT_FLAG_GET require a held reference.
+ * Callers must not call stack_depot_put() on persistent handles.
+ * Racing this helper with stack_depot_put() on the same handle is invalid.
*
- * Return: Number of frames for the fetched stack
+ * Return: Number of frames copied, 0 if @handle is 0, stack depot is disabled,
+ * or @max_entries is less than the number of stored frames.
*/
-unsigned int stack_depot_fetch(depot_stack_handle_t handle,
- unsigned long **entries);
+unsigned int stack_depot_fetch_into(depot_stack_handle_t handle,
+ unsigned long *entries,
+ unsigned int max_entries);
/**
* stack_depot_print - Print a stack trace from stack depot
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 2d22638ec13a63..861d0caf939130 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -2818,6 +2818,22 @@ config RESOURCE_KUNIT_TEST
If unsure, say N.
+config STACKDEPOT_KUNIT_TEST
+ bool "KUnit test for stack depot" if !KUNIT_ALL_TESTS
+ depends on KUNIT=y && STACKDEPOT
+ depends on STACKDEPOT_MAX_FRAMES >= 3
+ default KUNIT_ALL_TESTS
+ help
+ Enable this option to test stack depot API behavior at boot.
+ This test is built in, so KUNIT must also be built in.
+
+ KUnit tests run during boot and output the results to the debug log
+ in TAP format (https://testanything.org/). Only useful for kernel
+ developers running the KUnit test harness, and not intended for
+ inclusion into a production build.
+
+ If unsure, say N.
+
config SYSCTL_KUNIT_TEST
tristate "KUnit test for sysctl" if !KUNIT_ALL_TESTS
depends on KUNIT
diff --git a/lib/stackdepot.c b/lib/stackdepot.c
index 90c52f2e0d3f42..f323f1e97e1295 100644
--- a/lib/stackdepot.c
+++ b/lib/stackdepot.c
@@ -36,6 +36,8 @@
#include <linux/memblock.h>
#include <linux/kasan-enabled.h>
+#include <asm/stackdepot.h>
+
/*
* The pool_index is offset by 1 so the first record does not have a 0 handle.
*/
@@ -94,6 +96,7 @@ static const char *const counter_names[] = {
[DEPOT_COUNTER_PERSIST_BYTES] = "persistent_bytes",
};
static_assert(ARRAY_SIZE(counter_names) == DEPOT_COUNTER_COUNT);
+static_assert(CONFIG_STACKDEPOT_MAX_FRAMES <= U16_MAX);
static int __init disable_stack_depot(char *str)
{
@@ -419,9 +422,37 @@ static struct stack_record *depot_pop_free(void)
return stack;
}
-static inline size_t depot_stack_record_size(struct stack_record *s, unsigned int nr_entries)
+/* Check whether every frame of a stack can be stored in 32 bits. */
+static bool depot_entries_compressible(const unsigned long *entries,
+ unsigned int nr_entries)
+{
+ u32 payload;
+
+ for (unsigned int i = 0; i < nr_entries; i++) {
+ if (!arch_stack_depot_frame_try_compress(entries[i], &payload))
+ return false;
+ }
+ return true;
+}
+
+static inline unsigned long depot_stack_entry(const struct stack_record *stack,
+ unsigned int i)
{
- const size_t used = flex_array_size(s, entries, nr_entries);
+ unsigned long frame;
+
+ if (!(stack->flags & STACK_RECORD_COMPRESSED))
+ return stack->entries[i];
+ arch_stack_depot_frame_decompress(stack->compressed_entries[i], &frame);
+ return frame;
+}
+
+static inline size_t depot_stack_record_size(struct stack_record *s,
+ unsigned int nr_entries,
+ bool compressed)
+{
+ const size_t used = compressed ?
+ flex_array_size(s, compressed_entries, nr_entries) :
+ flex_array_size(s, entries, nr_entries);
const size_t unused = sizeof(s->entries) - used;
WARN_ON_ONCE(sizeof(s->entries) < used);
@@ -436,6 +467,7 @@ depot_alloc_stack(unsigned long *entries, unsigned int nr_entries, u32 hash, dep
{
struct stack_record *stack = NULL;
size_t record_size;
+ bool compressed = false;
lockdep_assert_held(&pool_lock);
@@ -452,10 +484,13 @@ depot_alloc_stack(unsigned long *entries, unsigned int nr_entries, u32 hash, dep
* Evictable entries have to allocate the max. size so they may
* safely be re-used by differently sized allocations.
*/
- record_size = depot_stack_record_size(stack, CONFIG_STACKDEPOT_MAX_FRAMES);
+ record_size = depot_stack_record_size(stack,
+ CONFIG_STACKDEPOT_MAX_FRAMES,
+ false);
stack = depot_pop_free();
} else {
- record_size = depot_stack_record_size(stack, nr_entries);
+ compressed = depot_entries_compressible(entries, nr_entries);
+ record_size = depot_stack_record_size(stack, nr_entries, compressed);
}
if (!stack) {
@@ -468,7 +503,16 @@ depot_alloc_stack(unsigned long *entries, unsigned int nr_entries, u32 hash, dep
stack->hash = hash;
stack->size = nr_entries;
/* stack->handle is already filled in by depot_pop_free_pool(). */
- memcpy(stack->entries, entries, flex_array_size(stack, entries, nr_entries));
+ if (compressed) {
+ stack->flags = STACK_RECORD_COMPRESSED;
+ for (unsigned int i = 0; i < nr_entries; i++)
+ arch_stack_depot_frame_try_compress(entries[i],
+ &stack->compressed_entries[i]);
+ } else {
+ stack->flags = 0;
+ memcpy(stack->entries, entries,
+ flex_array_size(stack, entries, nr_entries));
+ }
if (flags & STACK_DEPOT_FLAG_GET) {
refcount_set(&stack->count, 1);
@@ -588,6 +632,20 @@ int stackdepot_memcmp(const unsigned long *u1, const unsigned long *u2,
return 0;
}
+static inline bool depot_stack_equal(const struct stack_record *stack,
+ const unsigned long *entries,
+ unsigned int size)
+{
+ if (!(stack->flags & STACK_RECORD_COMPRESSED))
+ return !stackdepot_memcmp(entries, stack->entries, size);
+
+ for (unsigned int i = 0; i < size; i++) {
+ if (depot_stack_entry(stack, i) != entries[i])
+ return false;
+ }
+ return true;
+}
+
/* Finds a stack in a bucket of the hash table. */
static inline struct stack_record *find_stack(struct list_head *bucket,
unsigned long *entries, int size,
@@ -615,7 +673,7 @@ static inline struct stack_record *find_stack(struct list_head *bucket,
* management state unioned with @entries. The refcount is zero
* in that case and the below refcount_inc_not_zero() will fail.
*/
- if (data_race(stackdepot_memcmp(entries, stack->entries, size)))
+ if (!data_race(depot_stack_equal(stack, entries, size)))
continue;
/*
@@ -757,33 +815,59 @@ struct stack_record *__stack_depot_get_stack_record(depot_stack_handle_t handle)
return depot_fetch_stack(handle);
}
-unsigned int stack_depot_fetch(depot_stack_handle_t handle,
- unsigned long **entries)
+/* Copy the first @nr_entries frames of @stack into @entries. */
+static void depot_copy_entries(const struct stack_record *stack,
+ unsigned long *entries, unsigned int nr_entries)
+{
+ for (unsigned int i = 0; i < nr_entries; i++)
+ entries[i] = depot_stack_entry(stack, i);
+ /* stackdepot.c is not instrumented; tell KMSAN the copy is initialized. */
+ kmsan_unpoison_memory(entries, nr_entries * sizeof(*entries));
+}
+
+unsigned int stack_depot_fetch_into(depot_stack_handle_t handle,
+ unsigned long *entries,
+ unsigned int max_entries)
{
struct stack_record *stack;
+ unsigned int nr_entries;
- *entries = NULL;
- /*
- * Let KMSAN know *entries is initialized. This shall prevent false
- * positive reports if instrumented code accesses it.
- */
- kmsan_unpoison_memory(entries, sizeof(*entries));
+ if (!handle)
+ return 0;
+ if (stack_depot_disabled)
+ return 0;
+ if (WARN_ON_ONCE(!entries || !max_entries))
+ return 0;
- if (!handle || stack_depot_disabled)
+ stack = depot_fetch_stack(handle);
+ if (!stack)
return 0;
+ nr_entries = stack->size;
+ if (WARN_ON_ONCE(!nr_entries))
+ return 0;
+ if (nr_entries > max_entries)
+ return 0;
+
+ depot_copy_entries(stack, entries, nr_entries);
+ return nr_entries;
+}
+EXPORT_SYMBOL_GPL(stack_depot_fetch_into);
+
+static struct stack_record *depot_print_fetch(depot_stack_handle_t handle)
+{
+ struct stack_record *stack;
+
+ if (!handle || stack_depot_disabled)
+ return NULL;
stack = depot_fetch_stack(handle);
/*
* Should never be NULL, otherwise this is a use-after-put (or just a
* corrupt handle).
*/
- if (WARN(!stack, "corrupt handle or use after stack_depot_put()"))
- return 0;
-
- *entries = stack->entries;
- return stack->size;
+ WARN(!stack, "corrupt handle or use after stack_depot_put()");
+ return stack;
}
-EXPORT_SYMBOL_GPL(stack_depot_fetch);
void stack_depot_put(depot_stack_handle_t handle)
{
@@ -805,26 +889,42 @@ void stack_depot_put(depot_stack_handle_t handle)
}
EXPORT_SYMBOL_GPL(stack_depot_put);
-void stack_depot_print(depot_stack_handle_t stack)
+void stack_depot_print(depot_stack_handle_t handle)
{
- unsigned long *entries;
- unsigned int nr_entries;
+ struct stack_record *stack = depot_print_fetch(handle);
+ unsigned long frame;
- nr_entries = stack_depot_fetch(stack, &entries);
- if (nr_entries > 0)
- stack_trace_print(entries, nr_entries, 0);
+ if (!stack)
+ return;
+ for (unsigned int i = 0; i < stack->size; i++) {
+ frame = depot_stack_entry(stack, i);
+ kmsan_unpoison_memory(&frame, sizeof(frame));
+ stack_trace_print(&frame, 1, 0);
+ }
}
EXPORT_SYMBOL_GPL(stack_depot_print);
int stack_depot_snprint(depot_stack_handle_t handle, char *buf, size_t size,
int spaces)
{
- unsigned long *entries;
- unsigned int nr_entries;
+ struct stack_record *stack = depot_print_fetch(handle);
+ unsigned int generated, total = 0;
+ unsigned long frame;
- nr_entries = stack_depot_fetch(handle, &entries);
- return nr_entries ? stack_trace_snprint(buf, size, entries, nr_entries,
- spaces) : 0;
+ if (!stack)
+ return 0;
+ for (unsigned int i = 0; i < stack->size && size; i++) {
+ frame = depot_stack_entry(stack, i);
+ kmsan_unpoison_memory(&frame, sizeof(frame));
+ generated = stack_trace_snprint(buf, size, &frame, 1, spaces);
+ total += generated;
+ /* Stop once @buf is full, as stack_trace_snprint() does. */
+ if (generated >= size)
+ break;
+ buf += generated;
+ size -= generated;
+ }
+ return total;
}
EXPORT_SYMBOL_GPL(stack_depot_snprint);
diff --git a/lib/tests/Makefile b/lib/tests/Makefile
index df0537e1b91faf..bc6532d881505f 100644
--- a/lib/tests/Makefile
+++ b/lib/tests/Makefile
@@ -49,6 +49,7 @@ obj-$(CONFIG_RANDSTRUCT_KUNIT_TEST) += randstruct_kunit.o
obj-$(CONFIG_SCANF_KUNIT_TEST) += scanf_kunit.o
obj-$(CONFIG_SEQ_BUF_KUNIT_TEST) += seq_buf_kunit.o
obj-$(CONFIG_SLUB_KUNIT_TEST) += slub_kunit.o
+obj-$(CONFIG_STACKDEPOT_KUNIT_TEST) += stackdepot_kunit.o
obj-$(CONFIG_TEST_SORT) += test_sort.o
CFLAGS_stackinit_kunit.o += $(call cc-disable-warning, switch-unreachable)
obj-$(CONFIG_STACKINIT_KUNIT_TEST) += stackinit_kunit.o
diff --git a/lib/tests/stackdepot_kunit.c b/lib/tests/stackdepot_kunit.c
new file mode 100644
index 00000000000000..abcc34844125ac
--- /dev/null
+++ b/lib/tests/stackdepot_kunit.c
@@ -0,0 +1,312 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <kunit/test.h>
+#include <linux/array_size.h>
+#include <linux/gfp.h>
+#include <linux/limits.h>
+#include <linux/minmax.h>
+#include <linux/stacktrace.h>
+#include <linux/stackdepot.h>
+#include <linux/string.h>
+
+#include <asm/stackdepot.h>
+
+#ifdef CONFIG_ARM64
+#include <asm/sections.h>
+
+static inline unsigned long stackdepot_arm64_frame(long offset)
+{
+ return (unsigned long)((long)_text + offset);
+}
+#endif
+
+static void stackdepot_fetch_into_roundtrip(struct kunit *test)
+{
+ unsigned long entries[] = {
+ 0x101000UL,
+ 0x102000UL,
+ 0x103000UL,
+ };
+ unsigned long exact[ARRAY_SIZE(entries)] = {};
+ unsigned long fetched[ARRAY_SIZE(entries) + 1] = {
+ [ARRAY_SIZE(entries)] = 0xa5a5a5a5UL,
+ };
+ unsigned long expected_tail = fetched[ARRAY_SIZE(entries)];
+ depot_stack_handle_t handle;
+ unsigned int nr_entries;
+
+ KUNIT_ASSERT_EQ(test, stack_depot_init(), 0);
+
+ handle = stack_depot_save(entries, ARRAY_SIZE(entries), GFP_KERNEL);
+ KUNIT_ASSERT_NE(test, handle, (depot_stack_handle_t)0);
+
+ nr_entries = stack_depot_fetch_into(handle, exact, ARRAY_SIZE(exact));
+ KUNIT_EXPECT_EQ(test, nr_entries, (unsigned int)ARRAY_SIZE(entries));
+ KUNIT_EXPECT_MEMEQ(test, exact, entries, sizeof(entries));
+
+ nr_entries = stack_depot_fetch_into(handle, fetched, ARRAY_SIZE(fetched));
+ KUNIT_EXPECT_EQ(test, nr_entries, (unsigned int)ARRAY_SIZE(entries));
+ KUNIT_EXPECT_MEMEQ(test, fetched, entries, sizeof(entries));
+ KUNIT_EXPECT_EQ(test, fetched[ARRAY_SIZE(entries)], expected_tail);
+}
+
+static void stackdepot_fetch_into_rejects_missing_or_short_stack(struct kunit *test)
+{
+ unsigned long entries[] = {
+ 0x111000UL,
+ 0x112000UL,
+ 0x113000UL,
+ };
+ unsigned long fetched[ARRAY_SIZE(entries)] = {
+ 0xa1a1a1a1UL,
+ 0xb2b2b2b2UL,
+ 0xc3c3c3c3UL,
+ };
+ unsigned long expected[ARRAY_SIZE(fetched)];
+ depot_stack_handle_t handle;
+ unsigned int nr_entries;
+
+ KUNIT_ASSERT_EQ(test, stack_depot_init(), 0);
+
+ handle = stack_depot_save(entries, ARRAY_SIZE(entries), GFP_KERNEL);
+ KUNIT_ASSERT_NE(test, handle, (depot_stack_handle_t)0);
+ memcpy(expected, fetched, sizeof(expected));
+
+ nr_entries = stack_depot_fetch_into(0, fetched, ARRAY_SIZE(fetched));
+ KUNIT_EXPECT_EQ(test, nr_entries, 0U);
+ KUNIT_EXPECT_MEMEQ(test, fetched, expected, sizeof(expected));
+
+ nr_entries = stack_depot_fetch_into(0, NULL, 0);
+ KUNIT_EXPECT_EQ(test, nr_entries, 0U);
+
+ nr_entries = stack_depot_fetch_into(handle, fetched,
+ ARRAY_SIZE(fetched) - 1);
+ KUNIT_EXPECT_EQ(test, nr_entries, 0U);
+ KUNIT_EXPECT_MEMEQ(test, fetched, expected, sizeof(expected));
+}
+
+static void stackdepot_frame_raw_fallback(struct kunit *test)
+{
+ unsigned long frame = 0x1000UL;
+ bool compressed;
+ u32 payload;
+
+#ifdef CONFIG_ARM64
+ frame = (unsigned long)_text + (unsigned long)S32_MAX + 1UL;
+#endif
+
+ compressed = arch_stack_depot_frame_try_compress(frame, &payload);
+ KUNIT_EXPECT_FALSE(test, compressed);
+}
+
+#if defined(CONFIG_X86_64) && !defined(CONFIG_UML)
+static void stackdepot_frame_x86_64(struct kunit *test)
+{
+ unsigned long direct_map = 0xffff888000001000UL;
+ unsigned long frame = 0xffffffff81234567UL;
+ unsigned long out;
+ bool compressed;
+ u32 low;
+
+ compressed = arch_stack_depot_frame_try_compress(frame, &low);
+ KUNIT_EXPECT_TRUE(test, compressed);
+ KUNIT_EXPECT_EQ(test, low, (u32)0x81234567);
+ arch_stack_depot_frame_decompress(low, &out);
+ KUNIT_EXPECT_EQ(test, out, frame);
+
+ compressed = arch_stack_depot_frame_try_compress(direct_map, &low);
+ KUNIT_EXPECT_FALSE(test, compressed);
+}
+#endif /* CONFIG_X86_64 && !CONFIG_UML */
+
+#ifdef CONFIG_ARM64
+static void stackdepot_frame_arm64(struct kunit *test)
+{
+ long negative_offset = S32_MIN;
+ long positive_offset = S32_MAX;
+ long offset = 0x123456;
+ unsigned long frame = stackdepot_arm64_frame(offset);
+ unsigned long out;
+ bool compressed;
+ u32 payload;
+
+ compressed = arch_stack_depot_frame_try_compress(frame, &payload);
+ KUNIT_EXPECT_TRUE(test, compressed);
+ KUNIT_EXPECT_EQ(test, payload, (u32)(s32)offset);
+ arch_stack_depot_frame_decompress(payload, &out);
+ KUNIT_EXPECT_EQ(test, out, frame);
+
+ frame = stackdepot_arm64_frame(negative_offset);
+ compressed = arch_stack_depot_frame_try_compress(frame, &payload);
+ KUNIT_EXPECT_TRUE(test, compressed);
+ KUNIT_EXPECT_EQ(test, payload, (u32)(s32)negative_offset);
+ arch_stack_depot_frame_decompress(payload, &out);
+ KUNIT_EXPECT_EQ(test, out, frame);
+
+ frame = stackdepot_arm64_frame(positive_offset);
+ compressed = arch_stack_depot_frame_try_compress(frame, &payload);
+ KUNIT_EXPECT_TRUE(test, compressed);
+ KUNIT_EXPECT_EQ(test, payload, (u32)(s32)positive_offset);
+ arch_stack_depot_frame_decompress(payload, &out);
+ KUNIT_EXPECT_EQ(test, out, frame);
+}
+#endif /* CONFIG_ARM64 */
+
+#if (defined(CONFIG_X86_64) && !defined(CONFIG_UML)) || defined(CONFIG_ARM64)
+#define STACKDEPOT_TEST_COMPRESSED
+
+/* Return a distinct compressible frame for each @i. */
+static unsigned long stackdepot_compressible_frame(unsigned int i)
+{
+#ifdef CONFIG_ARM64
+ return stackdepot_arm64_frame(0x1000L * (i + 1));
+#else
+ return 0xffffffff81000000UL + 0x1000UL * (i + 1);
+#endif
+}
+
+/* Return a frame that cannot be compressed but has the same 32-bit payload. */
+static unsigned long stackdepot_raw_frame(unsigned int i)
+{
+#ifdef CONFIG_ARM64
+ return stackdepot_compressible_frame(i) + BIT_ULL(32);
+#else
+ return stackdepot_compressible_frame(i) & U32_MAX;
+#endif
+}
+
+static void stackdepot_compressed_frames(struct kunit *test)
+{
+ unsigned long compressible[3], mixed[3], fetched[3];
+ depot_stack_handle_t compressed_handle, mixed_handle;
+ struct stack_record *record;
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_SIZE(compressible); i++)
+ compressible[i] = stackdepot_compressible_frame(0x100 + i);
+ memcpy(mixed, compressible, sizeof(mixed));
+ mixed[1] = stackdepot_raw_frame(0x101);
+
+ KUNIT_ASSERT_EQ(test, stack_depot_init(), 0);
+
+ compressed_handle = stack_depot_save(compressible,
+ ARRAY_SIZE(compressible), GFP_KERNEL);
+ KUNIT_ASSERT_NE(test, compressed_handle, (depot_stack_handle_t)0);
+ mixed_handle = stack_depot_save(mixed, ARRAY_SIZE(mixed), GFP_KERNEL);
+ KUNIT_ASSERT_NE(test, mixed_handle, (depot_stack_handle_t)0);
+ /* Equal payloads must not make different stacks compare equal. */
+ KUNIT_EXPECT_NE(test, compressed_handle, mixed_handle);
+ KUNIT_EXPECT_EQ(test, stack_depot_save(compressible, ARRAY_SIZE(compressible),
+ GFP_KERNEL), compressed_handle);
+
+ record = __stack_depot_get_stack_record(compressed_handle);
+ KUNIT_ASSERT_NOT_NULL(test, record);
+ KUNIT_EXPECT_TRUE(test, record->flags & STACK_RECORD_COMPRESSED);
+ record = __stack_depot_get_stack_record(mixed_handle);
+ KUNIT_ASSERT_NOT_NULL(test, record);
+ KUNIT_EXPECT_FALSE(test, record->flags & STACK_RECORD_COMPRESSED);
+
+ KUNIT_EXPECT_EQ(test, stack_depot_fetch_into(compressed_handle, fetched,
+ ARRAY_SIZE(fetched)),
+ (unsigned int)ARRAY_SIZE(compressible));
+ KUNIT_EXPECT_MEMEQ(test, fetched, compressible, sizeof(compressible));
+ KUNIT_EXPECT_EQ(test, stack_depot_fetch_into(mixed_handle, fetched,
+ ARRAY_SIZE(fetched)),
+ (unsigned int)ARRAY_SIZE(mixed));
+ KUNIT_EXPECT_MEMEQ(test, fetched, mixed, sizeof(mixed));
+}
+
+/* Evictable records are max-size, so their frames are not compressed. */
+static void stackdepot_get_record_not_compressed(struct kunit *test)
+{
+ unsigned long entries[3], fetched[3];
+ depot_stack_handle_t handle;
+ struct stack_record *record;
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_SIZE(entries); i++)
+ entries[i] = stackdepot_compressible_frame(0x200 + i);
+
+ KUNIT_ASSERT_EQ(test, stack_depot_init(), 0);
+
+ handle = stack_depot_save_flags(entries, ARRAY_SIZE(entries), GFP_KERNEL,
+ STACK_DEPOT_FLAG_CAN_ALLOC |
+ STACK_DEPOT_FLAG_GET);
+ KUNIT_ASSERT_NE(test, handle, (depot_stack_handle_t)0);
+ record = __stack_depot_get_stack_record(handle);
+ KUNIT_ASSERT_NOT_NULL(test, record);
+ KUNIT_EXPECT_FALSE(test, record->flags & STACK_RECORD_COMPRESSED);
+ KUNIT_EXPECT_EQ(test, stack_depot_fetch_into(handle, fetched,
+ ARRAY_SIZE(fetched)),
+ (unsigned int)ARRAY_SIZE(entries));
+ KUNIT_EXPECT_MEMEQ(test, fetched, entries, sizeof(entries));
+ stack_depot_put(handle);
+}
+#endif
+
+/* stack_depot_snprint() must match stack_trace_snprint(), with truncation. */
+static void stackdepot_snprint_matches_stack_trace(struct kunit *test)
+{
+ const unsigned int nr = min(40, CONFIG_STACKDEPOT_MAX_FRAMES);
+ const size_t size = 4096;
+ unsigned long entries[40];
+ depot_stack_handle_t handle;
+ char *got, *want;
+ unsigned int i;
+
+ for (i = 0; i < nr; i++) {
+#ifdef STACKDEPOT_TEST_COMPRESSED
+ entries[i] = stackdepot_compressible_frame(0x300 + i);
+#else
+ entries[i] = 0x301000UL + 0x1000UL * i;
+#endif
+ }
+ got = kunit_kzalloc(test, size, GFP_KERNEL);
+ want = kunit_kzalloc(test, size, GFP_KERNEL);
+ KUNIT_ASSERT_NOT_NULL(test, got);
+ KUNIT_ASSERT_NOT_NULL(test, want);
+
+ KUNIT_ASSERT_EQ(test, stack_depot_init(), 0);
+ handle = stack_depot_save(entries, nr, GFP_KERNEL);
+ KUNIT_ASSERT_NE(test, handle, (depot_stack_handle_t)0);
+
+ KUNIT_EXPECT_EQ(test, stack_depot_snprint(handle, got, size, 2),
+ stack_trace_snprint(want, size, entries, nr, 2));
+ KUNIT_EXPECT_STREQ(test, got, want);
+
+ /* Truncate part-way through the trace. */
+ memset(got, 0, size);
+ memset(want, 0, size);
+ KUNIT_EXPECT_EQ(test, stack_depot_snprint(handle, got, 700, 0),
+ stack_trace_snprint(want, 700, entries, nr, 0));
+ KUNIT_EXPECT_STREQ(test, got, want);
+}
+
+static struct kunit_case stackdepot_test_cases[] = {
+ KUNIT_CASE(stackdepot_fetch_into_roundtrip),
+ KUNIT_CASE(stackdepot_fetch_into_rejects_missing_or_short_stack),
+ KUNIT_CASE(stackdepot_snprint_matches_stack_trace),
+ KUNIT_CASE(stackdepot_frame_raw_fallback),
+#if defined(CONFIG_X86_64) && !defined(CONFIG_UML)
+ KUNIT_CASE(stackdepot_frame_x86_64),
+#endif
+#ifdef CONFIG_ARM64
+ KUNIT_CASE(stackdepot_frame_arm64),
+#endif
+#ifdef STACKDEPOT_TEST_COMPRESSED
+ KUNIT_CASE(stackdepot_compressed_frames),
+ KUNIT_CASE(stackdepot_get_record_not_compressed),
+#endif
+ {}
+};
+
+static struct kunit_suite stackdepot_test_suite = {
+ .name = "stackdepot",
+ .test_cases = stackdepot_test_cases,
+};
+
+kunit_test_suite(stackdepot_test_suite);
+
+MODULE_DESCRIPTION("KUnit tests for stack depot");
+MODULE_AUTHOR("Caleb Kan <ckan@cloudflare.com>");
+MODULE_LICENSE("GPL");
diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index 20c0eb41c8730b..61ff4a10ce11e2 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -378,10 +378,10 @@ static void __print_unreferenced(struct seq_file *seq,
bool hex_dump)
{
int i;
- unsigned long *entries;
+ unsigned long entries[MAX_TRACE];
unsigned int nr_entries;
- nr_entries = stack_depot_fetch(object->trace_handle, &entries);
+ nr_entries = stack_depot_fetch_into(object->trace_handle, entries, ARRAY_SIZE(entries));
warn_or_seq_printf(seq, "unreferenced object%s 0x%08lx (size %zu):\n",
__object_type_str(object),
object->pointer, object->size);
diff --git a/mm/kmsan/kmsan_test.c b/mm/kmsan/kmsan_test.c
index 31f47cc4dab400..7c04e4b21873d9 100644
--- a/mm/kmsan/kmsan_test.c
+++ b/mm/kmsan/kmsan_test.c
@@ -669,7 +669,7 @@ static void test_long_origin_chain(struct kunit *test)
*/
static void test_stackdepot_roundtrip(struct kunit *test)
{
- unsigned long src_entries[16], *dst_entries;
+ unsigned long src_entries[16], dst_entries[16];
unsigned int src_nentries, dst_nentries;
EXPECTATION_NO_REPORT(expect);
depot_stack_handle_t handle;
@@ -680,7 +680,7 @@ static void test_stackdepot_roundtrip(struct kunit *test)
stack_trace_save(src_entries, ARRAY_SIZE(src_entries), 1);
handle = stack_depot_save(src_entries, src_nentries, GFP_KERNEL);
stack_depot_print(handle);
- dst_nentries = stack_depot_fetch(handle, &dst_entries);
+ dst_nentries = stack_depot_fetch_into(handle, dst_entries, ARRAY_SIZE(dst_entries));
KUNIT_EXPECT_TRUE(test, src_nentries == dst_nentries);
kmsan_check_memory((void *)dst_entries,
diff --git a/mm/kmsan/report.c b/mm/kmsan/report.c
index d6853ce089541d..0770658ba932e5 100644
--- a/mm/kmsan/report.c
+++ b/mm/kmsan/report.c
@@ -83,9 +83,9 @@ static char *pretty_descr(char *descr)
return report_local_descr;
}
-void kmsan_print_origin(depot_stack_handle_t origin)
+static void kmsan_print_origin_with_buf(depot_stack_handle_t origin,
+ unsigned long *entries)
{
- unsigned long *entries = NULL, *chained_entries = NULL;
unsigned int nr_entries, chained_nr_entries, skipnr;
void *pc1 = NULL, *pc2 = NULL;
depot_stack_handle_t head;
@@ -97,7 +97,8 @@ void kmsan_print_origin(depot_stack_handle_t origin)
return;
while (true) {
- nr_entries = stack_depot_fetch(origin, &entries);
+ nr_entries =
+ stack_depot_fetch_into(origin, entries, KMSAN_STACK_DEPTH);
depth = kmsan_depth_from_eb(stack_depot_get_extra_bits(origin));
magic = nr_entries ? entries[0] : 0;
if ((nr_entries == 4) && (magic == KMSAN_ALLOCA_MAGIC_ORIGIN)) {
@@ -123,14 +124,10 @@ void kmsan_print_origin(depot_stack_handle_t origin)
origin = entries[2];
pr_err("Uninit was stored to memory at:\n");
chained_nr_entries =
- stack_depot_fetch(head, &chained_entries);
- kmsan_internal_unpoison_memory(
- chained_entries,
- chained_nr_entries * sizeof(*chained_entries),
- /*checked*/ false);
- skipnr = get_stack_skipnr(chained_entries,
- chained_nr_entries);
- stack_trace_print(chained_entries + skipnr,
+ stack_depot_fetch_into(head, entries,
+ KMSAN_STACK_DEPTH);
+ skipnr = get_stack_skipnr(entries, chained_nr_entries);
+ stack_trace_print(entries + skipnr,
chained_nr_entries - skipnr, 0);
pr_err("\n");
continue;
@@ -147,6 +144,13 @@ void kmsan_print_origin(depot_stack_handle_t origin)
}
}
+void kmsan_print_origin(depot_stack_handle_t origin)
+{
+ unsigned long entries[KMSAN_STACK_DEPTH];
+
+ kmsan_print_origin_with_buf(origin, entries);
+}
+
void kmsan_report(depot_stack_handle_t origin, void *address, int size,
int off_first, int off_last, const void __user *user_addr,
enum kmsan_bug_reason reason)
@@ -193,7 +197,7 @@ void kmsan_report(depot_stack_handle_t origin, void *address, int size,
0);
pr_err("\n");
- kmsan_print_origin(origin);
+ kmsan_print_origin_with_buf(origin, stack_entries);
if (size) {
pr_err("\n");
diff --git a/mm/page_owner.c b/mm/page_owner.c
index cfc31c92d76570..16429e70e00df8 100644
--- a/mm/page_owner.c
+++ b/mm/page_owner.c
@@ -1068,8 +1068,8 @@ static int stack_print(struct seq_file *m, void *v)
{
int i, nr_base_pages;
struct stack *stack = v;
- unsigned long *entries;
- unsigned long nr_entries;
+ unsigned long entries[PAGE_OWNER_STACK_DEPTH];
+ unsigned int nr_entries;
struct stack_record *stack_record = stack->stack_record;
struct stack_print_ctx *ctx = m->private;
@@ -1083,8 +1083,8 @@ static int stack_print(struct seq_file *m, void *v)
return 0;
if (ctx->flags & STACK_PRINT_FLAG_STACK) {
- nr_entries = stack_record->size;
- entries = stack_record->entries;
+ nr_entries = stack_depot_fetch_into(stack_record->handle.handle,
+ entries, ARRAY_SIZE(entries));
for (i = 0; i < nr_entries; i++)
seq_printf(m, " %pS\n", (void *)entries[i]);
}
diff --git a/mm/slub.c b/mm/slub.c
index cd671b93471918..32e6597a5c033c 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -8328,12 +8328,12 @@ void __kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct slab *slab)
#ifdef CONFIG_STACKDEPOT
{
depot_stack_handle_t handle;
- unsigned long *entries;
+ unsigned long entries[TRACK_ADDRS_COUNT];
unsigned int nr_entries;
handle = READ_ONCE(trackp->handle);
if (handle) {
- nr_entries = stack_depot_fetch(handle, &entries);
+ nr_entries = stack_depot_fetch_into(handle, entries, ARRAY_SIZE(entries));
for (i = 0; i < KS_ADDRS_COUNT && i < nr_entries; i++)
kpp->kp_stack[i] = (void *)entries[i];
}
@@ -8341,7 +8341,7 @@ void __kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct slab *slab)
trackp = get_track(s, objp, TRACK_FREE);
handle = READ_ONCE(trackp->handle);
if (handle) {
- nr_entries = stack_depot_fetch(handle, &entries);
+ nr_entries = stack_depot_fetch_into(handle, entries, ARRAY_SIZE(entries));
for (i = 0; i < KS_ADDRS_COUNT && i < nr_entries; i++)
kpp->kp_free_stack[i] = (void *)entries[i];
}
@@ -10031,12 +10031,14 @@ static int slab_debugfs_show(struct seq_file *seq, void *v)
#ifdef CONFIG_STACKDEPOT
{
depot_stack_handle_t handle;
- unsigned long *entries;
+ unsigned long entries[TRACK_ADDRS_COUNT];
unsigned int nr_entries, j;
handle = READ_ONCE(l->handle);
if (handle) {
- nr_entries = stack_depot_fetch(handle, &entries);
+ nr_entries =
+ stack_depot_fetch_into(handle, entries,
+ ARRAY_SIZE(entries));
seq_puts(seq, "\n");
for (j = 0; j < nr_entries; j++)
seq_printf(seq, " %pS\n", (void *)entries[j]);
diff --git a/scripts/gdb/linux/constants.py.in b/scripts/gdb/linux/constants.py.in
index dab8b80bed6988..da6b39c3dc13f5 100644
--- a/scripts/gdb/linux/constants.py.in
+++ b/scripts/gdb/linux/constants.py.in
@@ -22,6 +22,7 @@
#include <linux/radix-tree.h>
#include <linux/maple_tree.h>
#include <linux/slab.h>
+#include <linux/stackdepot.h>
#include <linux/threads.h>
#include <linux/vmalloc.h>
@@ -112,6 +113,10 @@ if IS_BUILTIN(CONFIG_PAGE_OWNER):
LX_GDBPARSED(PAGE_EXT_OWNER)
LX_GDBPARSED(PAGE_EXT_OWNER_ALLOCATED)
+/* linux/stackdepot.h */
+if IS_BUILTIN(CONFIG_STACKDEPOT):
+ LX_GDBPARSED(STACK_RECORD_COMPRESSED)
+
/* linux/slab.h */
LX_GDBPARSED(SLAB_RED_ZONE)
LX_GDBPARSED(SLAB_POISON)
diff --git a/scripts/gdb/linux/stackdepot.py b/scripts/gdb/linux/stackdepot.py
index aaa18af25cd121..f689cacb3cb703 100644
--- a/scripts/gdb/linux/stackdepot.py
+++ b/scripts/gdb/linux/stackdepot.py
@@ -20,6 +20,21 @@ def help():
gdb.write("Unrecognized command\n")
raise gdb.GdbError(t)
+def stack_record_entry(stack, i):
+ if not int(stack['flags']) & constants.LX_STACK_RECORD_COMPRESSED:
+ return int(stack['entries'][i])
+
+ # Mirror arch_stack_depot_frame_decompress().
+ payload = int(stack['compressed_entries'][i])
+ if utils.is_target_arch("x86-64"):
+ return 0xffffffff00000000 | payload
+ if utils.is_target_arch("aarch64"):
+ text = int(gdb.parse_and_eval("(unsigned long)_text"))
+ if payload & 0x80000000:
+ payload -= 1 << 32
+ return (text + payload) & 0xffffffffffffffff
+ raise gdb.GdbError("compressed stack depot frames are not supported on this architecture\n")
+
def stack_depot_fetch(handle):
global DEPOT_STACK_ALIGN
global stack_record_type
@@ -40,7 +55,7 @@ def stack_depot_fetch(handle):
pool_index = parts['pool_index_plus_1'] - 1
if pool_index >= pools_num:
gdb.write("pool index %d out of bounds (%d) for stack id 0x%08x\n" % (pool_index, pools_num, handle))
- return gdb.Value(0), 0
+ return [], 0
stack_pools = gdb.parse_and_eval('stack_pools')
@@ -48,10 +63,10 @@ def stack_depot_fetch(handle):
pool = stack_pools[pool_index]
stack = (pool + gdb.Value(offset).cast(utils.get_size_t_type())).cast(stack_record_type.get_type().pointer())
size = int(stack['size'].cast(utils.get_ulong_type()))
- return stack['entries'], size
+ return [stack_record_entry(stack, i) for i in range(size)], size
except Exception as e:
gdb.write("%s\n" % e)
- return gdb.Value(0), 0
+ return [], 0
def stack_depot_print(handle):
if not constants.LX_CONFIG_STACKDEPOT:
@@ -61,7 +76,7 @@ def stack_depot_print(handle):
if nr_entries > 0:
for i in range(0, nr_entries):
try:
- gdb.execute("x /i 0x%x" % (int(entries[i])))
+ gdb.execute("x /i 0x%x" % entries[i])
except Exception as e:
gdb.write("%s\n" % e)
|
| 59/3 | 2026/11/18 03:39 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 16941 output: 26 thoughts: 1247 Thoughts: **Analyzing the Stack Depot Compression Patch for KMSAN Implications** Okay, let's break this down. My initial thought was to quickly assess whether this patch, introducing stack depot compression for x86_64 and arm64, warranted a dedicated KMSAN fuzzing session. The patch touches several files across architecture-specific headers, generic headers, and the core `lib/stackdepot.c` file. It seems pretty straightforward, adding compression/decompression functions and modifying the `stack_record` struct to handle compressed entries. The `stack_depot_fetch` function is replaced with `stack_depot_fetch_into`, which is the key area for us to investigate. The presence of explicit KMSAN handling in `depot_copy_entries`, `stack_depot_print`, and `stack_depot_snprint` is interesting, particularly the calls to `kmsan_unpoison_memory`. This hints at potential uninitialized memory risks, which is precisely what KMSAN is designed to catch. Now, let's dig deeper, I need to know the potential for uninitialized memory usage. I see that `depot_copy_entries` copies data into the `entries` buffer, and the code explicitly unpoisons this after copying. This is encouraging because KMSAN is used as a safety net. I'm now focusing on `stack_depot_fetch_into`'s callers, especially those using a fixed-size buffer like `entries[KMSAN_STACK_DEPTH]`. I'm concerned about what happens if `stack_depot_fetch_into` returns fewer entries than the buffer size, or even zero. Looking at the code for `stack_depot_fetch_into`, it calls `depot_copy_entries` and sets the number of entries correctly. In the `depot_copy_entries` function there's a loop that copies `nr_entries` entries into the provided buffer. After the copy, it unpoisons this memory region. *However*, my question is: If the number of entries returned is smaller than the provided buffer, does this mean a KMSAN report? The code should be fine, because the number of entries is limited to the number of available entries in the depot, with explicit warnings to prevent buffer overruns. But wait a minute... it says "stackdepot.c is not instrumented." The comment says KMSAN explicitly unpoisons the memory after copying. But, *is* `stackdepot.c` actually instrumented, or not? I *need* to be sure about this to understand the true risk. I need to confirm if KMSAN is *really* disabled for `stackdepot.c`, so I'm going to check the `lib/Makefile` to see if KMSAN is disabled. Time to run a quick `grepper` and double-check those build flags. This will determine if the KMSAN unpoisoning is necessary or redundant. |
| 60/3 | 2026/11/18 03:40 | tool | grepper |
0mArgs:{
"Expression": "stackdepot",
"PathPrefixes": [
"lib/"
]
}Results: {
"Output": "lib/Makefile=244=obj-$(CONFIG_IRQ_POLL) += irq_poll.o\nlib/Makefile-245-\nlib/Makefile:246:# stackdepot.c should not be instrumented or call instrumented functions.\nlib/Makefile-247-# Prevent the compiler from calling builtins like memcmp() or bcmp() from this\nlib/Makefile-248-# file.\nlib/Makefile:249:CFLAGS_stackdepot.o += -fno-builtin\nlib/Makefile:250:CONTEXT_ANALYSIS_stackdepot.o := y\nlib/Makefile:251:obj-$(CONFIG_STACKDEPOT) += stackdepot.o\nlib/Makefile:252:KASAN_SANITIZE_stackdepot.o := n\nlib/Makefile:253:# In particular, instrumenting stackdepot.c with KMSAN will result in infinite\nlib/Makefile-254-# recursion.\nlib/Makefile:255:KMSAN_SANITIZE_stackdepot.o := n\nlib/Makefile:256:KCOV_INSTRUMENT_stackdepot.o := n\nlib/Makefile-257-\n--\nlib/ref_tracker.c-9-#include \u003clinux/stacktrace.h\u003e\nlib/ref_tracker.c:10:#include \u003clinux/stackdepot.h\u003e\nlib/ref_tracker.c-11-#include \u003clinux/seq_file.h\u003e\n--\nlib/stackdepot.c-14-\nlib/stackdepot.c:15:#define pr_fmt(fmt) \"stackdepot: \" fmt\nlib/stackdepot.c-16-\n--\nlib/stackdepot.c-32-#include \u003clinux/stacktrace.h\u003e\nlib/stackdepot.c:33:#include \u003clinux/stackdepot.h\u003e\nlib/stackdepot.c-34-#include \u003clinux/string.h\u003e\n--\nlib/stackdepot.c-38-\nlib/stackdepot.c:39:#include \u003casm/stackdepot.h\u003e\nlib/stackdepot.c-40-\n--\nlib/stackdepot.c=153=int __init stack_depot_early_init(void)\n--\nlib/stackdepot.c-192-\tpr_info(\"allocating hash table via alloc_large_system_hash\\n\");\nlib/stackdepot.c:193:\tstack_table = alloc_large_system_hash(\"stackdepot\",\nlib/stackdepot.c-194-\t\t\t\t\t\tsizeof(struct list_head),\n--\nlib/stackdepot.c=624=static inline\nlib/stackdepot.c:625:int stackdepot_memcmp(const unsigned long *u1, const unsigned long *u2,\nlib/stackdepot.c-626-\t\t\tunsigned int n)\n--\nlib/stackdepot.c=635=static inline bool depot_stack_equal(const struct stack_record *stack,\n--\nlib/stackdepot.c-639-\tif (!(stack-\u003eflags \u0026 STACK_RECORD_COMPRESSED))\nlib/stackdepot.c:640:\t\treturn !stackdepot_memcmp(entries, stack-\u003eentries, size);\nlib/stackdepot.c-641-\n--\nlib/stackdepot.c=819=static void depot_copy_entries(const struct stack_record *stack,\n--\nlib/stackdepot.c-823-\t\tentries[i] = depot_stack_entry(stack, i);\nlib/stackdepot.c:824:\t/* stackdepot.c is not instrumented; tell KMSAN the copy is initialized. */\nlib/stackdepot.c-825-\tkmsan_unpoison_memory(entries, nr_entries * sizeof(*entries));\n--\nlib/stackdepot.c=967=static int depot_debugfs_init(void)\n--\nlib/stackdepot.c-973-\nlib/stackdepot.c:974:\tdir = debugfs_create_dir(\"stackdepot\", NULL);\nlib/stackdepot.c-975-\tdebugfs_create_file(\"stats\", 0444, dir, NULL, \u0026stats_fops);\n--\nlib/tests/Makefile=51=obj-$(CONFIG_SLUB_KUNIT_TEST) += slub_kunit.o\nlib/tests/Makefile:52:obj-$(CONFIG_STACKDEPOT_KUNIT_TEST) += stackdepot_kunit.o\nlib/tests/Makefile-53-obj-$(CONFIG_TEST_SORT) += test_sort.o\n--\nlib/tests/stackdepot_kunit.c-8-#include \u003clinux/stacktrace.h\u003e\nlib/tests/stackdepot_kunit.c:9:#include \u003clinux/stackdepot.h\u003e\nlib/tests/stackdepot_kunit.c-10-#include \u003clinux/string.h\u003e\nlib/tests/stackdepot_kunit.c-11-\nlib/tests/stackdepot_kunit.c:12:#include \u003casm/stackdepot.h\u003e\nlib/tests/stackdepot_kunit.c-13-\n--\nlib/tests/stackdepot_kunit.c-16-\nlib/tests/stackdepot_kunit.c:17:static inline unsigned long stackdepot_arm64_frame(long offset)\nlib/tests/stackdepot_kunit.c-18-{\n--\nlib/tests/stackdepot_kunit.c-22-\nlib/tests/stackdepot_kunit.c:23:static void stackdepot_fetch_into_roundtrip(struct kunit *test)\nlib/tests/stackdepot_kunit.c-24-{\n--\nlib/tests/stackdepot_kunit.c-52-\nlib/tests/stackdepot_kunit.c:53:static void stackdepot_fetch_into_rejects_missing_or_short_stack(struct kunit *test)\nlib/tests/stackdepot_kunit.c-54-{\n--\nlib/tests/stackdepot_kunit.c-87-\nlib/tests/stackdepot_kunit.c:88:static void stackdepot_frame_raw_fallback(struct kunit *test)\nlib/tests/stackdepot_kunit.c-89-{\n--\nlib/tests/stackdepot_kunit.c-102-#if defined(CONFIG_X86_64) \u0026\u0026 !defined(CONFIG_UML)\nlib/tests/stackdepot_kunit.c:103:static void stackdepot_frame_x86_64(struct kunit *test)\nlib/tests/stackdepot_kunit.c-104-{\n--\nlib/tests/stackdepot_kunit.c-122-#ifdef CONFIG_ARM64\nlib/tests/stackdepot_kunit.c:123:static void stackdepot_frame_arm64(struct kunit *test)\nlib/tests/stackdepot_kunit.c-124-{\n--\nlib/tests/stackdepot_kunit.c-127-\tlong offset = 0x123456;\nlib/tests/stackdepot_kunit.c:128:\tunsigned long frame = stackdepot_arm64_frame(offset);\nlib/tests/stackdepot_kunit.c-129-\tunsigned long out;\n--\nlib/tests/stackdepot_kunit.c-138-\nlib/tests/stackdepot_kunit.c:139:\tframe = stackdepot_arm64_frame(negative_offset);\nlib/tests/stackdepot_kunit.c-140-\tcompressed = arch_stack_depot_frame_try_compress(frame, \u0026payload);\n--\nlib/tests/stackdepot_kunit.c-145-\nlib/tests/stackdepot_kunit.c:146:\tframe = stackdepot_arm64_frame(positive_offset);\nlib/tests/stackdepot_kunit.c-147-\tcompressed = arch_stack_depot_frame_try_compress(frame, \u0026payload);\n--\nlib/tests/stackdepot_kunit.c-158-/* Return a distinct compressible frame for each @i. */\nlib/tests/stackdepot_kunit.c:159:static unsigned long stackdepot_compressible_frame(unsigned int i)\nlib/tests/stackdepot_kunit.c-160-{\nlib/tests/stackdepot_kunit.c-161-#ifdef CONFIG_ARM64\nlib/tests/stackdepot_kunit.c:162:\treturn stackdepot_arm64_frame(0x1000L * (i + 1));\nlib/tests/stackdepot_kunit.c-163-#else\n--\nlib/tests/stackdepot_kunit.c-168-/* Return a frame that cannot be compressed but has the same 32-bit payload. */\nlib/tests/stackdepot_kunit.c:169:static unsigned long stackdepot_raw_frame(unsigned int i)\nlib/tests/stackdepot_kunit.c-170-{\nlib/tests/stackdepot_kunit.c-171-#ifdef CONFIG_ARM64\nlib/tests/stackdepot_kunit.c:172:\treturn stackdepot_compressible_frame(i) + BIT_ULL(32);\nlib/tests/stackdepot_kunit.c-173-#else\nlib/tests/stackdepot_kunit.c:174:\treturn stackdepot_compressible_frame(i) \u0026 U32_MAX;\nlib/tests/stackdepot_kunit.c-175-#endif\n--\nlib/tests/stackdepot_kunit.c-177-\nlib/tests/stackdepot_kunit.c:178:static void stackdepot_compressed_frames(struct kunit *test)\nlib/tests/stackdepot_kunit.c-179-{\n--\nlib/tests/stackdepot_kunit.c-185-\tfor (i = 0; i \u003c ARRAY_SIZE(compressible); i++)\nlib/tests/stackdepot_kunit.c:186:\t\tcompressible[i] = stackdepot_compressible_frame(0x100 + i);\nlib/tests/stackdepot_kunit.c-187-\tmemcpy(mixed, compressible, sizeof(mixed));\nlib/tests/stackdepot_kunit.c:188:\tmixed[1] = stackdepot_raw_frame(0x101);\nlib/tests/stackdepot_kunit.c-189-\n--\nlib/tests/stackdepot_kunit.c-219-/* Evictable records are max-size, so their frames are not compressed. */\nlib/tests/stackdepot_kunit.c:220:static void stackdepot_get_record_not_compressed(struct kunit *test)\nlib/tests/stackdepot_kunit.c-221-{\n--\nlib/tests/stackdepot_kunit.c-227-\tfor (i = 0; i \u003c ARRAY_SIZE(entries); i++)\nlib/tests/stackdepot_kunit.c:228:\t\tentries[i] = stackdepot_compressible_frame(0x200 + i);\nlib/tests/stackdepot_kunit.c-229-\n--\nlib/tests/stackdepot_kunit.c-247-/* stack_depot_snprint() must match stack_trace_snprint(), with truncation. */\nlib/tests/stackdepot_kunit.c:248:static void stackdepot_snprint_matches_stack_trace(struct kunit *test)\nlib/tests/stackdepot_kunit.c-249-{\n--\nlib/tests/stackdepot_kunit.c-258-#ifdef STACKDEPOT_TEST_COMPRESSED\nlib/tests/stackdepot_kunit.c:259:\t\tentries[i] = stackdepot_compressible_frame(0x300 + i);\nlib/tests/stackdepot_kunit.c-260-#else\n--\nlib/tests/stackdepot_kunit.c-284-\nlib/tests/stackdepot_kunit.c:285:static struct kunit_case stackdepot_test_cases[] = {\nlib/tests/stackdepot_kunit.c:286:\tKUNIT_CASE(stackdepot_fetch_into_roundtrip),\nlib/tests/stackdepot_kunit.c:287:\tKUNIT_CASE(stackdepot_fetch_into_rejects_missing_or_short_stack),\nlib/tests/stackdepot_kunit.c:288:\tKUNIT_CASE(stackdepot_snprint_matches_stack_trace),\nlib/tests/stackdepot_kunit.c:289:\tKUNIT_CASE(stackdepot_frame_raw_fallback),\nlib/tests/stackdepot_kunit.c-290-#if defined(CONFIG_X86_64) \u0026\u0026 !defined(CONFIG_UML)\nlib/tests/stackdepot_kunit.c:291:\tKUNIT_CASE(stackdepot_frame_x86_64),\nlib/tests/stackdepot_kunit.c-292-#endif\nlib/tests/stackdepot_kunit.c-293-#ifdef CONFIG_ARM64\nlib/tests/stackdepot_kunit.c:294:\tKUNIT_CASE(stackdepot_frame_arm64),\nlib/tests/stackdepot_kunit.c-295-#endif\nlib/tests/stackdepot_kunit.c-296-#ifdef STACKDEPOT_TEST_COMPRESSED\nlib/tests/stackdepot_kunit.c:297:\tKUNIT_CASE(stackdepot_compressed_frames),\nlib/tests/stackdepot_kunit.c:298:\tKUNIT_CASE(stackdepot_get_record_not_compressed),\nlib/tests/stackdepot_kunit.c-299-#endif\n--\nlib/tests/stackdepot_kunit.c-302-\nlib/tests/stackdepot_kunit.c:303:static struct kunit_suite stackdepot_test_suite = {\nlib/tests/stackdepot_kunit.c:304:\t.name = \"stackdepot\",\nlib/tests/stackdepot_kunit.c:305:\t.test_cases = stackdepot_test_cases,\nlib/tests/stackdepot_kunit.c-306-};\nlib/tests/stackdepot_kunit.c-307-\nlib/tests/stackdepot_kunit.c:308:kunit_test_suite(stackdepot_test_suite);\nlib/tests/stackdepot_kunit.c-309-\n"
} |
| 61/3 | 2026/11/18 03:40 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 22575 output: 36 thoughts: 850 Thoughts: **Analyzing KMSAN Patch Changes** Okay, let's dive into these KMSAN changes. My initial focus is on the `mm/kmsan` directory. I see a modification in `kmsan_test.c`, specifically in `test_stackdepot_roundtrip`. It looks like the patch is changing from a pointer to an array for `dst_entries`. It's now explicitly allocating `dst_entries[16]` instead of using `stack_depot_fetch` to dynamically allocate the memory. The code has been changed to use `stack_depot_fetch_into` with an array size limit. This indicates they're moving towards a more bounded approach, likely for stability or performance reasons. Next, I'm examining `mm/kmsan/report.c`. The `kmsan_print_origin` function has undergone some significant changes. Originally it would call `stack_depot_fetch` to allocate memory, and now it calls a private function `kmsan_print_origin_with_buf` using a local buffer. The code has moved from fetching stack entries into a dynamically allocated buffer to a local stack array `entries[KMSAN_STACK_DEPTH]`. Also, the function signature has been changed to accept a pre-allocated buffer. I see the main `kmsan_print_origin` has been updated to use the helper function using a local buffer, which is a good design practice. The original function `kmsan_print_origin` included logic for handling chained entries. Specifically, there's a loop that fetches depot stack entries, checking for `KMSAN_ALLOCA_MAGIC_ORIGIN`, and then calls `stack_trace_print`. The changes in `kmsan_print_origin` and the `stack_depot_fetch_into` calls suggest the same optimization is in place. I also see that an unpoison memory call is now skipped. The stack trace printing uses `stack_depot_fetch_into`. The logic uses `KMSAN_STACK_DEPTH` and calls `stack_trace_print` with a calculated skip value. The goal here seems to be improving how uninitialized memory origins are traced. There's a check for `KMSAN_ALLOCA_MAGIC_ORIGIN` which suggests they are trying to understand the alloca context. It's interesting they're printing an "Uninit was stored to memory" message with a stack trace. This reinforces the focus on tracking and reporting uninitialized memory usage. |
| 62/3 | 2026/11/18 03:41 | tool | read-file |
0mArgs:{
"File": "mm/kmsan/report.c",
"FirstLine": 150,
"LineCount": 70
}Results: {
"Contents": " 150:\t\n 151:\t\tkmsan_print_origin_with_buf(origin, entries);\n 152:\t}\n 153:\t\n 154:\tvoid kmsan_report(depot_stack_handle_t origin, void *address, int size,\n 155:\t\t\t int off_first, int off_last, const void __user *user_addr,\n 156:\t\t\t enum kmsan_bug_reason reason)\n 157:\t{\n 158:\t\tunsigned long stack_entries[KMSAN_STACK_DEPTH];\n 159:\t\tint num_stack_entries, skipnr;\n 160:\t\tchar *bug_type = NULL;\n 161:\t\tunsigned long ua_flags;\n 162:\t\tbool is_uaf;\n 163:\t\n 164:\t\tif (!kmsan_enabled || kmsan_in_runtime())\n 165:\t\t\treturn;\n 166:\t\tif (current-\u003ekmsan_ctx.depth)\n 167:\t\t\treturn;\n 168:\t\tif (!origin)\n 169:\t\t\treturn;\n 170:\t\n 171:\t\tkmsan_enter_runtime();\n 172:\t\tua_flags = user_access_save();\n 173:\t\traw_spin_lock(\u0026kmsan_report_lock);\n 174:\t\tpr_err(\"=====================================================\\n\");\n 175:\t\tis_uaf = kmsan_uaf_from_eb(stack_depot_get_extra_bits(origin));\n 176:\t\tswitch (reason) {\n 177:\t\tcase REASON_ANY:\n 178:\t\t\tbug_type = is_uaf ? \"use-after-free\" : \"uninit-value\";\n 179:\t\t\tbreak;\n 180:\t\tcase REASON_COPY_TO_USER:\n 181:\t\t\tbug_type = is_uaf ? \"kernel-infoleak-after-free\" :\n 182:\t\t\t\t\t \"kernel-infoleak\";\n 183:\t\t\tbreak;\n 184:\t\tcase REASON_SUBMIT_URB:\n 185:\t\t\tbug_type = is_uaf ? \"kernel-usb-infoleak-after-free\" :\n 186:\t\t\t\t\t \"kernel-usb-infoleak\";\n 187:\t\t\tbreak;\n 188:\t\t}\n 189:\t\n 190:\t\tnum_stack_entries =\n 191:\t\t\tstack_trace_save(stack_entries, KMSAN_STACK_DEPTH, 1);\n 192:\t\tskipnr = get_stack_skipnr(stack_entries, num_stack_entries);\n 193:\t\n 194:\t\tpr_err(\"BUG: KMSAN: %s in %pSb\\n\", bug_type,\n 195:\t\t (void *)stack_entries[skipnr]);\n 196:\t\tstack_trace_print(stack_entries + skipnr, num_stack_entries - skipnr,\n 197:\t\t\t\t 0);\n 198:\t\tpr_err(\"\\n\");\n 199:\t\n 200:\t\tkmsan_print_origin_with_buf(origin, stack_entries);\n 201:\t\n 202:\t\tif (size) {\n 203:\t\t\tpr_err(\"\\n\");\n 204:\t\t\tif (off_first == off_last)\n 205:\t\t\t\tpr_err(\"Byte %d of %d is uninitialized\\n\", off_first,\n 206:\t\t\t\t size);\n 207:\t\t\telse\n 208:\t\t\t\tpr_err(\"Bytes %d-%d of %d are uninitialized\\n\",\n 209:\t\t\t\t off_first, off_last, size);\n 210:\t\t}\n 211:\t\tif (address)\n 212:\t\t\tpr_err(\"Memory access of size %d starts at %px\\n\", size,\n 213:\t\t\t address);\n 214:\t\tif (user_addr \u0026\u0026 reason == REASON_COPY_TO_USER)\n 215:\t\t\tpr_err(\"Data copied to user address %px\\n\", user_addr);\n 216:\t\tpr_err(\"\\n\");\n 217:\t\tdump_stack_print_info(KERN_ERR);\n 218:\t\tpr_err(\"=====================================================\\n\");\n 219:\t\tadd_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);\n"
} |
| 63/3 | 2026/11/18 03:41 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 25151 output: 38 thoughts: 164 Thoughts: Okay, let me break this down. **Diving into the KMSAN Report Logic** Alright, I'm looking at this `kmsan_report` function. It seems like it's being quite clever with memory management. I see that the `stack_entries` array, the one printed out earlier at lines 196-197, is being reused. Instead of allocating yet another potentially large buffer, they're passing `stack_entries` directly to `kmsan_print_origin_with_buf` as a scratch buffer. Smart! Now, within `kmsan_print_origin_with_buf`, it looks like `stack_depot_fetch_into` populates the `entries` array, and then KMSAN, in `depot_copy_entries`, does the important unpoisoning part. It’s all flowing together nicely, reusing the same stack space. But… hold on a second. This brings up a potential point for scrutiny: What's the relationship between `KMSAN_STACK_DEPTH` and `nr_entries`? It's a key question when dealing with stack depth. I need to quickly compare `CONFIG_STACKDEPOT_MAX_FRAMES` and `KMSAN_STACK_DEPTH` to be absolutely sure that we're not missing any potential stack overflows here. Time to double-check those configuration values. |
| 64/3 | 2026/11/18 03:42 | tool | grepper |
0mArgs:{
"Expression": "KMSAN_STACK_DEPTH",
"PathPrefixes": [
"mm/kmsan/",
"include/"
]
}Results: {
"Output": "mm/kmsan/core.c=67=depot_stack_handle_t kmsan_save_stack_with_flags(gfp_t flags,\n--\nmm/kmsan/core.c-69-{\nmm/kmsan/core.c:70:\tunsigned long entries[KMSAN_STACK_DEPTH];\nmm/kmsan/core.c-71-\tunsigned int nr_entries;\n--\nmm/kmsan/core.c-73-\nmm/kmsan/core.c:74:\tnr_entries = stack_trace_save(entries, KMSAN_STACK_DEPTH, 0);\nmm/kmsan/core.c-75-\n--\nmm/kmsan/kmsan.h-32-\nmm/kmsan/kmsan.h:33:#define KMSAN_STACK_DEPTH 64\nmm/kmsan/kmsan.h-34-\n--\nmm/kmsan/report.c=86=static void kmsan_print_origin_with_buf(depot_stack_handle_t origin,\n--\nmm/kmsan/report.c-100-\t\tnr_entries =\nmm/kmsan/report.c:101:\t\t\tstack_depot_fetch_into(origin, entries, KMSAN_STACK_DEPTH);\nmm/kmsan/report.c-102-\t\tdepth = kmsan_depth_from_eb(stack_depot_get_extra_bits(origin));\n--\nmm/kmsan/report.c-127-\t\t\t\tstack_depot_fetch_into(head, entries,\nmm/kmsan/report.c:128:\t\t\t\t\t\t KMSAN_STACK_DEPTH);\nmm/kmsan/report.c-129-\t\t\tskipnr = get_stack_skipnr(entries, chained_nr_entries);\n--\nmm/kmsan/report.c=147=void kmsan_print_origin(depot_stack_handle_t origin)\nmm/kmsan/report.c-148-{\nmm/kmsan/report.c:149:\tunsigned long entries[KMSAN_STACK_DEPTH];\nmm/kmsan/report.c-150-\n--\nmm/kmsan/report.c=154=void kmsan_report(depot_stack_handle_t origin, void *address, int size,\n--\nmm/kmsan/report.c-157-{\nmm/kmsan/report.c:158:\tunsigned long stack_entries[KMSAN_STACK_DEPTH];\nmm/kmsan/report.c-159-\tint num_stack_entries, skipnr;\n--\nmm/kmsan/report.c-190-\tnum_stack_entries =\nmm/kmsan/report.c:191:\t\tstack_trace_save(stack_entries, KMSAN_STACK_DEPTH, 1);\nmm/kmsan/report.c-192-\tskipnr = get_stack_skipnr(stack_entries, num_stack_entries);\n"
} |
| 65/3 | 2026/11/18 03:42 | llm | kmsan-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 26389 output: 35 thoughts: 974 Thoughts: **KMSAN Risk Assessment** Okay, so I'm looking at this code and immediately my expert brain zeroes in on the implications for KMSAN. The code uses `KMSAN_STACK_DEPTH` which, as I recall, is 64 entries. The `stack_depot_save_flags` function utilizes this depth when saving and fetching stack traces. I'm already thinking about potential information leaks and uninitialized memory. First, I need to be sure that I am following the rules of when to enable KMSAN. The fundamental rule is that KMSAN should only be set to `true` if the patch has introduced or exposes risks that are *only* detectable by KMSAN. Since the current standard builds have comprehensive debugging tools enabled, including KASAN, LOCKDEP and various sanitizers, I want to confirm that there isn't something that KASAN or another tool could catch first. I am specifically looking for uninitialized memory usage risks or kernel-to-user info-leaks. Now, let's go over the criteria for the `NeedsKMSAN=true` flag. I need to ask myself whether the patch introduces or modifies any of the following: 1. Kernel structures sent to user space (via copy_to_user, put_user, netlink, ioctl, socket options, BPF buffers) where uninitialized fields are possible. 2. Conditional logic or branching that depends on uninitialized variables. 3. Allocation or initialization of complex data structures where uninitialized fields could be read later. 4. Bounds checks, lengths, or logic that allows access to uninitialized bytes of existing buffers. And, of course, I must make sure that none of the following statements apply: - Out-of-bounds access, array overflows, NULL pointer dereferences, locking deadlocks, or use-after-free bugs are not present (already caught by KASAN). - All touched stack/heap structures are fully zeroed or initialized. - The patch does not introduce any risk of uninitialized memory usage or info-leaks. Okay, let's dive into what this patch actually *does*. 1. I'm seeing some architecture-specific frame compression/decompression helpers in `arch/arm64/include/asm/stackdepot.h` and `arch/x86/include/asm/stackdepot.h`. Looks like pure bitwise operations on values. The x86 version checks if the upper 32 bits match a constant value. These appear to be purely internal functions. 2. Then, in `drivers/gpu/drm/drm_modeset_lock.c`, there's a replacement of `stack_depot_fetch` with `stack_depot_snprint`. `buf` is allocated with `kmalloc`, and then passed into the new function. The new function writes into `buf`. So I need to ensure there are no uninitialized variables being used, and that the buffer is safely handled. Specifically, I need to check whether `stack_depot_snprint` guarantees null-termination. And, in the event the allocation fails, I have to ensure the patch does not cause further problems. Based on the information I have collected, I will need to check those cases specifically to see if I need to set KMSAN=true. |
| 66/3 | 2026/11/18 03:43 | tool | grepper |
0mArgs:{
"Expression": "int stack_trace_snprint",
"PathPrefixes": [
"kernel/",
"lib/"
]
}Results: {
"Output": "kernel/stacktrace.c=35=EXPORT_SYMBOL_GPL(stack_trace_print);\n--\nkernel/stacktrace.c-46- */\nkernel/stacktrace.c:47:int stack_trace_snprint(char *buf, size_t size, const unsigned long *entries,\nkernel/stacktrace.c-48-\t\t\tunsigned int nr_entries, int spaces)\n"
} |
| 67/3 | 2026/11/18 03:43 | llm | kmsan-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 28217 output: 33 thoughts: 18 Thoughts: Okay, let's dive into this. Here's my take on what's going on, thinking through it like I would myself: **Analyzing `kernel/stacktrace.c` - Line 47 and Beyond** Alright, the next step is to examine the code in `kernel/stacktrace.c` around line 47. My immediate focus is on understanding the function's responsibility, and what kind of data structures or logic it manipulates around that specific point. I expect to see something related to how the stack trace is built, formatted, or potentially even output. I'll be looking for clues: Does it involve traversing frame pointers, reading register values, accessing symbol information, or perhaps interacting with the debug information tables? Is it part of the stack walking logic or only a helper function? The surrounding code will provide crucial context – the lines immediately before and after line 47. I'll be paying attention to the data types in use as well. Integers? Pointers? Structures? These types often tell a story about how information is represented in memory and how it's being manipulated. Any function calls in this section? Those could be critical. I'll need to know where those functions are defined, how they behave, and what information they are passing. I'm also ready to trace any loops or conditional statements that might be present. The goal is to build a mental model of that snippet, and how it fits into the greater whole of the stack tracing mechanism. My goal is to determine the design implications of this line of code. |
| 68/3 | 2026/11/18 03:44 | tool | read-file |
0mArgs:{
"File": "kernel/stacktrace.c",
"FirstLine": 45,
"LineCount": 40
}Results: {
"Contents": " 45:\t * Return: Number of bytes printed.\n 46:\t */\n 47:\tint stack_trace_snprint(char *buf, size_t size, const unsigned long *entries,\n 48:\t\t\t\tunsigned int nr_entries, int spaces)\n 49:\t{\n 50:\t\tunsigned int generated, i, total = 0;\n 51:\t\n 52:\t\tif (WARN_ON(!entries))\n 53:\t\t\treturn 0;\n 54:\t\n 55:\t\tfor (i = 0; i \u003c nr_entries \u0026\u0026 size; i++) {\n 56:\t\t\tgenerated = snprintf(buf, size, \"%*c%pS\\n\", 1 + spaces, ' ',\n 57:\t\t\t\t\t (void *)entries[i]);\n 58:\t\n 59:\t\t\ttotal += generated;\n 60:\t\t\tif (generated \u003e= size) {\n 61:\t\t\t\tbuf += size;\n 62:\t\t\t\tsize = 0;\n 63:\t\t\t} else {\n 64:\t\t\t\tbuf += generated;\n 65:\t\t\t\tsize -= generated;\n 66:\t\t\t}\n 67:\t\t}\n 68:\t\n 69:\t\treturn total;\n 70:\t}\n 71:\tEXPORT_SYMBOL_GPL(stack_trace_snprint);\n 72:\t\n 73:\t#ifdef CONFIG_ARCH_STACKWALK\n 74:\t\n 75:\tstruct stacktrace_cookie {\n 76:\t\tunsigned long\t*store;\n 77:\t\tunsigned int\tsize;\n 78:\t\tunsigned int\tskip;\n 79:\t\tunsigned int\tlen;\n 80:\t};\n 81:\t\n 82:\tstatic bool stack_trace_consume_entry(void *cookie, unsigned long addr)\n 83:\t{\n 84:\t\tstruct stacktrace_cookie *c = cookie;\n"
} |
| 69/3 | 2026/11/18 03:44 | llm | kmsan-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 29080 output: 36 thoughts: 1098 Thoughts: **Analyzing the Stack Trace Printing Logic** Okay, let's break this down. First, I see `stack_depot_snprint` in `lib/stackdepot.c`. This function takes a stack handle, a buffer, and a size. It iterates through the stack entries, calls `stack_trace_snprint` for each entry, and writes to the buffer. The important thing is if the stack handle is zero, or if the stack is null, `stack_depot_snprint` returns 0, and *nothing* is written to the buffer. That's a key observation. Now, looking at `drm_modeset_lock.c`, specifically `__drm_stack_depot_print`, it calls `stack_depot_snprint` with a `PAGE_SIZE` buffer allocated via `kmalloc`, but crucially, *not* `kzalloc`. The result of `stack_depot_snprint` is then passed to `drm_printf` with a `%s` format specifier. If `stack_depot_snprint` returns 0 (due to a null stack), the buffer might be uninitialized. Now, my mind goes back to the *previous* implementation, where `stack_depot_fetch` was called, and the returned entries were passed to `stack_trace_snprint`. Before, a similar problem existed: if `entries` was NULL or `nr_entries` was 0, `stack_trace_snprint` didn't write anything. The use of `kmalloc` without `kzalloc` is interesting. The previous code path used `kmalloc` but didn't initialize the buffer. The *new* code path is equivalent, potentially using an uninitialized buffer for `drm_printf`. So, the critical check is what happens if `stack_depot_snprint` returns 0. If the handle is zero (e.g., memory allocation failed), `stack_depot_snprint` will return 0 and not write anything. If the handle is valid, `snprintf` inside `stack_trace_snprint` *should* write a null-terminated string to `buf`, so then the buffer will be properly null-terminated. Now, considering `__drm_stack_depot_save()`: It saves a stack trace using `stack_trace_save` and then saves it in a depot using `stack_depot_save`. If the memory allocation in `stack_depot_save` fails, it returns 0. If the `stack_depot` handle is zero (e.g. allocation failed): `__drm_stack_depot_print` is called with zero. In the *old* logic, `stack_depot_fetch` returns zero, which sets `entries` to NULL, and now the code path is the same as the new code path, where `stack_trace_snprint` receives `NULL`. `stack_trace_snprint` includes a `WARN_ON(!entries)`, and returns 0, so the buffer is still potentially uninitialized. The question is, and this is where I need to look deeper, is `__drm_stack_depot_print` ever called with 0? That is the crucial issue. I need to trace the callers of `__drm_stack_depot_print` to see if that's a possible scenario. If it is, then the `drm_printf` call could be reading from an uninitialized buffer, which is a significant bug. |
| 70/3 | 2026/11/18 03:46 | tool | grepper |
0mArgs:{
"Expression": "__drm_stack_depot_print",
"PathPrefixes": [
"drivers/gpu/drm/"
]
}Results: {
"Output": "drivers/gpu/drm/drm_modeset_lock.c=84=static noinline depot_stack_handle_t __drm_stack_depot_save(void)\n--\ndrivers/gpu/drm/drm_modeset_lock.c-93-\ndrivers/gpu/drm/drm_modeset_lock.c:94:static void __drm_stack_depot_print(depot_stack_handle_t stack_depot)\ndrivers/gpu/drm/drm_modeset_lock.c-95-{\n--\ndrivers/gpu/drm/drm_modeset_lock.c=115=static depot_stack_handle_t __drm_stack_depot_save(void)\n--\ndrivers/gpu/drm/drm_modeset_lock.c-118-}\ndrivers/gpu/drm/drm_modeset_lock.c:119:static void __drm_stack_depot_print(depot_stack_handle_t stack_depot)\ndrivers/gpu/drm/drm_modeset_lock.c-120-{\n--\ndrivers/gpu/drm/drm_modeset_lock.c=269=void drm_modeset_drop_locks(struct drm_modeset_acquire_ctx *ctx)\n--\ndrivers/gpu/drm/drm_modeset_lock.c-271-\tif (WARN_ON(ctx-\u003econtended))\ndrivers/gpu/drm/drm_modeset_lock.c:272:\t\t__drm_stack_depot_print(ctx-\u003estack_depot);\ndrivers/gpu/drm/drm_modeset_lock.c-273-\n--\ndrivers/gpu/drm/drm_modeset_lock.c=285=static inline int modeset_lock(struct drm_modeset_lock *lock,\n--\ndrivers/gpu/drm/drm_modeset_lock.c-291-\tif (WARN_ON(ctx-\u003econtended))\ndrivers/gpu/drm/drm_modeset_lock.c:292:\t\t__drm_stack_depot_print(ctx-\u003estack_depot);\ndrivers/gpu/drm/drm_modeset_lock.c-293-\n"
} |
| 71/3 | 2026/11/18 03:46 | llm | kmsan-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 31507 output: 35 thoughts: 1704 Thoughts: **Analyzing Stack Depot Usage Across the Kernel** Okay, let's break this down. My initial observation is focused on how `stack_depot_fetch_into` is being used, specifically in relation to stack-allocated buffers. I've spotted a pattern across several key areas: `kmemleak.c`, `mm/page_owner.c`, `mm/slub.c`, and now, critically, `mm/kmsan/report.c`. In `kmemleak.c`, `page_owner.c`, and `slub.c`, it's clear that stack-allocated arrays like `entries[MAX_TRACE]`, `entries[PAGE_OWNER_STACK_DEPTH]`, and `entries[TRACK_ADDRS_COUNT]` respectively are being passed to `stack_depot_fetch_into`. The important thing here is, only `nr_entries` are read from these `entries` arrays. `stack_depot_fetch_into` fills the stack allocated entries, and the code subsequently iterates, reading at most the first `nr_entries` elements of the array. The other values in the array, are not read. All `nr_entries` are written in the cases where the entries came from `depot_copy_entries`. This seems safe from a functional perspective. However, things get really interesting when we examine `mm/kmsan/report.c`. Here, we also see the same pattern with `stack_depot_fetch_into` being used with a stack-allocated `entries` buffer. The code reads at most `nr_entries` entries. But, I'm now noticing a chained call structure within a `while` loop, that could potentially introduce subtle issues. There is a chained structure here, when using `stack_depot_fetch_into` where `entries[1]` is used as the next handle. `entries[1]` is not necessarily written by the prior `stack_depot_fetch_into` if `nr_entries` is too small. This could lead to uninitialized memory being used as the `head`. Specifically, within this while loop, a crucial distinction exists: the usage of `entries` within the chained stack trace retrieval. It looks like `entries[1]` is being used as a handle (`head`) in a nested call to `stack_depot_fetch_into`. Then, it calls `stack_trace_print` with a subset of the entries read in, using `entries + skipnr`. This, when `nr_entries` is small and `entries[1]` is not written, could lead to unexpected behavior. I need to dig deeper into the control flow and potential values of these variables, especially when `nr_entries` is small, or zero, or when it returns zero. I'm going to carefully review the conditions under which `stack_trace_print` is called and make sure the logic is sound and the chain of handles is valid. |
| 72/3 | 2026/11/18 03:47 | tool | read-file |
0mArgs:{
"File": "mm/kmsan/report.c",
"FirstLine": 90,
"LineCount": 60
}Results: {
"Contents": " 90:\t\tvoid *pc1 = NULL, *pc2 = NULL;\n 91:\t\tdepot_stack_handle_t head;\n 92:\t\tunsigned long magic;\n 93:\t\tchar *descr = NULL;\n 94:\t\tunsigned int depth;\n 95:\t\n 96:\t\tif (!origin)\n 97:\t\t\treturn;\n 98:\t\n 99:\t\twhile (true) {\n 100:\t\t\tnr_entries =\n 101:\t\t\t\tstack_depot_fetch_into(origin, entries, KMSAN_STACK_DEPTH);\n 102:\t\t\tdepth = kmsan_depth_from_eb(stack_depot_get_extra_bits(origin));\n 103:\t\t\tmagic = nr_entries ? entries[0] : 0;\n 104:\t\t\tif ((nr_entries == 4) \u0026\u0026 (magic == KMSAN_ALLOCA_MAGIC_ORIGIN)) {\n 105:\t\t\t\tdescr = (char *)entries[1];\n 106:\t\t\t\tpc1 = (void *)entries[2];\n 107:\t\t\t\tpc2 = (void *)entries[3];\n 108:\t\t\t\tpr_err(\"Local variable %s created at:\\n\",\n 109:\t\t\t\t pretty_descr(descr));\n 110:\t\t\t\tif (pc1)\n 111:\t\t\t\t\tpr_err(\" %pSb\\n\", pc1);\n 112:\t\t\t\tif (pc2)\n 113:\t\t\t\t\tpr_err(\" %pSb\\n\", pc2);\n 114:\t\t\t\tbreak;\n 115:\t\t\t}\n 116:\t\t\tif ((nr_entries == 3) \u0026\u0026 (magic == KMSAN_CHAIN_MAGIC_ORIGIN)) {\n 117:\t\t\t\t/*\n 118:\t\t\t\t * Origin chains deeper than KMSAN_MAX_ORIGIN_DEPTH are\n 119:\t\t\t\t * not stored, so the output may be incomplete.\n 120:\t\t\t\t */\n 121:\t\t\t\tif (depth == KMSAN_MAX_ORIGIN_DEPTH)\n 122:\t\t\t\t\tpr_err(\"\u003cZero or more stacks not recorded to save memory\u003e\\n\\n\");\n 123:\t\t\t\thead = entries[1];\n 124:\t\t\t\torigin = entries[2];\n 125:\t\t\t\tpr_err(\"Uninit was stored to memory at:\\n\");\n 126:\t\t\t\tchained_nr_entries =\n 127:\t\t\t\t\tstack_depot_fetch_into(head, entries,\n 128:\t\t\t\t\t\t\t KMSAN_STACK_DEPTH);\n 129:\t\t\t\tskipnr = get_stack_skipnr(entries, chained_nr_entries);\n 130:\t\t\t\tstack_trace_print(entries + skipnr,\n 131:\t\t\t\t\t\t chained_nr_entries - skipnr, 0);\n 132:\t\t\t\tpr_err(\"\\n\");\n 133:\t\t\t\tcontinue;\n 134:\t\t\t}\n 135:\t\t\tpr_err(\"Uninit was created at:\\n\");\n 136:\t\t\tif (nr_entries) {\n 137:\t\t\t\tskipnr = get_stack_skipnr(entries, nr_entries);\n 138:\t\t\t\tstack_trace_print(entries + skipnr, nr_entries - skipnr,\n 139:\t\t\t\t\t\t 0);\n 140:\t\t\t} else {\n 141:\t\t\t\tpr_err(\"(stack is not available)\\n\");\n 142:\t\t\t}\n 143:\t\t\tbreak;\n 144:\t\t}\n 145:\t}\n 146:\t\n 147:\tvoid kmsan_print_origin(depot_stack_handle_t origin)\n 148:\t{\n 149:\t\tunsigned long entries[KMSAN_STACK_DEPTH];\n"
} |
| 73/3 | 2026/11/18 03:47 | llm | kmsan-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 34815 output: 34 thoughts: 471 Thoughts: **KMSAN Origin Tracking and Potential Uninitialized Memory** Okay, let's break this down. In `kmsan_print_origin_with_buf`, it looks like `entries` is being overwritten using `stack_depot_fetch_into`. I need to remember that `kmsan_enter_runtime()` is active during the reporting phase within `mm/kmsan/report.c`, which means KMSAN is handling origin tracking at that point. This makes me consider a critical question: Could this process be introducing or reading uninitialized memory? The implications are significant. Now, let's shift our focus to `struct stack_record`. I see an interesting change. The `size` field is now a `u16` instead of `u32`. We also have the addition of `flags` with `STACK_RECORD_*` values. And, importantly, there's a union containing either `entries` (the frames) or `compressed_entries`. Looking at `depot_alloc_stack` function, I can see what's happening. `stack->hash` and `stack->size` are being set. The `stack->handle` seems to be pre-filled. If compression is enabled, `stack->flags` is set to `STACK_RECORD_COMPRESSED`, and frames are compressed. Otherwise, the frames are `memcpy`-ed. I need to understand where `stack` comes from in `depot_alloc_stack`, specifically. I'll need to go back and read `depot_alloc_stack` in `lib/stackdepot.c` for more context. |
| 74/3 | 2026/11/18 03:48 | tool | grepper |
0mArgs:{
"Expression": "depot_alloc_stack",
"PathPrefixes": [
"lib/stackdepot.c"
]
}Results: {
"Output": "lib/stackdepot.c=464=static struct stack_record *\nlib/stackdepot.c:465:depot_alloc_stack(unsigned long *entries, unsigned int nr_entries, u32 hash, depot_flags_t flags, void **prealloc)\nlib/stackdepot.c-466-\t__must_hold(\u0026pool_lock)\n--\nlib/stackdepot.c=699=depot_stack_handle_t stack_depot_save_flags(unsigned long *entries,\n--\nlib/stackdepot.c-763-\t\tstruct stack_record *new =\nlib/stackdepot.c:764:\t\t\tdepot_alloc_stack(entries, nr_entries, hash, depot_flags, \u0026prealloc);\nlib/stackdepot.c-765-\n--\nlib/stackdepot.c-778-\t\t * Either stack depot already contains this stack trace, or\nlib/stackdepot.c:779:\t\t * depot_alloc_stack() did not consume the preallocated memory.\nlib/stackdepot.c-780-\t\t * Try to keep the preallocated memory for future.\n"
} |
| 75/3 | 2026/11/18 03:48 | llm | kmsan-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 35958 output: 35 thoughts: 25 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Diving into `depot_alloc_stack` in `lib/stackdepot.c`** Alright, let's get down to it. Time to pull up `depot_alloc_stack` and the surrounding code in `lib/stackdepot.c`. My immediate goal is to understand how memory allocation for stacks is handled within this system. I need to refresh my memory on the interactions with the underlying memory management strategy. What's the allocation algorithm being used? Is it leveraging any specific memory pools or region-based allocators? Are there any obvious potential sources of fragmentation or inefficiencies I can spot quickly? I'll also be looking for any indications of thread-safety considerations, especially in the context of concurrent access to these stacks. I'm keen to examine the error handling and see how the function deals with allocation failures and potential resource exhaustion. Is there appropriate boundary checking? Are there safeguards for alignment or padding? I'll also be looking for any hints about the stack structure itself, like is it a fixed size or dynamically expandable? Let's see if there are any obvious opportunities for optimization or potential areas where a more sophisticated allocator might be beneficial. |
| 76/3 | 2026/11/18 03:50 | tool | read-file |
0mArgs:{
"File": "lib/stackdepot.c",
"FirstLine": 464,
"LineCount": 70
}Results: {
"Contents": " 464:\tstatic struct stack_record *\n 465:\tdepot_alloc_stack(unsigned long *entries, unsigned int nr_entries, u32 hash, depot_flags_t flags, void **prealloc)\n 466:\t\t__must_hold(\u0026pool_lock)\n 467:\t{\n 468:\t\tstruct stack_record *stack = NULL;\n 469:\t\tsize_t record_size;\n 470:\t\tbool compressed = false;\n 471:\t\n 472:\t\tlockdep_assert_held(\u0026pool_lock);\n 473:\t\n 474:\t\t/* This should already be checked by public API entry points. */\n 475:\t\tif (WARN_ON_ONCE(!nr_entries))\n 476:\t\t\treturn NULL;\n 477:\t\n 478:\t\t/* Limit number of saved frames to CONFIG_STACKDEPOT_MAX_FRAMES. */\n 479:\t\tif (nr_entries \u003e CONFIG_STACKDEPOT_MAX_FRAMES)\n 480:\t\t\tnr_entries = CONFIG_STACKDEPOT_MAX_FRAMES;\n 481:\t\n 482:\t\tif (flags \u0026 STACK_DEPOT_FLAG_GET) {\n 483:\t\t\t/*\n 484:\t\t\t * Evictable entries have to allocate the max. size so they may\n 485:\t\t\t * safely be re-used by differently sized allocations.\n 486:\t\t\t */\n 487:\t\t\trecord_size = depot_stack_record_size(stack,\n 488:\t\t\t\t\t\t\t CONFIG_STACKDEPOT_MAX_FRAMES,\n 489:\t\t\t\t\t\t\t false);\n 490:\t\t\tstack = depot_pop_free();\n 491:\t\t} else {\n 492:\t\t\tcompressed = depot_entries_compressible(entries, nr_entries);\n 493:\t\t\trecord_size = depot_stack_record_size(stack, nr_entries, compressed);\n 494:\t\t}\n 495:\t\n 496:\t\tif (!stack) {\n 497:\t\t\tstack = depot_pop_free_pool(prealloc, record_size);\n 498:\t\t\tif (!stack)\n 499:\t\t\t\treturn NULL;\n 500:\t\t}\n 501:\t\n 502:\t\t/* Save the stack trace. */\n 503:\t\tstack-\u003ehash = hash;\n 504:\t\tstack-\u003esize = nr_entries;\n 505:\t\t/* stack-\u003ehandle is already filled in by depot_pop_free_pool(). */\n 506:\t\tif (compressed) {\n 507:\t\t\tstack-\u003eflags = STACK_RECORD_COMPRESSED;\n 508:\t\t\tfor (unsigned int i = 0; i \u003c nr_entries; i++)\n 509:\t\t\t\tarch_stack_depot_frame_try_compress(entries[i],\n 510:\t\t\t\t\t\t\t\t \u0026stack-\u003ecompressed_entries[i]);\n 511:\t\t} else {\n 512:\t\t\tstack-\u003eflags = 0;\n 513:\t\t\tmemcpy(stack-\u003eentries, entries,\n 514:\t\t\t flex_array_size(stack, entries, nr_entries));\n 515:\t\t}\n 516:\t\n 517:\t\tif (flags \u0026 STACK_DEPOT_FLAG_GET) {\n 518:\t\t\trefcount_set(\u0026stack-\u003ecount, 1);\n 519:\t\t\tcounters[DEPOT_COUNTER_REFD_ALLOCS]++;\n 520:\t\t\tcounters[DEPOT_COUNTER_REFD_INUSE]++;\n 521:\t\t} else {\n 522:\t\t\t/* Warn on attempts to switch to refcounting this entry. */\n 523:\t\t\trefcount_set(\u0026stack-\u003ecount, REFCOUNT_SATURATED);\n 524:\t\t\tcounters[DEPOT_COUNTER_PERSIST_COUNT]++;\n 525:\t\t\tcounters[DEPOT_COUNTER_PERSIST_BYTES] += record_size;\n 526:\t\t}\n 527:\t\n 528:\t\t/*\n 529:\t\t * Let KMSAN know the stored stack record is initialized. This shall\n 530:\t\t * prevent false positive reports if instrumented code accesses it.\n 531:\t\t */\n 532:\t\tkmsan_unpoison_memory(stack, record_size);\n 533:\t\n"
} |
| 77/3 | 2026/11/18 03:50 | llm | kmsan-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 37386 output: 20 thoughts: 871 Thoughts: **KMSAN Concerns and Stack Record Initialization** Okay, so I'm diving into this `stackdepot.c` code and something is immediately jumping out at me. I see that lines 528-532 explicitly use `kmsan_unpoison_memory` on the `stack` record. This is interesting. The comments say this is to prevent false positives when KMSAN instruments code that accesses it. That's a good practice, and it makes sense, especially considering `stackdepot.c` is actually *explicitly* uninstrumented for KMSAN (`KMSAN_SANITIZE_stackdepot.o := n`). The code calls `kmsan_unpoison_memory` whenever it touches the stack records. The same pattern appears in `depot_copy_entries` where KMSAN is informed that the copied entries are initialized. And again, in both `stack_depot_print` and `stack_depot_snprint`, the code is meticulously unpoisoning individual stack frames before they are accessed. I see they are making sure each frame is unpoisoned with `kmsan_unpoison_memory(&frame, sizeof(frame))`, which makes sense since it is accessed in the loop. However, I've got to circle back to `find_stack`. I see the `depot_stack_equal` function is used, and it reads `stack->flags`. I need to make sure that `stack->flags` is initialized and safe to access. The `data_race` call is right next to it, and that's concerning. Could there be an uninitialized read? However, I'm using `list_for_each_entry_rcu(stack, bucket, hash_list)` to search the list of stack records. So the elements in the list are only added using `list_add_rcu(&new->hash_list, bucket)` AFTER a call to `depot_alloc_stack`. That should mean that all the fields of the `stack` record, including `stack->flags`, would be fully initialized before they get added to the list, and that memory barriers and RCU semantics would be observed. So there shouldn't be a race. Just to be absolutely sure, I'm going to scan the entire kernel with `grepper` and double-check all calls to `stack_depot_fetch` and `stack_depot_fetch_into` to see if there are any other potential issues. Better safe than sorry. |
| 78/3 | 2026/11/18 03:51 | tool | grepper |
0mArgs:{
"Expression": "stack_depot_fetch"
}Results: {
"Output": "include/linux/stackdepot.h=195=struct stack_record *__stack_depot_get_stack_record(depot_stack_handle_t handle);\n--\ninclude/linux/stackdepot.h-197-/**\ninclude/linux/stackdepot.h:198: * stack_depot_fetch_into - Fetch a stack trace into caller-owned storage\ninclude/linux/stackdepot.h-199- *\n--\ninclude/linux/stackdepot.h-228- */\ninclude/linux/stackdepot.h:229:unsigned int stack_depot_fetch_into(depot_stack_handle_t handle,\ninclude/linux/stackdepot.h-230-\t\t\t\t unsigned long *entries,\n--\nlib/stackdepot.c=819=static void depot_copy_entries(const struct stack_record *stack,\n--\nlib/stackdepot.c-827-\nlib/stackdepot.c:828:unsigned int stack_depot_fetch_into(depot_stack_handle_t handle,\nlib/stackdepot.c-829-\t\t\t\t unsigned long *entries,\n--\nlib/stackdepot.c-853-}\nlib/stackdepot.c:854:EXPORT_SYMBOL_GPL(stack_depot_fetch_into);\nlib/stackdepot.c-855-\n--\nlib/tests/stackdepot_kunit.c=23=static void stackdepot_fetch_into_roundtrip(struct kunit *test)\n--\nlib/tests/stackdepot_kunit.c-42-\nlib/tests/stackdepot_kunit.c:43:\tnr_entries = stack_depot_fetch_into(handle, exact, ARRAY_SIZE(exact));\nlib/tests/stackdepot_kunit.c-44-\tKUNIT_EXPECT_EQ(test, nr_entries, (unsigned int)ARRAY_SIZE(entries));\n--\nlib/tests/stackdepot_kunit.c-46-\nlib/tests/stackdepot_kunit.c:47:\tnr_entries = stack_depot_fetch_into(handle, fetched, ARRAY_SIZE(fetched));\nlib/tests/stackdepot_kunit.c-48-\tKUNIT_EXPECT_EQ(test, nr_entries, (unsigned int)ARRAY_SIZE(entries));\n--\nlib/tests/stackdepot_kunit.c=53=static void stackdepot_fetch_into_rejects_missing_or_short_stack(struct kunit *test)\n--\nlib/tests/stackdepot_kunit.c-74-\nlib/tests/stackdepot_kunit.c:75:\tnr_entries = stack_depot_fetch_into(0, fetched, ARRAY_SIZE(fetched));\nlib/tests/stackdepot_kunit.c-76-\tKUNIT_EXPECT_EQ(test, nr_entries, 0U);\n--\nlib/tests/stackdepot_kunit.c-78-\nlib/tests/stackdepot_kunit.c:79:\tnr_entries = stack_depot_fetch_into(0, NULL, 0);\nlib/tests/stackdepot_kunit.c-80-\tKUNIT_EXPECT_EQ(test, nr_entries, 0U);\nlib/tests/stackdepot_kunit.c-81-\nlib/tests/stackdepot_kunit.c:82:\tnr_entries = stack_depot_fetch_into(handle, fetched,\nlib/tests/stackdepot_kunit.c-83-\t\t\t\t\t ARRAY_SIZE(fetched) - 1);\n--\nlib/tests/stackdepot_kunit.c=178=static void stackdepot_compressed_frames(struct kunit *test)\n--\nlib/tests/stackdepot_kunit.c-208-\nlib/tests/stackdepot_kunit.c:209:\tKUNIT_EXPECT_EQ(test, stack_depot_fetch_into(compressed_handle, fetched,\nlib/tests/stackdepot_kunit.c-210-\t\t\t\t\t\t ARRAY_SIZE(fetched)),\n--\nlib/tests/stackdepot_kunit.c-212-\tKUNIT_EXPECT_MEMEQ(test, fetched, compressible, sizeof(compressible));\nlib/tests/stackdepot_kunit.c:213:\tKUNIT_EXPECT_EQ(test, stack_depot_fetch_into(mixed_handle, fetched,\nlib/tests/stackdepot_kunit.c-214-\t\t\t\t\t\t ARRAY_SIZE(fetched)),\n--\nlib/tests/stackdepot_kunit.c=220=static void stackdepot_get_record_not_compressed(struct kunit *test)\n--\nlib/tests/stackdepot_kunit.c-238-\tKUNIT_EXPECT_FALSE(test, record-\u003eflags \u0026 STACK_RECORD_COMPRESSED);\nlib/tests/stackdepot_kunit.c:239:\tKUNIT_EXPECT_EQ(test, stack_depot_fetch_into(handle, fetched,\nlib/tests/stackdepot_kunit.c-240-\t\t\t\t\t\t ARRAY_SIZE(fetched)),\n--\nmm/kmemleak.c=376=static void __print_unreferenced(struct seq_file *seq,\n--\nmm/kmemleak.c-383-\nmm/kmemleak.c:384:\tnr_entries = stack_depot_fetch_into(object-\u003etrace_handle, entries, ARRAY_SIZE(entries));\nmm/kmemleak.c-385-\twarn_or_seq_printf(seq, \"unreferenced object%s 0x%08lx (size %zu):\\n\",\n--\nmm/kmsan/kmsan_test.c=670=static void test_stackdepot_roundtrip(struct kunit *test)\n--\nmm/kmsan/kmsan_test.c-682-\tstack_depot_print(handle);\nmm/kmsan/kmsan_test.c:683:\tdst_nentries = stack_depot_fetch_into(handle, dst_entries, ARRAY_SIZE(dst_entries));\nmm/kmsan/kmsan_test.c-684-\tKUNIT_EXPECT_TRUE(test, src_nentries == dst_nentries);\n--\nmm/kmsan/report.c=86=static void kmsan_print_origin_with_buf(depot_stack_handle_t origin,\n--\nmm/kmsan/report.c-100-\t\tnr_entries =\nmm/kmsan/report.c:101:\t\t\tstack_depot_fetch_into(origin, entries, KMSAN_STACK_DEPTH);\nmm/kmsan/report.c-102-\t\tdepth = kmsan_depth_from_eb(stack_depot_get_extra_bits(origin));\n--\nmm/kmsan/report.c-126-\t\t\tchained_nr_entries =\nmm/kmsan/report.c:127:\t\t\t\tstack_depot_fetch_into(head, entries,\nmm/kmsan/report.c-128-\t\t\t\t\t\t KMSAN_STACK_DEPTH);\n--\nmm/page_owner.c=1067=static int stack_print(struct seq_file *m, void *v)\n--\nmm/page_owner.c-1085-\tif (ctx-\u003eflags \u0026 STACK_PRINT_FLAG_STACK) {\nmm/page_owner.c:1086:\t\tnr_entries = stack_depot_fetch_into(stack_record-\u003ehandle.handle,\nmm/page_owner.c-1087-\t\t\t\t\t\t entries, ARRAY_SIZE(entries));\n--\nmm/slub.c=8296=void __kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct slab *slab)\n--\nmm/slub.c-8335-\t\tif (handle) {\nmm/slub.c:8336:\t\t\tnr_entries = stack_depot_fetch_into(handle, entries, ARRAY_SIZE(entries));\nmm/slub.c-8337-\t\t\tfor (i = 0; i \u003c KS_ADDRS_COUNT \u0026\u0026 i \u003c nr_entries; i++)\n--\nmm/slub.c-8343-\t\tif (handle) {\nmm/slub.c:8344:\t\t\tnr_entries = stack_depot_fetch_into(handle, entries, ARRAY_SIZE(entries));\nmm/slub.c-8345-\t\t\tfor (i = 0; i \u003c KS_ADDRS_COUNT \u0026\u0026 i \u003c nr_entries; i++)\n--\nmm/slub.c=9989=static int slab_debugfs_show(struct seq_file *seq, void *v)\n--\nmm/slub.c-10039-\t\t\t\tnr_entries =\nmm/slub.c:10040:\t\t\t\t\tstack_depot_fetch_into(handle, entries,\nmm/slub.c-10041-\t\t\t\t\t\t\t ARRAY_SIZE(entries));\n--\nscripts/gdb/linux/stackdepot.py=23=def stack_record_entry(stack, i):\n--\nscripts/gdb/linux/stackdepot.py-37-\nscripts/gdb/linux/stackdepot.py:38:def stack_depot_fetch(handle):\nscripts/gdb/linux/stackdepot.py-39- global DEPOT_STACK_ALIGN\n--\nscripts/gdb/linux/stackdepot.py=71=def stack_depot_print(handle):\n--\nscripts/gdb/linux/stackdepot.py-74-\nscripts/gdb/linux/stackdepot.py:75: entries, nr_entries = stack_depot_fetch(handle)\nscripts/gdb/linux/stackdepot.py-76- if nr_entries \u003e 0:\n"
} |
| 79/3 | 2026/11/18 03:51 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 41263 output: 36 thoughts: 334 Thoughts: **My Analysis of the `stack_depot_fetch` Migration** Okay, so I've just finished reviewing the migration of all calls to `stack_depot_fetch` to either `stack_depot_fetch_into` or `stack_depot_snprint`. I've gone through each caller individually to make sure the transition is sound. Let's recap what I found: * **`kmemleak.c`**: The critical array `entries` is accessed only within the bounds `i < nr_entries`. No issues here. * **`kmsan_test.c`**: The code performs a sanity check. It ensures that the number of source entries (`src_nentries`) is equal to the destination entries (`dst_nentries`) and then calls `kmsan_check_memory` to examine the destination array. This seems correct. * **`kmsan/report.c`**: This module correctly iterates up to `nr_entries` (or `chained_nr_entries`) when printing data. No vulnerabilities identified. * **`page_owner.c`**: The code also safely handles the `entries` array, only accessing it up to `i < nr_entries`. * **`slub.c`**: Similarly, the access is bounded by `i < KS_ADDRS_COUNT && i < nr_entries`. This looks secure. * **`drm_modeset_lock.c`**: This uses `stack_depot_snprint`, which I've already scrutinized the implementation of. * **`stackdepot_kunit.c`**: These are just test cases, and they're probably fine. Now, my gut feeling is nagging me, as it always does. I have to be completely sure. I need to be *absolutely* certain that there aren't any sneaky direct accesses to `stack_record` or its `->entries` member lurking somewhere else, perhaps in DRM or a completely unrelated part of the codebase. It's time to do a thorough search of the entire kernel tree for those access patterns. Let's look for `->entries` or just the raw `stack_record` usage. I want to rule out *every* possibility. |
| 80/3 | 2026/11/18 03:52 | tool | grepper |
0mArgs:{
"Expression": "stack_record",
"PathPrefixes": [
"mm/",
"drivers/",
"lib/"
]
}Results: {
"Output": "\nFull output is too long, showing 200 out of 244 lines.\nUse more precise expression or PathPrefixes if possible.\n\nNumber of matching lines per file (3 files in total):\nlib/stackdepot.c:28\nlib/tests/stackdepot_kunit.c:5\nmm/page_owner.c:30\n\nlib/stackdepot.c=344=static void depot_keep_new_pool(void **prealloc)\n--\nlib/stackdepot.c-363- */\nlib/stackdepot.c:364:static struct stack_record *depot_pop_free_pool(void **prealloc, size_t size)\nlib/stackdepot.c-365-\t__must_hold(\u0026pool_lock)\nlib/stackdepot.c-366-{\nlib/stackdepot.c:367:\tstruct stack_record *stack;\nlib/stackdepot.c-368-\tvoid *current_pool;\n--\nlib/stackdepot.c-398-/* Try to find next free usable entry from the freelist. */\nlib/stackdepot.c:399:static struct stack_record *depot_pop_free(void)\nlib/stackdepot.c-400-\t__must_hold(\u0026pool_lock)\nlib/stackdepot.c-401-{\nlib/stackdepot.c:402:\tstruct stack_record *stack;\nlib/stackdepot.c-403-\n--\nlib/stackdepot.c-414-\t */\nlib/stackdepot.c:415:\tstack = list_first_entry(\u0026free_stacks, struct stack_record, free_list);\nlib/stackdepot.c-416-\tif (!poll_state_synchronize_rcu(stack-\u003ercu_state))\n--\nlib/stackdepot.c=426=static bool depot_entries_compressible(const unsigned long *entries,\n--\nlib/stackdepot.c-437-\nlib/stackdepot.c:438:static inline unsigned long depot_stack_entry(const struct stack_record *stack,\nlib/stackdepot.c-439-\t\t\t\t\t unsigned int i)\n--\nlib/stackdepot.c-448-\nlib/stackdepot.c:449:static inline size_t depot_stack_record_size(struct stack_record *s,\nlib/stackdepot.c-450-\t\t\t\t\t unsigned int nr_entries,\n--\nlib/stackdepot.c-459-\nlib/stackdepot.c:460:\treturn ALIGN(sizeof(struct stack_record) - unused, 1 \u003c\u003c DEPOT_STACK_ALIGN);\nlib/stackdepot.c-461-}\n--\nlib/stackdepot.c-463-/* Allocates a new stack in a stack depot pool. */\nlib/stackdepot.c:464:static struct stack_record *\nlib/stackdepot.c-465-depot_alloc_stack(unsigned long *entries, unsigned int nr_entries, u32 hash, depot_flags_t flags, void **prealloc)\n--\nlib/stackdepot.c-467-{\nlib/stackdepot.c:468:\tstruct stack_record *stack = NULL;\nlib/stackdepot.c-469-\tsize_t record_size;\n--\nlib/stackdepot.c-486-\t\t */\nlib/stackdepot.c:487:\t\trecord_size = depot_stack_record_size(stack,\nlib/stackdepot.c-488-\t\t\t\t\t\t CONFIG_STACKDEPOT_MAX_FRAMES,\n--\nlib/stackdepot.c-492-\t\tcompressed = depot_entries_compressible(entries, nr_entries);\nlib/stackdepot.c:493:\t\trecord_size = depot_stack_record_size(stack, nr_entries, compressed);\nlib/stackdepot.c-494-\t}\n--\nlib/stackdepot.c-536-\nlib/stackdepot.c:537:static struct stack_record *depot_fetch_stack(depot_stack_handle_t handle)\nlib/stackdepot.c-538-\t__must_not_hold(\u0026pool_lock)\n--\nlib/stackdepot.c-544-\tsize_t offset = parts.offset \u003c\u003c DEPOT_STACK_ALIGN;\nlib/stackdepot.c:545:\tstruct stack_record *stack;\nlib/stackdepot.c-546-\n--\nlib/stackdepot.c-567-/* Links stack into the freelist. */\nlib/stackdepot.c:568:static void depot_free_stack(struct stack_record *stack)\nlib/stackdepot.c-569-\t__must_not_hold(\u0026pool_lock)\n--\nlib/stackdepot.c=625=int stackdepot_memcmp(const unsigned long *u1, const unsigned long *u2,\n--\nlib/stackdepot.c-634-\nlib/stackdepot.c:635:static inline bool depot_stack_equal(const struct stack_record *stack,\nlib/stackdepot.c-636-\t\t\t\t const unsigned long *entries,\n--\nlib/stackdepot.c-649-/* Finds a stack in a bucket of the hash table. */\nlib/stackdepot.c:650:static inline struct stack_record *find_stack(struct list_head *bucket,\nlib/stackdepot.c-651-\t\t\t\t\t unsigned long *entries, int size,\n--\nlib/stackdepot.c-653-{\nlib/stackdepot.c:654:\tstruct stack_record *stack, *ret = NULL;\nlib/stackdepot.c-655-\n--\nlib/stackdepot.c=699=depot_stack_handle_t stack_depot_save_flags(unsigned long *entries,\n--\nlib/stackdepot.c-704-\tstruct list_head *bucket;\nlib/stackdepot.c:705:\tstruct stack_record *found = NULL;\nlib/stackdepot.c-706-\tdepot_stack_handle_t handle = 0;\n--\nlib/stackdepot.c-762-\tif (!found) {\nlib/stackdepot.c:763:\t\tstruct stack_record *new =\nlib/stackdepot.c-764-\t\t\tdepot_alloc_stack(entries, nr_entries, hash, depot_flags, \u0026prealloc);\n--\nlib/stackdepot.c=808=EXPORT_SYMBOL_GPL(stack_depot_save);\nlib/stackdepot.c-809-\nlib/stackdepot.c:810:struct stack_record *__stack_depot_get_stack_record(depot_stack_handle_t handle)\nlib/stackdepot.c-811-{\n--\nlib/stackdepot.c-818-/* Copy the first @nr_entries frames of @stack into @entries. */\nlib/stackdepot.c:819:static void depot_copy_entries(const struct stack_record *stack,\nlib/stackdepot.c-820-\t\t\t unsigned long *entries, unsigned int nr_entries)\n--\nlib/stackdepot.c=828=unsigned int stack_depot_fetch_into(depot_stack_handle_t handle,\n--\nlib/stackdepot.c-831-{\nlib/stackdepot.c:832:\tstruct stack_record *stack;\nlib/stackdepot.c-833-\tunsigned int nr_entries;\n--\nlib/stackdepot.c=854=EXPORT_SYMBOL_GPL(stack_depot_fetch_into);\nlib/stackdepot.c-855-\nlib/stackdepot.c:856:static struct stack_record *depot_print_fetch(depot_stack_handle_t handle)\nlib/stackdepot.c-857-{\nlib/stackdepot.c:858:\tstruct stack_record *stack;\nlib/stackdepot.c-859-\n--\nlib/stackdepot.c=872=void stack_depot_put(depot_stack_handle_t handle)\nlib/stackdepot.c-873-{\nlib/stackdepot.c:874:\tstruct stack_record *stack;\nlib/stackdepot.c-875-\n--\nlib/stackdepot.c=892=void stack_depot_print(depot_stack_handle_t handle)\nlib/stackdepot.c-893-{\nlib/stackdepot.c:894:\tstruct stack_record *stack = depot_print_fetch(handle);\nlib/stackdepot.c-895-\tunsigned long frame;\n--\nlib/stackdepot.c=907=int stack_depot_snprint(depot_stack_handle_t handle, char *buf, size_t size,\n--\nlib/stackdepot.c-909-{\nlib/stackdepot.c:910:\tstruct stack_record *stack = depot_print_fetch(handle);\nlib/stackdepot.c-911-\tunsigned int generated, total = 0;\n--\nlib/tests/stackdepot_kunit.c=178=static void stackdepot_compressed_frames(struct kunit *test)\n--\nlib/tests/stackdepot_kunit.c-181-\tdepot_stack_handle_t compressed_handle, mixed_handle;\nlib/tests/stackdepot_kunit.c:182:\tstruct stack_record *record;\nlib/tests/stackdepot_kunit.c-183-\tunsigned int i;\n--\nlib/tests/stackdepot_kunit.c-201-\nlib/tests/stackdepot_kunit.c:202:\trecord = __stack_depot_get_stack_record(compressed_handle);\nlib/tests/stackdepot_kunit.c-203-\tKUNIT_ASSERT_NOT_NULL(test, record);\nlib/tests/stackdepot_kunit.c-204-\tKUNIT_EXPECT_TRUE(test, record-\u003eflags \u0026 STACK_RECORD_COMPRESSED);\nlib/tests/stackdepot_kunit.c:205:\trecord = __stack_depot_get_stack_record(mixed_handle);\nlib/tests/stackdepot_kunit.c-206-\tKUNIT_ASSERT_NOT_NULL(test, record);\n--\nlib/tests/stackdepot_kunit.c=220=static void stackdepot_get_record_not_compressed(struct kunit *test)\n--\nlib/tests/stackdepot_kunit.c-223-\tdepot_stack_handle_t handle;\nlib/tests/stackdepot_kunit.c:224:\tstruct stack_record *record;\nlib/tests/stackdepot_kunit.c-225-\tunsigned int i;\n--\nlib/tests/stackdepot_kunit.c-235-\tKUNIT_ASSERT_NE(test, handle, (depot_stack_handle_t)0);\nlib/tests/stackdepot_kunit.c:236:\trecord = __stack_depot_get_stack_record(handle);\nlib/tests/stackdepot_kunit.c-237-\tKUNIT_ASSERT_NOT_NULL(test, record);\n--\nmm/page_owner.c=39=struct stack {\nmm/page_owner.c:40:\tstruct stack_record *stack_record;\nmm/page_owner.c-41-\tstruct stack *next;\n--\nmm/page_owner.c=140=static __init void init_page_owner(void)\n--\nmm/page_owner.c-149-\t/* Initialize dummy and failure stacks and link them to stack_list */\nmm/page_owner.c:150:\tdummy_stack.stack_record = __stack_depot_get_stack_record(dummy_handle);\nmm/page_owner.c:151:\tfailure_stack.stack_record = __stack_depot_get_stack_record(failure_handle);\nmm/page_owner.c:152:\tif (dummy_stack.stack_record)\nmm/page_owner.c:153:\t\trefcount_set(\u0026dummy_stack.stack_record-\u003ecount, 1);\nmm/page_owner.c:154:\tif (failure_stack.stack_record)\nmm/page_owner.c:155:\t\trefcount_set(\u0026failure_stack.stack_record-\u003ecount, 1);\nmm/page_owner.c-156-\tdummy_stack.next = \u0026failure_stack;\n--\nmm/page_owner.c=173=static noinline depot_stack_handle_t save_stack(gfp_t flags)\n--\nmm/page_owner.c-191-\nmm/page_owner.c:192:static void add_stack_record_to_list(struct stack_record *stack_record,\nmm/page_owner.c-193-\t\t\t\t gfp_t gfp_mask)\n--\nmm/page_owner.c-208-\nmm/page_owner.c:209:\tstack-\u003estack_record = stack_record;\nmm/page_owner.c-210-\tstack-\u003enext = NULL;\n--\nmm/page_owner.c-223-\nmm/page_owner.c:224:static void inc_stack_record_count(depot_stack_handle_t handle, gfp_t gfp_mask,\nmm/page_owner.c-225-\t\t\t\t int nr_base_pages)\nmm/page_owner.c-226-{\nmm/page_owner.c:227:\tstruct stack_record *stack_record = __stack_depot_get_stack_record(handle);\nmm/page_owner.c-228-\nmm/page_owner.c:229:\tif (!stack_record)\nmm/page_owner.c-230-\t\treturn;\n--\nmm/page_owner.c-232-\t/*\nmm/page_owner.c:233:\t * New stack_record's that do not use STACK_DEPOT_FLAG_GET start\nmm/page_owner.c-234-\t * with REFCOUNT_SATURATED to catch spurious increments of their\n--\nmm/page_owner.c-238-\t */\nmm/page_owner.c:239:\tif (refcount_read(\u0026stack_record-\u003ecount) == REFCOUNT_SATURATED) {\nmm/page_owner.c-240-\t\tint old = REFCOUNT_SATURATED;\nmm/page_owner.c-241-\nmm/page_owner.c:242:\t\tif (atomic_try_cmpxchg_relaxed(\u0026stack_record-\u003ecount.refs, \u0026old, 1))\nmm/page_owner.c:243:\t\t\t/* Add the new stack_record to our list */\nmm/page_owner.c:244:\t\t\tadd_stack_record_to_list(stack_record, gfp_mask);\nmm/page_owner.c-245-\t}\nmm/page_owner.c:246:\trefcount_add(nr_base_pages, \u0026stack_record-\u003ecount);\nmm/page_owner.c-247-}\nmm/page_owner.c-248-\nmm/page_owner.c:249:static void dec_stack_record_count(depot_stack_handle_t handle,\nmm/page_owner.c-250-\t\t\t\t int nr_base_pages)\nmm/page_owner.c-251-{\nmm/page_owner.c:252:\tstruct stack_record *stack_record = __stack_depot_get_stack_record(handle);\n\n"
} |
| 81/3 | 2026/11/18 03:52 | llm | kmsan-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 46117 output: 333 thoughts: 3531 Thoughts: **Analysis of Stack Depot Patch for Uninitialized Memory** Okay, let's break this down. I've been tasked with assessing this patch and determining if it introduces any uninitialized memory vulnerabilities or potential information leaks, particularly with regard to KMSAN. My initial thought process is to meticulously review the code, focusing on areas where uninitialized memory could be accessed or leaked. First, I examine the code in `mm/page_owner.c`, noting the access to `stack_record` primarily for `count` and within `stack_print`. This, however, is not a point of concern because of how those calls now work using `stack_depot_fetch_into`. The heart of the patch appears to be the compression/decompression logic for stack frames, particularly for x86-64 and arm64. I check the compression in `arch/x86/include/asm/stackdepot.h`. This compression uses a prefix to encode addresses. I carefully trace the `arch_stack_depot_frame_try_compress`, `arch_stack_depot_frame_decompress` calls, as well as `depot_entries_compressible` and `depot_alloc_stack`. I confirm that the compressed entries are correctly initialized, because there are explicit checks and initialization in those functions. I also double-check the `depot_stack_entry` and `depot_copy_entries` functions to confirm proper initialization and usage. I note the use of `kmsan_unpoison_memory` to mitigate risks of KMSAN false positives and data tracking. For arm64, I examine the equivalent functions: `arch_stack_depot_frame_from_payload`, `arch_stack_depot_frame_try_compress`, and `arch_stack_depot_frame_decompress`. These all have proper initialization. Next, I methodically apply the checklist for identifying potential uninitialized memory risks. First, kernel structures passed to user space: not applicable, since stack depot is internal to the kernel, used by KASAN, KMSAN, kmemleak, SLUB debug, page_owner, and DRM lock debugging. Second, conditional logic based on uninitialized data: none. All variables are explicitly initialized. Third, allocation of data structures where uninitialized fields could be read: In `struct stack_record`, `size` and `flags` are set and the entries are initialized either through `memcpy` or through `arch_stack_depot_frame_try_compress`. Also, `kmsan_unpoison_memory(stack, record_size)` is called. Fourth, bounds checks or logic that could allow access to uninitialized bytes of buffers: `stack_depot_fetch_into` explicitly checks `if (nr_entries > max_entries) return 0;`. It also bounds checks and copies only `nr_entries`. It returns `nr_entries` and marks the written slice initialized using `kmsan_unpoison_memory`. Callers only access what's returned. I pay special attention to the `lib/stackdepot.c` file and note that `kmsan_unpoison_memory` calls were updated to reflect the changes in the API, ensuring KMSAN does not report false positives and that the initialized data is properly tracked. I then ask myself, are there any scenarios where only KMSAN would catch something here? I conclude there is not: Out-of-bounds access would be detected by KASAN. Any incorrect pointers or memory corruption would also be caught by KASAN or standard debuggers. There are no uninitialized memory leaks to user space. There are no branching decisions on uninitialized data. To be absolutely sure, I methodically check all usages of the `stack_depot_fetch_into` function in the calling functions, one by one. In the DRM driver, `stack_depot_snprint` is used to print a stack trace to the kernel log. It's crucial that `buf` is null-terminated and no uninitialized memory is read. Then, I dive into the implementation of `stack_depot_snprint`. I see that the provided buffer is written to and then printed with `drm_printf`, not passed to user space. I check the logic with potential invalid `stack_depot` and null stacks; I confirm the existing and new code behave the same. I conclude this is not a DRM driver issue or stackdepot. Then, I check all other callers: `kmemleak.c`, `kmsan_test.c`, `report.c`, `page_owner.c`, `slub.c`, and `stackdepot_kunit.c`. I confirm that these callers all carefully use the number of entries returned, that is, `nr_entries`, to bounds-check everything. Finally, I |
| 82/3 | 2026/11/18 03:53 | tool | set-results |
0mArgs:{
"KMSANReasoning": "The patch series implements 32-bit frame compression for stack depot records on x86_64 and arm64, transitions the fetch API from stack_depot_fetch() returning internal pointers to stack_depot_fetch_into() writing into caller-provided buffers, and adds stack_depot_snprint().\n\nFrom an uninitialized memory perspective:\n1. Internal stack depot data structures: All fields in `struct stack_record` (including `size`, `flags`, and `compressed_entries`/`entries`) are completely written upon allocation in depot_alloc_stack(), followed by explicit kmsan_unpoison_memory(stack, record_size) annotations.\n2. Caller-provided buffers: In depot_copy_entries(), the copied frames are explicitly unpoisoned via kmsan_unpoison_memory(). All updated callers (kmemleak, page_owner, slub, kmsan report) strictly iterate up to the returned frame count `nr_entries`, avoiding any reads of trailing uninitialized buffer elements.\n3. User info-leaks: Stack depot data structures and stack frames are purely kernel-internal diagnostic data and are not copied to user space.\n4. KASAN vs KMSAN: Any potential issues arising from frame compression, index bounds, or array limits are out-of-bounds/corruption risks that are detected by standard KASAN and KUnit tests. There is no uninitialized memory risk uniquely detectable by KMSAN.",
"NeedsKMSAN": false
}Results: {
"KMSANReasoning": "The patch series implements 32-bit frame compression for stack depot records on x86_64 and arm64, transitions the fetch API from stack_depot_fetch() returning internal pointers to stack_depot_fetch_into() writing into caller-provided buffers, and adds stack_depot_snprint().\n\nFrom an uninitialized memory perspective:\n1. Internal stack depot data structures: All fields in `struct stack_record` (including `size`, `flags`, and `compressed_entries`/`entries`) are completely written upon allocation in depot_alloc_stack(), followed by explicit kmsan_unpoison_memory(stack, record_size) annotations.\n2. Caller-provided buffers: In depot_copy_entries(), the copied frames are explicitly unpoisoned via kmsan_unpoison_memory(). All updated callers (kmemleak, page_owner, slub, kmsan report) strictly iterate up to the returned frame count `nr_entries`, avoiding any reads of trailing uninitialized buffer elements.\n3. User info-leaks: Stack depot data structures and stack frames are purely kernel-internal diagnostic data and are not copied to user space.\n4. KASAN vs KMSAN: Any potential issues arising from frame compression, index bounds, or array limits are out-of-bounds/corruption risks that are detected by standard KASAN and KUnit tests. There is no uninitialized memory risk uniquely detectable by KMSAN.",
"NeedsKMSAN": false
} |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|