AI Trajectory


Trajectory: (Expand/Collapse All)
Seq Timestamp Type Name Duration
0/0 2026/09/25 01:53 flow patch-triage
4m Args:
null

Results:
{
  "EnableConfigs": [
    "KALLSYMS",
    "TEST_KALLSYMS_PERF",
    "KALLSYMS_SELFTEST",
    "KPROBE_EVENTS",
    "BPF_SYSCALL"
  ],
  "FocusSymbols": [
    "kallsyms_lookup_batch_start",
    "kallsyms_lookup_batch_end",
    "kallsyms_lookup_name",
    "kallsyms_on_each_match_symbol",
    "run_kallsyms_benchmark"
  ],
  "KMSANReasoning": "The patch optimizes kallsyms name lookup operations by:\n1. Comparing strings directly against compressed token stream in `kallsyms_strcmp_symbol()`, eliminating the temporary on-stack decompressed buffer in `kallsyms_lookup_names()`.\n2. Providing an optional batching mechanism (`kallsyms_lookup_batch_start()` / `kallsyms_lookup_batch_end()`) that builds a flat offset lookup table `dyn_kallsyms_offsets` allocated via `kvmalloc_array()`.\n3. Adding benchmark and selftest coverage in `lib/test_kallsyms_perf.c` and `kernel/kallsyms_selftest.c`.\n\nKASAN vs KMSAN applicability assessment:\n- No uninitialized memory exposure: The newly allocated buffer `dyn_kallsyms_offsets` is an array of `u32` (no padding) where every entry from 0 to `kallsyms_num_syms - 1` is populated sequentially in `kallsyms_build_offsets()` before the pointer is published via `rcu_assign_pointer()`. All other data structures involved (`kallsyms_names`, `kallsyms_token_table`, `kallsyms_token_index`) are read-only `.rodata` generated at build time.\n- No user-space info-leaks: No structures, padding, or uninitialized buffers are copied to user space (no `copy_to_user`, ioctl, netlink, or socket options touched).\n- Any potential risks introduced by the patch (such as out-of-bounds indexing in `offsets[pos]`, out-of-bounds reads on compressed names, RCU synchronization / lifetime issues, or mutex deadlocks) are strictly within the scope of KASAN, LOCKDEP, and standard kernel debug facilities.\n\nConsequently, there are no uninitialized memory hazards that warrant a dedicated KMSAN fuzzing session.",
  "NeedsKMSAN": false,
  "Reasoning": "The patch series introduces significant changes to the core kallsyms subsystem:\n1. Replaces full symbol name expansion during binary search with an on-the-fly token-by-token compressed string comparison function (kallsyms_strcmp_symbol).\n2. Introduces on-demand dynamic symbol offset indexing (dyn_kallsyms_offsets) protected by mutex, reference counts, and RCU dereferencing, bracketed by new batch lifecycle APIs (kallsyms_lookup_batch_start and kallsyms_lookup_batch_end) which include new runtime assertions (WARN_ON).\n3. Refactors symbol decompression and type extraction across kallsyms core.\n4. Adds a performance test module (lib/test_kallsyms_perf.c).\n\nThese code paths are reachable from userspace via BPF (e.g. bpf_kallsyms_lookup_name, kfunc resolution), tracefs/kprobes (e.g. writing to kprobe_events), and reading /proc/kallsyms. Due to complex pointer manipulation during compressed string comparison and dynamic memory lifetime management under RCU, this warrants fuzzing for memory corruption, buffer overreads, and race conditions.",
  "WorthFuzzing": true
}

1/1 2026/09/25 01:53 action read-patch-diff
0m Args:
null

Results:
{
  "PatchDiff": "commit f1fb56bfa08cc79fe520683bf24dcfad2ce5439d\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate:   Fri Sep 25 01:53:10 2026 +0000\n\n    syz-cluster: applied patch under review\n\ndiff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h\nindex d5dd54c53ace6..6e39795ac509b 100644\n--- a/include/linux/kallsyms.h\n+++ b/include/linux/kallsyms.h\n@@ -74,6 +74,10 @@ int kallsyms_on_each_symbol(int (*fn)(void *, const char *, unsigned long),\n int kallsyms_on_each_match_symbol(int (*fn)(void *, unsigned long),\n \t\t\t\t  const char *name, void *data);\n \n+/* Transient dynamic lookup index bracketing */\n+int kallsyms_lookup_batch_start(void);\n+void kallsyms_lookup_batch_end(void);\n+\n /* Lookup the address for a symbol. Returns 0 if not found. */\n unsigned long kallsyms_lookup_name(const char *name);\n \n@@ -164,6 +168,15 @@ static inline int kallsyms_on_each_match_symbol(int (*fn)(void *, unsigned long)\n {\n \treturn -EOPNOTSUPP;\n }\n+\n+static inline int kallsyms_lookup_batch_start(void)\n+{\n+\treturn 0;\n+}\n+\n+static inline void kallsyms_lookup_batch_end(void)\n+{\n+}\n #endif /*CONFIG_KALLSYMS*/\n \n static inline void print_ip_sym(const char *loglvl, unsigned long ip)\ndiff --git a/kernel/kallsyms.c b/kernel/kallsyms.c\nindex aec2f06858afd..8f76403e0e7be 100644\n--- a/kernel/kallsyms.c\n+++ b/kernel/kallsyms.c\n@@ -22,6 +22,9 @@\n #include \u003clinux/sched.h\u003e\t/* for cond_resched */\n #include \u003clinux/ctype.h\u003e\n #include \u003clinux/slab.h\u003e\n+#include \u003clinux/vmalloc.h\u003e\n+#include \u003clinux/mutex.h\u003e\n+#include \u003clinux/rcupdate.h\u003e\n #include \u003clinux/filter.h\u003e\n #include \u003clinux/ftrace.h\u003e\n #include \u003clinux/kprobes.h\u003e\n@@ -34,6 +37,21 @@\n \n #include \"kallsyms_internal.h\"\n \n+/*\n+ * Get the compressed symbol length and data pointer.\n+ */\n+static inline const u8 *get_symbol_data(unsigned int off, unsigned int *len)\n+{\n+\tconst u8 *p = \u0026kallsyms_names[off];\n+\tunsigned int l = *p++;\n+\n+\tif (unlikely(l \u0026 0x80))\n+\t\tl = (l \u0026 0x7F) | (*p++ \u003c\u003c 7);\n+\t*len = l;\n+\n+\treturn p;\n+}\n+\n /*\n  * Expand a compressed symbol data into the resulting uncompressed string,\n  * if uncompressed string is too long (\u003e= maxlen), it will be truncated,\n@@ -42,28 +60,12 @@\n static unsigned int kallsyms_expand_symbol(unsigned int off,\n \t\t\t\t\t   char *result, size_t maxlen)\n {\n-\tint len, skipped_first = 0;\n+\tint skipped_first = 0;\n \tconst char *tptr;\n-\tconst u8 *data;\n-\n-\t/* Get the compressed symbol length from the first symbol byte. */\n-\tdata = \u0026kallsyms_names[off];\n-\tlen = *data;\n-\tdata++;\n-\toff++;\n+\tunsigned int len;\n+\tconst u8 *data = get_symbol_data(off, \u0026len);\n \n-\t/* If MSB is 1, it is a \"big\" symbol, so needs an additional byte. */\n-\tif ((len \u0026 0x80) != 0) {\n-\t\tlen = (len \u0026 0x7F) | (*data \u003c\u003c 7);\n-\t\tdata++;\n-\t\toff++;\n-\t}\n-\n-\t/*\n-\t * Update the offset to return the offset for the next symbol on\n-\t * the compressed stream.\n-\t */\n-\toff += len;\n+\toff = (data - kallsyms_names) + len;\n \n \t/*\n \t * For every byte on the compressed symbol data, copy the table\n@@ -91,7 +93,7 @@ static unsigned int kallsyms_expand_symbol(unsigned int off,\n \tif (maxlen)\n \t\t*result = '\\0';\n \n-\t/* Return to offset to the next symbol. */\n+\t/* Return offset to the next symbol. */\n \treturn off;\n }\n \n@@ -101,22 +103,50 @@ static unsigned int kallsyms_expand_symbol(unsigned int off,\n  */\n static char kallsyms_get_symbol_type(unsigned int off)\n {\n-\t/*\n-\t * Get just the first code, look it up in the token table,\n-\t * and return the first char from this token. If MSB of length\n-\t * is 1, it is a \"big\" symbol, so needs an additional byte.\n-\t */\n-\tif (kallsyms_names[off] \u0026 0x80)\n-\t\toff++;\n-\treturn kallsyms_token_table[kallsyms_token_index[kallsyms_names[off + 1]]];\n+\tunsigned int len;\n+\tconst u8 *data = get_symbol_data(off, \u0026len);\n+\n+\treturn kallsyms_token_table[kallsyms_token_index[*data]];\n }\n \n+/*\n+ * Compare an uncompressed ASCII string against a compressed symbol table entry.\n+ * Returns negative if name \u003c sym, positive if name \u003e sym, 0 if equal.\n+ * Exits immediately on the first mismatched character without decompressing\n+ * the rest of the symbol name.\n+ */\n+static int kallsyms_strcmp_symbol(unsigned int off, const char *name)\n+{\n+\tconst char *tptr;\n+\tunsigned int len;\n+\tconst u8 *data = get_symbol_data(off, \u0026len);\n+\n+\ttptr = \u0026kallsyms_token_table[kallsyms_token_index[*data++]] + 1;\n+\twhile (*tptr) {\n+\t\tint diff = (unsigned char)*name++ - (unsigned char)*tptr++;\n+\n+\t\tif (diff)\n+\t\t\treturn diff;\n+\t}\n+\n+\twhile (--len) {\n+\t\ttptr = \u0026kallsyms_token_table[kallsyms_token_index[*data++]];\n+\t\tdo {\n+\t\t\tint diff = (unsigned char)*name++ - (unsigned char)*tptr++;\n+\n+\t\t\tif (diff)\n+\t\t\t\treturn diff;\n+\t\t} while (*tptr);\n+\t}\n+\n+\treturn (unsigned char)*name;\n+}\n \n /*\n- * Find the offset on the compressed stream given and index in the\n- * kallsyms array.\n+ * Find the offset on the compressed stream given an index in the\n+ * kallsyms array using legacy markers.\n  */\n-static unsigned int get_symbol_offset(unsigned long pos)\n+static unsigned int get_symbol_offset_marker(unsigned long pos)\n {\n \tconst u8 *name;\n \tint i, len;\n@@ -149,6 +179,100 @@ static unsigned int get_symbol_offset(unsigned long pos)\n \treturn name - kallsyms_names;\n }\n \n+/*\n+ * Dynamic symbol offset table.\n+ * Allocated on demand during high-volume lookup batches and reclaimed after.\n+ */\n+static u32 *dyn_kallsyms_offsets __read_mostly;\n+static DEFINE_MUTEX(dyn_kallsyms_mutex);\n+static unsigned int dyn_kallsyms_refcnt;\n+\n+static u32 *kallsyms_build_offsets(void)\n+{\n+\tconst u8 *name = kallsyms_names;\n+\tu32 *offsets;\n+\tunsigned int i;\n+\n+\toffsets = kvmalloc_array(kallsyms_num_syms, sizeof(u32), GFP_KERNEL);\n+\tif (!offsets)\n+\t\treturn NULL;\n+\n+\tfor (i = 0; i \u003c kallsyms_num_syms; i++) {\n+\t\tunsigned int len;\n+\t\tconst u8 *data;\n+\n+\t\toffsets[i] = name - kallsyms_names;\n+\t\tdata = get_symbol_data(offsets[i], \u0026len);\n+\t\tname = data + len;\n+\t}\n+\n+\treturn offsets;\n+}\n+\n+int kallsyms_lookup_batch_start(void)\n+{\n+\tint ret = 0;\n+\n+\tmutex_lock(\u0026dyn_kallsyms_mutex);\n+\tif (!dyn_kallsyms_refcnt) {\n+\t\tu32 *offsets = kallsyms_build_offsets();\n+\n+\t\tif (!offsets) {\n+\t\t\tret = -ENOMEM;\n+\t\t\tgoto out;\n+\t\t}\n+\t\trcu_assign_pointer(dyn_kallsyms_offsets, offsets);\n+\t}\n+\tdyn_kallsyms_refcnt++;\n+out:\n+\tmutex_unlock(\u0026dyn_kallsyms_mutex);\n+\treturn ret;\n+}\n+EXPORT_SYMBOL_GPL(kallsyms_lookup_batch_start);\n+\n+void kallsyms_lookup_batch_end(void)\n+{\n+\tu32 *offsets = NULL;\n+\n+\tmutex_lock(\u0026dyn_kallsyms_mutex);\n+\tif (WARN_ON(!dyn_kallsyms_refcnt))\n+\t\tgoto out;\n+\n+\tif (--dyn_kallsyms_refcnt == 0) {\n+\t\toffsets = dyn_kallsyms_offsets;\n+\t\trcu_assign_pointer(dyn_kallsyms_offsets, NULL);\n+\t}\n+out:\n+\tmutex_unlock(\u0026dyn_kallsyms_mutex);\n+\n+\tif (offsets) {\n+\t\tsynchronize_rcu();\n+\t\tkvfree(offsets);\n+\t}\n+}\n+EXPORT_SYMBOL_GPL(kallsyms_lookup_batch_end);\n+\n+/*\n+ * Find the offset on the compressed table given an index in the\n+ * kallsyms array.\n+ */\n+static inline unsigned int get_symbol_offset(unsigned long pos)\n+{\n+\tunsigned int off;\n+\tu32 *offsets;\n+\n+\trcu_read_lock();\n+\toffsets = rcu_dereference(dyn_kallsyms_offsets);\n+\tif (offsets) {\n+\t\toff = offsets[pos];\n+\t\trcu_read_unlock();\n+\t\treturn off;\n+\t}\n+\trcu_read_unlock();\n+\n+\treturn get_symbol_offset_marker(pos);\n+}\n+\n unsigned long kallsyms_sym_address(int idx)\n {\n \t/* non-relocatable 32-bit kernels just embed the value directly */\n@@ -157,14 +281,11 @@ unsigned long kallsyms_sym_address(int idx)\n \treturn (unsigned long)offset_to_ptr(kallsyms_offsets + idx);\n }\n \n-static unsigned int get_symbol_seq(int index)\n+static inline unsigned int get_symbol_seq(int index)\n {\n-\tunsigned int i, seq = 0;\n-\n-\tfor (i = 0; i \u003c 3; i++)\n-\t\tseq = (seq \u003c\u003c 8) | kallsyms_seqs_of_names[3 * index + i];\n+\tconst u8 *p = \u0026kallsyms_seqs_of_names[3 * index];\n \n-\treturn seq;\n+\treturn (p[0] \u003c\u003c 16) | (p[1] \u003c\u003c 8) | p[2];\n }\n \n static int kallsyms_lookup_names(const char *name,\n@@ -174,17 +295,16 @@ static int kallsyms_lookup_names(const char *name,\n \tint ret;\n \tint low, mid, high;\n \tunsigned int seq, off;\n-\tchar namebuf[KSYM_NAME_LEN];\n \n \tlow = 0;\n \thigh = kallsyms_num_syms - 1;\n \n+\trcu_read_lock();\n \twhile (low \u003c= high) {\n \t\tmid = low + (high - low) / 2;\n \t\tseq = get_symbol_seq(mid);\n \t\toff = get_symbol_offset(seq);\n-\t\tkallsyms_expand_symbol(off, namebuf, ARRAY_SIZE(namebuf));\n-\t\tret = strcmp(name, namebuf);\n+\t\tret = kallsyms_strcmp_symbol(off, name);\n \t\tif (ret \u003e 0)\n \t\t\tlow = mid + 1;\n \t\telse if (ret \u003c 0)\n@@ -193,15 +313,16 @@ static int kallsyms_lookup_names(const char *name,\n \t\t\tbreak;\n \t}\n \n-\tif (low \u003e high)\n+\tif (low \u003e high) {\n+\t\trcu_read_unlock();\n \t\treturn -ESRCH;\n+\t}\n \n \tlow = mid;\n \twhile (low) {\n \t\tseq = get_symbol_seq(low - 1);\n \t\toff = get_symbol_offset(seq);\n-\t\tkallsyms_expand_symbol(off, namebuf, ARRAY_SIZE(namebuf));\n-\t\tif (strcmp(name, namebuf))\n+\t\tif (kallsyms_strcmp_symbol(off, name) != 0)\n \t\t\tbreak;\n \t\tlow--;\n \t}\n@@ -212,13 +333,13 @@ static int kallsyms_lookup_names(const char *name,\n \t\twhile (high \u003c kallsyms_num_syms - 1) {\n \t\t\tseq = get_symbol_seq(high + 1);\n \t\t\toff = get_symbol_offset(seq);\n-\t\t\tkallsyms_expand_symbol(off, namebuf, ARRAY_SIZE(namebuf));\n-\t\t\tif (strcmp(name, namebuf))\n+\t\t\tif (kallsyms_strcmp_symbol(off, name) != 0)\n \t\t\t\tbreak;\n \t\t\thigh++;\n \t\t}\n \t\t*end = high;\n \t}\n+\trcu_read_unlock();\n \n \treturn 0;\n }\ndiff --git a/kernel/kallsyms_selftest.c b/kernel/kallsyms_selftest.c\nindex 8f6c4e9b3a1c0..aedffc058c0e6 100644\n--- a/kernel/kallsyms_selftest.c\n+++ b/kernel/kallsyms_selftest.c\n@@ -178,6 +178,7 @@ static int lookup_name(void *data, const char *name, unsigned long addr)\n static void test_perf_kallsyms_lookup_name(void)\n {\n \tstruct test_stat stat;\n+\tint ret;\n \n \tmemset(\u0026stat, 0, sizeof(stat));\n \tstat.min = INT_MAX;\n@@ -185,6 +186,21 @@ static void test_perf_kallsyms_lookup_name(void)\n \tpr_info(\"kallsyms_lookup_name() looked up %d symbols\\n\", stat.real_cnt);\n \tpr_info(\"The time spent on each symbol is (ns): min=%d, max=%d, avg=%lld\\n\",\n \t\tstat.min, stat.max, div_u64(stat.sum, stat.real_cnt));\n+\n+\tret = kallsyms_lookup_batch_start();\n+\tif (ret) {\n+\t\tpr_err(\"kallsyms_lookup_batch_start() failed: %d\\n\", ret);\n+\t\treturn;\n+\t}\n+\n+\tmemset(\u0026stat, 0, sizeof(stat));\n+\tstat.min = INT_MAX;\n+\tkallsyms_on_each_symbol(lookup_name, \u0026stat);\n+\tkallsyms_lookup_batch_end();\n+\n+\tpr_info(\"kallsyms_lookup_name() (batch) looked up %d symbols\\n\", stat.real_cnt);\n+\tpr_info(\"The time spent on each symbol is (ns): min=%d, max=%d, avg=%lld\\n\",\n+\t\tstat.min, stat.max, div_u64(stat.sum, stat.real_cnt));\n }\n \n static int find_symbol(void *data, const char *name, unsigned long addr)\ndiff --git a/lib/Kconfig.debug b/lib/Kconfig.debug\nindex 134b15a44625e..4b9669e64db9f 100644\n--- a/lib/Kconfig.debug\n+++ b/lib/Kconfig.debug\n@@ -3122,6 +3122,16 @@ config TEST_STATIC_KEYS\n \n \t  If unsure, say N.\n \n+config TEST_KALLSYMS_PERF\n+\tbool \"kallsyms performance benchmark test module\"\n+\tdepends on KALLSYMS\n+\thelp\n+\t  This builds test_kallsyms_perf to benchmark latency across\n+\t  Name-to-Address binary search, Address-to-Name resolution,\n+\t  and full table walks.\n+\n+\t  If unsure, say N.\n+\n config TEST_DYNAMIC_DEBUG\n \ttristate \"Test DYNAMIC_DEBUG\"\n \tdepends on DYNAMIC_DEBUG\ndiff --git a/lib/Makefile b/lib/Makefile\nindex dfab958327c5c..149968ff3f6bd 100644\n--- a/lib/Makefile\n+++ b/lib/Makefile\n@@ -85,6 +85,7 @@ obj-$(CONFIG_TEST_RHASHTABLE) += test_rhashtable.o\n obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_keys.o\n obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_key_base.o\n obj-$(CONFIG_TEST_DYNAMIC_DEBUG) += test_dynamic_debug.o\n+obj-$(CONFIG_TEST_KALLSYMS_PERF) += test_kallsyms_perf.o\n \n obj-$(CONFIG_TEST_BITMAP) += test_bitmap.o\n ifeq ($(CONFIG_CC_IS_CLANG)$(CONFIG_KASAN),yy)\ndiff --git a/lib/test_kallsyms_perf.c b/lib/test_kallsyms_perf.c\nnew file mode 100644\nindex 0000000000000..6f74ade4a0184\n--- /dev/null\n+++ b/lib/test_kallsyms_perf.c\n@@ -0,0 +1,281 @@\n+// SPDX-License-Identifier: GPL-2.0-only\n+/*\n+ * Microbenchmark and correctness test module for kallsyms subsystem\n+ *\n+ * Measures CPU latency across:\n+ *  - Name-to-Address binary search (hits \u0026 misses)\n+ *  - Address-to-Name symbol resolution (sprint_symbol, buildid)\n+ *  - Full kernel symbol iteration (kallsyms_on_each_symbol)\n+ */\n+\n+#define pr_fmt(fmt) \"test_kallsyms: \" fmt\n+\n+#include \u003clinux/init.h\u003e\n+#include \u003clinux/module.h\u003e\n+#include \u003clinux/kernel.h\u003e\n+#include \u003clinux/kallsyms.h\u003e\n+#include \u003clinux/ktime.h\u003e\n+#include \u003clinux/compiler.h\u003e\n+#include \u003clinux/sched.h\u003e\n+#include \u003clinux/math.h\u003e\n+\n+static unsigned int num_iters = 100000;\n+module_param(num_iters, uint, 0644);\n+MODULE_PARM_DESC(num_iters, \"Number of iterations per microbenchmark\");\n+\n+static const char * const hit_symbols[] = {\n+\t\"_printk\",\n+\t\"schedule\",\n+\t\"vfs_read\",\n+\t\"do_sys_openat2\",\n+\t\"kernel_clone\",\n+\t\"panic\",\n+\t\"kallsyms_lookup_names\",\n+\t\"vm_area_alloc\",\n+};\n+\n+static const char * const miss_symbols[] = {\n+\t\"nonexistent_symbol_0001\",\n+\t\"xyz_dummy_missing_symbol\",\n+\t\"__never_compiled_in_kernel\",\n+\t\"ext4_nonexistent_func_xyz\",\n+\t\"bpf_not_real_helper_stub\",\n+\t\"vfs_missing_handler_probe\",\n+\t\"tcp_v4_unimplemented_path\",\n+\t\"driver_fake_init_routine\",\n+};\n+\n+static int match_cb(void *data, unsigned long addr)\n+{\n+\tunsigned long *out = data;\n+\n+\t*out = addr;\n+\treturn 1;\n+}\n+\n+static int count_cb(void *data, const char *name, unsigned long addr)\n+{\n+\tunsigned long *cnt = data;\n+\n+\t(*cnt)++;\n+\treturn 0;\n+}\n+\n+static void run_name_lookup_bench(const char *mode, u64 *avg_hit_ns, u64 *avg_miss_ns)\n+{\n+\tu64 t0, t1, dt_hit, dt_miss;\n+\tunsigned long addr = 0;\n+\tunsigned int i, nr_hits, nr_misses;\n+\n+\tnr_hits = ARRAY_SIZE(hit_symbols);\n+\tnr_misses = ARRAY_SIZE(miss_symbols);\n+\n+\t/* 0. Correctness validation */\n+\tfor (i = 0; i \u003c nr_hits; i++) {\n+\t\tconst char *sym = hit_symbols[i];\n+\t\tunsigned long a1 = 0;\n+\n+\t\tkallsyms_on_each_match_symbol(match_cb, sym, \u0026a1);\n+\t\tif (!a1)\n+\t\t\tpr_err(\"CORRECTNESS FAILURE: hit sym '%s' not found\\n\", sym);\n+\t}\n+\tfor (i = 0; i \u003c nr_misses; i++) {\n+\t\tconst char *sym = miss_symbols[i];\n+\t\tunsigned long a1 = 0;\n+\n+\t\tkallsyms_on_each_match_symbol(match_cb, sym, \u0026a1);\n+\t\tif (a1)\n+\t\t\tpr_err(\"CORRECTNESS FAILURE: miss sym '%s' unexpectedly found a1=%lx\\n\",\n+\t\t\t       sym, a1);\n+\t}\n+\n+\t/* 1. Name search: Existing symbols (Hits) */\n+\tt0 = ktime_get_ns();\n+\tfor (i = 0; i \u003c num_iters; i++) {\n+\t\tconst char *sym = hit_symbols[i % nr_hits];\n+\n+\t\tif (unlikely(!(i \u0026 0x3fff)))\n+\t\t\tcond_resched();\n+\n+\t\tkallsyms_on_each_match_symbol(match_cb, sym, \u0026addr);\n+\t\tOPTIMIZER_HIDE_VAR(addr);\n+\t}\n+\tt1 = ktime_get_ns();\n+\tdt_hit = t1 - t0;\n+\n+\t/* 2. Name search: Non-existent symbols (Misses - 17 bsearch probes) */\n+\tt0 = ktime_get_ns();\n+\tfor (i = 0; i \u003c num_iters; i++) {\n+\t\tconst char *sym = miss_symbols[i % nr_misses];\n+\n+\t\tif (unlikely(!(i \u0026 0x3fff)))\n+\t\t\tcond_resched();\n+\n+\t\tkallsyms_on_each_match_symbol(match_cb, sym, \u0026addr);\n+\t\tOPTIMIZER_HIDE_VAR(addr);\n+\t}\n+\tt1 = ktime_get_ns();\n+\tdt_miss = t1 - t0;\n+\n+\tif (avg_hit_ns)\n+\t\t*avg_hit_ns = div_u64(dt_hit, num_iters);\n+\tif (avg_miss_ns)\n+\t\t*avg_miss_ns = div_u64(dt_miss, num_iters);\n+\n+\tpr_info(\"[%s] Name Search Hit:  %llu ns/lookup (%llu ms total, %u iters)\\n\",\n+\t\tmode, div_u64(dt_hit, num_iters), div_u64(dt_hit, 1000000), num_iters);\n+\tpr_info(\"[%s] Name Search Miss: %llu ns/lookup (%llu ms total, %u iters)\\n\",\n+\t\tmode, div_u64(dt_miss, num_iters), div_u64(dt_miss, 1000000), num_iters);\n+}\n+\n+static void run_address_lookup_bench(void)\n+{\n+\tu64 t0, t1, dt_sprint, dt_bldid;\n+\tchar symname[KSYM_SYMBOL_LEN];\n+\tunsigned long addrs[ARRAY_SIZE(hit_symbols)];\n+\tunsigned int i, nr_addrs = 0;\n+\n+\tfor (i = 0; i \u003c ARRAY_SIZE(hit_symbols); i++) {\n+\t\tunsigned long addr = 0;\n+\n+\t\tkallsyms_on_each_match_symbol(match_cb, hit_symbols[i], \u0026addr);\n+\t\tif (addr)\n+\t\t\taddrs[nr_addrs++] = addr;\n+\t}\n+\n+\tif (!nr_addrs) {\n+\t\tpr_warn(\"Address benchmark skipped: no test addresses resolved\\n\");\n+\t\treturn;\n+\t}\n+\n+\t/* 1. Address-to-name resolution (sprint_symbol) */\n+\tt0 = ktime_get_ns();\n+\tfor (i = 0; i \u003c num_iters; i++) {\n+\t\tunsigned long addr = addrs[i % nr_addrs];\n+\n+\t\tif (unlikely(!(i \u0026 0x3fff)))\n+\t\t\tcond_resched();\n+\n+\t\tsprint_symbol(symname, addr);\n+\t\tbarrier_data(symname);\n+\t}\n+\tt1 = ktime_get_ns();\n+\tdt_sprint = t1 - t0;\n+\n+\t/* 2. Address without offset (sprint_symbol_no_offset) */\n+\tt0 = ktime_get_ns();\n+\tfor (i = 0; i \u003c num_iters; i++) {\n+\t\tunsigned long addr = addrs[i % nr_addrs];\n+\n+\t\tif (unlikely(!(i \u0026 0x3fff)))\n+\t\t\tcond_resched();\n+\n+\t\tsprint_symbol_no_offset(symname, addr);\n+\t\tbarrier_data(symname);\n+\t}\n+\tt1 = ktime_get_ns();\n+\tdt_bldid = t1 - t0;\n+\n+\tpr_info(\"sprint_symbol:           %llu ns/lookup (%llu ms total, %u iters)\\n\",\n+\t\tdiv_u64(dt_sprint, num_iters), div_u64(dt_sprint, 1000000), num_iters);\n+\tpr_info(\"sprint_symbol_no_offset: %llu ns/lookup (%llu ms total, %u iters)\\n\",\n+\t\tdiv_u64(dt_bldid, num_iters), div_u64(dt_bldid, 1000000), num_iters);\n+}\n+\n+static void run_table_walk_bench(void)\n+{\n+\tu64 t0, t1, dt_walk;\n+\tunsigned long total_symbols = 0;\n+\tint iter = 50;\n+\tint i;\n+\n+\tt0 = ktime_get_ns();\n+\tfor (i = 0; i \u003c iter; i++) {\n+\t\ttotal_symbols = 0;\n+\t\tkallsyms_on_each_symbol(count_cb, \u0026total_symbols);\n+\t}\n+\tt1 = ktime_get_ns();\n+\tdt_walk = t1 - t0;\n+\n+\tpr_info(\"Table Full Walk:  %llu ns/sym (%llu us/pass, %lu symbols scanned, %d passes)\\n\",\n+\t\tdiv_u64(div_u64(dt_walk, iter), total_symbols ? total_symbols : 1),\n+\t\tdiv_u64(div_u64(dt_walk, iter), 1000), total_symbols, iter);\n+}\n+\n+static int run_kallsyms_benchmark(void)\n+{\n+\tu64 unindexed_hit = 0, unindexed_miss = 0;\n+\tu64 dyn_hit = 0, dyn_miss = 0;\n+\tu64 t0, t1, dt_start = 0, dt_end = 0;\n+\tint ret;\n+\n+\tif (!num_iters) {\n+\t\tpr_err(\"num_iters must be non-zero\\n\");\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tpr_info(\"==================================================\\n\");\n+\tpr_info(\"Starting kallsyms performance benchmark (iters=%u)\\n\", num_iters);\n+\tpr_info(\"==================================================\\n\");\n+\n+\t/* 1. Benchmark baseline unindexed marker scan */\n+\trun_name_lookup_bench(\"Unindexed (markers)\", \u0026unindexed_hit, \u0026unindexed_miss);\n+\n+\t/* 2. Benchmark dynamic lookup index */\n+\tt0 = ktime_get_ns();\n+\tret = kallsyms_lookup_batch_start();\n+\tt1 = ktime_get_ns();\n+\tdt_start = t1 - t0;\n+\n+\tif (ret) {\n+\t\tpr_err(\"Failed to start kallsyms lookup batch: %d\\n\", ret);\n+\t} else {\n+\t\trun_name_lookup_bench(\"Dynamic Index\", \u0026dyn_hit, \u0026dyn_miss);\n+\n+\t\tt0 = ktime_get_ns();\n+\t\tkallsyms_lookup_batch_end();\n+\t\tt1 = ktime_get_ns();\n+\t\tdt_end = t1 - t0;\n+\n+\t\tpr_info(\"[Dynamic Index] Batch setup: %llu us, teardown: %llu us\\n\",\n+\t\t\tdiv_u64(dt_start, 1000), div_u64(dt_end, 1000));\n+\n+\t\tif (unindexed_hit \u003e dyn_hit) {\n+\t\t\tu64 saved = unindexed_hit - dyn_hit;\n+\n+\t\t\tpr_info(\"[Dynamic Index] Amortization break-even: %llu queries (setup), %llu queries (total)\\n\",\n+\t\t\t\tDIV_ROUND_UP_ULL(dt_start, saved),\n+\t\t\t\tDIV_ROUND_UP_ULL(dt_start + dt_end, saved));\n+\t\t}\n+\t}\n+\n+\trun_address_lookup_bench();\n+\trun_table_walk_bench();\n+\n+\tpr_info(\"==================================================\\n\");\n+\tpr_info(\"kallsyms benchmark complete\\n\");\n+\tpr_info(\"==================================================\\n\");\n+\n+\treturn 0;\n+}\n+\n+static int param_set_trigger(const char *val, const struct kernel_param *kp)\n+{\n+\treturn run_kallsyms_benchmark();\n+}\n+\n+static const struct kernel_param_ops param_ops_trigger = {\n+\t.set = param_set_trigger,\n+};\n+module_param_cb(run_test, \u0026param_ops_trigger, NULL, 0200);\n+MODULE_PARM_DESC(run_test, \"Write 1 to trigger kallsyms benchmark run\");\n+\n+static int __init test_kallsyms_init(void)\n+{\n+\treturn run_kallsyms_benchmark();\n+}\n+late_initcall(test_kallsyms_init);\n+\n+MODULE_DESCRIPTION(\"Microbenchmark test module for kallsyms subsystem\");\n+MODULE_AUTHOR(\"Jim Cromie \u003cjim.cromie@gmail.com\u003e\");\n+MODULE_LICENSE(\"GPL\");\n"
}

2/1 2026/09/25 01:53 agent patch-evaluator
2m Model:
core

Args:
null

Results:
{
  "EnableConfigs": [
    "KALLSYMS",
    "TEST_KALLSYMS_PERF",
    "KALLSYMS_SELFTEST",
    "KPROBE_EVENTS",
    "BPF_SYSCALL"
  ],
  "FocusSymbols": [
    "kallsyms_lookup_batch_start",
    "kallsyms_lookup_batch_end",
    "kallsyms_lookup_name",
    "kallsyms_on_each_match_symbol",
    "run_kallsyms_benchmark"
  ],
  "Reasoning": "The patch series introduces significant changes to the core kallsyms subsystem:\n1. Replaces full symbol name expansion during binary search with an on-the-fly token-by-token compressed string comparison function (kallsyms_strcmp_symbol).\n2. Introduces on-demand dynamic symbol offset indexing (dyn_kallsyms_offsets) protected by mutex, reference counts, and RCU dereferencing, bracketed by new batch lifecycle APIs (kallsyms_lookup_batch_start and kallsyms_lookup_batch_end) which include new runtime assertions (WARN_ON).\n3. Refactors symbol decompression and type extraction across kallsyms core.\n4. Adds a performance test module (lib/test_kallsyms_perf.c).\n\nThese code paths are reachable from userspace via BPF (e.g. bpf_kallsyms_lookup_name, kfunc resolution), tracefs/kprobes (e.g. writing to kprobe_events), and reading /proc/kallsyms. Due to complex pointer manipulation during compressed string comparison and dynamic memory lifetime management under RCU, this warrants fuzzing for memory corruption, buffer overreads, and race conditions.",
  "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 f1fb56bfa08cc79fe520683bf24dcfad2ce5439d
Author: syz-cluster <triage@syzkaller.com>
Date:   Fri Sep 25 01:53:10 2026 +0000

    syz-cluster: applied patch under review

diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
index d5dd54c53ace6..6e39795ac509b 100644
--- a/include/linux/kallsyms.h
+++ b/include/linux/kallsyms.h
@@ -74,6 +74,10 @@ int kallsyms_on_each_symbol(int (*fn)(void *, const char *, unsigned long),
 int kallsyms_on_each_match_symbol(int (*fn)(void *, unsigned long),
 				  const char *name, void *data);
 
+/* Transient dynamic lookup index bracketing */
+int kallsyms_lookup_batch_start(void);
+void kallsyms_lookup_batch_end(void);
+
 /* Lookup the address for a symbol. Returns 0 if not found. */
 unsigned long kallsyms_lookup_name(const char *name);
 
@@ -164,6 +168,15 @@ static inline int kallsyms_on_each_match_symbol(int (*fn)(void *, unsigned long)
 {
 	return -EOPNOTSUPP;
 }
+
+static inline int kallsyms_lookup_batch_start(void)
+{
+	return 0;
+}
+
+static inline void kallsyms_lookup_batch_end(void)
+{
+}
 #endif /*CONFIG_KALLSYMS*/
 
 static inline void print_ip_sym(const char *loglvl, unsigned long ip)
diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
index aec2f06858afd..8f76403e0e7be 100644
--- a/kernel/kallsyms.c
+++ b/kernel/kallsyms.c
@@ -22,6 +22,9 @@
 #include <linux/sched.h>	/* for cond_resched */
 #include <linux/ctype.h>
 #include <linux/slab.h>
+#include <linux/vmalloc.h>
+#include <linux/mutex.h>
+#include <linux/rcupdate.h>
 #include <linux/filter.h>
 #include <linux/ftrace.h>
 #include <linux/kprobes.h>
@@ -34,6 +37,21 @@
 
 #include "kallsyms_internal.h"
 
+/*
+ * Get the compressed symbol length and data pointer.
+ */
+static inline const u8 *get_symbol_data(unsigned int off, unsigned int *len)
+{
+	const u8 *p = &kallsyms_names[off];
+	unsigned int l = *p++;
+
+	if (unlikely(l & 0x80))
+		l = (l & 0x7F) | (*p++ << 7);
+	*len = l;
+
+	return p;
+}
+
 /*
  * Expand a compressed symbol data into the resulting uncompressed string,
  * if uncompressed string is too long (>= maxlen), it will be truncated,
@@ -42,28 +60,12 @@
 static unsigned int kallsyms_expand_symbol(unsigned int off,
 					   char *result, size_t maxlen)
 {
-	int len, skipped_first = 0;
+	int skipped_first = 0;
 	const char *tptr;
-	const u8 *data;
-
-	/* Get the compressed symbol length from the first symbol byte. */
-	data = &kallsyms_names[off];
-	len = *data;
-	data++;
-	off++;
+	unsigned int len;
+	const u8 *data = get_symbol_data(off, &len);
 
-	/* If MSB is 1, it is a "big" symbol, so needs an additional byte. */
-	if ((len & 0x80) != 0) {
-		len = (len & 0x7F) | (*data << 7);
-		data++;
-		off++;
-	}
-
-	/*
-	 * Update the offset to return the offset for the next symbol on
-	 * the compressed stream.
-	 */
-	off += len;
+	off = (data - kallsyms_names) + len;
 
 	/*
 	 * For every byte on the compressed symbol data, copy the table
@@ -91,7 +93,7 @@ static unsigned int kallsyms_expand_symbol(unsigned int off,
 	if (maxlen)
 		*result = '\0';
 
-	/* Return to offset to the next symbol. */
+	/* Return offset to the next symbol. */
 	return off;
 }
 
@@ -101,22 +103,50 @@ static unsigned int kallsyms_expand_symbol(unsigned int off,
  */
 static char kallsyms_get_symbol_type(unsigned int off)
 {
-	/*
-	 * Get just the first code, look it up in the token table,
-	 * and return the first char from this token. If MSB of length
-	 * is 1, it is a "big" symbol, so needs an additional byte.
-	 */
-	if (kallsyms_names[off] & 0x80)
-		off++;
-	return kallsyms_token_table[kallsyms_token_index[kallsyms_names[off + 1]]];
+	unsigned int len;
+	const u8 *data = get_symbol_data(off, &len);
+
+	return kallsyms_token_table[kallsyms_token_index[*data]];
 }
 
+/*
+ * Compare an uncompressed ASCII string against a compressed symbol table entry.
+ * Returns negative if name < sym, positive if name > sym, 0 if equal.
+ * Exits immediately on the first mismatched character without decompressing
+ * the rest of the symbol name.
+ */
+static int kallsyms_strcmp_symbol(unsigned int off, const char *name)
+{
+	const char *tptr;
+	unsigned int len;
+	const u8 *data = get_symbol_data(off, &len);
+
+	tptr = &kallsyms_token_table[kallsyms_token_index[*data++]] + 1;
+	while (*tptr) {
+		int diff = (unsigned char)*name++ - (unsigned char)*tptr++;
+
+		if (diff)
+			return diff;
+	}
+
+	while (--len) {
+		tptr = &kallsyms_token_table[kallsyms_token_index[*data++]];
+		do {
+			int diff = (unsigned char)*name++ - (unsigned char)*tptr++;
+
+			if (diff)
+				return diff;
+		} while (*tptr);
+	}
+
+	return (unsigned char)*name;
+}
 
 /*
- * Find the offset on the compressed stream given and index in the
- * kallsyms array.
+ * Find the offset on the compressed stream given an index in the
+ * kallsyms array using legacy markers.
  */
-static unsigned int get_symbol_offset(unsigned long pos)
+static unsigned int get_symbol_offset_marker(unsigned long pos)
 {
 	const u8 *name;
 	int i, len;
@@ -149,6 +179,100 @@ static unsigned int get_symbol_offset(unsigned long pos)
 	return name - kallsyms_names;
 }
 
+/*
+ * Dynamic symbol offset table.
+ * Allocated on demand during high-volume lookup batches and reclaimed after.
+ */
+static u32 *dyn_kallsyms_offsets __read_mostly;
+static DEFINE_MUTEX(dyn_kallsyms_mutex);
+static unsigned int dyn_kallsyms_refcnt;
+
+static u32 *kallsyms_build_offsets(void)
+{
+	const u8 *name = kallsyms_names;
+	u32 *offsets;
+	unsigned int i;
+
+	offsets = kvmalloc_array(kallsyms_num_syms, sizeof(u32), GFP_KERNEL);
+	if (!offsets)
+		return NULL;
+
+	for (i = 0; i < kallsyms_num_syms; i++) {
+		unsigned int len;
+		const u8 *data;
+
+		offsets[i] = name - kallsyms_names;
+		data = get_symbol_data(offsets[i], &len);
+		name = data + len;
+	}
+
+	return offsets;
+}
+
+int kallsyms_lookup_batch_start(void)
+{
+	int ret = 0;
+
+	mutex_lock(&dyn_kallsyms_mutex);
+	if (!dyn_kallsyms_refcnt) {
+		u32 *offsets = kallsyms_build_offsets();
+
+		if (!offsets) {
+			ret = -ENOMEM;
+			goto out;
+		}
+		rcu_assign_pointer(dyn_kallsyms_offsets, offsets);
+	}
+	dyn_kallsyms_refcnt++;
+out:
+	mutex_unlock(&dyn_kallsyms_mutex);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(kallsyms_lookup_batch_start);
+
+void kallsyms_lookup_batch_end(void)
+{
+	u32 *offsets = NULL;
+
+	mutex_lock(&dyn_kallsyms_mutex);
+	if (WARN_ON(!dyn_kallsyms_refcnt))
+		goto out;
+
+	if (--dyn_kallsyms_refcnt == 0) {
+		offsets = dyn_kallsyms_offsets;
+		rcu_assign_pointer(dyn_kallsyms_offsets, NULL);
+	}
+out:
+	mutex_unlock(&dyn_kallsyms_mutex);
+
+	if (offsets) {
+		synchronize_rcu();
+		kvfree(offsets);
+	}
+}
+EXPORT_SYMBOL_GPL(kallsyms_lookup_batch_end);
+
+/*
+ * Find the offset on the compressed table given an index in the
+ * kallsyms array.
+ */
+static inline unsigned int get_symbol_offset(unsigned long pos)
+{
+	unsigned int off;
+	u32 *offsets;
+
+	rcu_read_lock();
+	offsets = rcu_dereference(dyn_kallsyms_offsets);
+	if (offsets) {
+		off = offsets[pos];
+		rcu_read_unlock();
+		return off;
+	}
+	rcu_read_unlock();
+
+	return get_symbol_offset_marker(pos);
+}
+
 unsigned long kallsyms_sym_address(int idx)
 {
 	/* non-relocatable 32-bit kernels just embed the value directly */
@@ -157,14 +281,11 @@ unsigned long kallsyms_sym_address(int idx)
 	return (unsigned long)offset_to_ptr(kallsyms_offsets + idx);
 }
 
-static unsigned int get_symbol_seq(int index)
+static inline unsigned int get_symbol_seq(int index)
 {
-	unsigned int i, seq = 0;
-
-	for (i = 0; i < 3; i++)
-		seq = (seq << 8) | kallsyms_seqs_of_names[3 * index + i];
+	const u8 *p = &kallsyms_seqs_of_names[3 * index];
 
-	return seq;
+	return (p[0] << 16) | (p[1] << 8) | p[2];
 }
 
 static int kallsyms_lookup_names(const char *name,
@@ -174,17 +295,16 @@ static int kallsyms_lookup_names(const char *name,
 	int ret;
 	int low, mid, high;
 	unsigned int seq, off;
-	char namebuf[KSYM_NAME_LEN];
 
 	low = 0;
 	high = kallsyms_num_syms - 1;
 
+	rcu_read_lock();
 	while (low <= high) {
 		mid = low + (high - low) / 2;
 		seq = get_symbol_seq(mid);
 		off = get_symbol_offset(seq);
-		kallsyms_expand_symbol(off, namebuf, ARRAY_SIZE(namebuf));
-		ret = strcmp(name, namebuf);
+		ret = kallsyms_strcmp_symbol(off, name);
 		if (ret > 0)
 			low = mid + 1;
 		else if (ret < 0)
@@ -193,15 +313,16 @@ static int kallsyms_lookup_names(const char *name,
 			break;
 	}
 
-	if (low > high)
+	if (low > high) {
+		rcu_read_unlock();
 		return -ESRCH;
+	}
 
 	low = mid;
 	while (low) {
 		seq = get_symbol_seq(low - 1);
 		off = get_symbol_offset(seq);
-		kallsyms_expand_symbol(off, namebuf, ARRAY_SIZE(namebuf));
-		if (strcmp(name, namebuf))
+		if (kallsyms_strcmp_symbol(off, name) != 0)
 			break;
 		low--;
 	}
@@ -212,13 +333,13 @@ static int kallsyms_lookup_names(const char *name,
 		while (high < kallsyms_num_syms - 1) {
 			seq = get_symbol_seq(high + 1);
 			off = get_symbol_offset(seq);
-			kallsyms_expand_symbol(off, namebuf, ARRAY_SIZE(namebuf));
-			if (strcmp(name, namebuf))
+			if (kallsyms_strcmp_symbol(off, name) != 0)
 				break;
 			high++;
 		}
 		*end = high;
 	}
+	rcu_read_unlock();
 
 	return 0;
 }
diff --git a/kernel/kallsyms_selftest.c b/kernel/kallsyms_selftest.c
index 8f6c4e9b3a1c0..aedffc058c0e6 100644
--- a/kernel/kallsyms_selftest.c
+++ b/kernel/kallsyms_selftest.c
@@ -178,6 +178,7 @@ static int lookup_name(void *data, const char *name, unsigned long addr)
 static void test_perf_kallsyms_lookup_name(void)
 {
 	struct test_stat stat;
+	int ret;
 
 	memset(&stat, 0, sizeof(stat));
 	stat.min = INT_MAX;
@@ -185,6 +186,21 @@ static void test_perf_kallsyms_lookup_name(void)
 	pr_info("kallsyms_lookup_name() looked up %d symbols\n", stat.real_cnt);
 	pr_info("The time spent on each symbol is (ns): min=%d, max=%d, avg=%lld\n",
 		stat.min, stat.max, div_u64(stat.sum, stat.real_cnt));
+
+	ret = kallsyms_lookup_batch_start();
+	if (ret) {
+		pr_err("kallsyms_lookup_batch_start() failed: %d\n", ret);
+		return;
+	}
+
+	memset(&stat, 0, sizeof(stat));
+	stat.min = INT_MAX;
+	kallsyms_on_each_symbol(lookup_name, &stat);
+	kallsyms_lookup_batch_end();
+
+	pr_info("kallsyms_lookup_name() (batch) looked up %d symbols\n", stat.real_cnt);
+	pr_info("The time spent on each symbol is (ns): min=%d, max=%d, avg=%lld\n",
+		stat.min, stat.max, div_u64(stat.sum, stat.real_cnt));
 }
 
 static int find_symbol(void *data, const char *name, unsigned long addr)
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 134b15a44625e..4b9669e64db9f 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -3122,6 +3122,16 @@ config TEST_STATIC_KEYS
 
 	  If unsure, say N.
 
+config TEST_KALLSYMS_PERF
+	bool "kallsyms performance benchmark test module"
+	depends on KALLSYMS
+	help
+	  This builds test_kallsyms_perf to benchmark latency across
+	  Name-to-Address binary search, Address-to-Name resolution,
+	  and full table walks.
+
+	  If unsure, say N.
+
 config TEST_DYNAMIC_DEBUG
 	tristate "Test DYNAMIC_DEBUG"
 	depends on DYNAMIC_DEBUG
diff --git a/lib/Makefile b/lib/Makefile
index dfab958327c5c..149968ff3f6bd 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -85,6 +85,7 @@ obj-$(CONFIG_TEST_RHASHTABLE) += test_rhashtable.o
 obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_keys.o
 obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_key_base.o
 obj-$(CONFIG_TEST_DYNAMIC_DEBUG) += test_dynamic_debug.o
+obj-$(CONFIG_TEST_KALLSYMS_PERF) += test_kallsyms_perf.o
 
 obj-$(CONFIG_TEST_BITMAP) += test_bitmap.o
 ifeq ($(CONFIG_CC_IS_CLANG)$(CONFIG_KASAN),yy)
diff --git a/lib/test_kallsyms_perf.c b/lib/test_kallsyms_perf.c
new file mode 100644
index 0000000000000..6f74ade4a0184
--- /dev/null
+++ b/lib/test_kallsyms_perf.c
@@ -0,0 +1,281 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Microbenchmark and correctness test module for kallsyms subsystem
+ *
+ * Measures CPU latency across:
+ *  - Name-to-Address binary search (hits & misses)
+ *  - Address-to-Name symbol resolution (sprint_symbol, buildid)
+ *  - Full kernel symbol iteration (kallsyms_on_each_symbol)
+ */
+
+#define pr_fmt(fmt) "test_kallsyms: " fmt
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/kallsyms.h>
+#include <linux/ktime.h>
+#include <linux/compiler.h>
+#include <linux/sched.h>
+#include <linux/math.h>
+
+static unsigned int num_iters = 100000;
+module_param(num_iters, uint, 0644);
+MODULE_PARM_DESC(num_iters, "Number of iterations per microbenchmark");
+
+static const char * const hit_symbols[] = {
+	"_printk",
+	"schedule",
+	"vfs_read",
+	"do_sys_openat2",
+	"kernel_clone",
+	"panic",
+	"kallsyms_lookup_names",
+	"vm_area_alloc",
+};
+
+static const char * const miss_symbols[] = {
+	"nonexistent_symbol_0001",
+	"xyz_dummy_missing_symbol",
+	"__never_compiled_in_kernel",
+	"ext4_nonexistent_func_xyz",
+	"bpf_not_real_helper_stub",
+	"vfs_missing_handler_probe",
+	"tcp_v4_unimplemented_path",
+	"driver_fake_init_routine",
+};
+
+static int match_cb(void *data, unsigned long addr)
+{
+	unsigned long *out = data;
+
+	*out = addr;
+	return 1;
+}
+
+static int count_cb(void *data, const char *name, unsigned long addr)
+{
+	unsigned long *cnt = data;
+
+	(*cnt)++;
+	return 0;
+}
+
+static void run_name_lookup_bench(const char *mode, u64 *avg_hit_ns, u64 *avg_miss_ns)
+{
+	u64 t0, t1, dt_hit, dt_miss;
+	unsigned long addr = 0;
+	unsigned int i, nr_hits, nr_misses;
+
+	nr_hits = ARRAY_SIZE(hit_symbols);
+	nr_misses = ARRAY_SIZE(miss_symbols);
+
+	/* 0. Correctness validation */
+	for (i = 0; i < nr_hits; i++) {
+		const char *sym = hit_symbols[i];
+		unsigned long a1 = 0;
+
+		kallsyms_on_each_match_symbol(match_cb, sym, &a1);
+		if (!a1)
+			pr_err("CORRECTNESS FAILURE: hit sym '%s' not found\n", sym);
+	}
+	for (i = 0; i < nr_misses; i++) {
+		const char *sym = miss_symbols[i];
+		unsigned long a1 = 0;
+
+		kallsyms_on_each_match_symbol(match_cb, sym, &a1);
+		if (a1)
+			pr_err("CORRECTNESS FAILURE: miss sym '%s' unexpectedly found a1=%lx\n",
+			       sym, a1);
+	}
+
+	/* 1. Name search: Existing symbols (Hits) */
+	t0 = ktime_get_ns();
+	for (i = 0; i < num_iters; i++) {
+		const char *sym = hit_symbols[i % nr_hits];
+
+		if (unlikely(!(i & 0x3fff)))
+			cond_resched();
+
+		kallsyms_on_each_match_symbol(match_cb, sym, &addr);
+		OPTIMIZER_HIDE_VAR(addr);
+	}
+	t1 = ktime_get_ns();
+	dt_hit = t1 - t0;
+
+	/* 2. Name search: Non-existent symbols (Misses - 17 bsearch probes) */
+	t0 = ktime_get_ns();
+	for (i = 0; i < num_iters; i++) {
+		const char *sym = miss_symbols[i % nr_misses];
+
+		if (unlikely(!(i & 0x3fff)))
+			cond_resched();
+
+		kallsyms_on_each_match_symbol(match_cb, sym, &addr);
+		OPTIMIZER_HIDE_VAR(addr);
+	}
+	t1 = ktime_get_ns();
+	dt_miss = t1 - t0;
+
+	if (avg_hit_ns)
+		*avg_hit_ns = div_u64(dt_hit, num_iters);
+	if (avg_miss_ns)
+		*avg_miss_ns = div_u64(dt_miss, num_iters);
+
+	pr_info("[%s] Name Search Hit:  %llu ns/lookup (%llu ms total, %u iters)\n",
+		mode, div_u64(dt_hit, num_iters), div_u64(dt_hit, 1000000), num_iters);
+	pr_info("[%s] Name Search Miss: %llu ns/lookup (%llu ms total, %u iters)\n",
+		mode, div_u64(dt_miss, num_iters), div_u64(dt_miss, 1000000), num_iters);
+}
+
+static void run_address_lookup_bench(void)
+{
+	u64 t0, t1, dt_sprint, dt_bldid;
+	char symname[KSYM_SYMBOL_LEN];
+	unsigned long addrs[ARRAY_SIZE(hit_symbols)];
+	unsigned int i, nr_addrs = 0;
+
+	for (i = 0; i < ARRAY_SIZE(hit_symbols); i++) {
+		unsigned long addr = 0;
+
+		kallsyms_on_each_match_symbol(match_cb, hit_symbols[i], &addr);
+		if (addr)
+			addrs[nr_addrs++] = addr;
+	}
+
+	if (!nr_addrs) {
+		pr_warn("Address benchmark skipped: no test addresses resolved\n");
+		return;
+	}
+
+	/* 1. Address-to-name resolution (sprint_symbol) */
+	t0 = ktime_get_ns();
+	for (i = 0; i < num_iters; i++) {
+		unsigned long addr = addrs[i % nr_addrs];
+
+		if (unlikely(!(i & 0x3fff)))
+			cond_resched();
+
+		sprint_symbol(symname, addr);
+		barrier_data(symname);
+	}
+	t1 = ktime_get_ns();
+	dt_sprint = t1 - t0;
+
+	/* 2. Address without offset (sprint_symbol_no_offset) */
+	t0 = ktime_get_ns();
+	for (i = 0; i < num_iters; i++) {
+		unsigned long addr = addrs[i % nr_addrs];
+
+		if (unlikely(!(i & 0x3fff)))
+			cond_resched();
+
+		sprint_symbol_no_offset(symname, addr);
+		barrier_data(symname);
+	}
+	t1 = ktime_get_ns();
+	dt_bldid = t1 - t0;
+
+	pr_info("sprint_symbol:           %llu ns/lookup (%llu ms total, %u iters)\n",
+		div_u64(dt_sprint, num_iters), div_u64(dt_sprint, 1000000), num_iters);
+	pr_info("sprint_symbol_no_offset: %llu ns/lookup (%llu ms total, %u iters)\n",
+		div_u64(dt_bldid, num_iters), div_u64(dt_bldid, 1000000), num_iters);
+}
+
+static void run_table_walk_bench(void)
+{
+	u64 t0, t1, dt_walk;
+	unsigned long total_symbols = 0;
+	int iter = 50;
+	int i;
+
+	t0 = ktime_get_ns();
+	for (i = 0; i < iter; i++) {
+		total_symbols = 0;
+		kallsyms_on_each_symbol(count_cb, &total_symbols);
+	}
+	t1 = ktime_get_ns();
+	dt_walk = t1 - t0;
+
+	pr_info("Table Full Walk:  %llu ns/sym (%llu us/pass, %lu symbols scanned, %d passes)\n",
+		div_u64(div_u64(dt_walk, iter), total_symbols ? total_symbols : 1),
+		div_u64(div_u64(dt_walk, iter), 1000), total_symbols, iter);
+}
+
+static int run_kallsyms_benchmark(void)
+{
+	u64 unindexed_hit = 0, unindexed_miss = 0;
+	u64 dyn_hit = 0, dyn_miss = 0;
+	u64 t0, t1, dt_start = 0, dt_end = 0;
+	int ret;
+
+	if (!num_iters) {
+		pr_err("num_iters must be non-zero\n");
+		return -EINVAL;
+	}
+
+	pr_info("==================================================\n");
+	pr_info("Starting kallsyms performance benchmark (iters=%u)\n", num_iters);
+	pr_info("==================================================\n");
+
+	/* 1. Benchmark baseline unindexed marker scan */
+	run_name_lookup_bench("Unindexed (markers)", &unindexed_hit, &unindexed_miss);
+
+	/* 2. Benchmark dynamic lookup index */
+	t0 = ktime_get_ns();
+	ret = kallsyms_lookup_batch_start();
+	t1 = ktime_get_ns();
+	dt_start = t1 - t0;
+
+	if (ret) {
+		pr_err("Failed to start kallsyms lookup batch: %d\n", ret);
+	} else {
+		run_name_lookup_bench("Dynamic Index", &dyn_hit, &dyn_miss);
+
+		t0 = ktime_get_ns();
+		kallsyms_lookup_batch_end();
+		t1 = ktime_get_ns();
+		dt_end = t1 - t0;
+
+		pr_info("[Dynamic Index] Batch setup: %llu us, teardown: %llu us\n",
+			div_u64(dt_start, 1000), div_u64(dt_end, 1000));
+
+		if (unindexed_hit > dyn_hit) {
+			u64 saved = unindexed_hit - dyn_hit;
+
+			pr_info("[Dynamic Index] Amortization break-even: %llu queries (setup), %llu queries (total)\n",
+				DIV_ROUND_UP_ULL(dt_start, saved),
+				DIV_ROUND_UP_ULL(dt_start + dt_end, saved));
+		}
+	}
+
+	run_address_lookup_bench();
+	run_table_walk_bench();
+
+	pr_info("==================================================\n");
+	pr_info("kallsyms benchmark complete\n");
+	pr_info("==================================================\n");
+
+	return 0;
+}
+
+static int param_set_trigger(const char *val, const struct kernel_param *kp)
+{
+	return run_kallsyms_benchmark();
+}
+
+static const struct kernel_param_ops param_ops_trigger = {
+	.set = param_set_trigger,
+};
+module_param_cb(run_test, &param_ops_trigger, NULL, 0200);
+MODULE_PARM_DESC(run_test, "Write 1 to trigger kallsyms benchmark run");
+
+static int __init test_kallsyms_init(void)
+{
+	return run_kallsyms_benchmark();
+}
+late_initcall(test_kallsyms_init);
+
+MODULE_DESCRIPTION("Microbenchmark test module for kallsyms subsystem");
+MODULE_AUTHOR("Jim Cromie <jim.cromie@gmail.com>");
+MODULE_LICENSE("GPL");

3/2 2026/09/25 01:53 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 10823
							output: 44
							thoughts: 603
						

Thoughts:
**Analyzing the Kallsyms Patch: A Deep Dive**

Okay, let's break this down. My initial assessment is that this patch is focused on optimizing and enhancing the `kallsyms` functionality within the Linux kernel. The changes are quite extensive, and it looks like a concerted effort to improve performance, particularly in symbol lookups.

First, I see the core `kallsyms` data structures and functions are being modified. The introduction of `kallsyms_lookup_batch_start` and `kallsyms_lookup_batch_end`, along with the new `get_symbol_data` helper, suggests they're creating infrastructure for batch processing of symbol lookups. This likely aims to reduce overhead by grouping related lookups, possibly improving cache utilization and overall efficiency. The refactoring of `kallsyms_expand_symbol` and `kallsyms_get_symbol_type` to use `get_symbol_data` indicates a move towards a more modular and potentially more efficient data access strategy. `kallsyms_strcmp_symbol` seems to be an optimization for string comparisons within the symbol table, avoiding unnecessary string expansions. The renaming of `get_symbol_offset` to `get_symbol_offset_marker` is interesting; it hints at a more refined way to handle offsets.

The addition of a dynamic symbol offset table (`dyn_kallsyms_offsets`, mutex, and reference count) is significant. This strongly implies the patch is dealing with the challenges of handling dynamic symbols, probably to address issues with modules or late-loaded components. The implementation of `kallsyms_build_offsets`, `kallsyms_lookup_batch_start`, and `kallsyms_lookup_batch_end` confirms this dynamic handling. The new `get_symbol_offset` function, with its RCU read lock and fallback mechanism, is a sophisticated approach to ensuring safe and concurrent access to these dynamically changing symbol offsets.

In `kallsyms_lookup_names`, the replacement of expansion and `strcmp` with `kallsyms_strcmp_symbol` is a definite optimization. The inclusion of an RCU read lock within this crucial function highlights the importance of concurrent access control in this critical path. The optimization of `get_symbol_seq` further reinforces the focus on improving lookup performance.

The presence of the selftest changes, specifically the calls to the batch start/end functions, and the new `CONFIG_TEST_KALLSYMS_PERF` option, point towards a dedicated performance testing and benchmarking framework. This is crucial for verifying the effectiveness of the optimizations and ensuring that the patch doesn't introduce regressions. The addition of `test_kallsyms_perf.o` is the test module's artifact.

Now, to fully understand the impact, I need to investigate where `kallsyms_lookup_names` is being used. Using `grepper` or examining the callers of `kallsyms_lookup_name` and `kallsyms_on_each_match_symbol` will reveal the downstream implications of these changes. This will also give a better view of performance metrics and the effects of dynamic symbol updates. This patch looks promising, but the real test lies in its practical performance improvements and its ability to handle dynamic symbol updates effectively.



4/2 2026/09/25 01:53 tool grepper
0m Args:
{
  "Expression": "kallsyms_lookup_name|kallsyms_on_each_match_symbol|kallsyms_lookup_names"
}

Results:
{
  "Output": "Documentation/trace/kprobes.rst=338=Also make sure that CONFIG_KALLSYMS and perhaps even CONFIG_KALLSYMS_ALL\nDocumentation/trace/kprobes.rst:339:are set to \"y\", since kallsyms_lookup_name() is used by the in-kernel\nDocumentation/trace/kprobes.rst-340-kprobe address resolution code.\n--\narch/mips/kernel/process.c=475=static unsigned long get___schedule_addr(void)\narch/mips/kernel/process.c-476-{\narch/mips/kernel/process.c:477:\treturn kallsyms_lookup_name(\"__schedule\");\narch/mips/kernel/process.c-478-}\n--\narch/powerpc/include/asm/text-patching.h=208=static inline unsigned long ppc_global_function_entry(void *func)\n--\narch/powerpc/include/asm/text-patching.h-223- */\narch/powerpc/include/asm/text-patching.h:224:static inline unsigned long ppc_kallsyms_lookup_name(const char *name)\narch/powerpc/include/asm/text-patching.h-225-{\n--\narch/powerpc/include/asm/text-patching.h-243-\t}\narch/powerpc/include/asm/text-patching.h:244:\taddr = kallsyms_lookup_name(dot_name);\narch/powerpc/include/asm/text-patching.h-245-\tif (!addr \u0026\u0026 dot_appended)\narch/powerpc/include/asm/text-patching.h-246-\t\t/* Let's try the original non-dot symbol lookup\t*/\narch/powerpc/include/asm/text-patching.h:247:\t\taddr = kallsyms_lookup_name(name);\narch/powerpc/include/asm/text-patching.h-248-#elif defined(CONFIG_PPC64_ELF_ABI_V2)\narch/powerpc/include/asm/text-patching.h:249:\taddr = kallsyms_lookup_name(name);\narch/powerpc/include/asm/text-patching.h-250-\tif (addr)\n--\narch/powerpc/include/asm/text-patching.h-252-#else\narch/powerpc/include/asm/text-patching.h:253:\taddr = kallsyms_lookup_name(name);\narch/powerpc/include/asm/text-patching.h-254-#endif\n--\narch/powerpc/kernel/kprobes.c=44=kprobe_opcode_t *kprobe_lookup_name(const char *name, unsigned int offset)\n--\narch/powerpc/kernel/kprobes.c-49-\t/* PPC64 ABIv2 needs local entry point */\narch/powerpc/kernel/kprobes.c:50:\taddr = (kprobe_opcode_t *)kallsyms_lookup_name(name);\narch/powerpc/kernel/kprobes.c-51-\tif (addr \u0026\u0026 !offset) {\n--\narch/powerpc/kernel/kprobes.c-95-\tif (ret \u003e 0)\narch/powerpc/kernel/kprobes.c:96:\t\taddr = (kprobe_opcode_t *)kallsyms_lookup_name(dot_name);\narch/powerpc/kernel/kprobes.c-97-\n--\narch/powerpc/kernel/kprobes.c-99-\tif (!addr \u0026\u0026 dot_appended)\narch/powerpc/kernel/kprobes.c:100:\t\taddr = (kprobe_opcode_t *)kallsyms_lookup_name(name);\narch/powerpc/kernel/kprobes.c-101-#else\narch/powerpc/kernel/kprobes.c:102:\taddr = (kprobe_opcode_t *)kallsyms_lookup_name(name);\narch/powerpc/kernel/kprobes.c-103-#endif\n--\narch/powerpc/kernel/optprobes.c=154=int arch_prepare_optimized_kprobe(struct optimized_kprobe *op, struct kprobe *p)\n--\narch/powerpc/kernel/optprobes.c-208-\t */\narch/powerpc/kernel/optprobes.c:209:\top_callback_addr = ppc_kallsyms_lookup_name(\"optimized_callback\");\narch/powerpc/kernel/optprobes.c:210:\temulate_step_addr = ppc_kallsyms_lookup_name(\"emulate_step\");\narch/powerpc/kernel/optprobes.c-211-\tif (!op_callback_addr || !emulate_step_addr) {\n--\narch/powerpc/xmon/xmon.c=3480=scanhex(unsigned long *vp)\n--\narch/powerpc/xmon/xmon.c-3541-\t\t\tsync();\narch/powerpc/xmon/xmon.c:3542:\t\t\t*vp = kallsyms_lookup_name(tmpstr);\narch/powerpc/xmon/xmon.c-3543-\t\t\tsync();\n--\narch/powerpc/xmon/xmon.c=3643=symbol_lookup(void)\n--\narch/powerpc/xmon/xmon.c-3660-\t\t\tsync();\narch/powerpc/xmon/xmon.c:3661:\t\t\taddr = kallsyms_lookup_name(tmp);\narch/powerpc/xmon/xmon.c-3662-\t\t\tif (addr)\n--\narch/powerpc/xmon/xmon.c-3675-\t\t\tsync();\narch/powerpc/xmon/xmon.c:3676:\t\t\tptr = (void __percpu *)kallsyms_lookup_name(tmp);\narch/powerpc/xmon/xmon.c-3677-\t\t\tsync();\n--\ndrivers/misc/kgdbts.c=201=static noinline void kgdbts_break_test(void)\n--\ndrivers/misc/kgdbts.c-206-/*\ndrivers/misc/kgdbts.c:207: * This is a cached wrapper for kallsyms_lookup_name().\ndrivers/misc/kgdbts.c-208- *\n--\ndrivers/misc/kgdbts.c=218=static unsigned long lookup_addr(char *arg)\n--\ndrivers/misc/kgdbts.c-224-\t\tstrscpy(cached_arg, arg, KSYM_NAME_LEN);\ndrivers/misc/kgdbts.c:225:\t\tcached_addr = kallsyms_lookup_name(arg);\ndrivers/misc/kgdbts.c-226-\t}\n--\ninclude/linux/kallsyms.h=72=int kallsyms_on_each_symbol(int (*fn)(void *, const char *, unsigned long),\ninclude/linux/kallsyms.h-73-\t\t\t    void *data);\ninclude/linux/kallsyms.h:74:int kallsyms_on_each_match_symbol(int (*fn)(void *, unsigned long),\ninclude/linux/kallsyms.h-75-\t\t\t\t  const char *name, void *data);\n--\ninclude/linux/kallsyms.h=79=void kallsyms_lookup_batch_end(void);\n--\ninclude/linux/kallsyms.h-81-/* Lookup the address for a symbol. Returns 0 if not found. */\ninclude/linux/kallsyms.h:82:unsigned long kallsyms_lookup_name(const char *name);\ninclude/linux/kallsyms.h-83-\n--\ninclude/linux/kallsyms.h=101=int lookup_symbol_name(unsigned long addr, char *symname);\n--\ninclude/linux/kallsyms.h-104-\ninclude/linux/kallsyms.h:105:static inline unsigned long kallsyms_lookup_name(const char *name)\ninclude/linux/kallsyms.h-106-{\n--\ninclude/linux/kallsyms.h=160=static inline int kallsyms_on_each_symbol(int (*fn)(void *, const char *, unsigned long),\n--\ninclude/linux/kallsyms.h-165-\ninclude/linux/kallsyms.h:166:static inline int kallsyms_on_each_match_symbol(int (*fn)(void *, unsigned long),\ninclude/linux/kallsyms.h-167-\t\t\t\t\t\tconst char *name, void *data)\n--\ninclude/linux/module.h=966=int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,\n--\ninclude/linux/module.h-969-/* Look for this name: can be of form module:name. */\ninclude/linux/module.h:970:unsigned long module_kallsyms_lookup_name(const char *name);\ninclude/linux/module.h-971-\n--\ninclude/linux/module.h=999=static inline int module_get_kallsym(unsigned int symnum, unsigned long *value,\n--\ninclude/linux/module.h-1005-\ninclude/linux/module.h:1006:static inline unsigned long module_kallsyms_lookup_name(const char *name)\ninclude/linux/module.h-1007-{\n--\ninclude/uapi/linux/bpf.h=1527=union bpf_attr {\n--\ninclude/uapi/linux/bpf.h-5532- *\ninclude/uapi/linux/bpf.h:5533: * long bpf_kallsyms_lookup_name(const char *name, int name_sz, int flags, u64 *res)\ninclude/uapi/linux/bpf.h-5534- *\tDescription\n--\ninclude/uapi/linux/bpf.h-6181-\tFN(skc_to_unix_sock, 178, ##ctx)\t\t\\\ninclude/uapi/linux/bpf.h:6182:\tFN(kallsyms_lookup_name, 179, ##ctx)\t\t\\\ninclude/uapi/linux/bpf.h-6183-\tFN(find_vma, 180, ##ctx)\t\t\t\\\n--\ninit/Kconfig=2104=config KALLSYMS_SELFTEST\n--\ninit/Kconfig-2109-\t  Test the basic functions and performance of some interfaces, such as\ninit/Kconfig:2110:\t  kallsyms_lookup_name. It also calculates the compression rate of the\ninit/Kconfig-2111-\t  kallsyms compression algorithm for the current symbol set.\n--\nkernel/bpf/btf.c=3974=static int btf_parse_kptr(const struct btf *btf, struct btf_field *field,\n--\nkernel/bpf/btf.c-4043-\t\tdtor_func_name = __btf_name_by_offset(kptr_btf, dtor_func-\u003ename_off);\nkernel/bpf/btf.c:4044:\t\taddr = kallsyms_lookup_name(dtor_func_name);\nkernel/bpf/btf.c-4045-\t\tif (!addr) {\n--\nkernel/bpf/syscall.c=6594=static const struct bpf_func_proto bpf_sys_close_proto = {\n--\nkernel/bpf/syscall.c-6601-\nkernel/bpf/syscall.c:6602:BPF_CALL_4(bpf_kallsyms_lookup_name, const char *, name, int, name_sz, int, flags, u64 *, res)\nkernel/bpf/syscall.c-6603-{\n--\nkernel/bpf/syscall.c-6613-\nkernel/bpf/syscall.c:6614:\t*res = kallsyms_lookup_name(name);\nkernel/bpf/syscall.c-6615-\treturn *res ? 0 : -ENOENT;\n--\nkernel/bpf/syscall.c-6617-\nkernel/bpf/syscall.c:6618:static const struct bpf_func_proto bpf_kallsyms_lookup_name_proto = {\nkernel/bpf/syscall.c:6619:\t.func\t\t= bpf_kallsyms_lookup_name,\nkernel/bpf/syscall.c-6620-\t.gpl_only\t= false,\n--\nkernel/bpf/syscall.c=6630=syscall_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)\n--\nkernel/bpf/syscall.c-6639-\t\treturn \u0026bpf_sys_close_proto;\nkernel/bpf/syscall.c:6640:\tcase BPF_FUNC_kallsyms_lookup_name:\nkernel/bpf/syscall.c:6641:\t\treturn \u0026bpf_kallsyms_lookup_name_proto;\nkernel/bpf/syscall.c-6642-\tdefault:\n--\nkernel/bpf/verifier.c=2802=int bpf_add_kfunc_call(struct bpf_verifier_env *env, u32 func_id, u16 offset)\n--\nkernel/bpf/verifier.c-2873-\nkernel/bpf/verifier.c:2874:\taddr = kallsyms_lookup_name(kfunc.name);\nkernel/bpf/verifier.c-2875-\tif (!addr) {\n--\nkernel/bpf/verifier.c=18626=static int __check_pseudo_btf_id(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-18652-\tsym_name = btf_name_by_offset(btf, t-\u003ename_off);\nkernel/bpf/verifier.c:18653:\taddr = kallsyms_lookup_name(sym_name);\nkernel/bpf/verifier.c-18654-\tif (!addr) {\n--\nkernel/bpf/verifier.c=20037=int bpf_check_attach_target(struct bpf_verifier_log *log,\n--\nkernel/bpf/verifier.c-20342-\t\t\t} else {\nkernel/bpf/verifier.c:20343:\t\t\t\taddr = kallsyms_lookup_name(tname);\nkernel/bpf/verifier.c-20344-\t\t\t}\n--\nkernel/bpf/verifier.c=20560=int bpf_check_attach_btf_id_multi(struct btf *btf, struct bpf_prog *prog, u32 btf_id,\n--\nkernel/bpf/verifier.c-20601-\t} else {\nkernel/bpf/verifier.c:20602:\t\taddr = kallsyms_lookup_name(tname);\nkernel/bpf/verifier.c-20603-\t}\n--\nkernel/debug/kdb/kdb_support.c=37=int kdbgetsymval(const char *symname, kdb_symtab_t *symtab)\n--\nkernel/debug/kdb/kdb_support.c-40-\tmemset(symtab, 0, sizeof(*symtab));\nkernel/debug/kdb/kdb_support.c:41:\tsymtab-\u003esym_start = kallsyms_lookup_name(symname);\nkernel/debug/kdb/kdb_support.c-42-\tif (symtab-\u003esym_start) {\n--\nkernel/fail_function.c=236=static ssize_t fei_write(struct file *file, const char __user *buffer,\n--\nkernel/fail_function.c-273-\nkernel/fail_function.c:274:\taddr = kallsyms_lookup_name(sym);\nkernel/fail_function.c-275-\tif (!addr) {\n--\nkernel/kallsyms.c=284=static inline unsigned int get_symbol_seq(int index)\n--\nkernel/kallsyms.c-290-\nkernel/kallsyms.c:291:static int kallsyms_lookup_names(const char *name,\nkernel/kallsyms.c-292-\t\t\t\t unsigned int *start,\n--\nkernel/kallsyms.c-347-/* Lookup the address for this symbol. Returns 0 if not found. */\nkernel/kallsyms.c:348:unsigned long kallsyms_lookup_name(const char *name)\nkernel/kallsyms.c-349-{\n--\nkernel/kallsyms.c-356-\nkernel/kallsyms.c:357:\tret = kallsyms_lookup_names(name, \u0026i, NULL);\nkernel/kallsyms.c-358-\tif (!ret)\n--\nkernel/kallsyms.c-360-\nkernel/kallsyms.c:361:\treturn module_kallsyms_lookup_name(name);\nkernel/kallsyms.c-362-}\n--\nkernel/kallsyms.c=368=int kallsyms_on_each_symbol(int (*fn)(void *, const char *, unsigned long),\n--\nkernel/kallsyms.c-385-\nkernel/kallsyms.c:386:int kallsyms_on_each_match_symbol(int (*fn)(void *, unsigned long),\nkernel/kallsyms.c-387-\t\t\t\t  const char *name, void *data)\n--\nkernel/kallsyms.c-391-\nkernel/kallsyms.c:392:\tret = kallsyms_lookup_names(name, \u0026start, \u0026end);\nkernel/kallsyms.c-393-\tif (ret)\n--\nkernel/kallsyms_selftest.c=156=static int lookup_name(void *data, const char *name, unsigned long addr)\n--\nkernel/kallsyms_selftest.c-161-\tt0 = ktime_get_ns();\nkernel/kallsyms_selftest.c:162:\t(void)kallsyms_lookup_name(name);\nkernel/kallsyms_selftest.c-163-\tt1 = ktime_get_ns();\n--\nkernel/kallsyms_selftest.c-177-\nkernel/kallsyms_selftest.c:178:static void test_perf_kallsyms_lookup_name(void)\nkernel/kallsyms_selftest.c-179-{\n--\nkernel/kallsyms_selftest.c-185-\tkallsyms_on_each_symbol(lookup_name, \u0026stat);\nkernel/kallsyms_selftest.c:186:\tpr_info(\"kallsyms_lookup_name() looked up %d symbols\\n\", stat.real_cnt);\nkernel/kallsyms_selftest.c-187-\tpr_info(\"The time spent on each symbol is (ns): min=%d, max=%d, avg=%lld\\n\",\n--\nkernel/kallsyms_selftest.c-200-\nkernel/kallsyms_selftest.c:201:\tpr_info(\"kallsyms_lookup_name() (batch) looked up %d symbols\\n\", stat.real_cnt);\nkernel/kallsyms_selftest.c-202-\tpr_info(\"The time spent on each symbol is (ns): min=%d, max=%d, avg=%lld\\n\",\n--\nkernel/kallsyms_selftest.c=241=static int match_symbol(void *data, unsigned long addr)\n--\nkernel/kallsyms_selftest.c-258-\nkernel/kallsyms_selftest.c:259:static void test_perf_kallsyms_on_each_match_symbol(void)\nkernel/kallsyms_selftest.c-260-{\n--\nkernel/kallsyms_selftest.c-267-\tt0 = ktime_get_ns();\nkernel/kallsyms_selftest.c:268:\tkallsyms_on_each_match_symbol(match_symbol, stat.name, \u0026stat);\nkernel/kallsyms_selftest.c-269-\tt1 = ktime_get_ns();\nkernel/kallsyms_selftest.c:270:\tpr_info(\"kallsyms_on_each_match_symbol() traverse all: %lld ns\\n\", t1 - t0);\nkernel/kallsyms_selftest.c-271-}\n--\nkernel/kallsyms_selftest.c=273=static int test_kallsyms_basic_function(void)\n--\nkernel/kallsyms_selftest.c-287-\nkernel/kallsyms_selftest.c:288:\tprefix = \"kallsyms_lookup_name() for\";\nkernel/kallsyms_selftest.c-289-\tfor (i = 0; i \u003c ARRAY_SIZE(test_items); i++) {\nkernel/kallsyms_selftest.c:290:\t\taddr = kallsyms_lookup_name(test_items[i].name);\nkernel/kallsyms_selftest.c-291-\t\tif (addr != test_items[i].addr) {\n--\nkernel/kallsyms_selftest.c-311-\nkernel/kallsyms_selftest.c:312:\tprefix = \"kallsyms_on_each_match_symbol() for\";\nkernel/kallsyms_selftest.c-313-\tfor (i = 0; i \u003c ARRAY_SIZE(test_items); i++) {\n--\nkernel/kallsyms_selftest.c-316-\t\tstat-\u003ename = test_items[i].name;\nkernel/kallsyms_selftest.c:317:\t\tkallsyms_on_each_match_symbol(match_symbol, test_items[i].name, stat);\nkernel/kallsyms_selftest.c-318-\t\tif (stat-\u003eaddr != test_items[i].addr || stat-\u003ereal_cnt != 1) {\n--\nkernel/kallsyms_selftest.c-342-\nkernel/kallsyms_selftest.c:343:\t\tlookup_addr = kallsyms_lookup_name(namebuf);\nkernel/kallsyms_selftest.c-344-\n--\nkernel/kallsyms_selftest.c-346-\t\tstat-\u003emax = INT_MAX;\nkernel/kallsyms_selftest.c:347:\t\tkallsyms_on_each_match_symbol(match_symbol, namebuf, stat);\nkernel/kallsyms_selftest.c-348-\n--\nkernel/kallsyms_selftest.c-359-\t\t\t/*\nkernel/kallsyms_selftest.c:360:\t\t\t * kallsyms_on_each_symbol() and kallsyms_on_each_match_symbol()\nkernel/kallsyms_selftest.c-361-\t\t\t * need to get the same traversal result.\n--\nkernel/kallsyms_selftest.c-366-\t\t\t\t   stat-\u003esave_cnt * sizeof(stat-\u003eaddrs[0]))) {\nkernel/kallsyms_selftest.c:367:\t\t\t\tpr_info(\"%s: mismatch between kallsyms_on_each_symbol() and kallsyms_on_each_match_symbol()\\n\",\nkernel/kallsyms_selftest.c-368-\t\t\t\t\tnamebuf);\n--\nkernel/kallsyms_selftest.c-386-\t\t/*\nkernel/kallsyms_selftest.c:387:\t\t * kallsyms_lookup_name() returns the address of the first\nkernel/kallsyms_selftest.c-388-\t\t * symbol found and cannot be NULL.\n--\nkernel/kallsyms_selftest.c=426=static int test_entry(void *p)\n--\nkernel/kallsyms_selftest.c-441-\ttest_kallsyms_compression_ratio();\nkernel/kallsyms_selftest.c:442:\ttest_perf_kallsyms_lookup_name();\nkernel/kallsyms_selftest.c-443-\ttest_perf_kallsyms_on_each_symbol();\nkernel/kallsyms_selftest.c:444:\ttest_perf_kallsyms_on_each_match_symbol();\nkernel/kallsyms_selftest.c-445-\tpr_info(\"finish\\n\");\n--\nkernel/kcsan/debugfs.c=138=static ssize_t insert_report_filterlist(const char *func)\n--\nkernel/kcsan/debugfs.c-140-\tunsigned long flags;\nkernel/kcsan/debugfs.c:141:\tunsigned long addr = kallsyms_lookup_name(func);\nkernel/kcsan/debugfs.c-142-\tunsigned long *delay_free = NULL;\n--\nkernel/kprobes.c=73=kprobe_opcode_t * __weak kprobe_lookup_name(const char *name,\n--\nkernel/kprobes.c-75-{\nkernel/kprobes.c:76:\treturn ((kprobe_opcode_t *)(kallsyms_lookup_name(name)));\nkernel/kprobes.c-77-}\n--\nkernel/livepatch/core.c=160=static int klp_find_object_symbol(const char *objname, const char *name,\n--\nkernel/livepatch/core.c-172-\telse\nkernel/livepatch/core.c:173:\t\tkallsyms_on_each_match_symbol(klp_match_callback, name, \u0026args);\nkernel/livepatch/core.c-174-\n--\nkernel/module/kallsyms.c=407=static unsigned long __find_kallsyms_symbol_value(struct module *mod, const char *name)\n--\nkernel/module/kallsyms.c-421-\nkernel/module/kallsyms.c:422:static unsigned long __module_kallsyms_lookup_name(const char *name)\nkernel/module/kallsyms.c-423-{\n--\nkernel/module/kallsyms.c-447-/* Look for this name: can be of form module:name. */\nkernel/module/kallsyms.c:448:unsigned long module_kallsyms_lookup_name(const char *name)\nkernel/module/kallsyms.c-449-{\n--\nkernel/module/kallsyms.c-451-\tguard(rcu)();\nkernel/module/kallsyms.c:452:\treturn __module_kallsyms_lookup_name(name);\nkernel/module/kallsyms.c-453-}\n--\nkernel/trace/ftrace.c=9314=static int kallsyms_callback(void *data, const char *name, unsigned long addr)\n--\nkernel/trace/ftrace.c-9348- *\nkernel/trace/ftrace.c:9349: * For a single symbol (cnt == 1), uses kallsyms_lookup_name() which\nkernel/trace/ftrace.c-9350- * performs an O(log N) binary search via the sorted kallsyms index.\n--\nkernel/trace/ftrace.c=9360=int ftrace_lookup_symbols(const char **sorted_syms, size_t cnt, unsigned long *addrs)\n--\nkernel/trace/ftrace.c-9366-\tif (cnt == 1) {\nkernel/trace/ftrace.c:9367:\t\taddrs[0] = kallsyms_lookup_name(sorted_syms[0]);\nkernel/trace/ftrace.c-9368-\t\tif (addrs[0] \u0026\u0026 ftrace_location(addrs[0]))\n--\nkernel/trace/rv/monitors/deadline/deadline.c=24=static int __init register_deadline(void)\n--\nkernel/trace/rv/monitors/deadline/deadline.c-26-\tif (IS_ENABLED(CONFIG_SCHED_CLASS_EXT)) {\nkernel/trace/rv/monitors/deadline/deadline.c:27:\t\trv_ext_sched_class = (void *)kallsyms_lookup_name(\"ext_sched_class\");\nkernel/trace/rv/monitors/deadline/deadline.c-28-\t\tif (!rv_ext_sched_class)\n--\nkernel/trace/trace.c=9185=bool module_exists(const char *module)\n--\nkernel/trace/trace.c-9197-\nkernel/trace/trace.c:9198:\tval = module_kallsyms_lookup_name(modname);\nkernel/trace/trace.c-9199-\treturn val != 0;\n--\nkernel/trace/trace_events_filter.c=1629=static int parse_pred(const char *str, void *data,\n--\nkernel/trace/trace_events_filter.c-1765-\t\t\t\tgoto err_mem;\nkernel/trace/trace_events_filter.c:1766:\t\t\tip = kallsyms_lookup_name(name);\nkernel/trace/trace_events_filter.c-1767-\t\t\tkfree(name);\n--\nkernel/trace/trace_kprobe.c=209=unsigned long trace_kprobe_address(struct trace_kprobe *tk)\n--\nkernel/trace/trace_kprobe.c-214-\t\taddr = (unsigned long)\nkernel/trace/trace_kprobe.c:215:\t\t\tkallsyms_lookup_name(trace_kprobe_symbol(tk));\nkernel/trace/trace_kprobe.c-216-\t\tif (addr)\n--\nkernel/trace/trace_kprobe.c=770=static unsigned int number_of_same_symbols(const char *mod, const char *func_name)\n--\nkernel/trace/trace_kprobe.c-774-\tif (!mod)\nkernel/trace/trace_kprobe.c:775:\t\tkallsyms_on_each_match_symbol(count_symbols, func_name, \u0026ctx.count);\nkernel/trace/trace_kprobe.c-776-\n--\nkernel/trace/trace_probe.c=2428=int traceprobe_update_arg(struct probe_arg *arg)\n--\nkernel/trace/trace_probe.c-2449-\t\t\tcode[1].immediate =\nkernel/trace/trace_probe.c:2450:\t\t\t\t(unsigned long)kallsyms_lookup_name(code-\u003edata);\nkernel/trace/trace_probe.c-2451-\t\t\tif (tmp)\n--\nlib/codetag.c=156=static void *get_symbol(struct module *mod, const char *prefix, const char *name)\n--\nlib/codetag.c-169-\t\t(void *)find_kallsyms_symbol_value(mod, buf) :\nlib/codetag.c:170:\t\t(void *)kallsyms_lookup_name(buf);\nlib/codetag.c-171-\tpreempt_enable();\n--\nlib/test_kallsyms_perf.c=26=static const char * const hit_symbols[] = {\n--\nlib/test_kallsyms_perf.c-32-\t\"panic\",\nlib/test_kallsyms_perf.c:33:\t\"kallsyms_lookup_names\",\nlib/test_kallsyms_perf.c-34-\t\"vm_area_alloc\",\n--\nlib/test_kallsyms_perf.c=64=static void run_name_lookup_bench(const char *mode, u64 *avg_hit_ns, u64 *avg_miss_ns)\n--\nlib/test_kallsyms_perf.c-77-\nlib/test_kallsyms_perf.c:78:\t\tkallsyms_on_each_match_symbol(match_cb, sym, \u0026a1);\nlib/test_kallsyms_perf.c-79-\t\tif (!a1)\n--\nlib/test_kallsyms_perf.c-85-\nlib/test_kallsyms_perf.c:86:\t\tkallsyms_on_each_match_symbol(match_cb, sym, \u0026a1);\nlib/test_kallsyms_perf.c-87-\t\tif (a1)\n--\nlib/test_kallsyms_perf.c-99-\nlib/test_kallsyms_perf.c:100:\t\tkallsyms_on_each_match_symbol(match_cb, sym, \u0026addr);\nlib/test_kallsyms_perf.c-101-\t\tOPTIMIZER_HIDE_VAR(addr);\n--\nlib/test_kallsyms_perf.c-113-\nlib/test_kallsyms_perf.c:114:\t\tkallsyms_on_each_match_symbol(match_cb, sym, \u0026addr);\nlib/test_kallsyms_perf.c-115-\t\tOPTIMIZER_HIDE_VAR(addr);\n--\nlib/test_kallsyms_perf.c=131=static void run_address_lookup_bench(void)\n--\nlib/test_kallsyms_perf.c-140-\nlib/test_kallsyms_perf.c:141:\t\tkallsyms_on_each_match_symbol(match_cb, hit_symbols[i], \u0026addr);\nlib/test_kallsyms_perf.c-142-\t\tif (addr)\n--\nlib/tests/longest_symbol_kunit.c=43=static void test_longest_symbol_kallsyms(struct kunit *test)\nlib/tests/longest_symbol_kunit.c-44-{\nlib/tests/longest_symbol_kunit.c:45:\tunsigned long (*kallsyms_lookup_name)(const char *name);\nlib/tests/longest_symbol_kunit.c-46-\tstatic int (*longest_sym)(void);\n--\nlib/tests/longest_symbol_kunit.c-48-\tstruct kprobe kp = {\nlib/tests/longest_symbol_kunit.c:49:\t\t.symbol_name = \"kallsyms_lookup_name\",\nlib/tests/longest_symbol_kunit.c-50-\t};\n--\nlib/tests/longest_symbol_kunit.c-58-\tkunit_warn(test, \"test_longest_symbol kallsyms: kprobe registered\\n\");\nlib/tests/longest_symbol_kunit.c:59:\tkallsyms_lookup_name = (unsigned long (*)(const char *name))kp.addr;\nlib/tests/longest_symbol_kunit.c-60-\tunregister_kprobe(\u0026kp);\n--\nlib/tests/longest_symbol_kunit.c-62-\tlongest_sym =\nlib/tests/longest_symbol_kunit.c:63:\t\t(void *) kallsyms_lookup_name(__stringify(LONGEST_SYM_NAME));\nlib/tests/longest_symbol_kunit.c-64-\tKUNIT_EXPECT_EQ(test, RETURN_LONGEST_SYM, longest_sym());\n--\nmm/alloc_tag.c=607=void __init alloc_tag_sec_init(void)\n--\nmm/alloc_tag.c-616-\nmm/alloc_tag.c:617:\tkernel_tags.first_tag = (struct alloc_tag *)kallsyms_lookup_name(\nmm/alloc_tag.c-618-\t\t\t\t\tSECTION_START(ALLOC_TAG_SECTION_NAME));\nmm/alloc_tag.c:619:\tlast_codetag = (struct alloc_tag *)kallsyms_lookup_name(\nmm/alloc_tag.c-620-\t\t\t\t\tSECTION_STOP(ALLOC_TAG_SECTION_NAME));\n--\ntools/include/uapi/linux/bpf.h=1527=union bpf_attr {\n--\ntools/include/uapi/linux/bpf.h-5532- *\ntools/include/uapi/linux/bpf.h:5533: * long bpf_kallsyms_lookup_name(const char *name, int name_sz, int flags, u64 *res)\ntools/include/uapi/linux/bpf.h-5534- *\tDescription\n--\ntools/include/uapi/linux/bpf.h-6181-\tFN(skc_to_unix_sock, 178, ##ctx)\t\t\\\ntools/include/uapi/linux/bpf.h:6182:\tFN(kallsyms_lookup_name, 179, ##ctx)\t\t\\\ntools/include/uapi/linux/bpf.h-6183-\tFN(find_vma, 180, ##ctx)\t\t\t\\\n--\ntools/lib/bpf/gen_loader.c=666=static void emit_bpf_find_by_name_kind(struct bpf_gen *gen, struct ksym_relo_desc *relo)\n--\ntools/lib/bpf/gen_loader.c-684- */\ntools/lib/bpf/gen_loader.c:685:static void emit_bpf_kallsyms_lookup_name(struct bpf_gen *gen, struct ksym_relo_desc *relo)\ntools/lib/bpf/gen_loader.c-686-{\n--\ntools/lib/bpf/gen_loader.c-697-\temit(gen, BPF_MOV64_REG(BPF_REG_7, BPF_REG_4));\ntools/lib/bpf/gen_loader.c:698:\temit(gen, BPF_EMIT_CALL(BPF_FUNC_kallsyms_lookup_name));\ntools/lib/bpf/gen_loader.c-699-\temit(gen, BPF_LDX_MEM(BPF_DW, BPF_REG_9, BPF_REG_7, 0));\ntools/lib/bpf/gen_loader.c-700-\temit(gen, BPF_MOV64_REG(BPF_REG_7, BPF_REG_0));\ntools/lib/bpf/gen_loader.c:701:\tdebug_ret(gen, \"kallsyms_lookup_name(%s,%d)\", relo-\u003ename, relo-\u003ekind);\ntools/lib/bpf/gen_loader.c-702-}\n--\ntools/lib/bpf/gen_loader.c=804=static void emit_relo_ksym_typeless(struct bpf_gen *gen,\n--\ntools/lib/bpf/gen_loader.c-823-\tkdesc-\u003etypeless = true;\ntools/lib/bpf/gen_loader.c:824:\temit_bpf_kallsyms_lookup_name(gen, relo);\ntools/lib/bpf/gen_loader.c-825-\temit(gen, BPF_JMP_IMM(BPF_JEQ, BPF_REG_7, -ENOENT, 1));\n--\ntools/objtool/klp-sympos.c=298=static int find_vmlinux_symid_addr(u64 id, u64 *addr)\n--\ntools/objtool/klp-sympos.c-314- * among the duplicately named symbols in the linked orig vmlinux, replicating\ntools/objtool/klp-sympos.c:315: * the order in which kallsyms_on_each_match_symbol() counts them.\ntools/objtool/klp-sympos.c-316- */\n--\ntools/testing/selftests/bpf/prog_tests/tracing_multi.c=665=void serial_test_tracing_multi_bench_attach(void)\n--\ntools/testing/selftests/bpf/prog_tests/tracing_multi.c-707-\t * Collect names that are not unique in kallsyms. The kernel resolves a\ntools/testing/selftests/bpf/prog_tests/tracing_multi.c:708:\t * tracing-multi BTF id to an address with kallsyms_lookup_name(), which\ntools/testing/selftests/bpf/prog_tests/tracing_multi.c-709-\t * returns the first symbol of that name. For a duplicate name that may\n"
}

5/2 2026/09/25 01:53 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 22511
							output: 33
							thoughts: 487
						

Thoughts:
**My Investigation into Kernel Symbol Lookup**

Okay, so I'm diving into where these `kallsyms` functions are actually used. My initial thought is to trace the execution from the core functions: `kallsyms_lookup_name`, `kallsyms_on_each_match_symbol`, and I should probably include `kallsyms_expand_symbol` and `kallsyms_get_symbol_type` in the scope of this investigation. The initial jump point is the fact that both `kallsyms_lookup_name` and `kallsyms_on_each_match_symbol` eventually call `kallsyms_lookup_names()`. But where does user space actually get to these?

First, BPF is a big one. I see:

1.  **BPF:** The BPF syscall includes a `bpf_kallsyms_lookup_name` helper (`BPF_FUNC_kallsyms_lookup_name`), which can be called from syscall programs (`BPF_PROG_TYPE_SYSCALL`). The BPF verifier uses `kallsyms_lookup_name` to resolve kfunc names via `bpf_add_kfunc_call` and also for symbol names in `__check_pseudo_btf_id`. BPF attach logic is also using it in `bpf_check_attach_target` and `bpf_check_attach_btf_id_multi`. Also, I can't forget kprobes and tracepoints using BPF! Clearly, BPF is a major consumer.

2.  **trace\_kprobe:** I'm also seeing that writing to `/sys/kernel/tracing/kprobe_events` with symbol names triggers `trace_kprobe_address()`, which in turn calls either `kallsyms_lookup_name` or `kallsyms_on_each_match_symbol` when resolving multiple matching symbols.

3.  **fail\_function:** The `/sys/kernel/debug/fail_function/inject` interface also leverages `kallsyms_lookup_name` through `fei_write` to look up the target symbol.

4.  **trace\_events\_filter:** Filtering trace events via `parse_pred` also calls `kallsyms_lookup_name`.

5.  **proc/kallsyms:** And, of course, the obvious one is `/proc/kallsyms`! Now I have to check: does `/proc/kallsyms` call `kallsyms_expand_symbol` and `kallsyms_get_symbol_type`? I'm going to have to dive into that code and confirm.



6/2 2026/09/25 01:53 tool grepper
0m Args:
{
  "Expression": "kallsyms_expand_symbol|kallsyms_get_symbol_type"
}

Results:
{
  "Output": "kernel/kallsyms.c=43=static inline const u8 *get_symbol_data(unsigned int off, unsigned int *len)\n--\nkernel/kallsyms.c-59- */\nkernel/kallsyms.c:60:static unsigned int kallsyms_expand_symbol(unsigned int off,\nkernel/kallsyms.c-61-\t\t\t\t\t   char *result, size_t maxlen)\n--\nkernel/kallsyms.c-103- */\nkernel/kallsyms.c:104:static char kallsyms_get_symbol_type(unsigned int off)\nkernel/kallsyms.c-105-{\n--\nkernel/kallsyms.c=368=int kallsyms_on_each_symbol(int (*fn)(void *, const char *, unsigned long),\n--\nkernel/kallsyms.c-376-\tfor (i = 0, off = 0; i \u003c kallsyms_num_syms; i++) {\nkernel/kallsyms.c:377:\t\toff = kallsyms_expand_symbol(off, namebuf, ARRAY_SIZE(namebuf));\nkernel/kallsyms.c-378-\t\tret = fn(data, namebuf, kallsyms_sym_address(i));\n--\nkernel/kallsyms.c=474=static int kallsyms_lookup_buildid(unsigned long addr,\n--\nkernel/kallsyms.c-501-\t\t/* Grab name */\nkernel/kallsyms.c:502:\t\tkallsyms_expand_symbol(get_symbol_offset(pos),\nkernel/kallsyms.c-503-\t\t\t\t       namebuf, KSYM_NAME_LEN);\n--\nkernel/kallsyms.c=542=int lookup_symbol_name(unsigned long addr, char *symname)\n--\nkernel/kallsyms.c-551-\t\t/* Grab name */\nkernel/kallsyms.c:552:\t\tkallsyms_expand_symbol(get_symbol_offset(pos),\nkernel/kallsyms.c-553-\t\t\t\t       symname, KSYM_NAME_LEN);\n--\nkernel/kallsyms.c=794=static unsigned long get_ksymbol_core(struct kallsym_iter *iter)\n--\nkernel/kallsyms.c-800-\nkernel/kallsyms.c:801:\titer-\u003etype = kallsyms_get_symbol_type(off);\nkernel/kallsyms.c-802-\nkernel/kallsyms.c:803:\toff = kallsyms_expand_symbol(off, iter-\u003ename, ARRAY_SIZE(iter-\u003ename));\nkernel/kallsyms.c-804-\n"
}

7/2 2026/09/25 01:53 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 24330
							output: 22
							thoughts: 146
						

Thoughts:
**Kernel Symbol Lookup Deep Dive**

Okay, so I'm trying to wrap my head around the kernel's symbol lookup mechanism, and it's all coming back to me now. First, I remember that `get_ksymbol_core` – the core function, naturally – is defined within `kernel/kallsyms.c`. That's the starting point. Now, what's *calling* `get_ksymbol_core`? Bingo, it's tied to reading from `/proc/kallsyms`! I need to keep that in mind as a key interface.

Then, there's `kallsyms_lookup_buildid` and `lookup_symbol_name`. Aha, the classic callers: `sprint_symbol`, stack trace functions, and so on. That makes sense, those are the functions that need the symbolic names to output user-friendly information. They're trying to resolve addresses, presumably in many contexts.

I also see `kallsyms_lookup_batch_start` and `kallsyms_lookup_batch_end`. Batch operations? That suggests optimized lookup for cases where you need a group of symbols. I wonder where they're being used... Now that's the next critical question, who calls those batch functions? I'd better dive into the source tree and find that out. Time to trace the calls.



8/2 2026/09/25 01:53 tool grepper
0m Args:
{
  "Expression": "kallsyms_lookup_batch"
}

Results:
{
  "Output": "include/linux/kallsyms.h=74=int kallsyms_on_each_match_symbol(int (*fn)(void *, unsigned long),\n--\ninclude/linux/kallsyms.h-77-/* Transient dynamic lookup index bracketing */\ninclude/linux/kallsyms.h:78:int kallsyms_lookup_batch_start(void);\ninclude/linux/kallsyms.h:79:void kallsyms_lookup_batch_end(void);\ninclude/linux/kallsyms.h-80-\n--\ninclude/linux/kallsyms.h=166=static inline int kallsyms_on_each_match_symbol(int (*fn)(void *, unsigned long),\n--\ninclude/linux/kallsyms.h-171-\ninclude/linux/kallsyms.h:172:static inline int kallsyms_lookup_batch_start(void)\ninclude/linux/kallsyms.h-173-{\n--\ninclude/linux/kallsyms.h-176-\ninclude/linux/kallsyms.h:177:static inline void kallsyms_lookup_batch_end(void)\ninclude/linux/kallsyms.h-178-{\n--\nkernel/kallsyms.c=190=static u32 *kallsyms_build_offsets(void)\n--\nkernel/kallsyms.c-211-\nkernel/kallsyms.c:212:int kallsyms_lookup_batch_start(void)\nkernel/kallsyms.c-213-{\n--\nkernel/kallsyms.c-230-}\nkernel/kallsyms.c:231:EXPORT_SYMBOL_GPL(kallsyms_lookup_batch_start);\nkernel/kallsyms.c-232-\nkernel/kallsyms.c:233:void kallsyms_lookup_batch_end(void)\nkernel/kallsyms.c-234-{\n--\nkernel/kallsyms.c-252-}\nkernel/kallsyms.c:253:EXPORT_SYMBOL_GPL(kallsyms_lookup_batch_end);\nkernel/kallsyms.c-254-\n--\nkernel/kallsyms_selftest.c=178=static void test_perf_kallsyms_lookup_name(void)\n--\nkernel/kallsyms_selftest.c-189-\nkernel/kallsyms_selftest.c:190:\tret = kallsyms_lookup_batch_start();\nkernel/kallsyms_selftest.c-191-\tif (ret) {\nkernel/kallsyms_selftest.c:192:\t\tpr_err(\"kallsyms_lookup_batch_start() failed: %d\\n\", ret);\nkernel/kallsyms_selftest.c-193-\t\treturn;\n--\nkernel/kallsyms_selftest.c-198-\tkallsyms_on_each_symbol(lookup_name, \u0026stat);\nkernel/kallsyms_selftest.c:199:\tkallsyms_lookup_batch_end();\nkernel/kallsyms_selftest.c-200-\n--\nlib/test_kallsyms_perf.c=205=static int run_kallsyms_benchmark(void)\n--\nlib/test_kallsyms_perf.c-225-\tt0 = ktime_get_ns();\nlib/test_kallsyms_perf.c:226:\tret = kallsyms_lookup_batch_start();\nlib/test_kallsyms_perf.c-227-\tt1 = ktime_get_ns();\n--\nlib/test_kallsyms_perf.c-235-\t\tt0 = ktime_get_ns();\nlib/test_kallsyms_perf.c:236:\t\tkallsyms_lookup_batch_end();\nlib/test_kallsyms_perf.c-237-\t\tt1 = ktime_get_ns();\n"
}

9/2 2026/09/25 01:53 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 25842
							output: 22
							thoughts: 8393
						

Thoughts:
**Deep Dive into `kallsyms_strcmp_symbol` and Binary Search in the Kernel**

Okay, so I've been digging into the `kallsyms.c` file, specifically the `kallsyms_strcmp_symbol` function, as it's the core of string comparison within the kernel's symbol lookup. It appears to be an optimized function for comparing a given string (`name`) against compressed symbols stored in `kallsyms_names`. My primary focus has been verifying if there is a buffer over-read here.

First, I examined `get_symbol_data` as the workhorse for retrieving symbol data and length. It handles the compressed format, where the first byte (or two) encodes the length. Then, `kallsyms_expand_symbol` expands the compressed symbol to a string in `kallsyms_names`. Then, I also looked at `kallsyms_get_symbol_type`. However, most of my focus is on `kallsyms_strcmp_symbol`. The initial comparisons, specifically `kallsyms_strcmp_symbol`'s implementation, triggered some concern because of the way it handles potentially shorter input strings versus longer compressed symbol strings. In particular, the potential over-read that may exist if `*name` is `\0` before `*tptr`.

I carefully traced the logic: the function iterates through the compressed symbol, comparing characters. A key observation: it immediately returns a non-zero value if a mismatch is found, or if the input string (`name`) terminates before the compressed symbol (`sym`), in the case where the input string is shorter.

*   **Boundary Conditions:**  The most critical point seems to be when `*name` reaches `\0` (end of the input string) before `*tptr` does. The old code in the kernel would read beyond `name`, which represents a security flaw. Now, I have traced the code and it seems to have been updated to compare `diff = 0 - *tptr`, which returns a non-zero, and terminates before a buffer over-read.
*   **Multiple Tokens:** The symbol compression uses a token-based system. Each symbol can be broken into multiple tokens. The first character of a token points to the table. I considered scenarios with multiple tokens, and how the comparison behaves if the input string terminates mid-token, or if the tokens are of varying lengths.
*   **Return Value:** The return value is key to the binary search used in `kallsyms_lookup_names`. I carefully considered all scenarios, including where the symbol matched and how that relates to searching higher in the binary search tree. The old code had a logic flaw in returning a negative diff. If name ended before token, the old code's implementation returned -1, so `name < sym`, which is the correct behaviour.
*   **Empty String/Symbol:** I thought about empty strings as input and empty symbols within the compressed table. I traced the execution and found that comparing "" to "" returns 0. If name is "" and symbol is not empty, returns negative. If name is not empty and symbol is "", returns positive, which is correct.
*   **`kallsyms_build_offsets`:**  I reviewed this function and the role of the offsets array.  `kallsyms_build_offsets` walks the compressed symbol table and calculates offsets. I verified that this function correctly calculates the offsets to each symbol within `kallsyms_names`.
*   **`kallsyms_lookup_names`:** I've dissected the binary search implementation.  The key is the correct comparison in `kallsyms_strcmp_symbol`.  If the comparison returns a non-zero result, it's used to adjust the search range. The important thing is that `kallsyms_strcmp_symbol` functions like `strcmp`, by returning negative if less, 0 if equal, and positive if greater.
*   **Zero Bytes in Token:** What if a token contains `\0`? No, because tokens are not empty. Token is made by frequent substrings of a symbol, so tokens never start with `\0`.

In conclusion, I've confirmed that `kallsyms_strcmp_symbol` has no buffer over-read now. Also, it efficiently and correctly handles various length comparisons in its logic. The comparison returns a negative, zero, or positive value, consistent with `strcmp`, ensuring the binary search function works correctly. The tests will be key to confirm these thoughts.



10/2 2026/09/25 01:54 tool grepper
0m Args:
{
  "Expression": "kallsyms_token_table"
}

Results:
{
  "Output": "kernel/kallsyms.c=60=static unsigned int kallsyms_expand_symbol(unsigned int off,\n--\nkernel/kallsyms.c-74-\twhile (len) {\nkernel/kallsyms.c:75:\t\ttptr = \u0026kallsyms_token_table[kallsyms_token_index[*data]];\nkernel/kallsyms.c-76-\t\tdata++;\n--\nkernel/kallsyms.c=104=static char kallsyms_get_symbol_type(unsigned int off)\n--\nkernel/kallsyms.c-108-\nkernel/kallsyms.c:109:\treturn kallsyms_token_table[kallsyms_token_index[*data]];\nkernel/kallsyms.c-110-}\n--\nkernel/kallsyms.c=118=static int kallsyms_strcmp_symbol(unsigned int off, const char *name)\n--\nkernel/kallsyms.c-123-\nkernel/kallsyms.c:124:\ttptr = \u0026kallsyms_token_table[kallsyms_token_index[*data++]] + 1;\nkernel/kallsyms.c-125-\twhile (*tptr) {\n--\nkernel/kallsyms.c-132-\twhile (--len) {\nkernel/kallsyms.c:133:\t\ttptr = \u0026kallsyms_token_table[kallsyms_token_index[*data++]];\nkernel/kallsyms.c-134-\t\tdo {\n--\nkernel/kallsyms_internal.h=10=extern const unsigned int kallsyms_num_syms;\nkernel/kallsyms_internal.h-11-\nkernel/kallsyms_internal.h:12:extern const char kallsyms_token_table[];\nkernel/kallsyms_internal.h-13-extern const u16 kallsyms_token_index[];\n--\nkernel/kallsyms_selftest.c=104=static void test_kallsyms_compression_ratio(void)\n--\nkernel/kallsyms_selftest.c-138-\t * 1. The length fields is not counted\nkernel/kallsyms_selftest.c:139:\t * 2. The memory occupied by array kallsyms_token_table[] and\nkernel/kallsyms_selftest.c-140-\t *    kallsyms_token_index[] needs to be counted.\n--\nkernel/kallsyms_selftest.c-143-\tpos = kallsyms_token_index[0xff];\nkernel/kallsyms_selftest.c:144:\ttotal_size += pos + strlen(\u0026kallsyms_token_table[pos]) + 1;\nkernel/kallsyms_selftest.c-145-\ttotal_size += 0x100 * sizeof(u16);\n--\nkernel/vmcore_info.c=140=static int __init crash_save_vmcoreinfo_init(void)\n--\nkernel/vmcore_info.c-241-\tVMCOREINFO_SYMBOL(kallsyms_num_syms);\nkernel/vmcore_info.c:242:\tVMCOREINFO_SYMBOL(kallsyms_token_table);\nkernel/vmcore_info.c-243-\tVMCOREINFO_SYMBOL(kallsyms_token_index);\n--\nscripts/kallsyms.c=339=static void write_src(void)\n--\nscripts/kallsyms.c-411-\nscripts/kallsyms.c:412:\toutput_label(\"kallsyms_token_table\");\nscripts/kallsyms.c-413-\toff = 0;\n--\nscripts/kallsyms.c-419-\t}\nscripts/kallsyms.c:420:\tprintf(\".size kallsyms_token_table, . - kallsyms_token_table\\n\");\nscripts/kallsyms.c-421-\tprintf(\"\\n\");\n--\ntools/perf/tests/vmlinux-kallsyms.c=18=static bool is_ignored_symbol(const char *name, char type)\n--\ntools/perf/tests/vmlinux-kallsyms.c-32-\t\t\"kallsyms_markers\",\ntools/perf/tests/vmlinux-kallsyms.c:33:\t\t\"kallsyms_token_table\",\ntools/perf/tests/vmlinux-kallsyms.c-34-\t\t\"kallsyms_token_index\",\n"
}

11/2 2026/09/25 01:54 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 36408
							output: 36
							thoughts: 29
						

Thoughts:
Okay, here's my take on those thoughts, tailored for an expert audience:

**Diving into Kallsyms Token Handling**

Alright, so I need to refresh my memory on the tokenization process within `kallsyms.c`. Specifically, I'm thinking about how the symbols themselves are stored and formatted. My intuition says line 412 is a good place to start digging into the details of the internal representation. Let's see how they're handling those symbols, and the metadata associated with each. I expect there might be some tricks for memory efficiency there given the size of kallsyms. I want to see how the code avoids any performance bottlenecks when parsing or querying the symbols. Should be interesting. Let's see what we can find!



12/2 2026/09/25 01:54 tool read-file
0m Args:
{
  "File": "scripts/kallsyms.c",
  "FirstLine": 405,
  "LineCount": 30
}

Results:
{
  "Contents": " 405:\t\tfor (i = 0; i \u003c markers_cnt; i++)\n 406:\t\t\tprintf(\"\\t.long\\t%u\\n\", markers[i]);\n 407:\t\tprintf(\".size kallsyms_markers, . - kallsyms_markers\\n\");\n 408:\t\tprintf(\"\\n\");\n 409:\t\n 410:\t\tfree(markers);\n 411:\t\n 412:\t\toutput_label(\"kallsyms_token_table\");\n 413:\t\toff = 0;\n 414:\t\tfor (i = 0; i \u003c 256; i++) {\n 415:\t\t\tbest_idx[i] = off;\n 416:\t\t\texpand_symbol(best_table[i], best_table_len[i], buf);\n 417:\t\t\tprintf(\"\\t.asciz\\t\\\"%s\\\"\\n\", buf);\n 418:\t\t\toff += strlen(buf) + 1;\n 419:\t\t}\n 420:\t\tprintf(\".size kallsyms_token_table, . - kallsyms_token_table\\n\");\n 421:\t\tprintf(\"\\n\");\n 422:\t\n 423:\t\toutput_label(\"kallsyms_token_index\");\n 424:\t\tfor (i = 0; i \u003c 256; i++)\n 425:\t\t\tprintf(\"\\t.short\\t%d\\n\", best_idx[i]);\n 426:\t\tprintf(\"\\n\");\n 427:\t\n 428:\t\toutput_label(\"kallsyms_offsets\");\n 429:\t\n 430:\t\tfor (i = 0; i \u003c table_cnt; i++) {\n 431:\t\t\tif (pc_relative) {\n 432:\t\t\t\tlong long offset = table[i]-\u003eaddr - _text;\n 433:\t\n 434:\t\t\t\tif (offset \u003c INT_MIN || offset \u003e INT_MAX) {\n"
}

13/2 2026/09/25 01:54 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 37152
							output: 39
							thoughts: 96
						

Thoughts:
Here's my thought process, as it stands:

**Navigating the Kallsyms Landscape**

Okay, so I'm looking at how kallsyms works, specifically focusing on the name resolution process. I've noted that `scripts/kallsyms.c` seems to be responsible for generating these kallsyms entries, and it's putting out `.asciz "%s"` for each token. That's a good starting point. Now, I need to understand the connection between that and the actual lookup function, `kallsyms_lookup_names()`. The critical piece here is how the names are sorted within kallsyms. How is that achieved? I need to track down the sorting mechanism. I'll go back to `scripts/kallsyms.c` to see how `kallsyms_seqs_of_names` is generated. That should reveal the sorting strategy used within kallsyms.



14/2 2026/09/25 01:54 tool grepper
0m Args:
{
  "Expression": "kallsyms_seqs_of_names",
  "PathPrefix": "scripts/kallsyms.c"
}

Results:
{
  "Output": "scripts/kallsyms.c=339=static void write_src(void)\n--\nscripts/kallsyms.c-450-\tsort_symbols_by_name();\nscripts/kallsyms.c:451:\toutput_label(\"kallsyms_seqs_of_names\");\nscripts/kallsyms.c-452-\tfor (i = 0; i \u003c table_cnt; i++)\n"
}

15/2 2026/09/25 01:54 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 37611
							output: 35
							thoughts: 24
						

Thoughts:
Okay, here's my take on those thoughts, tailored for an expert audience:

**Diving into `sort_symbols_by_name()`**

Alright, let's get down to brass tacks. My initial thought process is immediately zeroing in on `sort_symbols_by_name()` within `scripts/kallsyms.c`. I need to understand its function and how it contributes to the overall process. This likely involves symbol sorting, which has implications for lookup efficiency, binary analysis, and possibly even kernel debugging. I'm already anticipating questions related to the sorting algorithm used (is it stable? Efficient for large symbol tables?), any potential memory bottlenecks, and whether it handles edge cases like duplicate or malformed symbol names gracefully. Knowing kallsyms intimately, I bet it utilizes a common algorithm but I still want to check the implementation details. Time to pull it up and take a closer look at the code.



16/2 2026/09/25 01:54 tool grepper
0m Args:
{
  "Expression": "sort_symbols_by_name",
  "PathPrefix": "scripts/kallsyms.c"
}

Results:
{
  "Output": "scripts/kallsyms.c=314=static int compare_names(const void *a, const void *b)\n--\nscripts/kallsyms.c-333-\nscripts/kallsyms.c:334:static void sort_symbols_by_name(void)\nscripts/kallsyms.c-335-{\n--\nscripts/kallsyms.c=339=static void write_src(void)\n--\nscripts/kallsyms.c-449-\nscripts/kallsyms.c:450:\tsort_symbols_by_name();\nscripts/kallsyms.c-451-\toutput_label(\"kallsyms_seqs_of_names\");\n"
}

17/2 2026/09/25 01:54 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 38056
							output: 36
							thoughts: 20
						

Thoughts:
Okay, here's my take on those thoughts, tailored for an expert audience:

**Diving into `compare_names` in `scripts/kallsyms.c`**

Alright, let's pull up that `compare_names` function within `scripts/kallsyms.c`. I'm specifically interested in its implementation. We're obviously talking about name comparison, likely string comparisons, within the context of handling kernel symbol information. Given that this is in `kallsyms.c`, I'm assuming this is related to parsing and interpreting output from `/proc/kallsyms` or a similar source. The way the names are compared could have significant performance implications, particularly when dealing with a large symbol table. I need to see if it's a simple `strcmp`, a more sophisticated comparison with potential optimizations, or something else entirely. Are they handling any special cases, such as mangled C++ symbols? Are they considering case sensitivity? Are there any potential vulnerabilities related to string buffer overflows or other related vulnerabilities that could have been introduced? This is going to be about understanding the underlying mechanism for parsing kernel symbols. I expect to be focusing on the logic that is used to compare each name string to another. This is where I begin the analysis.



18/2 2026/09/25 01:54 tool read-file
0m Args:
{
  "File": "scripts/kallsyms.c",
  "FirstLine": 314,
  "LineCount": 25
}

Results:
{
  "Contents": " 314:\tstatic int compare_names(const void *a, const void *b)\n 315:\t{\n 316:\t\tint ret;\n 317:\t\tconst struct sym_entry *sa = *(const struct sym_entry **)a;\n 318:\t\tconst struct sym_entry *sb = *(const struct sym_entry **)b;\n 319:\t\n 320:\t\tret = strcmp(sym_name(sa), sym_name(sb));\n 321:\t\tif (!ret) {\n 322:\t\t\tif (sa-\u003eaddr \u003e sb-\u003eaddr)\n 323:\t\t\t\treturn 1;\n 324:\t\t\telse if (sa-\u003eaddr \u003c sb-\u003eaddr)\n 325:\t\t\t\treturn -1;\n 326:\t\n 327:\t\t\t/* keep old order */\n 328:\t\t\treturn (int)(sa-\u003eseq - sb-\u003eseq);\n 329:\t\t}\n 330:\t\n 331:\t\treturn ret;\n 332:\t}\n 333:\t\n 334:\tstatic void sort_symbols_by_name(void)\n 335:\t{\n 336:\t\tqsort(table, table_cnt, sizeof(table[0]), compare_names);\n 337:\t}\n 338:\t\n"
}

19/2 2026/09/25 01:54 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 38725
							output: 31
							thoughts: 48
						

Thoughts:
Okay, here's my take on those thoughts, tailored for an expert audience:

**Analyzing the Name Comparison in `kallsyms`**

Alright, so I'm looking at `compare_names` and immediately see that it's relying on `strcmp` applied to the output of `sym_name`.  My first thought is, "Okay, `strcmp` is standard, so the sorting behavior is predictable lexically." But, what is `sym_name` *actually* doing in `scripts/kallsyms.c`?  I need to drill down into that to understand the potential for any quirks or hidden complexities in the name comparison.  It could be a simple pointer dereference or something with more involved string manipulation. Knowing that's critical to understanding the stability of the sorting. I'm heading there now to confirm my assumptions and ensure that the name comparison is behaving as I expect in relation to the overall kallsyms processing. I have to make sure there are no surprises with how it constructs the name used in the `strcmp`.



20/2 2026/09/25 01:54 tool grepper
0m Args:
{
  "Expression": "sym_name",
  "PathPrefix": "scripts/kallsyms.c"
}

Results:
{
  "Output": "scripts/kallsyms.c=68=static void usage(void)\n--\nscripts/kallsyms.c-73-\nscripts/kallsyms.c:74:static char *sym_name(const struct sym_entry *s)\nscripts/kallsyms.c-75-{\n--\nscripts/kallsyms.c=115=static struct sym_entry *read_symbol(FILE *in, char **buf, size_t *buf_len)\n--\nscripts/kallsyms.c-169-\tsym-\u003esym[0] = type;\nscripts/kallsyms.c:170:\tstrcpy(sym_name(sym), name);\nscripts/kallsyms.c-171-\n--\nscripts/kallsyms.c=196=static int symbol_valid(const struct sym_entry *s)\nscripts/kallsyms.c-197-{\nscripts/kallsyms.c:198:\tconst char *name = sym_name(s);\nscripts/kallsyms.c-199-\n--\nscripts/kallsyms.c=314=static int compare_names(const void *a, const void *b)\n--\nscripts/kallsyms.c-319-\nscripts/kallsyms.c:320:\tret = strcmp(sym_name(sa), sym_name(sb));\nscripts/kallsyms.c-321-\tif (!ret) {\n--\nscripts/kallsyms.c=616=static int may_be_linker_script_provide_symbol(const struct sym_entry *se)\nscripts/kallsyms.c-617-{\nscripts/kallsyms.c:618:\tconst char *symbol = sym_name(se);\nscripts/kallsyms.c-619-\tint len = se-\u003elen - 1;\n--\nscripts/kallsyms.c=650=static int compare_symbols(const void *a, const void *b)\n--\nscripts/kallsyms.c-674-\t/* sort by the number of prefix underscores */\nscripts/kallsyms.c:675:\twa = strspn(sym_name(sa), \"_\");\nscripts/kallsyms.c:676:\twb = strspn(sym_name(sb), \"_\");\nscripts/kallsyms.c-677-\tif (wa != wb)\n"
}

21/2 2026/09/25 01:54 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 39644
							output: 29
							thoughts: 1117
						

Thoughts:
**Analyzing Kallsyms RCU Usage**

Okay, so I'm digging into how `kallsyms` handles symbol lookups and I've got some concerns about RCU usage. First, I noticed that `sym_name(s)` is essentially a pointer to `&s->sym[1]`, skipping the type prefix byte.  Also, `strcmp` is using unsigned character comparison.  And, I recall that `kallsyms_strcmp_symbol` does a similar unsigned char comparison. Nothing unusual here yet, just laying the ground work.

Then, I started to trace the path of the lookup. Specifically, I went to check `get_symbol_offset(unsigned long pos)` in `kernel/kallsyms.c`.  I see it's using an RCU read lock, which is expected. The interesting part is that it acquires and releases the RCU read lock within a conditional block.  I check `kallsyms_lookup_names`.  This also holds an RCU read lock for the duration of its while loop, which is fine, as `get_symbol_offset()`'s nested RCU read lock and unlock are also fine. No issues here.

However, I started to wonder about batch operations and whether there are any potential conflicts. So, I looked at `kallsyms_lookup_batch_start` and `kallsyms_lookup_batch_end`.  I see they use a mutex (`dyn_kallsyms_mutex`) to protect the offset array.  `kallsyms_lookup_batch_start` builds the offset array and assigns it to `dyn_kallsyms_offsets`.  `kallsyms_lookup_batch_end` clears it after a reference count goes to zero.  The assignment and clearing are protected by the mutex, so that seems reasonable.

But, I need to know about the RCU usage. I have to think about whether these functions or other functions are ever called from an atomic context. This is important to ensure RCU guarantees are maintained.

I'm now back at `get_symbol_offset`, checking it specifically.  I see it always has `rcu_read_lock()` and `rcu_read_unlock()`. This is good. I need to be sure. I'm going to look at every call site. I can see it's called in `kallsyms_lookup_names`, `kallsyms_lookup_buildid`, and `lookup_symbol_name`. Now, I need to check what calls `lookup_symbol_name` and `kallsyms_lookup_buildid`. I need to track the call sites.



22/2 2026/09/25 01:54 tool grepper
0m Args:
{
  "Expression": "lookup_symbol_name|kallsyms_lookup_buildid"
}

Results:
{
  "Output": "fs/proc/base.c=413=static int proc_pid_wchan(struct seq_file *m, struct pid_namespace *ns,\n--\nfs/proc/base.c-426-\twchan = get_wchan(task);\nfs/proc/base.c:427:\tif (wchan \u0026\u0026 !lookup_symbol_name(wchan, symname)) {\nfs/proc/base.c-428-\t\tseq_puts(m, symname);\n--\ninclude/linux/kallsyms.h=99=extern int sprint_backtrace_build_id(char *buffer, unsigned long address);\ninclude/linux/kallsyms.h-100-\ninclude/linux/kallsyms.h:101:int lookup_symbol_name(unsigned long addr, char *symname);\ninclude/linux/kallsyms.h-102-\n--\ninclude/linux/kallsyms.h=149=static inline int sprint_backtrace_build_id(char *buffer, unsigned long addr)\n--\ninclude/linux/kallsyms.h-154-\ninclude/linux/kallsyms.h:155:static inline int lookup_symbol_name(unsigned long addr, char *symname)\ninclude/linux/kallsyms.h-156-{\n--\nkernel/kallsyms.c=461=int kallsyms_lookup_size_offset(unsigned long addr, unsigned long *symbolsize,\n--\nkernel/kallsyms.c-473-\nkernel/kallsyms.c:474:static int kallsyms_lookup_buildid(unsigned long addr,\nkernel/kallsyms.c-475-\t\t\tunsigned long *symbolsize,\n--\nkernel/kallsyms.c=528=const char *kallsyms_lookup(unsigned long addr,\n--\nkernel/kallsyms.c-532-{\nkernel/kallsyms.c:533:\tint ret = kallsyms_lookup_buildid(addr, symbolsize, offset, modname,\nkernel/kallsyms.c-534-\t\t\t\t\t  NULL, namebuf);\n--\nkernel/kallsyms.c-541-\nkernel/kallsyms.c:542:int lookup_symbol_name(unsigned long addr, char *symname)\nkernel/kallsyms.c-543-{\n--\nkernel/kallsyms.c=592=static int __sprint_symbol(char *buffer, unsigned long address,\n--\nkernel/kallsyms.c-603-\taddress += symbol_offset;\nkernel/kallsyms.c:604:\tlen = kallsyms_lookup_buildid(address, \u0026size, \u0026offset, \u0026modname, \u0026buildid,\nkernel/kallsyms.c-605-\t\t\t\t       buffer);\n--\nkernel/kallsyms_selftest.c=273=static int test_kallsyms_basic_function(void)\n--\nkernel/kallsyms_selftest.c-335-\nkernel/kallsyms_selftest.c:336:\t\tret = lookup_symbol_name(addr, namebuf);\nkernel/kallsyms_selftest.c-337-\t\tif (unlikely(ret)) {\nkernel/kallsyms_selftest.c-338-\t\t\tnamebuf[0] = 0;\nkernel/kallsyms_selftest.c:339:\t\t\tpr_info(\"%d: lookup_symbol_name(%lx) failed\\n\", i, addr);\nkernel/kallsyms_selftest.c-340-\t\t\tgoto failed;\n--\nkernel/kprobes.c=1464=bool within_kprobe_blacklist(unsigned long addr)\n--\nkernel/kprobes.c-1471-\t/* Check if the address is on a suffixed-symbol */\nkernel/kprobes.c:1472:\tif (!lookup_symbol_name(addr, symname)) {\nkernel/kprobes.c-1473-\t\tp = strchr(symname, '.');\n--\nkernel/kprobes.c=1613=static bool is_cfi_preamble_symbol(unsigned long addr)\n--\nkernel/kprobes.c-1616-\nkernel/kprobes.c:1617:\tif (lookup_symbol_name(addr, symbuf))\nkernel/kprobes.c-1618-\t\treturn false;\n--\nkernel/trace/trace_kprobe.c=469=static bool within_notrace_func(struct trace_kprobe *tk)\n--\nkernel/trace/trace_kprobe.c-477-\t/* Check if the address is on a suffixed-symbol */\nkernel/trace/trace_kprobe.c:478:\tif (!lookup_symbol_name(addr, symname)) {\nkernel/trace/trace_kprobe.c-479-\t\tp = strchr(symname, '.');\n--\nkernel/trace/trace_output.c=721=void print_function_args(struct trace_seq *s, unsigned long *args,\n--\nkernel/trace/trace_output.c-738-\t\tgoto out;\nkernel/trace/trace_output.c:739:\tif (lookup_symbol_name(func, name))\nkernel/trace/trace_output.c-740-\t\tgoto out;\n"
}

23/2 2026/09/25 01:54 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 42721
							output: 36
							thoughts: 5985
						

Thoughts:
**Kallsyms Investigation: A Deep Dive into Symbol Lookup**

Okay, so I'm digging into `kallsyms_lookup_buildid`, which is apparently crucial for backtraces and `proc` interfaces. I'm also looking at the relationship between `kallsyms_lookup_names`, `kallsyms_lookup_name`, and `kallsyms_on_each_match_symbol`, trying to get a handle on the overall flow. I'm also wondering about the performance implications and how those new batch lookup functions work: `kallsyms_lookup_batch_start` and `kallsyms_lookup_batch_end`.

First thing I checked, is there a performance test? Is `test_kallsyms_perf.c` built? Let me verify it with `CONFIG_TEST_KALLSYMS_PERF` in `lib/Kconfig.debug`. Yep, it's there. It looks like it is a bool, so I'll check to see if that test is available. I'm seeing it's designed to benchmark different search methods. I'm seeing a module parameter that triggers the test, `run_test`. Can I write to this parameter via sysfs? I need to check if it's built-in or a module. Since `CONFIG_TEST_KALLSYMS_PERF` is `bool`, it's compiled into the kernel! So, `run_test` will appear in `/sys/module/test_kallsyms_perf/parameters/run_test` and I can write to it as root.

But that's not the critical piece here. I'm focusing on the *core* code in `kernel/kallsyms.c`. That's where the real magic happens. This is in *every* Linux kernel with `CONFIG_KALLSYMS=y`. And what's been changed? I see these new functions: `get_symbol_data`, `kallsyms_strcmp_symbol`, `kallsyms_build_offsets`, `kallsyms_lookup_batch_start`, `kallsyms_lookup_batch_end`. Also, key functions have been modified: `kallsyms_expand_symbol`, `kallsyms_get_symbol_type`, `get_symbol_offset`, and `kallsyms_lookup_names`.

Let's dive into the changes. The new `get_symbol_data` helper and `get_symbol_offset` rewrite are interesting. I'm seeing a substantial rework of `kallsyms_lookup_names`, shifting from an `expand_symbol + strcmp` to a `kallsyms_strcmp_symbol` approach under `rcu_read_lock`. The other change is related to performance optimization: `get_symbol_seq` is rewritten to use direct assembly.

I'm now focusing on `kallsyms_expand_symbol`. It looks like it's decoding the compressed symbol data, but the new version uses `get_symbol_data`. I'm confirming that the new code mirrors the original in the way `data` and `off` are calculated, but it's simpler now.

Then `kallsyms_get_symbol_type`... the original code and the new code return the same thing.

Now, `kallsyms_strcmp_symbol`. This is where it gets interesting, as this compares the kallsyms symbol names. I'm carefully analyzing its implementation. I'm seeing two loops. The first loop, `while (*tptr)`, checks the first token. The second loop, `do { ... } while (*tptr)`, handles the rest of the symbol. The first loop has a critical check. What happens if the first token is just the type, and no name characters? The second loop handles that. Let me look at the code in `scripts/kallsyms.c` to see if tokens can have length 0. It appears that no, every token is guaranteed to have at least one character, so that's okay.

I'm looking at what happens if the input `name` is shorter than the symbol. I have to trace how the loops handle null terminators (`\0`). What is the behavior when `name` runs out of characters (null terminator) and the symbol has more? Okay, it advances past the end of the input buffer, but the code still seems sound; the comparison will return a non-zero value, and exit. Is there a scenario where this code crashes, given a malicious input? No.

Now I am looking at how `kallsyms_lookup_names` works, particularly how it uses `kallsyms_strcmp_symbol`. I'm


24/2 2026/09/25 01:54 tool read-file
0m Args:
{
  "File": "kernel/kallsyms.c",
  "FirstLine": 315,
  "LineCount": 40
}

Results:
{
  "Contents": " 315:\t\n 316:\t\tif (low \u003e high) {\n 317:\t\t\trcu_read_unlock();\n 318:\t\t\treturn -ESRCH;\n 319:\t\t}\n 320:\t\n 321:\t\tlow = mid;\n 322:\t\twhile (low) {\n 323:\t\t\tseq = get_symbol_seq(low - 1);\n 324:\t\t\toff = get_symbol_offset(seq);\n 325:\t\t\tif (kallsyms_strcmp_symbol(off, name) != 0)\n 326:\t\t\t\tbreak;\n 327:\t\t\tlow--;\n 328:\t\t}\n 329:\t\t*start = low;\n 330:\t\n 331:\t\tif (end) {\n 332:\t\t\thigh = mid;\n 333:\t\t\twhile (high \u003c kallsyms_num_syms - 1) {\n 334:\t\t\t\tseq = get_symbol_seq(high + 1);\n 335:\t\t\t\toff = get_symbol_offset(seq);\n 336:\t\t\t\tif (kallsyms_strcmp_symbol(off, name) != 0)\n 337:\t\t\t\t\tbreak;\n 338:\t\t\t\thigh++;\n 339:\t\t\t}\n 340:\t\t\t*end = high;\n 341:\t\t}\n 342:\t\trcu_read_unlock();\n 343:\t\n 344:\t\treturn 0;\n 345:\t}\n 346:\t\n 347:\t/* Lookup the address for this symbol. Returns 0 if not found. */\n 348:\tunsigned long kallsyms_lookup_name(const char *name)\n 349:\t{\n 350:\t\tint ret;\n 351:\t\tunsigned int i;\n 352:\t\n 353:\t\t/* Skip the search for empty string. */\n 354:\t\tif (!*name)\n"
}

25/2 2026/09/25 01:54 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 50287
							output: 36
							thoughts: 30
						

Thoughts:
Okay, here's my attempt at summarizing those thoughts from a first-person, expert perspective, focusing on the implied reasoning process:

**Diving into Symbol Table Lookups**

Alright, time to get down to brass tacks. I need to understand how the kernel symbol table works. Specifically, I want to drill into `kallsyms_lookup_name` and `kallsyms_on_each_match_symbol`. These are the core functions for symbol resolution, and I'll bet they're critical for understanding how the kernel does things, like the module loading I've been looking at. I'll need to see precisely how these functions work to understand how this all fits together and debug some tricky issues with kernel internals.



26/2 2026/09/25 01:54 tool read-file
0m Args:
{
  "File": "kernel/kallsyms.c",
  "FirstLine": 350,
  "LineCount": 55
}

Results:
{
  "Contents": " 350:\t\tint ret;\n 351:\t\tunsigned int i;\n 352:\t\n 353:\t\t/* Skip the search for empty string. */\n 354:\t\tif (!*name)\n 355:\t\t\treturn 0;\n 356:\t\n 357:\t\tret = kallsyms_lookup_names(name, \u0026i, NULL);\n 358:\t\tif (!ret)\n 359:\t\t\treturn kallsyms_sym_address(get_symbol_seq(i));\n 360:\t\n 361:\t\treturn module_kallsyms_lookup_name(name);\n 362:\t}\n 363:\t\n 364:\t/*\n 365:\t * Iterate over all symbols in vmlinux.  For symbols from modules use\n 366:\t * module_kallsyms_on_each_symbol instead.\n 367:\t */\n 368:\tint kallsyms_on_each_symbol(int (*fn)(void *, const char *, unsigned long),\n 369:\t\t\t\t    void *data)\n 370:\t{\n 371:\t\tchar namebuf[KSYM_NAME_LEN];\n 372:\t\tunsigned long i;\n 373:\t\tunsigned int off;\n 374:\t\tint ret;\n 375:\t\n 376:\t\tfor (i = 0, off = 0; i \u003c kallsyms_num_syms; i++) {\n 377:\t\t\toff = kallsyms_expand_symbol(off, namebuf, ARRAY_SIZE(namebuf));\n 378:\t\t\tret = fn(data, namebuf, kallsyms_sym_address(i));\n 379:\t\t\tif (ret != 0)\n 380:\t\t\t\treturn ret;\n 381:\t\t\tcond_resched();\n 382:\t\t}\n 383:\t\treturn 0;\n 384:\t}\n 385:\t\n 386:\tint kallsyms_on_each_match_symbol(int (*fn)(void *, unsigned long),\n 387:\t\t\t\t\t  const char *name, void *data)\n 388:\t{\n 389:\t\tint ret;\n 390:\t\tunsigned int i, start, end;\n 391:\t\n 392:\t\tret = kallsyms_lookup_names(name, \u0026start, \u0026end);\n 393:\t\tif (ret)\n 394:\t\t\treturn 0;\n 395:\t\n 396:\t\tfor (i = start; !ret \u0026\u0026 i \u003c= end; i++) {\n 397:\t\t\tret = fn(data, kallsyms_sym_address(get_symbol_seq(i)));\n 398:\t\t\tcond_resched();\n 399:\t\t}\n 400:\t\n 401:\t\treturn ret;\n 402:\t}\n 403:\t\n 404:\tstatic unsigned long get_symbol_pos(unsigned long addr,\n"
}

27/2 2026/09/25 01:54 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 51298
							output: 29
							thoughts: 2266
						

Thoughts:
**Fuzzing Decision for Kallsyms Changes**

Okay, let's break this down systematically. I see changes to `kallsyms_lookup_batch_start` and `kallsyms_lookup_batch_end`, which are exported symbols. The presence of `WARN_ON(!dyn_kallsyms_refcnt)` in `kallsyms_lookup_batch_end` is a clear red flag; that screams "potential invariant violation". The core triage philosophy is clear: any modification that introduces or alters runtime checks in *reachable* code *must* be fuzzed. And this definitely qualifies.

The next question, is the code reachable? Let's verify, because the core triage document is explicit on reachability as *the* primary gate. Looking at how `kallsyms.c` is used within the kernel... Yes, it absolutely is. `/proc/kallsyms` reads use it via `kallsyms_get_symbol_type` and `kallsyms_expand_symbol`. Stack traces/wchan use it via `kallsyms_lookup_buildid` and `get_symbol_offset`. BPF programs use `kallsyms_lookup_name`, both during program load and when a syscall BPF program calls the `bpf_kallsyms_lookup_name` helper. Kprobes use it via `kallsyms_lookup_name` and `kallsyms_on_each_match_symbol`. Trace events filters call `kallsyms_lookup_name`. Even `fail_function` uses `kallsyms_lookup_name`. And finally, there is even a specific self-test (`test_kallsyms_perf`) available.

No reason this wouldn't be worth fuzzing!

Let's look at the "negative criteria" in the triage philosophy. Is this a non-kernel change? No. Is this structurally unreachable hardware? No. Unreachable execution path? Absolutely not; kallsyms is used across the kernel. This is a core subsystem. The changes involve restructuring code (decompression logic, symbol string comparisons, offset resolution). And, critically, it introduces a new assertion. Applying the "positive criteria", this clearly hits several checkboxes: core subsystem, refactoring, new assertions. This screams `WorthFuzzing = true`.

Therefore, the next steps are to determine the Kconfig flags required to build and enable the code, identify non-ubiquitous kernel functions that could be targeted, and then write up a clear and concise explanation for why this is fuzz-worthy.



28/2 2026/09/25 01:55 tool grepper
0m Args:
{
  "Expression": "kallsyms\\.o",
  "PathPrefix": "kernel/Makefile"
}

Results:
{
  "Output": "kernel/Makefile=75=obj-$(CONFIG_MODULE_SIG_FORMAT) += module_signature.o\nkernel/Makefile:76:obj-$(CONFIG_KALLSYMS) += kallsyms.o\nkernel/Makefile-77-obj-$(CONFIG_KALLSYMS_SELFTEST) += kallsyms_selftest.o\n"
}

29/2 2026/09/25 01:55 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 54244
							output: 29
							thoughts: 42
						

Thoughts:
Okay, here's my interpretation of those thoughts, tailored for an expert audience, presented in the first person:

**Kernel Symbol Table Configuration Review**

Alright, so `CONFIG_KALLSYMS` is the key to building `kernel/kallsyms.c`. That's the core. My immediate thought is, "What about self-testing?" Given the importance of the symbol table, it's critical to ensure it's functioning correctly. I should quickly check `CONFIG_KALLSYMS_SELFTEST`. That option's definition should reside in `init/Kconfig`, so I need to navigate there and see the details of that configuration option. I need to understand if the self-tests are enabled and how robust they are. Any known issues or dependencies? Better to understand the self-test situation before proceeding further.



30/2 2026/09/25 01:55 tool grepper
0m Args:
{
  "Expression": "config KALLSYMS",
  "PathPrefix": "init/Kconfig"
}

Results:
{
  "Output": "init/Kconfig=2086=config CACHESTAT_SYSCALL\n--\ninit/Kconfig-2095-\ninit/Kconfig:2096:config KALLSYMS\ninit/Kconfig-2097-\tbool \"Load all symbols for debugging/ksymoops\" if EXPERT\n--\ninit/Kconfig-2103-\ninit/Kconfig:2104:config KALLSYMS_SELFTEST\ninit/Kconfig-2105-\tbool \"Test the basic functions and performance of kallsyms\"\n--\ninit/Kconfig-2116-\ninit/Kconfig:2117:config KALLSYMS_ALL\ninit/Kconfig-2118-\tbool \"Include all symbols in kallsyms\"\n"
}

31/2 2026/09/25 01:55 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 54691
							output: 33
							thoughts: 638
						

Thoughts:
**Analyzing Kallsyms Code Paths and Configurations**

Okay, let's dive into this. I need to re-examine `lib/Kconfig.debug`, specifically around `CONFIG_TEST_KALLSYMS_PERF`. Looking at the description, it's a test for benchmarking kallsyms performance, covering different lookup methods.

Now, what I really need to understand is: what configurations are *actually* enabling the code paths in `kernel/kallsyms.c` that were modified recently? It's pretty straightforward, actually.
*   `KALLSYMS` enables compilation of `kernel/kallsyms.c`, which is the core.
*   `TEST_KALLSYMS_PERF` compiles `lib/test_kallsyms_perf.c` and that module calls `kallsyms_lookup_batch_start` and `kallsyms_lookup_batch_end`.
*   `KALLSYMS_SELFTEST` enables `kernel/kallsyms_selftest.c`, which, again, uses `kallsyms_lookup_batch_start` and `kallsyms_lookup_batch_end`.
*   And, possibly, `KPROBE_EVENTS`, `BPF_SYSCALL` and/or `FAIL_FUNCTION`? I'll need to double check those.

Hold on a second! Back in `lib/test_kallsyms_perf.c`, I see a `late_initcall` for `test_kallsyms_init` and a `module_param_cb` for `run_test`. That's important.

The question is, if `TEST_KALLSYMS_PERF` is enabled, does Syzkaller utilize it? Or is it purely a benchmark module? Considering the description, I'm leaning toward the latter, and I need to confirm this. Ah, yes, it's a *test* module introduced by a specific patch series!

Okay, but the important question now is: are `kallsyms_lookup_batch_start` and `kallsyms_lookup_batch_end` used *anywhere else* in the kernel? I need to check for other callers.

Let's quickly check the grep output from earlier to be certain:
*   `include/linux/kallsyms.h`
*   `kernel/kallsyms.c`
*   `kernel/kallsyms_selftest.c`
*   `lib/test_kallsyms_perf.c`

Bingo! Only those files. That means the `kallsyms_lookup_batch_start` and `kallsyms_lookup_batch_end` are only invoked if either `CONFIG_TEST_KALLSYMS_PERF` or `CONFIG_KALLSYMS_SELFTEST` is enabled, or by another subsystem, although that seems unlikely considering the grep results.

Right, I should probably check `CONFIG_KALLSYMS_SELFTEST`'s description in `init/Kconfig` just to be completely thorough.



32/2 2026/09/25 01:55 tool read-file
0m Args:
{
  "File": "init/Kconfig",
  "FirstLine": 2100,
  "LineCount": 25
}

Results:
{
  "Contents": "2100:\t\t  Say Y here to let the kernel print out symbolic crash information and\n2101:\t\t  symbolic stack backtraces. This increases the size of the kernel\n2102:\t\t  somewhat, as all symbols have to be loaded into the kernel image.\n2103:\t\n2104:\tconfig KALLSYMS_SELFTEST\n2105:\t\tbool \"Test the basic functions and performance of kallsyms\"\n2106:\t\tdepends on KALLSYMS\n2107:\t\tdefault n\n2108:\t\thelp\n2109:\t\t  Test the basic functions and performance of some interfaces, such as\n2110:\t\t  kallsyms_lookup_name. It also calculates the compression rate of the\n2111:\t\t  kallsyms compression algorithm for the current symbol set.\n2112:\t\n2113:\t\t  Start self-test automatically after system startup. Suggest executing\n2114:\t\t  \"dmesg | grep kallsyms_selftest\" to collect test results. \"finish\" is\n2115:\t\t  displayed in the last line, indicating that the test is complete.\n2116:\t\n2117:\tconfig KALLSYMS_ALL\n2118:\t\tbool \"Include all symbols in kallsyms\"\n2119:\t\tdepends on DEBUG_KERNEL \u0026\u0026 KALLSYMS\n2120:\t\thelp\n2121:\t\t  Normally kallsyms only contains the symbols of functions for nicer\n2122:\t\t  OOPS messages and backtraces (i.e., symbols from the text and inittext\n2123:\t\t  sections). This is sufficient for most cases. And only if you want to\n2124:\t\t  enable kernel live patching, or other less common use cases (e.g.,\n"
}

33/2 2026/09/25 01:55 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 56495
							output: 32
							thoughts: 265
						

Thoughts:
**My Analysis of Kallsyms Accessibility**

Alright, let's break this down systematically. My immediate thought is to determine if syzkaller can reach `kallsyms_lookup_name` through two key avenues: `BPF_SYSCALL` and `KPROBE_EVENTS`. The question boils down to whether these mechanisms offer a pathway to this critical kernel symbol.

Aha! It looks like there's a clear connection. We can definitely hit `kallsyms_lookup_name` through both of them. Let's delve into the specifics, starting with `BPF_SYSCALL` and `KPROBE_EVENTS` again.

Here's what I'm seeing. In `kernel/bpf/syscall.c`, there's a `BPF_CALL_4(bpf_kallsyms_lookup_name, ...)` function, and within that, a direct call to `kallsyms_lookup_name(name)`. That's a strong indication.

Now, shifting gears to `kernel/trace/trace_kprobe.c`, it's equally clear. The `trace_kprobe_address()` function calls `kallsyms_lookup_name(trace_kprobe_symbol(tk))`. Further, `number_of_same_symbols()` calls `kallsyms_on_each_match_symbol(count_symbols, func_name, &ctx.count)`.

The crucial trigger here is writing to `/sys/kernel/tracing/kprobe_events`. And what config enables that? That's right, `CONFIG_KPROBE_EVENTS`. This is the core dependency. Time to see what *that* depends on.



34/2 2026/09/25 01:55 tool grepper
0m Args:
{
  "Expression": "config KPROBE_EVENTS",
  "PathPrefix": "kernel/trace/Kconfig"
}

Results:
{
  "Output": "kernel/trace/Kconfig=782=config PROBE_EVENTS_DUMP_FETCHARG\n--\nkernel/trace/Kconfig-793-\nkernel/trace/Kconfig:794:config KPROBE_EVENTS\nkernel/trace/Kconfig-795-\tdepends on KPROBES\n--\nkernel/trace/Kconfig-812-\nkernel/trace/Kconfig:813:config KPROBE_EVENTS_ON_NOTRACE\nkernel/trace/Kconfig-814-\tbool \"Do NOT protect notrace function from kprobe events\"\n"
}

35/2 2026/09/25 01:55 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 57313
							output: 401
							thoughts: 2439
						

Thoughts:
**Kallsyms Investigation: Fuzzing Target Identification**

Okay, let's break this down. My goal is to determine the best approach for fuzzing this kallsyms patch. I'm focusing on the key changes and how to reach them. First, I need to confirm the presence of a performance benchmark and confirm it's accessible. Aha, `CONFIG_TEST_KALLSYMS_PERF` seems promising, it calls `run_kallsyms_benchmark()`, which then calls into crucial functions like `kallsyms_lookup_batch_start`, `kallsyms_lookup_batch_end`, `kallsyms_lookup_name`, and `kallsyms_on_each_match_symbol`.

Now, the potential for `kallsyms_lookup_names` is also key here, but it's *static* which means the compiler might inline it. Section 4 reminds me that compiler-inlined functions aren't directly addressable for coverage analysis, so I need to make sure the changes I'm interested in are exercised through non-inlined caller functions, and that the static functions aren't ubiquitously used in the kernel.

I need to confirm if `kallsyms_lookup_name` and `kallsyms_on_each_match_symbol` are indeed the entrypoints I can focus on. According to the guidelines, I need to avoid ubiquitous lifecycle hot-paths, so I need to confirm these aren't called by every piece of code. I'm seeing that they're specific to symbol resolution, like kprobe registration and BPF kfunc lookups. Good, that's what I want!

Next, I look at which functions are exported from the kallsyms.c file: `kallsyms_lookup_batch_start`, `kallsyms_lookup_batch_end`, `kallsyms_lookup_name`, and `kallsyms_on_each_match_symbol` are all looking like good targets. The `test_kallsyms_init` or `run_kallsyms_benchmark` are also important to look at.

I must remember to confirm the enabling configs. I can see that `KALLSYMS` is required, and both `TEST_KALLSYMS_PERF` and `KALLSYMS_SELFTEST` directly call into the dynamic lookup functions. `KPROBE_EVENTS` and `BPF_SYSCALL` also open additional user-space entrypoints. Good. I need to make sure that dependencies are minimal. Confirming `TEST_KALLSYMS_PERF` only depends on `KALLSYMS` is the best scenario.

I need to check for static functions in the focus symbol list as well. `kallsyms_build_offsets` is static, but indirectly called, so it can be considered, and `kallsyms_lookup_names` is static, and directly called by the non-static functions.

Now, the key question: Is this *worth* fuzzing? Absolutely! The patch dramatically alters core symbol lookup by introducing token-based string comparison, dynamic offset indexing managed by RCU, and changes to RCU locking and related functions like `kallsyms_expand_symbol` and `kallsyms_get_symbol_type`. These changes touch highly reachable code in the kernel, and the complex pointer arithmetic, loop conditions, and RCU management are ripe for fuzzing. I anticipate potential issues from buffer overreads, RCU synchronization, and use-after-free scenarios.

So, I'm ready to prepare the call to `set-results`. The patch is worth fuzzing, I've got my reasoning laid out, my enabling configs are `["KALLSYMS", "TEST_KALLSYMS_PERF", "KALLSYMS_SELFTEST", "KPROBE_EVENTS", "BPF_SYSCALL"]`, and my focus symbols are `["kallsyms_lookup_batch_start", "kallsyms_lookup_batch_end", "kallsyms_lookup_name", "kallsyms_on_each_match_symbol", "run_kallsyms_benchmark"]`. Let's get this done.



36/2 2026/09/25 01:55 tool set-results
0m Args:
{
  "EnableConfigs": [
    "KALLSYMS",
    "TEST_KALLSYMS_PERF",
    "KALLSYMS_SELFTEST",
    "KPROBE_EVENTS",
    "BPF_SYSCALL"
  ],
  "FocusSymbols": [
    "kallsyms_lookup_batch_start",
    "kallsyms_lookup_batch_end",
    "kallsyms_lookup_name",
    "kallsyms_on_each_match_symbol",
    "run_kallsyms_benchmark"
  ],
  "Reasoning": "The patch series introduces significant changes to the core kallsyms subsystem:\n1. Replaces full symbol name expansion during binary search with an on-the-fly token-by-token compressed string comparison function (kallsyms_strcmp_symbol).\n2. Introduces on-demand dynamic symbol offset indexing (dyn_kallsyms_offsets) protected by mutex, reference counts, and RCU dereferencing, bracketed by new batch lifecycle APIs (kallsyms_lookup_batch_start and kallsyms_lookup_batch_end) which include new runtime assertions (WARN_ON).\n3. Refactors symbol decompression and type extraction across kallsyms core.\n4. Adds a performance test module (lib/test_kallsyms_perf.c).\n\nThese code paths are reachable from userspace via BPF (e.g. bpf_kallsyms_lookup_name, kfunc resolution), tracefs/kprobes (e.g. writing to kprobe_events), and reading /proc/kallsyms. Due to complex pointer manipulation during compressed string comparison and dynamic memory lifetime management under RCU, this warrants fuzzing for memory corruption, buffer overreads, and race conditions.",
  "WorthFuzzing": true
}

Results:
{
  "EnableConfigs": [
    "KALLSYMS",
    "TEST_KALLSYMS_PERF",
    "KALLSYMS_SELFTEST",
    "KPROBE_EVENTS",
    "BPF_SYSCALL"
  ],
  "FocusSymbols": [
    "kallsyms_lookup_batch_start",
    "kallsyms_lookup_batch_end",
    "kallsyms_lookup_name",
    "kallsyms_on_each_match_symbol",
    "run_kallsyms_benchmark"
  ],
  "Reasoning": "The patch series introduces significant changes to the core kallsyms subsystem:\n1. Replaces full symbol name expansion during binary search with an on-the-fly token-by-token compressed string comparison function (kallsyms_strcmp_symbol).\n2. Introduces on-demand dynamic symbol offset indexing (dyn_kallsyms_offsets) protected by mutex, reference counts, and RCU dereferencing, bracketed by new batch lifecycle APIs (kallsyms_lookup_batch_start and kallsyms_lookup_batch_end) which include new runtime assertions (WARN_ON).\n3. Refactors symbol decompression and type extraction across kallsyms core.\n4. Adds a performance test module (lib/test_kallsyms_perf.c).\n\nThese code paths are reachable from userspace via BPF (e.g. bpf_kallsyms_lookup_name, kfunc resolution), tracefs/kprobes (e.g. writing to kprobe_events), and reading /proc/kallsyms. Due to complex pointer manipulation during compressed string comparison and dynamic memory lifetime management under RCU, this warrants fuzzing for memory corruption, buffer overreads, and race conditions.",
  "WorthFuzzing": true
}

37/1 2026/09/25 01:55 action If
1m Args:
{
  "WorthFuzzing": true
}

Results:
null

38/2 2026/09/25 01:55 agent kmsan-evaluator
1m Model:
core

Args:
null

Results:
{
  "KMSANReasoning": "The patch optimizes kallsyms name lookup operations by:\n1. Comparing strings directly against compressed token stream in `kallsyms_strcmp_symbol()`, eliminating the temporary on-stack decompressed buffer in `kallsyms_lookup_names()`.\n2. Providing an optional batching mechanism (`kallsyms_lookup_batch_start()` / `kallsyms_lookup_batch_end()`) that builds a flat offset lookup table `dyn_kallsyms_offsets` allocated via `kvmalloc_array()`.\n3. Adding benchmark and selftest coverage in `lib/test_kallsyms_perf.c` and `kernel/kallsyms_selftest.c`.\n\nKASAN vs KMSAN applicability assessment:\n- No uninitialized memory exposure: The newly allocated buffer `dyn_kallsyms_offsets` is an array of `u32` (no padding) where every entry from 0 to `kallsyms_num_syms - 1` is populated sequentially in `kallsyms_build_offsets()` before the pointer is published via `rcu_assign_pointer()`. All other data structures involved (`kallsyms_names`, `kallsyms_token_table`, `kallsyms_token_index`) are read-only `.rodata` generated at build time.\n- No user-space info-leaks: No structures, padding, or uninitialized buffers are copied to user space (no `copy_to_user`, ioctl, netlink, or socket options touched).\n- Any potential risks introduced by the patch (such as out-of-bounds indexing in `offsets[pos]`, out-of-bounds reads on compressed names, RCU synchronization / lifetime issues, or mutex deadlocks) are strictly within the scope of KASAN, LOCKDEP, and standard kernel debug facilities.\n\nConsequently, there are no uninitialized memory hazards that warrant a dedicated KMSAN fuzzing session.",
  "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 f1fb56bfa08cc79fe520683bf24dcfad2ce5439d
Author: syz-cluster <triage@syzkaller.com>
Date:   Fri Sep 25 01:53:10 2026 +0000

    syz-cluster: applied patch under review

diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
index d5dd54c53ace6..6e39795ac509b 100644
--- a/include/linux/kallsyms.h
+++ b/include/linux/kallsyms.h
@@ -74,6 +74,10 @@ int kallsyms_on_each_symbol(int (*fn)(void *, const char *, unsigned long),
 int kallsyms_on_each_match_symbol(int (*fn)(void *, unsigned long),
 				  const char *name, void *data);
 
+/* Transient dynamic lookup index bracketing */
+int kallsyms_lookup_batch_start(void);
+void kallsyms_lookup_batch_end(void);
+
 /* Lookup the address for a symbol. Returns 0 if not found. */
 unsigned long kallsyms_lookup_name(const char *name);
 
@@ -164,6 +168,15 @@ static inline int kallsyms_on_each_match_symbol(int (*fn)(void *, unsigned long)
 {
 	return -EOPNOTSUPP;
 }
+
+static inline int kallsyms_lookup_batch_start(void)
+{
+	return 0;
+}
+
+static inline void kallsyms_lookup_batch_end(void)
+{
+}
 #endif /*CONFIG_KALLSYMS*/
 
 static inline void print_ip_sym(const char *loglvl, unsigned long ip)
diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
index aec2f06858afd..8f76403e0e7be 100644
--- a/kernel/kallsyms.c
+++ b/kernel/kallsyms.c
@@ -22,6 +22,9 @@
 #include <linux/sched.h>	/* for cond_resched */
 #include <linux/ctype.h>
 #include <linux/slab.h>
+#include <linux/vmalloc.h>
+#include <linux/mutex.h>
+#include <linux/rcupdate.h>
 #include <linux/filter.h>
 #include <linux/ftrace.h>
 #include <linux/kprobes.h>
@@ -34,6 +37,21 @@
 
 #include "kallsyms_internal.h"
 
+/*
+ * Get the compressed symbol length and data pointer.
+ */
+static inline const u8 *get_symbol_data(unsigned int off, unsigned int *len)
+{
+	const u8 *p = &kallsyms_names[off];
+	unsigned int l = *p++;
+
+	if (unlikely(l & 0x80))
+		l = (l & 0x7F) | (*p++ << 7);
+	*len = l;
+
+	return p;
+}
+
 /*
  * Expand a compressed symbol data into the resulting uncompressed string,
  * if uncompressed string is too long (>= maxlen), it will be truncated,
@@ -42,28 +60,12 @@
 static unsigned int kallsyms_expand_symbol(unsigned int off,
 					   char *result, size_t maxlen)
 {
-	int len, skipped_first = 0;
+	int skipped_first = 0;
 	const char *tptr;
-	const u8 *data;
-
-	/* Get the compressed symbol length from the first symbol byte. */
-	data = &kallsyms_names[off];
-	len = *data;
-	data++;
-	off++;
+	unsigned int len;
+	const u8 *data = get_symbol_data(off, &len);
 
-	/* If MSB is 1, it is a "big" symbol, so needs an additional byte. */
-	if ((len & 0x80) != 0) {
-		len = (len & 0x7F) | (*data << 7);
-		data++;
-		off++;
-	}
-
-	/*
-	 * Update the offset to return the offset for the next symbol on
-	 * the compressed stream.
-	 */
-	off += len;
+	off = (data - kallsyms_names) + len;
 
 	/*
 	 * For every byte on the compressed symbol data, copy the table
@@ -91,7 +93,7 @@ static unsigned int kallsyms_expand_symbol(unsigned int off,
 	if (maxlen)
 		*result = '\0';
 
-	/* Return to offset to the next symbol. */
+	/* Return offset to the next symbol. */
 	return off;
 }
 
@@ -101,22 +103,50 @@ static unsigned int kallsyms_expand_symbol(unsigned int off,
  */
 static char kallsyms_get_symbol_type(unsigned int off)
 {
-	/*
-	 * Get just the first code, look it up in the token table,
-	 * and return the first char from this token. If MSB of length
-	 * is 1, it is a "big" symbol, so needs an additional byte.
-	 */
-	if (kallsyms_names[off] & 0x80)
-		off++;
-	return kallsyms_token_table[kallsyms_token_index[kallsyms_names[off + 1]]];
+	unsigned int len;
+	const u8 *data = get_symbol_data(off, &len);
+
+	return kallsyms_token_table[kallsyms_token_index[*data]];
 }
 
+/*
+ * Compare an uncompressed ASCII string against a compressed symbol table entry.
+ * Returns negative if name < sym, positive if name > sym, 0 if equal.
+ * Exits immediately on the first mismatched character without decompressing
+ * the rest of the symbol name.
+ */
+static int kallsyms_strcmp_symbol(unsigned int off, const char *name)
+{
+	const char *tptr;
+	unsigned int len;
+	const u8 *data = get_symbol_data(off, &len);
+
+	tptr = &kallsyms_token_table[kallsyms_token_index[*data++]] + 1;
+	while (*tptr) {
+		int diff = (unsigned char)*name++ - (unsigned char)*tptr++;
+
+		if (diff)
+			return diff;
+	}
+
+	while (--len) {
+		tptr = &kallsyms_token_table[kallsyms_token_index[*data++]];
+		do {
+			int diff = (unsigned char)*name++ - (unsigned char)*tptr++;
+
+			if (diff)
+				return diff;
+		} while (*tptr);
+	}
+
+	return (unsigned char)*name;
+}
 
 /*
- * Find the offset on the compressed stream given and index in the
- * kallsyms array.
+ * Find the offset on the compressed stream given an index in the
+ * kallsyms array using legacy markers.
  */
-static unsigned int get_symbol_offset(unsigned long pos)
+static unsigned int get_symbol_offset_marker(unsigned long pos)
 {
 	const u8 *name;
 	int i, len;
@@ -149,6 +179,100 @@ static unsigned int get_symbol_offset(unsigned long pos)
 	return name - kallsyms_names;
 }
 
+/*
+ * Dynamic symbol offset table.
+ * Allocated on demand during high-volume lookup batches and reclaimed after.
+ */
+static u32 *dyn_kallsyms_offsets __read_mostly;
+static DEFINE_MUTEX(dyn_kallsyms_mutex);
+static unsigned int dyn_kallsyms_refcnt;
+
+static u32 *kallsyms_build_offsets(void)
+{
+	const u8 *name = kallsyms_names;
+	u32 *offsets;
+	unsigned int i;
+
+	offsets = kvmalloc_array(kallsyms_num_syms, sizeof(u32), GFP_KERNEL);
+	if (!offsets)
+		return NULL;
+
+	for (i = 0; i < kallsyms_num_syms; i++) {
+		unsigned int len;
+		const u8 *data;
+
+		offsets[i] = name - kallsyms_names;
+		data = get_symbol_data(offsets[i], &len);
+		name = data + len;
+	}
+
+	return offsets;
+}
+
+int kallsyms_lookup_batch_start(void)
+{
+	int ret = 0;
+
+	mutex_lock(&dyn_kallsyms_mutex);
+	if (!dyn_kallsyms_refcnt) {
+		u32 *offsets = kallsyms_build_offsets();
+
+		if (!offsets) {
+			ret = -ENOMEM;
+			goto out;
+		}
+		rcu_assign_pointer(dyn_kallsyms_offsets, offsets);
+	}
+	dyn_kallsyms_refcnt++;
+out:
+	mutex_unlock(&dyn_kallsyms_mutex);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(kallsyms_lookup_batch_start);
+
+void kallsyms_lookup_batch_end(void)
+{
+	u32 *offsets = NULL;
+
+	mutex_lock(&dyn_kallsyms_mutex);
+	if (WARN_ON(!dyn_kallsyms_refcnt))
+		goto out;
+
+	if (--dyn_kallsyms_refcnt == 0) {
+		offsets = dyn_kallsyms_offsets;
+		rcu_assign_pointer(dyn_kallsyms_offsets, NULL);
+	}
+out:
+	mutex_unlock(&dyn_kallsyms_mutex);
+
+	if (offsets) {
+		synchronize_rcu();
+		kvfree(offsets);
+	}
+}
+EXPORT_SYMBOL_GPL(kallsyms_lookup_batch_end);
+
+/*
+ * Find the offset on the compressed table given an index in the
+ * kallsyms array.
+ */
+static inline unsigned int get_symbol_offset(unsigned long pos)
+{
+	unsigned int off;
+	u32 *offsets;
+
+	rcu_read_lock();
+	offsets = rcu_dereference(dyn_kallsyms_offsets);
+	if (offsets) {
+		off = offsets[pos];
+		rcu_read_unlock();
+		return off;
+	}
+	rcu_read_unlock();
+
+	return get_symbol_offset_marker(pos);
+}
+
 unsigned long kallsyms_sym_address(int idx)
 {
 	/* non-relocatable 32-bit kernels just embed the value directly */
@@ -157,14 +281,11 @@ unsigned long kallsyms_sym_address(int idx)
 	return (unsigned long)offset_to_ptr(kallsyms_offsets + idx);
 }
 
-static unsigned int get_symbol_seq(int index)
+static inline unsigned int get_symbol_seq(int index)
 {
-	unsigned int i, seq = 0;
-
-	for (i = 0; i < 3; i++)
-		seq = (seq << 8) | kallsyms_seqs_of_names[3 * index + i];
+	const u8 *p = &kallsyms_seqs_of_names[3 * index];
 
-	return seq;
+	return (p[0] << 16) | (p[1] << 8) | p[2];
 }
 
 static int kallsyms_lookup_names(const char *name,
@@ -174,17 +295,16 @@ static int kallsyms_lookup_names(const char *name,
 	int ret;
 	int low, mid, high;
 	unsigned int seq, off;
-	char namebuf[KSYM_NAME_LEN];
 
 	low = 0;
 	high = kallsyms_num_syms - 1;
 
+	rcu_read_lock();
 	while (low <= high) {
 		mid = low + (high - low) / 2;
 		seq = get_symbol_seq(mid);
 		off = get_symbol_offset(seq);
-		kallsyms_expand_symbol(off, namebuf, ARRAY_SIZE(namebuf));
-		ret = strcmp(name, namebuf);
+		ret = kallsyms_strcmp_symbol(off, name);
 		if (ret > 0)
 			low = mid + 1;
 		else if (ret < 0)
@@ -193,15 +313,16 @@ static int kallsyms_lookup_names(const char *name,
 			break;
 	}
 
-	if (low > high)
+	if (low > high) {
+		rcu_read_unlock();
 		return -ESRCH;
+	}
 
 	low = mid;
 	while (low) {
 		seq = get_symbol_seq(low - 1);
 		off = get_symbol_offset(seq);
-		kallsyms_expand_symbol(off, namebuf, ARRAY_SIZE(namebuf));
-		if (strcmp(name, namebuf))
+		if (kallsyms_strcmp_symbol(off, name) != 0)
 			break;
 		low--;
 	}
@@ -212,13 +333,13 @@ static int kallsyms_lookup_names(const char *name,
 		while (high < kallsyms_num_syms - 1) {
 			seq = get_symbol_seq(high + 1);
 			off = get_symbol_offset(seq);
-			kallsyms_expand_symbol(off, namebuf, ARRAY_SIZE(namebuf));
-			if (strcmp(name, namebuf))
+			if (kallsyms_strcmp_symbol(off, name) != 0)
 				break;
 			high++;
 		}
 		*end = high;
 	}
+	rcu_read_unlock();
 
 	return 0;
 }
diff --git a/kernel/kallsyms_selftest.c b/kernel/kallsyms_selftest.c
index 8f6c4e9b3a1c0..aedffc058c0e6 100644
--- a/kernel/kallsyms_selftest.c
+++ b/kernel/kallsyms_selftest.c
@@ -178,6 +178,7 @@ static int lookup_name(void *data, const char *name, unsigned long addr)
 static void test_perf_kallsyms_lookup_name(void)
 {
 	struct test_stat stat;
+	int ret;
 
 	memset(&stat, 0, sizeof(stat));
 	stat.min = INT_MAX;
@@ -185,6 +186,21 @@ static void test_perf_kallsyms_lookup_name(void)
 	pr_info("kallsyms_lookup_name() looked up %d symbols\n", stat.real_cnt);
 	pr_info("The time spent on each symbol is (ns): min=%d, max=%d, avg=%lld\n",
 		stat.min, stat.max, div_u64(stat.sum, stat.real_cnt));
+
+	ret = kallsyms_lookup_batch_start();
+	if (ret) {
+		pr_err("kallsyms_lookup_batch_start() failed: %d\n", ret);
+		return;
+	}
+
+	memset(&stat, 0, sizeof(stat));
+	stat.min = INT_MAX;
+	kallsyms_on_each_symbol(lookup_name, &stat);
+	kallsyms_lookup_batch_end();
+
+	pr_info("kallsyms_lookup_name() (batch) looked up %d symbols\n", stat.real_cnt);
+	pr_info("The time spent on each symbol is (ns): min=%d, max=%d, avg=%lld\n",
+		stat.min, stat.max, div_u64(stat.sum, stat.real_cnt));
 }
 
 static int find_symbol(void *data, const char *name, unsigned long addr)
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 134b15a44625e..4b9669e64db9f 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -3122,6 +3122,16 @@ config TEST_STATIC_KEYS
 
 	  If unsure, say N.
 
+config TEST_KALLSYMS_PERF
+	bool "kallsyms performance benchmark test module"
+	depends on KALLSYMS
+	help
+	  This builds test_kallsyms_perf to benchmark latency across
+	  Name-to-Address binary search, Address-to-Name resolution,
+	  and full table walks.
+
+	  If unsure, say N.
+
 config TEST_DYNAMIC_DEBUG
 	tristate "Test DYNAMIC_DEBUG"
 	depends on DYNAMIC_DEBUG
diff --git a/lib/Makefile b/lib/Makefile
index dfab958327c5c..149968ff3f6bd 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -85,6 +85,7 @@ obj-$(CONFIG_TEST_RHASHTABLE) += test_rhashtable.o
 obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_keys.o
 obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_key_base.o
 obj-$(CONFIG_TEST_DYNAMIC_DEBUG) += test_dynamic_debug.o
+obj-$(CONFIG_TEST_KALLSYMS_PERF) += test_kallsyms_perf.o
 
 obj-$(CONFIG_TEST_BITMAP) += test_bitmap.o
 ifeq ($(CONFIG_CC_IS_CLANG)$(CONFIG_KASAN),yy)
diff --git a/lib/test_kallsyms_perf.c b/lib/test_kallsyms_perf.c
new file mode 100644
index 0000000000000..6f74ade4a0184
--- /dev/null
+++ b/lib/test_kallsyms_perf.c
@@ -0,0 +1,281 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Microbenchmark and correctness test module for kallsyms subsystem
+ *
+ * Measures CPU latency across:
+ *  - Name-to-Address binary search (hits & misses)
+ *  - Address-to-Name symbol resolution (sprint_symbol, buildid)
+ *  - Full kernel symbol iteration (kallsyms_on_each_symbol)
+ */
+
+#define pr_fmt(fmt) "test_kallsyms: " fmt
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/kallsyms.h>
+#include <linux/ktime.h>
+#include <linux/compiler.h>
+#include <linux/sched.h>
+#include <linux/math.h>
+
+static unsigned int num_iters = 100000;
+module_param(num_iters, uint, 0644);
+MODULE_PARM_DESC(num_iters, "Number of iterations per microbenchmark");
+
+static const char * const hit_symbols[] = {
+	"_printk",
+	"schedule",
+	"vfs_read",
+	"do_sys_openat2",
+	"kernel_clone",
+	"panic",
+	"kallsyms_lookup_names",
+	"vm_area_alloc",
+};
+
+static const char * const miss_symbols[] = {
+	"nonexistent_symbol_0001",
+	"xyz_dummy_missing_symbol",
+	"__never_compiled_in_kernel",
+	"ext4_nonexistent_func_xyz",
+	"bpf_not_real_helper_stub",
+	"vfs_missing_handler_probe",
+	"tcp_v4_unimplemented_path",
+	"driver_fake_init_routine",
+};
+
+static int match_cb(void *data, unsigned long addr)
+{
+	unsigned long *out = data;
+
+	*out = addr;
+	return 1;
+}
+
+static int count_cb(void *data, const char *name, unsigned long addr)
+{
+	unsigned long *cnt = data;
+
+	(*cnt)++;
+	return 0;
+}
+
+static void run_name_lookup_bench(const char *mode, u64 *avg_hit_ns, u64 *avg_miss_ns)
+{
+	u64 t0, t1, dt_hit, dt_miss;
+	unsigned long addr = 0;
+	unsigned int i, nr_hits, nr_misses;
+
+	nr_hits = ARRAY_SIZE(hit_symbols);
+	nr_misses = ARRAY_SIZE(miss_symbols);
+
+	/* 0. Correctness validation */
+	for (i = 0; i < nr_hits; i++) {
+		const char *sym = hit_symbols[i];
+		unsigned long a1 = 0;
+
+		kallsyms_on_each_match_symbol(match_cb, sym, &a1);
+		if (!a1)
+			pr_err("CORRECTNESS FAILURE: hit sym '%s' not found\n", sym);
+	}
+	for (i = 0; i < nr_misses; i++) {
+		const char *sym = miss_symbols[i];
+		unsigned long a1 = 0;
+
+		kallsyms_on_each_match_symbol(match_cb, sym, &a1);
+		if (a1)
+			pr_err("CORRECTNESS FAILURE: miss sym '%s' unexpectedly found a1=%lx\n",
+			       sym, a1);
+	}
+
+	/* 1. Name search: Existing symbols (Hits) */
+	t0 = ktime_get_ns();
+	for (i = 0; i < num_iters; i++) {
+		const char *sym = hit_symbols[i % nr_hits];
+
+		if (unlikely(!(i & 0x3fff)))
+			cond_resched();
+
+		kallsyms_on_each_match_symbol(match_cb, sym, &addr);
+		OPTIMIZER_HIDE_VAR(addr);
+	}
+	t1 = ktime_get_ns();
+	dt_hit = t1 - t0;
+
+	/* 2. Name search: Non-existent symbols (Misses - 17 bsearch probes) */
+	t0 = ktime_get_ns();
+	for (i = 0; i < num_iters; i++) {
+		const char *sym = miss_symbols[i % nr_misses];
+
+		if (unlikely(!(i & 0x3fff)))
+			cond_resched();
+
+		kallsyms_on_each_match_symbol(match_cb, sym, &addr);
+		OPTIMIZER_HIDE_VAR(addr);
+	}
+	t1 = ktime_get_ns();
+	dt_miss = t1 - t0;
+
+	if (avg_hit_ns)
+		*avg_hit_ns = div_u64(dt_hit, num_iters);
+	if (avg_miss_ns)
+		*avg_miss_ns = div_u64(dt_miss, num_iters);
+
+	pr_info("[%s] Name Search Hit:  %llu ns/lookup (%llu ms total, %u iters)\n",
+		mode, div_u64(dt_hit, num_iters), div_u64(dt_hit, 1000000), num_iters);
+	pr_info("[%s] Name Search Miss: %llu ns/lookup (%llu ms total, %u iters)\n",
+		mode, div_u64(dt_miss, num_iters), div_u64(dt_miss, 1000000), num_iters);
+}
+
+static void run_address_lookup_bench(void)
+{
+	u64 t0, t1, dt_sprint, dt_bldid;
+	char symname[KSYM_SYMBOL_LEN];
+	unsigned long addrs[ARRAY_SIZE(hit_symbols)];
+	unsigned int i, nr_addrs = 0;
+
+	for (i = 0; i < ARRAY_SIZE(hit_symbols); i++) {
+		unsigned long addr = 0;
+
+		kallsyms_on_each_match_symbol(match_cb, hit_symbols[i], &addr);
+		if (addr)
+			addrs[nr_addrs++] = addr;
+	}
+
+	if (!nr_addrs) {
+		pr_warn("Address benchmark skipped: no test addresses resolved\n");
+		return;
+	}
+
+	/* 1. Address-to-name resolution (sprint_symbol) */
+	t0 = ktime_get_ns();
+	for (i = 0; i < num_iters; i++) {
+		unsigned long addr = addrs[i % nr_addrs];
+
+		if (unlikely(!(i & 0x3fff)))
+			cond_resched();
+
+		sprint_symbol(symname, addr);
+		barrier_data(symname);
+	}
+	t1 = ktime_get_ns();
+	dt_sprint = t1 - t0;
+
+	/* 2. Address without offset (sprint_symbol_no_offset) */
+	t0 = ktime_get_ns();
+	for (i = 0; i < num_iters; i++) {
+		unsigned long addr = addrs[i % nr_addrs];
+
+		if (unlikely(!(i & 0x3fff)))
+			cond_resched();
+
+		sprint_symbol_no_offset(symname, addr);
+		barrier_data(symname);
+	}
+	t1 = ktime_get_ns();
+	dt_bldid = t1 - t0;
+
+	pr_info("sprint_symbol:           %llu ns/lookup (%llu ms total, %u iters)\n",
+		div_u64(dt_sprint, num_iters), div_u64(dt_sprint, 1000000), num_iters);
+	pr_info("sprint_symbol_no_offset: %llu ns/lookup (%llu ms total, %u iters)\n",
+		div_u64(dt_bldid, num_iters), div_u64(dt_bldid, 1000000), num_iters);
+}
+
+static void run_table_walk_bench(void)
+{
+	u64 t0, t1, dt_walk;
+	unsigned long total_symbols = 0;
+	int iter = 50;
+	int i;
+
+	t0 = ktime_get_ns();
+	for (i = 0; i < iter; i++) {
+		total_symbols = 0;
+		kallsyms_on_each_symbol(count_cb, &total_symbols);
+	}
+	t1 = ktime_get_ns();
+	dt_walk = t1 - t0;
+
+	pr_info("Table Full Walk:  %llu ns/sym (%llu us/pass, %lu symbols scanned, %d passes)\n",
+		div_u64(div_u64(dt_walk, iter), total_symbols ? total_symbols : 1),
+		div_u64(div_u64(dt_walk, iter), 1000), total_symbols, iter);
+}
+
+static int run_kallsyms_benchmark(void)
+{
+	u64 unindexed_hit = 0, unindexed_miss = 0;
+	u64 dyn_hit = 0, dyn_miss = 0;
+	u64 t0, t1, dt_start = 0, dt_end = 0;
+	int ret;
+
+	if (!num_iters) {
+		pr_err("num_iters must be non-zero\n");
+		return -EINVAL;
+	}
+
+	pr_info("==================================================\n");
+	pr_info("Starting kallsyms performance benchmark (iters=%u)\n", num_iters);
+	pr_info("==================================================\n");
+
+	/* 1. Benchmark baseline unindexed marker scan */
+	run_name_lookup_bench("Unindexed (markers)", &unindexed_hit, &unindexed_miss);
+
+	/* 2. Benchmark dynamic lookup index */
+	t0 = ktime_get_ns();
+	ret = kallsyms_lookup_batch_start();
+	t1 = ktime_get_ns();
+	dt_start = t1 - t0;
+
+	if (ret) {
+		pr_err("Failed to start kallsyms lookup batch: %d\n", ret);
+	} else {
+		run_name_lookup_bench("Dynamic Index", &dyn_hit, &dyn_miss);
+
+		t0 = ktime_get_ns();
+		kallsyms_lookup_batch_end();
+		t1 = ktime_get_ns();
+		dt_end = t1 - t0;
+
+		pr_info("[Dynamic Index] Batch setup: %llu us, teardown: %llu us\n",
+			div_u64(dt_start, 1000), div_u64(dt_end, 1000));
+
+		if (unindexed_hit > dyn_hit) {
+			u64 saved = unindexed_hit - dyn_hit;
+
+			pr_info("[Dynamic Index] Amortization break-even: %llu queries (setup), %llu queries (total)\n",
+				DIV_ROUND_UP_ULL(dt_start, saved),
+				DIV_ROUND_UP_ULL(dt_start + dt_end, saved));
+		}
+	}
+
+	run_address_lookup_bench();
+	run_table_walk_bench();
+
+	pr_info("==================================================\n");
+	pr_info("kallsyms benchmark complete\n");
+	pr_info("==================================================\n");
+
+	return 0;
+}
+
+static int param_set_trigger(const char *val, const struct kernel_param *kp)
+{
+	return run_kallsyms_benchmark();
+}
+
+static const struct kernel_param_ops param_ops_trigger = {
+	.set = param_set_trigger,
+};
+module_param_cb(run_test, &param_ops_trigger, NULL, 0200);
+MODULE_PARM_DESC(run_test, "Write 1 to trigger kallsyms benchmark run");
+
+static int __init test_kallsyms_init(void)
+{
+	return run_kallsyms_benchmark();
+}
+late_initcall(test_kallsyms_init);
+
+MODULE_DESCRIPTION("Microbenchmark test module for kallsyms subsystem");
+MODULE_AUTHOR("Jim Cromie <jim.cromie@gmail.com>");
+MODULE_LICENSE("GPL");

39/3 2026/09/25 01:55 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 10035
							output: 30
							thoughts: 1804
						

Thoughts:
**KMSAN Fuzzing Evaluation for Kallsyms Patch**

Okay, I need to decide if this patch series warrants a KMSAN fuzzing run. Let's break down the changes to see if there are any potential uninitialized memory vulnerabilities.

First, this patch touches quite a few files: `kallsyms.h`, `kallsyms.c`, `kallsyms_selftest.c`, some Kconfig and Makefile changes, and a performance test. The core logic change appears to be in `kallsyms.c`, where a helper `get_symbol_data` is introduced and several functions (`kallsyms_expand_symbol`, `kallsyms_get_symbol_type`, `kallsyms_lookup_names`) are modified to use it. Additionally, a new dynamic symbol offset table is added, along with associated lookup start/end functions and a batch lookup mechanism.

The initial thought is to check `get_symbol_data` to make sure `len` is always written to, which it is. Then look at the callers.  The original offset calculation in `kallsyms_expand_symbol` seems to be correctly replicated with the new function and pointer arithmetic. The new `kallsyms_strcmp_symbol` function, however, raises a concern.

Looking at `kallsyms_strcmp_symbol`, it seems to be iterating based on a length (`len`) provided by `get_symbol_data`.  The code correctly initializes `tptr` to skip the first token character, which is the symbol type. The function then iterates over the compressed symbol data, comparing it with the provided name.

A major concern comes up in the final `while` loop. The code decrements `len` **before** the loop. If `len` is zero, the loop should not run, but the initial read from `data` occurs, and then the `--len` operation causes a wrap-around. So if `len` is 0, then `data` is read once, and then the loop runs `UINT_MAX` times, causing a buffer over-read!  That is a serious vulnerability!

This means I need to investigate if the compressed symbol table can actually contain a zero-length symbol name. The `kallsyms` building process (likely in `scripts/kallsyms.c` or similar) is key here. I'll need to check the generation of the kallsyms table to understand the possibility of a zero-length symbol.

If a zero-length name is possible, this patch is *definitely* KMSAN-worthy. I should look into the generation of the kallsyms table to see if it allows for the generation of zero-length entries. If it can, this is a serious vulnerability.



40/3 2026/09/25 01:56 tool grepper
0m Args:
{
  "Expression": "kallsyms_token_table",
  "PathPrefix": "kernel/"
}

Results:
{
  "Output": "kernel/kallsyms.c=60=static unsigned int kallsyms_expand_symbol(unsigned int off,\n--\nkernel/kallsyms.c-74-\twhile (len) {\nkernel/kallsyms.c:75:\t\ttptr = \u0026kallsyms_token_table[kallsyms_token_index[*data]];\nkernel/kallsyms.c-76-\t\tdata++;\n--\nkernel/kallsyms.c=104=static char kallsyms_get_symbol_type(unsigned int off)\n--\nkernel/kallsyms.c-108-\nkernel/kallsyms.c:109:\treturn kallsyms_token_table[kallsyms_token_index[*data]];\nkernel/kallsyms.c-110-}\n--\nkernel/kallsyms.c=118=static int kallsyms_strcmp_symbol(unsigned int off, const char *name)\n--\nkernel/kallsyms.c-123-\nkernel/kallsyms.c:124:\ttptr = \u0026kallsyms_token_table[kallsyms_token_index[*data++]] + 1;\nkernel/kallsyms.c-125-\twhile (*tptr) {\n--\nkernel/kallsyms.c-132-\twhile (--len) {\nkernel/kallsyms.c:133:\t\ttptr = \u0026kallsyms_token_table[kallsyms_token_index[*data++]];\nkernel/kallsyms.c-134-\t\tdo {\n--\nkernel/kallsyms_internal.h=10=extern const unsigned int kallsyms_num_syms;\nkernel/kallsyms_internal.h-11-\nkernel/kallsyms_internal.h:12:extern const char kallsyms_token_table[];\nkernel/kallsyms_internal.h-13-extern const u16 kallsyms_token_index[];\n--\nkernel/kallsyms_selftest.c=104=static void test_kallsyms_compression_ratio(void)\n--\nkernel/kallsyms_selftest.c-138-\t * 1. The length fields is not counted\nkernel/kallsyms_selftest.c:139:\t * 2. The memory occupied by array kallsyms_token_table[] and\nkernel/kallsyms_selftest.c-140-\t *    kallsyms_token_index[] needs to be counted.\n--\nkernel/kallsyms_selftest.c-143-\tpos = kallsyms_token_index[0xff];\nkernel/kallsyms_selftest.c:144:\ttotal_size += pos + strlen(\u0026kallsyms_token_table[pos]) + 1;\nkernel/kallsyms_selftest.c-145-\ttotal_size += 0x100 * sizeof(u16);\n--\nkernel/vmcore_info.c=140=static int __init crash_save_vmcoreinfo_init(void)\n--\nkernel/vmcore_info.c-241-\tVMCOREINFO_SYMBOL(kallsyms_num_syms);\nkernel/vmcore_info.c:242:\tVMCOREINFO_SYMBOL(kallsyms_token_table);\nkernel/vmcore_info.c-243-\tVMCOREINFO_SYMBOL(kallsyms_token_index);\n"
}

41/3 2026/09/25 01:56 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 13349
							output: 25
							thoughts: 19
						

Thoughts:
Here's a first-person summary, keeping in mind the audience is an expert:

**Investigating Kallsyms Symbol Generation**

Okay, let's dive into the guts of how symbols are actually materialized. My immediate focus is going to be `scripts/kallsyms.c`. I need to refresh my memory on the specifics of the symbol table generation process. I know the general workflow, of course – it involves reading from `/proc/kallsyms` (or rather, the data feeding it), parsing the entries, handling various symbol types (text, data, BSS, etc.), and, crucially, managing relocation information. But the finer points are always worth a refresher. I'm particularly interested in how they're handling things like symbol names, addresses, and the associated module data. I'm expecting to see pretty straightforward C code, given the nature of the task, but I'm curious about any clever optimizations they might employ, especially around memory allocation and string handling. The goal is to get a very clear picture of the symbol data and where these reside during the build and what they are used for when running.



42/3 2026/09/25 01:56 tool grepper
0m Args:
{
  "Expression": "write_src",
  "PathPrefix": "scripts/"
}

Results:
{
  "Output": "scripts/kallsyms.c=334=static void sort_symbols_by_name(void)\n--\nscripts/kallsyms.c-338-\nscripts/kallsyms.c:339:static void write_src(void)\nscripts/kallsyms.c-340-{\n--\nscripts/kallsyms.c=689=int main(int argc, char **argv)\n--\nscripts/kallsyms.c-712-\toptimize_token_table();\nscripts/kallsyms.c:713:\twrite_src();\nscripts/kallsyms.c-714-\n"
}

43/3 2026/09/25 01:56 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 13803
							output: 36
							thoughts: 26
						

Thoughts:
Here's my attempt at summarizing the thought process, tailored for an expert audience:

**Diving into `kallsyms.c`**

Alright, let's get down to brass tacks. I need to refresh my memory on how `kallsyms` handles symbol lookups, particularly how it interacts with the compressed data structures. The question at hand relates to symbol table parsing. My intuition tells me a good place to start would be in `scripts/kallsyms.c`, around line 339, or at least in that general area. I'm expecting to find the core logic for decompressing and interpreting the symbol data there. Specifically, I'm thinking about the routines involved in walking through the compressed representation and reconstructing the symbol names and addresses. Let's see what the code actually *says*. I'm anticipating to see where the offset and name decoding logic is implemented so I can build a model for how the symbol information is parsed. I'll be looking for any hints on how the compressed data structures are indexed and iterated. Let's see if the code confirms what I hypothesize.



44/3 2026/09/25 01:56 tool read-file
0m Args:
{
  "File": "scripts/kallsyms.c",
  "FirstLine": 340,
  "LineCount": 60
}

Results:
{
  "Contents": " 340:\t{\n 341:\t\tunsigned int i, k, off;\n 342:\t\tunsigned int best_idx[256];\n 343:\t\tunsigned int *markers, markers_cnt;\n 344:\t\tchar buf[KSYM_NAME_LEN];\n 345:\t\n 346:\t\tprintf(\"\\t.section .rodata, \\\"a\\\"\\n\");\n 347:\t\n 348:\t\toutput_label(\"kallsyms_num_syms\");\n 349:\t\tprintf(\"\\t.long\\t%u\\n\", table_cnt);\n 350:\t\tprintf(\"\\n\");\n 351:\t\n 352:\t\t/* table of offset markers, that give the offset in the compressed stream\n 353:\t\t * every 256 symbols */\n 354:\t\tmarkers_cnt = (table_cnt + 255) / 256;\n 355:\t\tmarkers = xmalloc(sizeof(*markers) * markers_cnt);\n 356:\t\n 357:\t\toutput_label(\"kallsyms_names\");\n 358:\t\toff = 0;\n 359:\t\tfor (i = 0; i \u003c table_cnt; i++) {\n 360:\t\t\tif ((i \u0026 0xFF) == 0)\n 361:\t\t\t\tmarkers[i \u003e\u003e 8] = off;\n 362:\t\t\ttable[i]-\u003eseq = i;\n 363:\t\n 364:\t\t\t/* There cannot be any symbol of length zero. */\n 365:\t\t\tif (table[i]-\u003elen == 0) {\n 366:\t\t\t\tfprintf(stderr, \"kallsyms failure: \"\n 367:\t\t\t\t\t\"unexpected zero symbol length\\n\");\n 368:\t\t\t\texit(EXIT_FAILURE);\n 369:\t\t\t}\n 370:\t\n 371:\t\t\t/* Only lengths that fit in up-to-two-byte ULEB128 are supported. */\n 372:\t\t\tif (table[i]-\u003elen \u003e 0x3FFF) {\n 373:\t\t\t\tfprintf(stderr, \"kallsyms failure: \"\n 374:\t\t\t\t\t\"unexpected huge symbol length\\n\");\n 375:\t\t\t\texit(EXIT_FAILURE);\n 376:\t\t\t}\n 377:\t\n 378:\t\t\t/* Encode length with ULEB128. */\n 379:\t\t\tif (table[i]-\u003elen \u003c= 0x7F) {\n 380:\t\t\t\t/* Most symbols use a single byte for the length. */\n 381:\t\t\t\tprintf(\"\\t.byte 0x%02x\", table[i]-\u003elen);\n 382:\t\t\t\toff += table[i]-\u003elen + 1;\n 383:\t\t\t} else {\n 384:\t\t\t\t/* \"Big\" symbols use two bytes. */\n 385:\t\t\t\tprintf(\"\\t.byte 0x%02x, 0x%02x\",\n 386:\t\t\t\t\t(table[i]-\u003elen \u0026 0x7F) | 0x80,\n 387:\t\t\t\t\t(table[i]-\u003elen \u003e\u003e 7) \u0026 0x7F);\n 388:\t\t\t\toff += table[i]-\u003elen + 2;\n 389:\t\t\t}\n 390:\t\t\tfor (k = 0; k \u003c table[i]-\u003elen; k++)\n 391:\t\t\t\tprintf(\", 0x%02x\", table[i]-\u003esym[k]);\n 392:\t\n 393:\t\t\t/*\n 394:\t\t\t * Now that we wrote out the compressed symbol name, restore the\n 395:\t\t\t * original name and print it in the comment.\n 396:\t\t\t */\n 397:\t\t\texpand_symbol(table[i]-\u003esym, table[i]-\u003elen, buf);\n 398:\t\t\tstrcpy((char *)table[i]-\u003esym, buf);\n 399:\t\t\tprintf(\"\\t/* %s */\\n\", table[i]-\u003esym);\n"
}

45/3 2026/09/25 01:56 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 15111
							output: 33
							thoughts: 2325
						

Thoughts:
**Analyzing `kallsyms_strcmp_symbol` for Potential Vulnerabilities**

Okay, so I'm diving back into this `kallsyms_strcmp_symbol` function to really get a handle on its logic. The goal is to identify any potential risks, particularly those related to uninitialized memory access, given the context of KMSAN vs. KASAN and the stated criteria.

Initially, I'm reminding myself that there's no such thing as a zero-length symbol. Each entry in the symbol table, `table[i]->len`, must be at least one, and it's actually greater due to the prefix indicating symbol type. Right, let's step through `kallsyms_strcmp_symbol` again.

My first thought is around the logic of comparing the input `name` against the symbol stored in the table. The way it works, it seems to split each symbol into tokens. The code checks if the input `name` is shorter than a symbol. It first processes the initial token with a while loop (`while (*tptr)`). If `name` ends before all of the symbol's characters in the initial token are processed, that looks problematic. I see a negative value can be returned as a result of that.

Then, there's the `while (--len)` loop which handles the comparison of subsequent tokens. The inner `do...while` loop handles individual token comparisons. The key here is null termination (`\0`) within the `kallsyms_token_table`, which makes sense. I have to think about what happens when the lengths don't match exactly. If `name` is completely matched before the symbol's end, the function returns zero, which is correct. The problem is if the symbol's characters are exhausted, but `name` has more characters. In that case, the function should return a positive number, which it does. Also, I am making sure that I am understanding that the symbol can be composed of multiple tokens in `kallsyms_token_table`.

Also, I'm trying to work out what happens when `name` matches the symbol completely. It returns 0 in that case. That seems correct. I'm focusing on scenarios where the lengths are different, especially where `name` is shorter or longer.

Then, I'm thinking about the edge cases. It's also important to consider scenarios with empty tokens. If the first token is empty, the `while (*tptr)` loop skips, and we proceed to the subsequent tokens via `while (--len)`. This also seems okay.

The important pattern here is to remember that tokens in `kallsyms_token_table` are null terminated.

I have to carefully analyze `do ... while (*tptr)` in `while (--len)`. The while loop in the second part advances as long as the second token does not end with `\0`, so that's okay. I'm thinking about how the inner loop compares characters, especially when `name` ends prematurely, and making sure that the conditions I established earlier are handled properly.

I'm stepping through the scenarios. What if `name` matches the whole symbol, but token 1 is empty? No, token 1 always has a prefix. If token 1 has just a prefix (e.g., "T" for text, then it will also run as intended.

Now, I'm thinking about uninitialized memory access. It's critical to determine if any of the code changes, specifically the ones in this patch, introduce the risk of reading uninitialized memory. KMSAN is the right tool if there is such a risk, but it must be distinguished from KASAN.

I'm focused on the changes in `kallsyms_build_offsets`, and I can see `offsets` are allocated using `kvmalloc_array`. I confirm that it allocates and initializes every element of the `offsets` array in the loop. The access to `offsets` happens in `get_symbol_offset()`, where `pos` is always within the array bounds. The code initializes `offsets`. I'm checking the callers of `get_symbol_offset()` and verifying `pos` (symbol index) is also always within the bounds. So no uninitialized read here. I have to check this in the next steps too!



46/3 2026/09/25 01:56 tool grepper
0m Args:
{
  "Expression": "get_symbol_offset",
  "PathPrefix": "kernel/kallsyms.c"
}

Results:
{
  "Output": "kernel/kallsyms.c=118=static int kallsyms_strcmp_symbol(unsigned int off, const char *name)\n--\nkernel/kallsyms.c-148- */\nkernel/kallsyms.c:149:static unsigned int get_symbol_offset_marker(unsigned long pos)\nkernel/kallsyms.c-150-{\n--\nkernel/kallsyms.c=253=EXPORT_SYMBOL_GPL(kallsyms_lookup_batch_end);\n--\nkernel/kallsyms.c-258- */\nkernel/kallsyms.c:259:static inline unsigned int get_symbol_offset(unsigned long pos)\nkernel/kallsyms.c-260-{\n--\nkernel/kallsyms.c-272-\nkernel/kallsyms.c:273:\treturn get_symbol_offset_marker(pos);\nkernel/kallsyms.c-274-}\n--\nkernel/kallsyms.c=291=static int kallsyms_lookup_names(const char *name,\n--\nkernel/kallsyms.c-305-\t\tseq = get_symbol_seq(mid);\nkernel/kallsyms.c:306:\t\toff = get_symbol_offset(seq);\nkernel/kallsyms.c-307-\t\tret = kallsyms_strcmp_symbol(off, name);\n--\nkernel/kallsyms.c-323-\t\tseq = get_symbol_seq(low - 1);\nkernel/kallsyms.c:324:\t\toff = get_symbol_offset(seq);\nkernel/kallsyms.c-325-\t\tif (kallsyms_strcmp_symbol(off, name) != 0)\n--\nkernel/kallsyms.c-334-\t\t\tseq = get_symbol_seq(high + 1);\nkernel/kallsyms.c:335:\t\t\toff = get_symbol_offset(seq);\nkernel/kallsyms.c-336-\t\t\tif (kallsyms_strcmp_symbol(off, name) != 0)\n--\nkernel/kallsyms.c=474=static int kallsyms_lookup_buildid(unsigned long addr,\n--\nkernel/kallsyms.c-501-\t\t/* Grab name */\nkernel/kallsyms.c:502:\t\tkallsyms_expand_symbol(get_symbol_offset(pos),\nkernel/kallsyms.c-503-\t\t\t\t       namebuf, KSYM_NAME_LEN);\n--\nkernel/kallsyms.c=542=int lookup_symbol_name(unsigned long addr, char *symname)\n--\nkernel/kallsyms.c-551-\t\t/* Grab name */\nkernel/kallsyms.c:552:\t\tkallsyms_expand_symbol(get_symbol_offset(pos),\nkernel/kallsyms.c-553-\t\t\t\t       symname, KSYM_NAME_LEN);\n--\nkernel/kallsyms.c=709=int sprint_backtrace_build_id(char *buffer, unsigned long address)\n--\nkernel/kallsyms.c-713-\nkernel/kallsyms.c:714:/* To avoid using get_symbol_offset for every symbol, we carry prefix along. */\nkernel/kallsyms.c-715-struct kallsym_iter {\n--\nkernel/kallsyms.c=808=static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)\n--\nkernel/kallsyms.c-810-\titer-\u003ename[0] = '\\0';\nkernel/kallsyms.c:811:\titer-\u003enameoff = get_symbol_offset(new_pos);\nkernel/kallsyms.c-812-\titer-\u003epos = new_pos;\n--\nkernel/kallsyms.c=1005=static int kallsyms_open(struct inode *inode, struct file *file)\n--\nkernel/kallsyms.c-1009-\t * s_start from where we left off, so we avoid doing\nkernel/kallsyms.c:1010:\t * using get_symbol_offset for every symbol.\nkernel/kallsyms.c-1011-\t */\n"
}

47/3 2026/09/25 01:56 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 19488
							output: 36
							thoughts: 46
						

Thoughts:
Here's my thought process, as if I were analyzing that code:

**Debugging a Potential Offset Issue**

Okay, hold on a minute! Something feels off with this positioning logic. I need to get to the bottom of this. My gut is telling me to double-check the iteration reset or wherever `get_symbol_offset(new_pos)` is actually called. That function seems like a likely culprit in any offset calculation.

Let's dive into the kernel sources. Time to go right into `kernel/kallsyms.c`. I'm specifically looking around line 808. That's a likely area given the context. Let's see if we can spot something there that's not quite working as expected. I need to see if the reset is happening correctly, or if there's an error in logic within the `get_symbol_offset` call chain that's resulting in an inaccurate offset.



48/3 2026/09/25 01:56 tool read-file
0m Args:
{
  "File": "kernel/kallsyms.c",
  "FirstLine": 800,
  "LineCount": 40
}

Results:
{
  "Contents": " 800:\t\n 801:\t\titer-\u003etype = kallsyms_get_symbol_type(off);\n 802:\t\n 803:\t\toff = kallsyms_expand_symbol(off, iter-\u003ename, ARRAY_SIZE(iter-\u003ename));\n 804:\t\n 805:\t\treturn off - iter-\u003enameoff;\n 806:\t}\n 807:\t\n 808:\tstatic void reset_iter(struct kallsym_iter *iter, loff_t new_pos)\n 809:\t{\n 810:\t\titer-\u003ename[0] = '\\0';\n 811:\t\titer-\u003enameoff = get_symbol_offset(new_pos);\n 812:\t\titer-\u003epos = new_pos;\n 813:\t\tif (new_pos == 0) {\n 814:\t\t\titer-\u003epos_mod_end = 0;\n 815:\t\t\titer-\u003epos_ftrace_mod_end = 0;\n 816:\t\t\titer-\u003epos_bpf_end = 0;\n 817:\t\t}\n 818:\t}\n 819:\t\n 820:\t/*\n 821:\t * The end position (last + 1) of each additional kallsyms section is recorded\n 822:\t * in iter-\u003epos_..._end as each section is added, and so can be used to\n 823:\t * determine which get_ksymbol_...() function to call next.\n 824:\t */\n 825:\tstatic int update_iter_mod(struct kallsym_iter *iter, loff_t pos)\n 826:\t{\n 827:\t\titer-\u003epos = pos;\n 828:\t\n 829:\t\tif ((!iter-\u003epos_mod_end || iter-\u003epos_mod_end \u003e pos) \u0026\u0026\n 830:\t\t    get_ksymbol_mod(iter))\n 831:\t\t\treturn 1;\n 832:\t\n 833:\t\tif ((!iter-\u003epos_ftrace_mod_end || iter-\u003epos_ftrace_mod_end \u003e pos) \u0026\u0026\n 834:\t\t    get_ksymbol_ftrace_mod(iter))\n 835:\t\t\treturn 1;\n 836:\t\n 837:\t\tif ((!iter-\u003epos_bpf_end || iter-\u003epos_bpf_end \u003e pos) \u0026\u0026\n 838:\t\t    get_ksymbol_bpf(iter))\n 839:\t\t\treturn 1;\n"
}

49/3 2026/09/25 01:56 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 20425
							output: 31
							thoughts: 22
						

Thoughts:
Here's my thought process, as if I were considering this code:

**Debugging the Iteration Reset**

Okay, hold on a minute. I need to understand the lifecycle of this iteration. The critical question here is, when *exactly* does `reset_iter` get called? It's crucial for the correct behavior of the whole process. So, let's dive into the code. Time to fire up the editor and see who's actually invoking `reset_iter`. I need to review all the code that might be using the iterator and then think if this makes sense. Let's see... looking for the callers...



50/3 2026/09/25 01:56 tool grepper
0m Args:
{
  "Expression": "reset_iter",
  "PathPrefix": "kernel/kallsyms.c"
}

Results:
{
  "Output": "kernel/kallsyms.c=794=static unsigned long get_ksymbol_core(struct kallsym_iter *iter)\n--\nkernel/kallsyms.c-807-\nkernel/kallsyms.c:808:static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)\nkernel/kallsyms.c-809-{\n--\nkernel/kallsyms.c=845=static int update_iter(struct kallsym_iter *iter, loff_t pos)\n--\nkernel/kallsyms.c-852-\tif (pos != iter-\u003epos)\nkernel/kallsyms.c:853:\t\treset_iter(iter, pos);\nkernel/kallsyms.c-854-\n--\nkernel/kallsyms.c=959=static int bpf_iter_ksym_init(void *priv_data, struct bpf_iter_aux_info *aux)\n--\nkernel/kallsyms.c-962-\nkernel/kallsyms.c:963:\treset_iter(iter, 0);\nkernel/kallsyms.c-964-\n--\nkernel/kallsyms.c=1005=static int kallsyms_open(struct inode *inode, struct file *file)\n--\nkernel/kallsyms.c-1015-\t\treturn -ENOMEM;\nkernel/kallsyms.c:1016:\treset_iter(iter, 0);\nkernel/kallsyms.c-1017-\n--\nkernel/kallsyms.c=1027=const char *kdb_walk_kallsyms(loff_t *pos)\n--\nkernel/kallsyms.c-1032-\t\t       sizeof(kdb_walk_kallsyms_iter));\nkernel/kallsyms.c:1033:\t\treset_iter(\u0026kdb_walk_kallsyms_iter, 0);\nkernel/kallsyms.c-1034-\t}\n"
}

51/3 2026/09/25 01:56 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 21143
							output: 36
							thoughts: 53
						

Thoughts:
Okay, let's break this down.

**Diving into the `kallsyms` Iterator**

Alright, I'm focusing in on `update_iter` within `kallsyms_iter`, specifically at the function signature: `update_iter(struct kallsym_iter *iter, loff_t pos)`. My immediate thought is, "Okay, this is how the kallsyms iterator is being advanced or initialized." I need to understand its position within the process. To get a handle on what's going on, I'm going to look at the relevant source code, lines 845 to 870 in `kernel/kallsyms.c`. That should give me the context I need regarding how the iterator state is managed, how the given position `pos` is used, and how the internal kallsyms data structures interact with it. I expect to see the meat of how symbol lookups or traversals are performed and any related boundary conditions. I anticipate this function is critical in providing an efficient way to iterate over the kernel's symbol table, and getting the details of `update_iter` is a must to figure out how it works.



52/3 2026/09/25 01:56 tool read-file
0m Args:
{
  "File": "kernel/kallsyms.c",
  "FirstLine": 845,
  "LineCount": 35
}

Results:
{
  "Contents": " 845:\tstatic int update_iter(struct kallsym_iter *iter, loff_t pos)\n 846:\t{\n 847:\t\t/* Module symbols can be accessed randomly. */\n 848:\t\tif (pos \u003e= kallsyms_num_syms)\n 849:\t\t\treturn update_iter_mod(iter, pos);\n 850:\t\n 851:\t\t/* If we're not on the desired position, reset to new position. */\n 852:\t\tif (pos != iter-\u003epos)\n 853:\t\t\treset_iter(iter, pos);\n 854:\t\n 855:\t\titer-\u003enameoff += get_ksymbol_core(iter);\n 856:\t\titer-\u003epos++;\n 857:\t\n 858:\t\treturn 1;\n 859:\t}\n 860:\t\n 861:\tstatic void *s_next(struct seq_file *m, void *p, loff_t *pos)\n 862:\t{\n 863:\t\t(*pos)++;\n 864:\t\n 865:\t\tif (!update_iter(m-\u003eprivate, *pos))\n 866:\t\t\treturn NULL;\n 867:\t\treturn p;\n 868:\t}\n 869:\t\n 870:\tstatic void *s_start(struct seq_file *m, loff_t *pos)\n 871:\t{\n 872:\t\tif (!update_iter(m-\u003eprivate, *pos))\n 873:\t\t\treturn NULL;\n 874:\t\treturn m-\u003eprivate;\n 875:\t}\n 876:\t\n 877:\tstatic void s_stop(struct seq_file *m, void *p)\n 878:\t{\n 879:\t}\n"
}

53/3 2026/09/25 01:56 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 21968
							output: 36
							thoughts: 1104
						

Thoughts:
**KMSAN Analysis of Kallsyms Code**

Okay, let's break this down. First, I noticed a potential off-by-one error, or at least an out-of-bounds access if the `pos` value in `get_symbol_offset` somehow exceeded `kallsyms_num_syms`. However, a quick check of the calling logic shows that `pos` is always within the bounds. Good.

Now, I need to evaluate this patch according to the KMSAN criteria. Let's see...

1.  Kernel structures passed to userspace with possible uninitialized data? Not directly visible here, but I'll keep an eye out.
2.  Conditional logic based on uninitialized variables? Not obviously present in the snippets.
3.  Allocation of complex data structures with uninitialized fields? Again, not directly visible in these functions, but I will remain diligent.
4.  Bounds checks that could lead to reading uninitialized memory? This is where it gets interesting, especially given my initial thought.

Now I am going to examine the snippets in `kernel/kallsyms.c`.

In `get_symbol_data`: The code accesses `kallsyms_names`, which is in `.rodata` during kernel build time. It is statically initialized. Good. The `len` variable is written before the return. No issues here.

In `kallsyms_expand_symbol`: The `off` calculation seems sound, essentially replicating the checks in `get_symbol_data`. No concerns.

In `kallsyms_get_symbol_type`: Again, `len` is an out-parameter but it is always initialized. `data` points to the token index in `kallsyms_names`. So no issues.

In `kallsyms_strcmp_symbol`: Here, the `name` argument is passed by a caller. That could be a source of uninitialized data, but it seems there aren't any obvious places in this snippet. However, the `name` comes from the caller. That means there's a potential for the caller providing a bad `name`. Now, I need to find out where `kallsyms_lookup_names`, `kallsyms_on_each_match_symbol`, and `kallsyms_lookup_name` are called from to see how those string arguments are formed. I need to trace back from those functions to the callers, to see how that `name` string gets formed. Specifically, it could be a kernel structure sent to userspace, or be used in a conditional logic, or a case of bad bounds checks. Let's start with `kallsyms_lookup_names`...



54/3 2026/09/25 01:57 tool grepper
0m Args:
{
  "Expression": "kallsyms_lookup_names",
  "PathPrefix": "kernel/kallsyms.c"
}

Results:
{
  "Output": "kernel/kallsyms.c=284=static inline unsigned int get_symbol_seq(int index)\n--\nkernel/kallsyms.c-290-\nkernel/kallsyms.c:291:static int kallsyms_lookup_names(const char *name,\nkernel/kallsyms.c-292-\t\t\t\t unsigned int *start,\n--\nkernel/kallsyms.c=348=unsigned long kallsyms_lookup_name(const char *name)\n--\nkernel/kallsyms.c-356-\nkernel/kallsyms.c:357:\tret = kallsyms_lookup_names(name, \u0026i, NULL);\nkernel/kallsyms.c-358-\tif (!ret)\n--\nkernel/kallsyms.c=386=int kallsyms_on_each_match_symbol(int (*fn)(void *, unsigned long),\n--\nkernel/kallsyms.c-391-\nkernel/kallsyms.c:392:\tret = kallsyms_lookup_names(name, \u0026start, \u0026end);\nkernel/kallsyms.c-393-\tif (ret)\n"
}

55/3 2026/09/25 01:57 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 24002
							output: 452
							thoughts: 3301
						

Thoughts:
**KMSAN Assessment: No Need Here!**

Alright, let's break this down. First, I noticed a change in `kallsyms_lookup_names`: the stack buffer `namebuf` got removed, and `kallsyms_strcmp_symbol` is used instead. That's a stack usage reduction, which is good. Then, the code carefully checks if the target `name` is shorter than the symbol. I traced the comparison logic in `kallsyms_strcmp_symbol`, making sure it doesn't read past a null terminator. It's safe! Also, a new `kallsyms_build_offsets` function is called. The `offsets` array is allocated, but not zero-initialized, I did notice the loop initialization ensures all elements are set before use, so it's fully initialized. No use-after-free or leak issues.

I checked the test code (`test_perf_kallsyms_lookup_name`, `test_kallsyms_perf.c`) and everything there is properly initialized too. I dug deeper to see if `kallsyms_lookup_batch_start`, `get_symbol_offset`, or `kallsyms_strcmp_symbol` could be called in places that interact with userspace. Nothing. The patch touches internal kallsyms lookup routines, adds a dynamic indexing table, updates symbol comparison to use compressed tokens, and adds tests. No user-space copies. No uninitialized variables in any branching. The dynamically allocated `offsets` array is fully initialized immediately after allocation. The logic is sound, no uninitialized reads! There are no potential risks for uninitialized memory usage or info-leaks, KMSAN isn't needed here. All existing kernel bug detectors (KASAN, LOCKDEP, etc.) will catch any memory corruption or concurrency issues. So, NeedsKMSAN should be false. It's time to set the results!



56/3 2026/09/25 01:57 tool set-results
0m Args:
{
  "KMSANReasoning": "The patch optimizes kallsyms name lookup operations by:\n1. Comparing strings directly against compressed token stream in `kallsyms_strcmp_symbol()`, eliminating the temporary on-stack decompressed buffer in `kallsyms_lookup_names()`.\n2. Providing an optional batching mechanism (`kallsyms_lookup_batch_start()` / `kallsyms_lookup_batch_end()`) that builds a flat offset lookup table `dyn_kallsyms_offsets` allocated via `kvmalloc_array()`.\n3. Adding benchmark and selftest coverage in `lib/test_kallsyms_perf.c` and `kernel/kallsyms_selftest.c`.\n\nKASAN vs KMSAN applicability assessment:\n- No uninitialized memory exposure: The newly allocated buffer `dyn_kallsyms_offsets` is an array of `u32` (no padding) where every entry from 0 to `kallsyms_num_syms - 1` is populated sequentially in `kallsyms_build_offsets()` before the pointer is published via `rcu_assign_pointer()`. All other data structures involved (`kallsyms_names`, `kallsyms_token_table`, `kallsyms_token_index`) are read-only `.rodata` generated at build time.\n- No user-space info-leaks: No structures, padding, or uninitialized buffers are copied to user space (no `copy_to_user`, ioctl, netlink, or socket options touched).\n- Any potential risks introduced by the patch (such as out-of-bounds indexing in `offsets[pos]`, out-of-bounds reads on compressed names, RCU synchronization / lifetime issues, or mutex deadlocks) are strictly within the scope of KASAN, LOCKDEP, and standard kernel debug facilities.\n\nConsequently, there are no uninitialized memory hazards that warrant a dedicated KMSAN fuzzing session.",
  "NeedsKMSAN": false
}

Results:
{
  "KMSANReasoning": "The patch optimizes kallsyms name lookup operations by:\n1. Comparing strings directly against compressed token stream in `kallsyms_strcmp_symbol()`, eliminating the temporary on-stack decompressed buffer in `kallsyms_lookup_names()`.\n2. Providing an optional batching mechanism (`kallsyms_lookup_batch_start()` / `kallsyms_lookup_batch_end()`) that builds a flat offset lookup table `dyn_kallsyms_offsets` allocated via `kvmalloc_array()`.\n3. Adding benchmark and selftest coverage in `lib/test_kallsyms_perf.c` and `kernel/kallsyms_selftest.c`.\n\nKASAN vs KMSAN applicability assessment:\n- No uninitialized memory exposure: The newly allocated buffer `dyn_kallsyms_offsets` is an array of `u32` (no padding) where every entry from 0 to `kallsyms_num_syms - 1` is populated sequentially in `kallsyms_build_offsets()` before the pointer is published via `rcu_assign_pointer()`. All other data structures involved (`kallsyms_names`, `kallsyms_token_table`, `kallsyms_token_index`) are read-only `.rodata` generated at build time.\n- No user-space info-leaks: No structures, padding, or uninitialized buffers are copied to user space (no `copy_to_user`, ioctl, netlink, or socket options touched).\n- Any potential risks introduced by the patch (such as out-of-bounds indexing in `offsets[pos]`, out-of-bounds reads on compressed names, RCU synchronization / lifetime issues, or mutex deadlocks) are strictly within the scope of KASAN, LOCKDEP, and standard kernel debug facilities.\n\nConsequently, there are no uninitialized memory hazards that warrant a dedicated KMSAN fuzzing session.",
  "NeedsKMSAN": false
}

LLM Calls Summary:
Total Calls Total Tokens Avg Tokens Total Duration (Seconds) Avg Duration (Seconds)
Tool Calls Summary:
Total Calls Total Duration (Seconds) Avg Duration (Seconds)