| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/09/25 03:39 | flow | patch-triage |
4mArgs:null Results: {
"EnableConfigs": [
"KALLSYMS",
"TEST_KALLSYMS_PERF",
"KPROBE_EVENTS",
"BPF_SYSCALL"
],
"FocusSymbols": [
"kallsyms_lookup_batch_start",
"kallsyms_lookup_batch_end",
"kallsyms_lookup_names",
"kallsyms_strcmp_symbol",
"kallsyms_lookup_name",
"kallsyms_on_each_match_symbol"
],
"KMSANReasoning": "The patch series optimizes symbol lookup in the kernel kallsyms subsystem by introducing direct in-place comparison against compressed symbols (`kallsyms_strcmp_symbol`), removing the temporary stack buffer (`namebuf`), and adding an optional transient dynamic offset index (`dyn_kallsyms_offsets`) managed via RCU for batch lookups.\n\nKMSAN vs KASAN analysis:\n1. No uninitialized memory or info-leaks: No kernel structures or data are exposed to user space. The stack buffer `namebuf` in `kallsyms_lookup_names()` was eliminated rather than added. The dynamically allocated offset array (`dyn_kallsyms_offsets`) created by `kallsyms_build_offsets()` allocates memory via `kvmalloc_array()` and fully populates every index from 0 through `kallsyms_num_syms - 1` prior to publishing the pointer via `rcu_assign_pointer()`.\n2. Applicability of other detectors: Any potential memory safety bugs introduced by this patch series would involve out-of-bounds reads into `kallsyms_names`, concurrency/lifetime issues (RCU grace periods, kvfree), or locking bugs in `dyn_kallsyms_mutex`. These issues are covered by KASAN and LOCKDEP.\n\nTherefore, this patch series does not pose uninitialized memory risks that would necessitate a dedicated KMSAN fuzzing session.",
"NeedsKMSAN": false,
"Reasoning": "The patch refactors the core kallsyms symbol lookup and decoding subsystem. It implements a direct-comparison helper (kallsyms_strcmp_symbol) that parses compressed tokens against input strings, modifies kallsyms_expand_symbol and kallsyms_get_symbol_type, adds dynamic offset indexing with RCU and mutex synchronization (kallsyms_lookup_batch_start/end), and adds a new benchmark module (test_kallsyms_perf). These paths are reachable from user space via /proc/kallsyms reads, tracefs kprobe configuration (kprobe_events), BPF program loading with kfuncs/BTF resolution, and test module sysfs parameters. Refactored parsing logic and new synchronization primitives warrant fuzzing.",
"WorthFuzzing": true
} |
| 1/1 | 2026/09/25 03:39 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit 01b29fa3a45ccf7bf7dca3ff0e9d96cad2a3c17e\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Fri Sep 25 03:39:15 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..35484361201f3 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,99 @@ 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 __rcu *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 = rcu_replace_pointer(dyn_kallsyms_offsets, NULL,\n+\t\t\t\t\t lockdep_is_held(\u0026dyn_kallsyms_mutex));\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 +280,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 +294,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 +312,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 +332,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..f6c3d5d82e5d0\n--- /dev/null\n+++ b/lib/test_kallsyms_perf.c\n@@ -0,0 +1,341 @@\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+#include \u003clinux/mutex.h\u003e\n+#include \u003clinux/minmax.h\u003e\n+\n+#define BENCH_CHUNK_SIZE 4096\n+\n+static unsigned int num_iters = 100000;\n+\n+static int param_set_num_iters(const char *val, const struct kernel_param *kp)\n+{\n+\tunsigned int n;\n+\tint ret;\n+\n+\tret = kstrtouint(val, 0, \u0026n);\n+\tif (ret)\n+\t\treturn ret;\n+\tif (!n)\n+\t\treturn -EINVAL;\n+\n+\t*((unsigned int *)kp-\u003earg) = n;\n+\treturn 0;\n+}\n+\n+static const struct kernel_param_ops param_ops_num_iters = {\n+\t.set = param_set_num_iters,\n+\t.get = param_get_uint,\n+};\n+module_param_cb(num_iters, \u0026param_ops_num_iters, \u0026num_iters, 0644);\n+MODULE_PARM_DESC(num_iters, \"Number of iterations per microbenchmark (must be \u003e 0)\");\n+\n+static bool run_on_boot;\n+module_param(run_on_boot, bool, 0444);\n+MODULE_PARM_DESC(run_on_boot, \"Run benchmark during boot (default: false)\");\n+\n+static DEFINE_MUTEX(bench_lock);\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, unsigned int iters,\n+\t\t\t\t u64 *avg_hit_ns, u64 *avg_miss_ns)\n+{\n+\tu64 t0, t1, dt_hit = 0, dt_miss = 0;\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+\tfor (i = 0; i \u003c iters; i += BENCH_CHUNK_SIZE) {\n+\t\tunsigned int chunk = min_t(unsigned int, BENCH_CHUNK_SIZE, iters - i);\n+\t\tunsigned int j;\n+\n+\t\tcond_resched();\n+\t\tt0 = ktime_get_ns();\n+\t\tfor (j = 0; j \u003c chunk; j++) {\n+\t\t\tconst char *sym = hit_symbols[(i + j) % nr_hits];\n+\n+\t\t\tkallsyms_on_each_match_symbol(match_cb, sym, \u0026addr);\n+\t\t\tOPTIMIZER_HIDE_VAR(addr);\n+\t\t}\n+\t\tt1 = ktime_get_ns();\n+\t\tdt_hit += t1 - t0;\n+\t}\n+\n+\t/* 2. Name search: Non-existent symbols (Misses - 17 bsearch probes) */\n+\tfor (i = 0; i \u003c iters; i += BENCH_CHUNK_SIZE) {\n+\t\tunsigned int chunk = min_t(unsigned int, BENCH_CHUNK_SIZE, iters - i);\n+\t\tunsigned int j;\n+\n+\t\tcond_resched();\n+\t\tt0 = ktime_get_ns();\n+\t\tfor (j = 0; j \u003c chunk; j++) {\n+\t\t\tconst char *sym = miss_symbols[(i + j) % nr_misses];\n+\n+\t\t\tkallsyms_on_each_match_symbol(match_cb, sym, \u0026addr);\n+\t\t\tOPTIMIZER_HIDE_VAR(addr);\n+\t\t}\n+\t\tt1 = ktime_get_ns();\n+\t\tdt_miss += t1 - t0;\n+\t}\n+\n+\tif (avg_hit_ns)\n+\t\t*avg_hit_ns = div_u64(dt_hit, iters);\n+\tif (avg_miss_ns)\n+\t\t*avg_miss_ns = div_u64(dt_miss, 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, iters), div_u64(dt_hit, 1000000), iters);\n+\tpr_info(\"[%s] Name Search Miss: %llu ns/lookup (%llu ms total, %u iters)\\n\",\n+\t\tmode, div_u64(dt_miss, iters), div_u64(dt_miss, 1000000), iters);\n+}\n+\n+static void run_address_lookup_bench(unsigned int iters)\n+{\n+\tu64 t0, t1, dt_sprint = 0, dt_bldid = 0;\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+\tfor (i = 0; i \u003c iters; i += BENCH_CHUNK_SIZE) {\n+\t\tunsigned int chunk = min_t(unsigned int, BENCH_CHUNK_SIZE, iters - i);\n+\t\tunsigned int j;\n+\n+\t\tcond_resched();\n+\t\tt0 = ktime_get_ns();\n+\t\tfor (j = 0; j \u003c chunk; j++) {\n+\t\t\tunsigned long addr = addrs[(i + j) % nr_addrs];\n+\n+\t\t\tsprint_symbol(symname, addr);\n+\t\t\tbarrier_data(symname);\n+\t\t}\n+\t\tt1 = ktime_get_ns();\n+\t\tdt_sprint += t1 - t0;\n+\t}\n+\n+\t/* 2. Address without offset (sprint_symbol_no_offset) */\n+\tfor (i = 0; i \u003c iters; i += BENCH_CHUNK_SIZE) {\n+\t\tunsigned int chunk = min_t(unsigned int, BENCH_CHUNK_SIZE, iters - i);\n+\t\tunsigned int j;\n+\n+\t\tcond_resched();\n+\t\tt0 = ktime_get_ns();\n+\t\tfor (j = 0; j \u003c chunk; j++) {\n+\t\t\tunsigned long addr = addrs[(i + j) % nr_addrs];\n+\n+\t\t\tsprint_symbol_no_offset(symname, addr);\n+\t\t\tbarrier_data(symname);\n+\t\t}\n+\t\tt1 = ktime_get_ns();\n+\t\tdt_bldid += t1 - t0;\n+\t}\n+\n+\tpr_info(\"sprint_symbol: %llu ns/lookup (%llu ms total, %u iters)\\n\",\n+\t\tdiv_u64(dt_sprint, iters), div_u64(dt_sprint, 1000000), iters);\n+\tpr_info(\"sprint_symbol_no_offset: %llu ns/lookup (%llu ms total, %u iters)\\n\",\n+\t\tdiv_u64(dt_bldid, iters), div_u64(dt_bldid, 1000000), iters);\n+}\n+\n+static void run_table_walk_bench(void)\n+{\n+\tu64 t0, t1, dt_walk = 0;\n+\tunsigned long total_symbols = 0;\n+\tint iter = 50;\n+\tint i;\n+\n+\tfor (i = 0; i \u003c iter; i++) {\n+\t\ttotal_symbols = 0;\n+\t\tcond_resched();\n+\t\tt0 = ktime_get_ns();\n+\t\tkallsyms_on_each_symbol(count_cb, \u0026total_symbols);\n+\t\tt1 = ktime_get_ns();\n+\t\tdt_walk += t1 - t0;\n+\t}\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+\tunsigned int iters;\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 = 0;\n+\n+\tif (!mutex_trylock(\u0026bench_lock)) {\n+\t\tpr_warn(\"Benchmark already running\\n\");\n+\t\treturn -EBUSY;\n+\t}\n+\n+\titers = READ_ONCE(num_iters);\n+\tif (!iters) {\n+\t\tpr_err(\"num_iters must be non-zero\\n\");\n+\t\tret = -EINVAL;\n+\t\tgoto out;\n+\t}\n+\n+\tpr_info(\"==================================================\\n\");\n+\tpr_info(\"Starting kallsyms performance benchmark (iters=%u)\\n\", iters);\n+\tpr_info(\"==================================================\\n\");\n+\n+\t/* 1. Benchmark baseline unindexed marker scan */\n+\trun_name_lookup_bench(\"Unindexed (markers)\", iters, \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\", iters, \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(iters);\n+\trun_table_walk_bench();\n+\n+\tpr_info(\"==================================================\\n\");\n+\tpr_info(\"kallsyms benchmark complete\\n\");\n+\tpr_info(\"==================================================\\n\");\n+\n+out:\n+\tmutex_unlock(\u0026bench_lock);\n+\treturn ret;\n+}\n+\n+static int param_set_trigger(const char *val, const struct kernel_param *kp)\n+{\n+\tif (system_state \u003c SYSTEM_RUNNING) {\n+\t\tpr_warn(\"Early boot run ignored; use test_kallsyms_perf.run_on_boot=1 or trigger via sysfs\\n\");\n+\t\treturn 0;\n+\t}\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+\tif (run_on_boot)\n+\t\treturn run_kallsyms_benchmark();\n+\treturn 0;\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 03:39 | agent | patch-evaluator |
2mModel:core Args: null Results: {
"EnableConfigs": [
"KALLSYMS",
"TEST_KALLSYMS_PERF",
"KPROBE_EVENTS",
"BPF_SYSCALL"
],
"FocusSymbols": [
"kallsyms_lookup_batch_start",
"kallsyms_lookup_batch_end",
"kallsyms_lookup_names",
"kallsyms_strcmp_symbol",
"kallsyms_lookup_name",
"kallsyms_on_each_match_symbol"
],
"Reasoning": "The patch refactors the core kallsyms symbol lookup and decoding subsystem. It implements a direct-comparison helper (kallsyms_strcmp_symbol) that parses compressed tokens against input strings, modifies kallsyms_expand_symbol and kallsyms_get_symbol_type, adds dynamic offset indexing with RCU and mutex synchronization (kallsyms_lookup_batch_start/end), and adds a new benchmark module (test_kallsyms_perf). These paths are reachable from user space via /proc/kallsyms reads, tracefs kprobe configuration (kprobe_events), BPF program loading with kfuncs/BTF resolution, and test module sysfs parameters. Refactored parsing logic and new synchronization primitives warrant fuzzing.",
"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 01b29fa3a45ccf7bf7dca3ff0e9d96cad2a3c17e
Author: syz-cluster <triage@syzkaller.com>
Date: Fri Sep 25 03:39:15 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..35484361201f3 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,99 @@ 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 __rcu *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 = rcu_replace_pointer(dyn_kallsyms_offsets, NULL,
+ lockdep_is_held(&dyn_kallsyms_mutex));
+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 +280,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 +294,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 +312,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 +332,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..f6c3d5d82e5d0
--- /dev/null
+++ b/lib/test_kallsyms_perf.c
@@ -0,0 +1,341 @@
+// 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>
+#include <linux/mutex.h>
+#include <linux/minmax.h>
+
+#define BENCH_CHUNK_SIZE 4096
+
+static unsigned int num_iters = 100000;
+
+static int param_set_num_iters(const char *val, const struct kernel_param *kp)
+{
+ unsigned int n;
+ int ret;
+
+ ret = kstrtouint(val, 0, &n);
+ if (ret)
+ return ret;
+ if (!n)
+ return -EINVAL;
+
+ *((unsigned int *)kp->arg) = n;
+ return 0;
+}
+
+static const struct kernel_param_ops param_ops_num_iters = {
+ .set = param_set_num_iters,
+ .get = param_get_uint,
+};
+module_param_cb(num_iters, ¶m_ops_num_iters, &num_iters, 0644);
+MODULE_PARM_DESC(num_iters, "Number of iterations per microbenchmark (must be > 0)");
+
+static bool run_on_boot;
+module_param(run_on_boot, bool, 0444);
+MODULE_PARM_DESC(run_on_boot, "Run benchmark during boot (default: false)");
+
+static DEFINE_MUTEX(bench_lock);
+
+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, unsigned int iters,
+ u64 *avg_hit_ns, u64 *avg_miss_ns)
+{
+ u64 t0, t1, dt_hit = 0, dt_miss = 0;
+ 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) */
+ for (i = 0; i < iters; i += BENCH_CHUNK_SIZE) {
+ unsigned int chunk = min_t(unsigned int, BENCH_CHUNK_SIZE, iters - i);
+ unsigned int j;
+
+ cond_resched();
+ t0 = ktime_get_ns();
+ for (j = 0; j < chunk; j++) {
+ const char *sym = hit_symbols[(i + j) % nr_hits];
+
+ 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) */
+ for (i = 0; i < iters; i += BENCH_CHUNK_SIZE) {
+ unsigned int chunk = min_t(unsigned int, BENCH_CHUNK_SIZE, iters - i);
+ unsigned int j;
+
+ cond_resched();
+ t0 = ktime_get_ns();
+ for (j = 0; j < chunk; j++) {
+ const char *sym = miss_symbols[(i + j) % nr_misses];
+
+ 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, iters);
+ if (avg_miss_ns)
+ *avg_miss_ns = div_u64(dt_miss, iters);
+
+ pr_info("[%s] Name Search Hit: %llu ns/lookup (%llu ms total, %u iters)\n",
+ mode, div_u64(dt_hit, iters), div_u64(dt_hit, 1000000), iters);
+ pr_info("[%s] Name Search Miss: %llu ns/lookup (%llu ms total, %u iters)\n",
+ mode, div_u64(dt_miss, iters), div_u64(dt_miss, 1000000), iters);
+}
+
+static void run_address_lookup_bench(unsigned int iters)
+{
+ u64 t0, t1, dt_sprint = 0, dt_bldid = 0;
+ 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) */
+ for (i = 0; i < iters; i += BENCH_CHUNK_SIZE) {
+ unsigned int chunk = min_t(unsigned int, BENCH_CHUNK_SIZE, iters - i);
+ unsigned int j;
+
+ cond_resched();
+ t0 = ktime_get_ns();
+ for (j = 0; j < chunk; j++) {
+ unsigned long addr = addrs[(i + j) % nr_addrs];
+
+ sprint_symbol(symname, addr);
+ barrier_data(symname);
+ }
+ t1 = ktime_get_ns();
+ dt_sprint += t1 - t0;
+ }
+
+ /* 2. Address without offset (sprint_symbol_no_offset) */
+ for (i = 0; i < iters; i += BENCH_CHUNK_SIZE) {
+ unsigned int chunk = min_t(unsigned int, BENCH_CHUNK_SIZE, iters - i);
+ unsigned int j;
+
+ cond_resched();
+ t0 = ktime_get_ns();
+ for (j = 0; j < chunk; j++) {
+ unsigned long addr = addrs[(i + j) % nr_addrs];
+
+ 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, iters), div_u64(dt_sprint, 1000000), iters);
+ pr_info("sprint_symbol_no_offset: %llu ns/lookup (%llu ms total, %u iters)\n",
+ div_u64(dt_bldid, iters), div_u64(dt_bldid, 1000000), iters);
+}
+
+static void run_table_walk_bench(void)
+{
+ u64 t0, t1, dt_walk = 0;
+ unsigned long total_symbols = 0;
+ int iter = 50;
+ int i;
+
+ for (i = 0; i < iter; i++) {
+ total_symbols = 0;
+ cond_resched();
+ t0 = ktime_get_ns();
+ 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)
+{
+ unsigned int iters;
+ 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 = 0;
+
+ if (!mutex_trylock(&bench_lock)) {
+ pr_warn("Benchmark already running\n");
+ return -EBUSY;
+ }
+
+ iters = READ_ONCE(num_iters);
+ if (!iters) {
+ pr_err("num_iters must be non-zero\n");
+ ret = -EINVAL;
+ goto out;
+ }
+
+ pr_info("==================================================\n");
+ pr_info("Starting kallsyms performance benchmark (iters=%u)\n", iters);
+ pr_info("==================================================\n");
+
+ /* 1. Benchmark baseline unindexed marker scan */
+ run_name_lookup_bench("Unindexed (markers)", iters, &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", iters, &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(iters);
+ run_table_walk_bench();
+
+ pr_info("==================================================\n");
+ pr_info("kallsyms benchmark complete\n");
+ pr_info("==================================================\n");
+
+out:
+ mutex_unlock(&bench_lock);
+ return ret;
+}
+
+static int param_set_trigger(const char *val, const struct kernel_param *kp)
+{
+ if (system_state < SYSTEM_RUNNING) {
+ pr_warn("Early boot run ignored; use test_kallsyms_perf.run_on_boot=1 or trigger via sysfs\n");
+ return 0;
+ }
+ return run_kallsyms_benchmark();
+}
+
+static const struct kernel_param_ops param_ops_trigger = {
+ .set = param_set_trigger,
+};
+module_param_cb(run_test, ¶m_ops_trigger, NULL, 0200);
+MODULE_PARM_DESC(run_test, "Write 1 to trigger kallsyms benchmark run");
+
+static int __init test_kallsyms_init(void)
+{
+ if (run_on_boot)
+ return run_kallsyms_benchmark();
+ return 0;
+}
+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 03:39 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 11515 output: 22 thoughts: 543 Thoughts: **Analyzing the Kallsyms Patch** Okay, let's dive into this patch and review request. My initial assessment is that it looks like we're optimizing and extending the kernel's symbol lookup mechanisms, specifically focusing on `kallsyms`. The diff reveals several key changes, and my initial thought is that this is a solid attempt to improve performance, particularly in scenarios where symbol lookups are frequent. First, I see the addition of `kallsyms_lookup_batch_start()` and `kallsyms_lookup_batch_end()` prototypes. The stub implementations for `!CONFIG_KALLSYMS` suggest conditional compilation, which is standard practice here. Then, there are significant modifications within `kernel/kallsyms.c`. I note the refactoring around `kallsyms_expand_symbol` and `kallsyms_get_symbol_type` using a new `get_symbol_data()`. The implementation of `kallsyms_strcmp_symbol()` is particularly interesting. Comparing uncompressed strings against compressed symbol table entries without decompressing the entire name is a smart optimization, and likely a key to performance gains. I also see the renaming of `get_symbol_offset` to `get_symbol_offset_marker`, and the introduction of a dynamic symbol offset table (`dyn_kallsyms_offsets`, etc.). This dynamic table seems to indicate a more flexible approach to symbol offset management and the introduction of batch operations will be a key performance booster, particularly if we are adding and removing modules dynamically. The updated `get_symbol_offset()` now prioritizes the dynamic table, falling back to the marker if unavailable. This seems well-thought-out and should improve robustness, and the optimization of `get_symbol_seq()` makes sense. Looking at `kallsyms_lookup_names()`, the inclusion of `rcu_read_lock()` indicates a focus on concurrent access, which is crucial for scalability. The use of `kallsyms_strcmp_symbol()` within `kallsyms_lookup_names()` further supports the performance focus. The additions to `kernel/kallsyms_selftest.c`, `lib/Kconfig.debug`, `lib/Makefile`, and `lib/test_kallsyms_perf.c` all point toward good testing and benchmarking. Including a batch test in `test_perf_kallsyms_lookup_name()` suggests a direct attempt to validate the performance improvements claimed by the patch. Now, let's see how `kallsyms_lookup_names` is actually used. I will run `grepper` to see where it is called from. |
| 4/2 | 2026/09/25 03:39 | tool | grepper |
0mArgs:{
"Expression": "kallsyms_lookup_names"
}Results: {
"Output": "kernel/kallsyms.c=283=static inline unsigned int get_symbol_seq(int index)\n--\nkernel/kallsyms.c-289-\nkernel/kallsyms.c:290:static int kallsyms_lookup_names(const char *name,\nkernel/kallsyms.c-291-\t\t\t\t unsigned int *start,\n--\nkernel/kallsyms.c=347=unsigned long kallsyms_lookup_name(const char *name)\n--\nkernel/kallsyms.c-355-\nkernel/kallsyms.c:356:\tret = kallsyms_lookup_names(name, \u0026i, NULL);\nkernel/kallsyms.c-357-\tif (!ret)\n--\nkernel/kallsyms.c=385=int kallsyms_on_each_match_symbol(int (*fn)(void *, unsigned long),\n--\nkernel/kallsyms.c-390-\nkernel/kallsyms.c:391:\tret = kallsyms_lookup_names(name, \u0026start, \u0026end);\nkernel/kallsyms.c-392-\tif (ret)\n--\nlib/test_kallsyms_perf.c=56=static const char * const hit_symbols[] = {\n--\nlib/test_kallsyms_perf.c-62-\t\"panic\",\nlib/test_kallsyms_perf.c:63:\t\"kallsyms_lookup_names\",\nlib/test_kallsyms_perf.c-64-\t\"vm_area_alloc\",\n"
} |
| 5/2 | 2026/09/25 03:39 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 13074 output: 24 thoughts: 91 Thoughts: Okay, here's my summary, tailored for an expert audience, as if it's a direct stream of my thought process: **Tracing the kallsyms Dependency Chain** Right, so I'm digging into `kallsyms_lookup_names`. I know it's a core function, but I need to understand its call graph a bit better. My immediate concern is, what functions directly call `kallsyms_lookup_names`? The notes tell me `kallsyms_lookup_name` and `kallsyms_on_each_match_symbol` are the direct callers. That's a good starting point. I need to now understand the calls made by `kallsyms_on_each_match_symbol` and `kallsyms_lookup_name`, and also who calls `kallsyms_lookup_batch_start`. That should paint a clearer picture of the data flow and potential performance bottlenecks or security considerations associated with symbol lookup within the kernel. I will make a note to examine the locking strategy around these calls as well. |
| 6/2 | 2026/09/25 03:39 | tool | grepper |
0mArgs:{
"Expression": "kallsyms_lookup_batch_start"
}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);\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--\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-\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--\nlib/test_kallsyms_perf.c=249=static int run_kallsyms_benchmark(void)\n--\nlib/test_kallsyms_perf.c-277-\tt0 = ktime_get_ns();\nlib/test_kallsyms_perf.c:278:\tret = kallsyms_lookup_batch_start();\nlib/test_kallsyms_perf.c-279-\tt1 = ktime_get_ns();\n"
} |
| 7/2 | 2026/09/25 03:39 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 14111 output: 26 thoughts: 63 Thoughts: Okay, let's dive into this. I'm curious about the call graph for `kallsyms_lookup_name` and `kallsyms_on_each_match_symbol` within the kernel. It's time to figure out which components are utilizing these symbols. I'll start by focusing on `kallsyms_on_each_match_symbol` and map out its callers. I need to understand the dependencies and how this function is being leveraged throughout the system. I'll need to know which modules or kernel parts rely on the function and their overall behavior. |
| 8/2 | 2026/09/25 03:39 | tool | grepper |
0mArgs:{
"Expression": "kallsyms_on_each_match_symbol"
}Results: {
"Output": "include/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=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--\nkernel/kallsyms.c=367=int kallsyms_on_each_symbol(int (*fn)(void *, const char *, unsigned long),\n--\nkernel/kallsyms.c-384-\nkernel/kallsyms.c:385:int kallsyms_on_each_match_symbol(int (*fn)(void *, unsigned long),\nkernel/kallsyms.c-386-\t\t\t\t const char *name, void *data)\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-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-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=426=static int test_entry(void *p)\n--\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/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/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--\nlib/test_kallsyms_perf.c=94=static void run_name_lookup_bench(const char *mode, unsigned int iters,\n--\nlib/test_kallsyms_perf.c-108-\nlib/test_kallsyms_perf.c:109:\t\tkallsyms_on_each_match_symbol(match_cb, sym, \u0026a1);\nlib/test_kallsyms_perf.c-110-\t\tif (!a1)\n--\nlib/test_kallsyms_perf.c-116-\nlib/test_kallsyms_perf.c:117:\t\tkallsyms_on_each_match_symbol(match_cb, sym, \u0026a1);\nlib/test_kallsyms_perf.c-118-\t\tif (a1)\n--\nlib/test_kallsyms_perf.c-132-\nlib/test_kallsyms_perf.c:133:\t\t\tkallsyms_on_each_match_symbol(match_cb, sym, \u0026addr);\nlib/test_kallsyms_perf.c-134-\t\t\tOPTIMIZER_HIDE_VAR(addr);\n--\nlib/test_kallsyms_perf.c-149-\nlib/test_kallsyms_perf.c:150:\t\t\tkallsyms_on_each_match_symbol(match_cb, sym, \u0026addr);\nlib/test_kallsyms_perf.c-151-\t\t\tOPTIMIZER_HIDE_VAR(addr);\n--\nlib/test_kallsyms_perf.c=168=static void run_address_lookup_bench(unsigned int iters)\n--\nlib/test_kallsyms_perf.c-177-\nlib/test_kallsyms_perf.c:178:\t\tkallsyms_on_each_match_symbol(match_cb, hit_symbols[i], \u0026addr);\nlib/test_kallsyms_perf.c-179-\t\tif (addr)\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"
} |
| 9/2 | 2026/09/25 03:39 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 16525 output: 23 thoughts: 72 Thoughts: Here's my summary, as I delve into this code: **Diving into Kprobe Symbol Resolution** Okay, let's get into this. My focus is on understanding how `trace_kprobe.c` interacts with the kernel's symbol table. My initial thought is to examine the kprobe creation process itself. Specifically, I'm noting that the code, during kprobe creation, calls `number_of_same_symbols`. This function, in turn, calls `kallsyms_on_each_match_symbol`. Interesting. This seems like a potential choke point, or maybe a good area for optimization. Now, I'm pivoting. What about `kallsyms_lookup_name`? That's a core function for looking up symbol addresses in the kernel. I should really check the callers of `kallsyms_lookup_name`. Knowing *where* and *how often* it's called will give me a better understanding of its overall performance impact and where bottlenecks might exist. This should show me all the places in the code where it is used to obtain kernel addresses. |
| 10/2 | 2026/09/25 03:39 | tool | grepper |
0mArgs:{
"Expression": "kallsyms_lookup_name\\("
}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=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/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--\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=6602=BPF_CALL_4(bpf_kallsyms_lookup_name, const char *, name, int, name_sz, int, flags, u64 *, res)\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/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=290=static int kallsyms_lookup_names(const char *name,\n--\nkernel/kallsyms.c-346-/* Lookup the address for this symbol. Returns 0 if not found. */\nkernel/kallsyms.c:347:unsigned long kallsyms_lookup_name(const char *name)\nkernel/kallsyms.c-348-{\n--\nkernel/kallsyms.c-359-\nkernel/kallsyms.c:360:\treturn module_kallsyms_lookup_name(name);\nkernel/kallsyms.c-361-}\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=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-342-\nkernel/kallsyms_selftest.c:343:\t\tlookup_addr = kallsyms_lookup_name(namebuf);\nkernel/kallsyms_selftest.c-344-\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();\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/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_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/tests/longest_symbol_kunit.c=43=static void test_longest_symbol_kallsyms(struct kunit *test)\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/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-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/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"
} |
| 11/2 | 2026/09/25 03:39 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 23701 output: 36 thoughts: 334 Thoughts: **My Analysis of `kallsyms_lookup_name` and Related Functions** Okay, let's break down where `kallsyms_lookup_name()` and `kallsyms_on_each_match_symbol()` are being used, particularly from a user-space or system call perspective. My initial thought is to zero in on the implications for kernel security. First, BPF is a major point of interest. The `bpf(BPF_PROG_LOAD)` syscall specifically, as the verifier resolves kfunc calls using `bpf_add_kfunc_call`, and deals with pseudo BTF IDs via `__check_pseudo_btf_id`, it is also used for attach targets (`bpf_check_attach_target`, `bpf_check_attach_btf_id_multi`), and `btf_parse_kptr`. The `bpf_kallsyms_lookup_name` helper itself is directly reachable within BPF programs, which is concerning in itself as BPF programs can be loaded from user space. Next, tracing is critical. The use of `kallsyms_lookup_name` in `trace_kprobe.c`, specifically when creating kprobes through debugfs/tracefs and file writes which triggers `trace_kprobe_address` and `number_of_same_symbols` is a key path. Also, trace filters are parsing symbols with this function. The presence of `traceprobe_update_arg` is another vector. Then, there's the `fail_function.c` file which handles `fei_write` via debugfs, under `fail_function/inject`. This is a less common path, but still warrants attention. Finally, I need to thoroughly examine the actual kernel code in `kernel/kallsyms.c`. I will be very careful to inspect the specific modifications to that file and I will need to read the surrounding code in `kernel/kallsyms.c` to fully understand the context. The diff is key here, and I need to carefully scrutinize the logic. |
| 12/2 | 2026/09/25 03:39 | tool | read-file |
0mArgs:{
"File": "kernel/kallsyms.c",
"FirstLine": 100,
"LineCount": 80
}Results: {
"Contents": " 100:\t/*\n 101:\t * Get symbol type information. This is encoded as a single char at the\n 102:\t * beginning of the symbol name.\n 103:\t */\n 104:\tstatic char kallsyms_get_symbol_type(unsigned int off)\n 105:\t{\n 106:\t\tunsigned int len;\n 107:\t\tconst u8 *data = get_symbol_data(off, \u0026len);\n 108:\t\n 109:\t\treturn kallsyms_token_table[kallsyms_token_index[*data]];\n 110:\t}\n 111:\t\n 112:\t/*\n 113:\t * Compare an uncompressed ASCII string against a compressed symbol table entry.\n 114:\t * Returns negative if name \u003c sym, positive if name \u003e sym, 0 if equal.\n 115:\t * Exits immediately on the first mismatched character without decompressing\n 116:\t * the rest of the symbol name.\n 117:\t */\n 118:\tstatic int kallsyms_strcmp_symbol(unsigned int off, const char *name)\n 119:\t{\n 120:\t\tconst char *tptr;\n 121:\t\tunsigned int len;\n 122:\t\tconst u8 *data = get_symbol_data(off, \u0026len);\n 123:\t\n 124:\t\ttptr = \u0026kallsyms_token_table[kallsyms_token_index[*data++]] + 1;\n 125:\t\twhile (*tptr) {\n 126:\t\t\tint diff = (unsigned char)*name++ - (unsigned char)*tptr++;\n 127:\t\n 128:\t\t\tif (diff)\n 129:\t\t\t\treturn diff;\n 130:\t\t}\n 131:\t\n 132:\t\twhile (--len) {\n 133:\t\t\ttptr = \u0026kallsyms_token_table[kallsyms_token_index[*data++]];\n 134:\t\t\tdo {\n 135:\t\t\t\tint diff = (unsigned char)*name++ - (unsigned char)*tptr++;\n 136:\t\n 137:\t\t\t\tif (diff)\n 138:\t\t\t\t\treturn diff;\n 139:\t\t\t} while (*tptr);\n 140:\t\t}\n 141:\t\n 142:\t\treturn (unsigned char)*name;\n 143:\t}\n 144:\t\n 145:\t/*\n 146:\t * Find the offset on the compressed stream given an index in the\n 147:\t * kallsyms array using legacy markers.\n 148:\t */\n 149:\tstatic unsigned int get_symbol_offset_marker(unsigned long pos)\n 150:\t{\n 151:\t\tconst u8 *name;\n 152:\t\tint i, len;\n 153:\t\n 154:\t\t/*\n 155:\t\t * Use the closest marker we have. We have markers every 256 positions,\n 156:\t\t * so that should be close enough.\n 157:\t\t */\n 158:\t\tname = \u0026kallsyms_names[kallsyms_markers[pos \u003e\u003e 8]];\n 159:\t\n 160:\t\t/*\n 161:\t\t * Sequentially scan all the symbols up to the point we're searching\n 162:\t\t * for. Every symbol is stored in a [\u003clen\u003e][\u003clen\u003e bytes of data] format,\n 163:\t\t * so we just need to add the len to the current pointer for every\n 164:\t\t * symbol we wish to skip.\n 165:\t\t */\n 166:\t\tfor (i = 0; i \u003c (pos \u0026 0xFF); i++) {\n 167:\t\t\tlen = *name;\n 168:\t\n 169:\t\t\t/*\n 170:\t\t\t * If MSB is 1, it is a \"big\" symbol, so we need to look into\n 171:\t\t\t * the next byte (and skip it, too).\n 172:\t\t\t */\n 173:\t\t\tif ((len \u0026 0x80) != 0)\n 174:\t\t\t\tlen = ((len \u0026 0x7F) | (name[1] \u003c\u003c 7)) + 1;\n 175:\t\n 176:\t\t\tname = name + len + 1;\n 177:\t\t}\n 178:\t\n 179:\t\treturn name - kallsyms_names;\n"
} |
| 13/2 | 2026/09/25 03:39 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 25695 output: 22 thoughts: 2178 Thoughts: **Deep Dive into `kallsyms_strcmp_symbol`**
Okay, let's break down this `kallsyms_strcmp_symbol` function. I see it's designed to compare a symbol name against a compressed representation within the kernel's symbol table. Let's start with the basics, and the crucial point is that we are looking at lines 118-143.
The first thing that grabs my attention is the `+ 1` in `tptr = &kallsyms_token_table[...] + 1;`. It's skipping the first character of the token. Ah, right, that first byte is the symbol type. Got it. This makes sense when compared with `kallsyms_expand_symbol`: that function skips the first character of the *first* token, but not subsequent tokens.
Now, consider this: if `*name` (the string being compared) is shorter than the symbol. When `*name` reaches `\0`, `name++` continues to increment, and the `diff` calculation will return a non-zero value, which is correct. So, the comparison is short-circuiting properly. But what if the symbol is shorter? In that case, the `len` counter would run out, and the function would return `(unsigned char)*name;` after incrementing the pointer past the end of the compared string.
Let's do a quick trace of a single-character symbol. If we were comparing against `"a"`, the first token expands to `"Ta"`. The `+ 1` on `tptr` makes it point to `'a'`. The loop correctly returns 0 if the input is "a" and compares the end of the string.
Now, let's scrutinize Loop 2, particularly `do ... while (*tptr)`. I'm focusing on that `*tptr++`. What if the token is "xyz"? Each `tptr` increment is correct: the loop correctly steps through the token's characters. What if it's just one character, "x"? Also correct. The loop terminates correctly. But wait - what about an *empty* token? Could that happen?
Hang on! We're talking about tokens in the `kallsyms_token_table`. How are those tokens actually created? I should check `scripts/kallsyms.c` to see the structure of the `kallsyms_token_table`, because tokens are null-terminated strings there. So, an empty token is impossible.
Okay, suppose the symbol name is `"T\0"`. The first loop is skipped. And in the second loop: if the symbol has MORE tokens, then `while (--len)` runs.
Okay, let's step back and look at the loops, again, and compare the two: the first token `while (*tptr)`, versus the second tokens `do ... while (*tptr)`.
In the first loop, `tptr = &kallsyms_token_table[kallsyms_token_index[*data++]] + 1;`
In the second loop: `while (--len) { tptr = &kallsyms_token_table[kallsyms_token_index[*data++]]; do { ... } while (*tptr);`
Looks like I need to dig deeper into the symbol table creation to ensure this whole process is robust.
|
| 14/2 | 2026/09/25 03:40 | tool | grepper |
0mArgs:{
"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"
} |
| 15/2 | 2026/09/25 03:40 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 29812 output: 36 thoughts: 21 Thoughts: Here's my take on the thought process, tailored for an expert audience: **Diving into `kallsyms.c` – Line 410 is the Target** Okay, time to get specific. Instead of a general scan, I'm zeroing in on a particular area. Based on the problem, I suspect the issue might be rooted in the `scripts/kallsyms.c` file. This utility is crucial for creating and managing symbol tables, so any anomalies there can have wide-ranging effects. I'm focusing on around line 410. That's a reasonable jumping-off point; I've got a mental map of that file, so I already have some idea of what kind of logic and functionality I should encounter in that vicinity, and I'm ready to investigate. |
| 16/2 | 2026/09/25 03:40 | tool | read-file |
0mArgs:{
"File": "scripts/kallsyms.c",
"FirstLine": 400,
"LineCount": 40
}Results: {
"Contents": " 400:\t\t}\n 401:\t\tprintf(\".size kallsyms_names, . - kallsyms_names\\n\");\n 402:\t\tprintf(\"\\n\");\n 403:\t\n 404:\t\toutput_label(\"kallsyms_markers\");\n 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 435:\t\t\t\t\tfprintf(stderr, \"kallsyms failure: \"\n 436:\t\t\t\t\t\t\"relative symbol value %#llx out of range\\n\",\n 437:\t\t\t\t\t\ttable[i]-\u003eaddr);\n 438:\t\t\t\t\texit(EXIT_FAILURE);\n 439:\t\t\t\t}\n"
} |
| 17/2 | 2026/09/25 03:40 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 30704 output: 36 thoughts: 2491 Thoughts: **Deep Dive into `kallsyms_strcmp_symbol`**
Okay, I need to really get into this `kallsyms_strcmp_symbol` function. I see how it compares an uncompressed string against a compressed symbol table entry. My initial thought is to make sure every entry in `kallsyms_token_table` has a length of at least one, to avoid potential issues. But, wait, what about the case where the input `name` string ends *before* the symbol?
Let's say `name` is "abc" and the symbol is "abcdef". I see the comparison logic will work its way through "abc", but then when it hits the fourth character in the symbol string ("d"), `*name` will be `\0`. The code calculates the difference: `diff = 0 - 'd'`. The function correctly returns negative. Nice, it correctly flags that `"abc"` comes before `"abcdef"`.
But, what if it's the other way around? `name` is "abcdef" and the symbol is "abc". The initial three characters match, and it falls through to compare the fourth character of `name` (which would be 'd') with the null terminator of the symbol. The function returns a positive value, because `(unsigned char)*name;` results in the value of 'd'. Perfect, that's what I want.
What if both strings are identical, "abc" vs "abc"? In that case, the while loops finish, and `(unsigned char)*name` results in `\0`, indicating equality. That works as expected.
Now, let's explore some edge cases: what if the first token in `kallsyms_token_table` is length 1, and the second is the remainder of the symbol? `tptr = &kallsyms_token_table[...] + 1;` If that token is of length 1, like the type character ('T'), the comparison in `while (*tptr)` will start immediately. The interesting part is that `name` is NOT advanced until AFTER `tptr` is incremented. Does this mean it will then proceed to compare `name` with the second character of the symbol name? Yes, because that character is the first character in the second token!
Could the symbol name in a Linux kernel be empty? No, symbol names are valid C identifiers. Even if it *were* empty, the second `while (--len)` loop wouldn't run, and it would return the terminating null, from the `name` argument, which would be correct.
Now, look at how the code compares strings: `* Compare an uncompressed ASCII string against a compressed symbol table entry.` The function returns negative if `name < sym`, positive if `name > sym`, and 0 if equal. It's essentially implementing the standard `strcmp` functionality. I need to make sure the order of arguments works: `kallsyms_strcmp_symbol(off, name)`. The first argument seems to be an offset, but `name` is the uncompressed string, and it should be compared against the symbol, right?
So, if `name` is `"abc"`, and `sym` is `"abcdef"`, `diff = name - sym` and `0 - 'd' = -100`. The return is negative, signifying that `"abc"` comes before `"abcdef"`. And when `name` is `"abcdef"` and `sym` is `"abc"`, `(unsigned char)*name` would be the fourth character, which is 'd'. The return would be positive, signifying that `"abcdef"` comes after `"abc"`. Finally, when `name` and `sym` are equal, we return zero. The calculation of the `diff` variable, using `(unsigned char)`, looks safe from overflows.
Let's go back and think... what if `name` becomes `\0` during the first comparison loop?
If the string `name` is empty or ends up at null for any reason... Let's say `name` is `""` (empty string) and `sym` is `"ab"`. The code compares the first char in `sym`, with a null char.
The value of `*tptr` will ALWAYS be non-zero, due to `while (*tptr)`.
In the first iteration of the first loop, `diff = 0 - 'b' != 0`.
The function will immediately return!
If `*name` is `\0` during that process, it immediately returns a non-zero value, without attempting to read from `name` past the terminating null.
The same is true for the second loop.
But wait, can tokens in `kallsyms_
|
| 18/2 | 2026/09/25 03:40 | tool | read-file |
0mArgs:{
"File": "kernel/kallsyms.c",
"FirstLine": 180,
"LineCount": 85
}Results: {
"Contents": " 180:\t}\n 181:\t\n 182:\t/*\n 183:\t * Dynamic symbol offset table.\n 184:\t * Allocated on demand during high-volume lookup batches and reclaimed after.\n 185:\t */\n 186:\tstatic u32 __rcu *dyn_kallsyms_offsets __read_mostly;\n 187:\tstatic DEFINE_MUTEX(dyn_kallsyms_mutex);\n 188:\tstatic unsigned int dyn_kallsyms_refcnt;\n 189:\t\n 190:\tstatic u32 *kallsyms_build_offsets(void)\n 191:\t{\n 192:\t\tconst u8 *name = kallsyms_names;\n 193:\t\tu32 *offsets;\n 194:\t\tunsigned int i;\n 195:\t\n 196:\t\toffsets = kvmalloc_array(kallsyms_num_syms, sizeof(u32), GFP_KERNEL);\n 197:\t\tif (!offsets)\n 198:\t\t\treturn NULL;\n 199:\t\n 200:\t\tfor (i = 0; i \u003c kallsyms_num_syms; i++) {\n 201:\t\t\tunsigned int len;\n 202:\t\t\tconst u8 *data;\n 203:\t\n 204:\t\t\toffsets[i] = name - kallsyms_names;\n 205:\t\t\tdata = get_symbol_data(offsets[i], \u0026len);\n 206:\t\t\tname = data + len;\n 207:\t\t}\n 208:\t\n 209:\t\treturn offsets;\n 210:\t}\n 211:\t\n 212:\tint kallsyms_lookup_batch_start(void)\n 213:\t{\n 214:\t\tint ret = 0;\n 215:\t\n 216:\t\tmutex_lock(\u0026dyn_kallsyms_mutex);\n 217:\t\tif (!dyn_kallsyms_refcnt) {\n 218:\t\t\tu32 *offsets = kallsyms_build_offsets();\n 219:\t\n 220:\t\t\tif (!offsets) {\n 221:\t\t\t\tret = -ENOMEM;\n 222:\t\t\t\tgoto out;\n 223:\t\t\t}\n 224:\t\t\trcu_assign_pointer(dyn_kallsyms_offsets, offsets);\n 225:\t\t}\n 226:\t\tdyn_kallsyms_refcnt++;\n 227:\tout:\n 228:\t\tmutex_unlock(\u0026dyn_kallsyms_mutex);\n 229:\t\treturn ret;\n 230:\t}\n 231:\tEXPORT_SYMBOL_GPL(kallsyms_lookup_batch_start);\n 232:\t\n 233:\tvoid kallsyms_lookup_batch_end(void)\n 234:\t{\n 235:\t\tu32 *offsets = NULL;\n 236:\t\n 237:\t\tmutex_lock(\u0026dyn_kallsyms_mutex);\n 238:\t\tif (WARN_ON(!dyn_kallsyms_refcnt))\n 239:\t\t\tgoto out;\n 240:\t\n 241:\t\tif (--dyn_kallsyms_refcnt == 0)\n 242:\t\t\toffsets = rcu_replace_pointer(dyn_kallsyms_offsets, NULL,\n 243:\t\t\t\t\t\t lockdep_is_held(\u0026dyn_kallsyms_mutex));\n 244:\tout:\n 245:\t\tmutex_unlock(\u0026dyn_kallsyms_mutex);\n 246:\t\n 247:\t\tif (offsets) {\n 248:\t\t\tsynchronize_rcu();\n 249:\t\t\tkvfree(offsets);\n 250:\t\t}\n 251:\t}\n 252:\tEXPORT_SYMBOL_GPL(kallsyms_lookup_batch_end);\n 253:\t\n 254:\t/*\n 255:\t * Find the offset on the compressed table given an index in the\n 256:\t * kallsyms array.\n 257:\t */\n 258:\tstatic inline unsigned int get_symbol_offset(unsigned long pos)\n 259:\t{\n 260:\t\tunsigned int off;\n 261:\t\tu32 *offsets;\n 262:\t\n 263:\t\trcu_read_lock();\n 264:\t\toffsets = rcu_dereference(dyn_kallsyms_offsets);\n"
} |
| 19/2 | 2026/09/25 03:40 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 35456 output: 36 thoughts: 23 Thoughts: Okay, here's my attempt at summarizing those thoughts, tailored for an expert audience, and written in the first person: **Diving Deeper into Symbol Resolution** Alright, so I'm revisiting the `get_symbol_offset` and `kallsyms_lookup_names` functions. It's clear that understanding how these work is *crucial* for reverse engineering, debugging, and definitely for anything related to kernel module development, or any work requiring introspection of the running kernel. I need to be completely comfortable with how symbol tables are queried and interpreted. This likely involves understanding how the kernel manages its symbol data, how the `kallsyms` table is constructed and accessed, and the optimizations that might be in place for efficiency. The architecture-specific details of how these functions relate to virtual memory layouts and relocation are also important. I'm imagining that I'll need to correlate the outputs with debugging information in, for example, a gdb session. I anticipate having to trace calls, inspect data structures, and perhaps even disassemble portions of the relevant code to fully grasp the implementation details. Time to start digging! |
| 20/2 | 2026/09/25 03:40 | tool | read-file |
0mArgs:{
"File": "kernel/kallsyms.c",
"FirstLine": 260,
"LineCount": 85
}Results: {
"Contents": " 260:\t\tunsigned int off;\n 261:\t\tu32 *offsets;\n 262:\t\n 263:\t\trcu_read_lock();\n 264:\t\toffsets = rcu_dereference(dyn_kallsyms_offsets);\n 265:\t\tif (offsets) {\n 266:\t\t\toff = offsets[pos];\n 267:\t\t\trcu_read_unlock();\n 268:\t\t\treturn off;\n 269:\t\t}\n 270:\t\trcu_read_unlock();\n 271:\t\n 272:\t\treturn get_symbol_offset_marker(pos);\n 273:\t}\n 274:\t\n 275:\tunsigned long kallsyms_sym_address(int idx)\n 276:\t{\n 277:\t\t/* non-relocatable 32-bit kernels just embed the value directly */\n 278:\t\tif (!IS_ENABLED(CONFIG_64BIT) \u0026\u0026 !IS_ENABLED(CONFIG_RELOCATABLE))\n 279:\t\t\treturn (u32)kallsyms_offsets[idx];\n 280:\t\treturn (unsigned long)offset_to_ptr(kallsyms_offsets + idx);\n 281:\t}\n 282:\t\n 283:\tstatic inline unsigned int get_symbol_seq(int index)\n 284:\t{\n 285:\t\tconst u8 *p = \u0026kallsyms_seqs_of_names[3 * index];\n 286:\t\n 287:\t\treturn (p[0] \u003c\u003c 16) | (p[1] \u003c\u003c 8) | p[2];\n 288:\t}\n 289:\t\n 290:\tstatic int kallsyms_lookup_names(const char *name,\n 291:\t\t\t\t\t unsigned int *start,\n 292:\t\t\t\t\t unsigned int *end)\n 293:\t{\n 294:\t\tint ret;\n 295:\t\tint low, mid, high;\n 296:\t\tunsigned int seq, off;\n 297:\t\n 298:\t\tlow = 0;\n 299:\t\thigh = kallsyms_num_syms - 1;\n 300:\t\n 301:\t\trcu_read_lock();\n 302:\t\twhile (low \u003c= high) {\n 303:\t\t\tmid = low + (high - low) / 2;\n 304:\t\t\tseq = get_symbol_seq(mid);\n 305:\t\t\toff = get_symbol_offset(seq);\n 306:\t\t\tret = kallsyms_strcmp_symbol(off, name);\n 307:\t\t\tif (ret \u003e 0)\n 308:\t\t\t\tlow = mid + 1;\n 309:\t\t\telse if (ret \u003c 0)\n 310:\t\t\t\thigh = mid - 1;\n 311:\t\t\telse\n 312:\t\t\t\tbreak;\n 313:\t\t}\n 314:\t\n 315:\t\tif (low \u003e high) {\n 316:\t\t\trcu_read_unlock();\n 317:\t\t\treturn -ESRCH;\n 318:\t\t}\n 319:\t\n 320:\t\tlow = mid;\n 321:\t\twhile (low) {\n 322:\t\t\tseq = get_symbol_seq(low - 1);\n 323:\t\t\toff = get_symbol_offset(seq);\n 324:\t\t\tif (kallsyms_strcmp_symbol(off, name) != 0)\n 325:\t\t\t\tbreak;\n 326:\t\t\tlow--;\n 327:\t\t}\n 328:\t\t*start = low;\n 329:\t\n 330:\t\tif (end) {\n 331:\t\t\thigh = mid;\n 332:\t\t\twhile (high \u003c kallsyms_num_syms - 1) {\n 333:\t\t\t\tseq = get_symbol_seq(high + 1);\n 334:\t\t\t\toff = get_symbol_offset(seq);\n 335:\t\t\t\tif (kallsyms_strcmp_symbol(off, name) != 0)\n 336:\t\t\t\t\tbreak;\n 337:\t\t\t\thigh++;\n 338:\t\t\t}\n 339:\t\t\t*end = high;\n 340:\t\t}\n 341:\t\trcu_read_unlock();\n 342:\t\n 343:\t\treturn 0;\n 344:\t}\n"
} |
| 21/2 | 2026/09/25 03:40 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 36923 output: 25 thoughts: 1603 Thoughts: **Analyzing `kallsyms_lookup_names` and its Security Implications** Okay, so I'm diving into `kallsyms_lookup_names` again. My focus is on the binary search implementation and, specifically, how it compares symbol names. I see the binary search loop, which is pretty standard. But the interesting part is the comparison: `kallsyms_strcmp_symbol`. This is where I need to focus because that's where any potential vulnerability would lie. The original code used `strcmp`, which is a well-understood, classic function, but this new code is using a custom comparison function, `kallsyms_strcmp_symbol`. I need to figure out the exact comparison logic to understand if there is a way to potentially control execution here. I went and looked at the new `kallsyms_strcmp_symbol`. It seems to involve token tables (`kallsyms_token_table`, `kallsyms_token_index`) and some custom logic for comparing these symbols. The key line here is: `int diff = (unsigned char)*name++ - (unsigned char)*tptr++;`. Essentially, the function is subtracting the characters of the searched name from the characters of the symbol name. My concern is whether the comparison function could have some logic errors. I am walking through the different return conditions: - If the strings are identical (`"abc"` and `"abc"`), it returns 0, and the search continues. - If the searched name is shorter (`"ab"` and `"abc"`), the function returns a negative value, causing the search to narrow to the lower half. - If the searched name is longer (`"abcd"` and `"abc"`), the function returns a positive value, causing the search to narrow to the upper half. So, the logic here is `name - sym`. I need to check how to handle cases where the passed-in symbol isn't null-terminated. And, in `kallsyms_lookup_name`, the `name` is null-terminated, which seems okay. Now, I was looking at the new performance benchmark test module (`test_kallsyms_perf.c`). I want to understand what this module does, but it does require `CONFIG_TEST_KALLSYMS_PERF` config. I looked to see if this config is enabled by default. The new module has a `run_test` module param. I see the `bool "kallsyms performance benchmark test module"` and it's a module. Since it's a module, it's not present by default. But my main concern is: can `kallsyms_lookup_names` be reached from userspace without any special test modules? Let's see. I need to confirm that `kallsyms_lookup_name` itself can be called directly from userspace. I know the BPF verifier uses it: `kallsyms_lookup_name(kfunc.name);` and `kallsyms_lookup_name(tname);`. The BPF system has `bpf_kallsyms_lookup_name()` that BPF programs can call. So yes, it is directly reachable, and I'm very interested in understanding exactly how `name` is handled in all these call sites. |
| 22/2 | 2026/09/25 03:40 | tool | grepper |
0mArgs:{
"Expression": "bpf_kallsyms_lookup_name"
}Results: {
"Output": "include/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--\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-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-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--\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/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=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"
} |
| 23/2 | 2026/09/25 03:40 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 40198 output: 21 thoughts: 94 Thoughts: Okay, here's my breakdown of what I'm thinking about when looking at kprobes, summarized as though I'm thinking it: **Tracing Kprobes: A Deeper Dive** Right, so I'm thinking about how this whole kprobe tracing thing works. I'm focusing on the mechanics of *creating* these probes. Specifically, I'm noting the process of writing to `/sys/kernel/tracing/kprobe_events`. That's where it all begins, right? I'd issue a command something like `p:myprobe <symbol_name>`. And then, what actually *happens* when that write occurs? Ah, that's it - `trace_kprobe_create()` gets called. Excellent. Now, *that's* the function I need to look into. I'm going to take a peek at the source code for `trace_kprobe_create` and see exactly what it does. I want to see how `trace_kprobe_address` and `number_of_same_symbols` are involved. These are the critical functions that will tell me how the kernel actually resolves the symbol, gets the address, and handles multiple instances of the same symbol. It's all about digging into the implementation details and understanding the flow! |
| 24/2 | 2026/09/25 03:40 | tool | grepper |
0mArgs:{
"Expression": "number_of_same_symbols"
}Results: {
"Output": "kernel/trace/trace_kprobe.c=760=static int count_mod_symbols(void *data, const char *name, unsigned long unused)\n--\nkernel/trace/trace_kprobe.c-769-\nkernel/trace/trace_kprobe.c:770:static unsigned int number_of_same_symbols(const char *mod, const char *func_name)\nkernel/trace/trace_kprobe.c-771-{\n--\nkernel/trace/trace_kprobe.c=790=static int validate_module_probe_symbol(const char *modname, const char *symbol)\nkernel/trace/trace_kprobe.c-791-{\nkernel/trace/trace_kprobe.c:792:\tunsigned int count = number_of_same_symbols(modname, symbol);\nkernel/trace/trace_kprobe.c-793-\n"
} |
| 25/2 | 2026/09/25 03:40 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 40816 output: 38 thoughts: 19 Thoughts: Here's a summary of my thought process, keeping in mind my expert understanding: **Navigating the Labyrinth of Kernel Tracing** Okay, so I'm diving into this trace situation. Based on my existing knowledge of the system and the symptoms I'm seeing, my hunch points me toward `trace_kprobe.c`. I'm immediately thinking, "Let's zero in on line 770." That area likely deals with a crucial aspect of kprobe handling, maybe event filtering, data aggregation, or some critical state management. Line numbers are a good starting point and often correlate to function calls. Line 770 would have to be handled because of a critical call to a function. Based on the symptoms it seems as though this is the first step. I will quickly check if the surrounding lines will provide the context I need. This will hopefully be the key to unlocking what's gone wrong here. |
| 26/2 | 2026/09/25 03:40 | tool | read-file |
0mArgs:{
"File": "kernel/trace/trace_kprobe.c",
"FirstLine": 765,
"LineCount": 40
}Results: {
"Contents": " 765:\t\t\tctx-\u003ecount++;\n 766:\t\n 767:\t\treturn 0;\n 768:\t}\n 769:\t\n 770:\tstatic unsigned int number_of_same_symbols(const char *mod, const char *func_name)\n 771:\t{\n 772:\t\tstruct sym_count_ctx ctx = { .count = 0, .name = func_name };\n 773:\t\n 774:\t\tif (!mod)\n 775:\t\t\tkallsyms_on_each_match_symbol(count_symbols, func_name, \u0026ctx.count);\n 776:\t\n 777:\t\t/*\n 778:\t\t * If the symbol is found in vmlinux, use vmlinux resolution only.\n 779:\t\t * This prevents module symbols from shadowing vmlinux symbols\n 780:\t\t * and causing -EADDRNOTAVAIL for unqualified kprobe targets.\n 781:\t\t */\n 782:\t\tif (!mod \u0026\u0026 ctx.count \u003e 0)\n 783:\t\t\treturn ctx.count;\n 784:\t\n 785:\t\tmodule_kallsyms_on_each_symbol(mod, count_mod_symbols, \u0026ctx);\n 786:\t\n 787:\t\treturn ctx.count;\n 788:\t}\n 789:\t\n 790:\tstatic int validate_module_probe_symbol(const char *modname, const char *symbol)\n 791:\t{\n 792:\t\tunsigned int count = number_of_same_symbols(modname, symbol);\n 793:\t\n 794:\t\tif (count \u003e 1) {\n 795:\t\t\t/*\n 796:\t\t\t * Users should use ADDR to remove the ambiguity of\n 797:\t\t\t * using KSYM only.\n 798:\t\t\t */\n 799:\t\t\treturn -EADDRNOTAVAIL;\n 800:\t\t} else if (count == 0) {\n 801:\t\t\t/*\n 802:\t\t\t * We can return ENOENT earlier than when register the\n 803:\t\t\t * kprobe.\n 804:\t\t\t */\n"
} |
| 27/2 | 2026/09/25 03:40 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 41638 output: 29 thoughts: 574 Thoughts: **My Immediate Concerns Regarding Symbol Lookup Vulnerabilities** Okay, so I'm putting this all together... `validate_module_probe_symbol` directly feeds user-provided symbol names into `kallsyms_on_each_match_symbol` through `number_of_same_symbols`. That's a direct path for injecting potentially malicious symbols. Then I recall how syzkaller interacts with `tracefs` and `kprobe_events`. It's writing strings, right? Like `syz_mount_image$tracefs`, directly to `/sys/kernel/tracing/events/...` and `kprobe_events`. And `trace_events_filter.c`? It's writing those filter strings to `/sys/kernel/tracing/events/.../filter`. I remember now: `ip = kallsyms_lookup_name(name);` is used *inside* `trace_events_filter.c`! So, users can craft arbitrary strings within trace filter expressions. Then there's BPF! The verifier allows arbitrary strings for kfunc lookups, BTF targets, all that. And the fail_function method? More symbol names written to debugfs. But wait, hold on. This new batching API... `kallsyms_lookup_batch_start()` and `kallsyms_lookup_batch_end()`... Where are *those* called? I need to know the context here. Okay, let's see. After a quick code dive, I can see that `kallsyms.c` defines them and exports them. `kernel/kallsyms_selftest.c` calls it in `test_perf_kallsyms_lookup_name()`. And `lib/test_kallsyms_perf.c` is calling it in `run_kallsyms_benchmark()`. Any other callers in the kernel? No. Okay, are those test functions potentially exploitable? Can they be loaded as modules or triggered in a particular way? `TEST_KALLSYMS_PERF` is in `lib/Kconfig.debug`. Wait... it's a `bool`! So, if selected, it's *built-in*. But what about `kallsyms_selftest.c`? Time to check `CONFIG_KALLSYMS_SELFTEST`. I'm starting to see a pattern here. This could get interesting. |
| 28/2 | 2026/09/25 03:40 | tool | grepper |
0mArgs:{
"Expression": "KALLSYMS_SELFTEST",
"PathPrefix": "kernel/"
}Results: {
"Output": "kernel/Makefile=76=obj-$(CONFIG_KALLSYMS) += kallsyms.o\nkernel/Makefile:77:obj-$(CONFIG_KALLSYMS_SELFTEST) += kallsyms_selftest.o\nkernel/Makefile-78-obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o\n--\nkernel/kallsyms_selftest.h-1-/* SPDX-License-Identifier: GPL-2.0-or-later */\nkernel/kallsyms_selftest.h:2:#ifndef LINUX_KALLSYMS_SELFTEST_H_\nkernel/kallsyms_selftest.h:3:#define LINUX_KALLSYMS_SELFTEST_H_\nkernel/kallsyms_selftest.h-4-\n--\nkernel/kallsyms_selftest.h=11=extern int kallsyms_test_func_weak(void);\nkernel/kallsyms_selftest.h-12-\nkernel/kallsyms_selftest.h:13:#endif // LINUX_KALLSYMS_SELFTEST_H_\n"
} |
| 29/2 | 2026/09/25 03:40 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 43041 output: 29 thoughts: 22 Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and written in the first person: **Navigating the Kconfig Labyrinth for Self-Tests** Right, let's dive into this. I'm thinking, "Where would a self-test configuration option reside, especially one related to kernel symbol management?" My immediate intuition is to check within the debugging-related Kconfig file. So, my train of thought is: *Let's specifically zero in on* `lib/Kconfig.debug`. That's the likely spot for options that enable internal tests, especially if they are related to something as fundamental as kernel symbol tables. I want to see if `KALLSYMS_SELFTEST` is defined in there. That's the most logical place to begin my search. |
| 30/2 | 2026/09/25 03:40 | tool | grepper |
0mError:no matches Args: {
"Expression": "KALLSYMS_SELFTEST",
"PathPrefix": "lib/"
}Results: {
"error": "no matches"
} |
| 31/2 | 2026/09/25 03:40 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 43278 output: 22 thoughts: 19 Thoughts: Here's my thought process, as if I were thinking it: **Tracing `CONFIG_KALLSYMS_SELFTEST`** Alright, let's get down to brass tacks. I need to track down where this `CONFIG_KALLSYMS_SELFTEST` symbol is defined within the kernel configuration. I know it's a Kconfig option, so the usual suspects are likely the Kconfig files spread throughout the source tree. This is a pretty standard debugging step, so I'll approach it methodically. Time to dive into the source and see what I can dig up. |
| 32/2 | 2026/09/25 03:40 | tool | grepper |
0mArgs:{
"Expression": "config KALLSYMS_SELFTEST"
}Results: {
"Output": "init/Kconfig=2096=config KALLSYMS\n--\ninit/Kconfig-2103-\ninit/Kconfig:2104:config KALLSYMS_SELFTEST\ninit/Kconfig-2105-\tbool \"Test the basic functions and performance of kallsyms\"\n"
} |
| 33/2 | 2026/09/25 03:40 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 43531 output: 28 thoughts: 3891 Thoughts: **Deep Dive into `kallsyms_strcmp_symbol`**
Okay, I need to revisit `kernel/kallsyms.c` and specifically, the `kallsyms_lookup_names` function. Let's start with a focused look at `kallsyms_strcmp_symbol`. This is the core of the string comparison in the binary search. It's crucial for efficiently finding symbol names.
My immediate thought is, what's with that `ret` variable? Let's trace the logic line by line. This looks like a standard binary search setup. `kallsyms_strcmp_symbol` is the comparison function, and the `ret` value determines the search direction. If `ret > 0`, we move `low` up. If `ret < 0`, we move `high` down. Makes sense, that follows the algorithm.
But hold on, let's look at `kallsyms_strcmp_symbol` itself. It's comparing a provided `name` string to a compressed symbol table entry. The compression, with tokens, is the key here. The function returns negative, positive, or zero, just like `strcmp`. The immediate exit strategy on the first mismatched character is exactly what we would expect in this context, to make things fast.
Analyzing the code: The core comparison happens here: `diff = (unsigned char)*name++ - (unsigned char)*tptr++;`. Okay, it's comparing the ASCII values, and the `unsigned char` casts are important to prevent sign extension issues. So, If `name` is 'a', and `sym` is 'b' this means `diff` is `-1`. Thus, the binary search needs to search lower!
Let's carefully think about what `kallsyms_strcmp_symbol` actually does. What happens if the end of `name` is reached prematurely? Let's say we have the `name` "abc" and the symbol "ab". The first two characters will match. Then the code proceeds to: `return (unsigned char)*name;`, and what does it return? Because it only returns once when a character mismatches, or at the end of the `tptr`, it should properly return the difference of `name` and the current `tptr` character. In our "abc" vs. "ab" example, the result is positive which means the binary search searches higher.
Now what if we reverse the scenario to "ab" vs "abc"? `name` is now `\0` and `tptr` is 'c'. The return value will be negative, resulting in the correct search direction. Makes sense!
And if we want to compare equal strings? We can check, the code will make it to the end of both strings. And returns 0, the correct answer!
Now, the tokenizing scheme adds another level of complexity. What happens if we run into a token boundary? Like "ab" versus "Tabc"? It uses the compressed `kallsyms_token_table`, to store the token, and proceeds to the next token as required. This still looks solid. If they match the entire way, at the end it will return 0.
Let's test edge cases. We want to test when the `name` is shorter. And we encounter the first part of the symbol's name:
* Let's say `name` is "a" and the symbol has two tokens: `"Ta"` and `"b"`. So, We go through the first characters, which are the same, and then the next character from name is `\0`. And the current token gives us 'b'. So, the return value is a negative value.
Now, what if, the first token is just the type char (length is 1). Like just `T`. So, `tptr` points to the `\0` and the first loop won't run. Let's say `name` is "". We will return -'a' immediately. So we return the difference and this is good.
But what if both are empty? Like if the token is just T and there is no characters after. Can this ever be an issue?
Now the most important question!
What if the first string ends in 0 and `diff` is 0? The key line is: `diff = (unsigned char)*name++ - (unsigned char)*tptr++;` How can `diff` be zero if `*name` is zero? `*tptr` MUST be zero! Can `*tptr` ever be zero within this loop?
Let's consider these loops. The first loop: `while (*tptr)`. *tptr* is checked! It can never be 0 in that loop! Now let's look at the second: `do { ...
|
| 34/2 | 2026/09/25 03:41 | tool | grepper |
0mArgs:{
"Expression": "kallsyms_names",
"PathPrefix": "scripts/"
}Results: {
"Output": "scripts/kallsyms.c=339=static void write_src(void)\n--\nscripts/kallsyms.c-356-\nscripts/kallsyms.c:357:\toutput_label(\"kallsyms_names\");\nscripts/kallsyms.c-358-\toff = 0;\n--\nscripts/kallsyms.c-400-\t}\nscripts/kallsyms.c:401:\tprintf(\".size kallsyms_names, . - kallsyms_names\\n\");\nscripts/kallsyms.c-402-\tprintf(\"\\n\");\n"
} |
| 35/2 | 2026/09/25 03:41 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 48644 output: 36 thoughts: 21 Thoughts: Okay, let's dive into this. Here's my take on those instructions: **Analyzing `scripts/kallsyms.c` Around Line 356** Right, so the task at hand is to pinpoint a specific section within the `scripts/kallsyms.c` file, specifically around line 356. Knowing the project and the context, I immediately start to form an idea of what might be happening there. Given the file name, it's likely related to symbol table handling within the kernel build process. Line 356 is a pretty specific target, which suggests the instruction is focusing on a particular function, a data structure, or a specific operation within the broader symbol table generation logic. Without further context, it is hard to say but this sounds like a potential bug fix or perhaps a new feature that needs to be assessed. |
| 36/2 | 2026/09/25 03:41 | tool | read-file |
0mArgs:{
"File": "scripts/kallsyms.c",
"FirstLine": 355,
"LineCount": 45
}Results: {
"Contents": " 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"
} |
| 37/2 | 2026/09/25 03:41 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 49660 output: 22 thoughts: 2238 Thoughts: **Kallsyms Offset Analysis and Optimization** Alright, let's break this down. First, I confirmed that symbol lengths are always at least one byte long, due to the check in the code, which is good. Then, the process of building the `dyn_kallsyms_offsets` table in `kallsyms_build_offsets` seemed standard. I went through the setup of read and write locks, which is good. The `WARN_ON` in `kallsyms_lookup_batch_end` raised a flag, I need to make sure `dyn_kallsyms_refcnt` is handled correctly. Nested read locks are fine here. The critical part is calculating the offset: `offsets[i] = name - kallsyms_names;`. The index `i`, which is passed as `pos` to `get_symbol_offset(pos)` matches up. This `pos` is an index into the symbol table. It looks like it is accessing the `offsets` array that was built. Now, the core question is: do the offset calculations match between the `kallsyms_build_offsets` and the original `get_symbol_offset` and `get_symbol_offset_marker`? I needed to confirm that the offset calculation using the `kallsyms_markers` and the byte-by-byte length extraction in the original `get_symbol_offset_marker` lined up with the direct offset assignment during table construction. After going through the two-byte length encoding, I confirmed that the calculations are, in fact, identical, whether the length is encoded in a single byte or two bytes. In short, both computations get the same offset in the end. Finally, I noticed the change to `kallsyms_expand_symbol` that consolidates the length extraction. That could be good! I need to confirm the change. I need to know where it is used. I am going to find all calls to `kallsyms_expand_symbol` to see if the change is safe. I must confirm that all users of `kallsyms_expand_symbol` handle the updated logic correctly! I need to ensure that the logic is correct in all cases, especially when the symbol length is represented across two bytes. |
| 38/2 | 2026/09/25 03:41 | tool | grepper |
0mArgs:{
"Expression": "kallsyms_expand_symbol"
}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=367=int kallsyms_on_each_symbol(int (*fn)(void *, const char *, unsigned long),\n--\nkernel/kallsyms.c-375-\tfor (i = 0, off = 0; i \u003c kallsyms_num_syms; i++) {\nkernel/kallsyms.c:376:\t\toff = kallsyms_expand_symbol(off, namebuf, ARRAY_SIZE(namebuf));\nkernel/kallsyms.c-377-\t\tret = fn(data, namebuf, kallsyms_sym_address(i));\n--\nkernel/kallsyms.c=473=static int kallsyms_lookup_buildid(unsigned long addr,\n--\nkernel/kallsyms.c-500-\t\t/* Grab name */\nkernel/kallsyms.c:501:\t\tkallsyms_expand_symbol(get_symbol_offset(pos),\nkernel/kallsyms.c-502-\t\t\t\t namebuf, KSYM_NAME_LEN);\n--\nkernel/kallsyms.c=541=int lookup_symbol_name(unsigned long addr, char *symname)\n--\nkernel/kallsyms.c-550-\t\t/* Grab name */\nkernel/kallsyms.c:551:\t\tkallsyms_expand_symbol(get_symbol_offset(pos),\nkernel/kallsyms.c-552-\t\t\t\t symname, KSYM_NAME_LEN);\n--\nkernel/kallsyms.c=793=static unsigned long get_ksymbol_core(struct kallsym_iter *iter)\n--\nkernel/kallsyms.c-801-\nkernel/kallsyms.c:802:\toff = kallsyms_expand_symbol(off, iter-\u003ename, ARRAY_SIZE(iter-\u003ename));\nkernel/kallsyms.c-803-\n"
} |
| 39/2 | 2026/09/25 03:41 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 53003 output: 24 thoughts: 306 Thoughts: **Analyzing Kernel Symbol Table Interactions** Okay, let's break down this `kallsyms` situation. First, I need to see the scope of `kallsyms_expand_symbol`. I see it's used in `kallsyms_on_each_symbol`, `kallsyms_lookup_buildid`, `lookup_symbol_name`, and, importantly, `get_ksymbol_core`. Ah, and that's the function that drives `/proc/kallsyms`! And, that's being read by syzkaller and other user-space programs, all the time. Makes sense to be careful there. Now, I also see that `kallsyms_get_symbol_type` has been modified, and the change looks pretty significant. Let's see how that affects the surrounding functions by checking it's uses. |
| 40/2 | 2026/09/25 03:41 | tool | grepper |
0mArgs:{
"Expression": "kallsyms_get_symbol_type"
}Results: {
"Output": "kernel/kallsyms.c=60=static unsigned int kallsyms_expand_symbol(unsigned int off,\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=793=static unsigned long get_ksymbol_core(struct kallsym_iter *iter)\n--\nkernel/kallsyms.c-799-\nkernel/kallsyms.c:800:\titer-\u003etype = kallsyms_get_symbol_type(off);\nkernel/kallsyms.c-801-\n"
} |
| 41/2 | 2026/09/25 03:41 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 53721 output: 27 thoughts: 1236 Thoughts: **WorthFuzzing Analysis: Kallsyms Patch**
Okay, so I've got this patch touching `kernel/kallsyms.c`, and my initial gut feeling is that it's *absolutely* worth fuzzing. Let's break this down systematically.
First, I see that `get_ksymbol_core` is, at its heart, the core handler for `/proc/kallsyms` reads. Every time someone touches that, `kallsyms_get_symbol_type` and `kallsyms_expand_symbol` get hammered for *every* symbol. That alone is a pretty fat attack surface. And of course, `lookup_symbol_name` is critical for stack traces, oopses, `/proc/*/stack`, and all the tracing tools – basically anything trying to resolve an address to a symbol. `get_symbol_offset()` is now using `rcu_dereference(dyn_kallsyms_offsets)`, adding another potential layer of complexity and a potential source of errors. `get_symbol_offset()` is also fundamental to `kallsyms_lookup_names()`, which, in turn, is used by a host of functions, including the BPF verifier and trace probe creation – huge areas in the kernel.
Now, let's go back to the instructions. "Reachable executable code modified or refactored? Must be fuzzed." Seems pretty clear-cut, given that the patch makes major changes to core kernel code. Looking at the instructions, the patch fundamentally alters:
* Replaces string expansion with a compressed byte-by-byte comparator: `kallsyms_strcmp_symbol()`.
* Restructures `kallsyms_expand_symbol()`, `kallsyms_get_symbol_type()`, and `get_symbol_seq()`.
* Introduces caching with RCU synchronization, mutex locking, and `WARN_ON`.
* Rewrites `get_symbol_offset()` and `kallsyms_lookup_names()`.
* Adds new functions `kallsyms_lookup_batch_start()` and `kallsyms_lookup_batch_end()`.
All this is in `kernel/kallsyms.c`. So is it reachable? Oh, *hell* yes.
* `/proc/kallsyms` reads exercise `kallsyms_expand_symbol()` and `kallsyms_get_symbol_type()`.
* Address-to-symbol resolution (printing stack traces, `/proc/*/stack`, oopses, warnings, perf, ftrace, etc.) exercises `get_symbol_offset()`, `lookup_symbol_name()`, `kallsyms_lookup_buildid()`, `kallsyms_expand_symbol()`.
* Name-to-address resolution (`kallsyms_lookup_names()`, `kallsyms_strcmp_symbol()`, `get_symbol_seq()`, `get_symbol_offset()`) is reachable via:
* BPF verifier kfunc and attach target lookups (`bpf(BPF_PROG_LOAD)`),
* BPF helper `bpf_kallsyms_lookup_name()`,
* Tracefs `kprobe_events` creation (`kallsyms_on_each_match_symbol()`),
* Trace filter parsing,
* `CONFIG_TEST_KALLSYMS_PERF` module / sysfs trigger `run_test`.
Therefore, based on the triage philosophy, I can definitively say that the `WorthFuzzing` flag is `true`. We are hitting code that's reachable, modified, and potentially introducing new locking behavior with RCU.
Next, I need to figure out the `EnableConfigs`. Obviously, `CONFIG_KALLSYMS` is required. I need to determine if `KALLSYMS_ALL` makes it more valuable, or if there's any value in enabling that as well. A quick look at the `Kconfig` should reveal the answer.
|
| 42/2 | 2026/09/25 03:41 | tool | grepper |
0mArgs:{
"Expression": "config KALLSYMS",
"PathPrefix": "init/"
}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"
} |
| 43/2 | 2026/09/25 03:41 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 56073 output: 20 thoughts: 181 Thoughts: Okay, let's see. My first thought is to dig into the kernel configuration options to understand how `kallsyms` is tested and used, especially considering performance implications. I'm going to start by checking `lib/Kconfig.debug`. I recall some relevant options there, specifically `TEST_KALLSYMS_PERF`: **Investigating Kallsyms Testing and Usage** Alright, the `TEST_KALLSYMS_PERF` option looks like a good starting point. It's a boolean, and it's contingent on `KALLSYMS` being enabled, which makes sense. I see it's a "kallsyms performance benchmark test module," which is exactly the kind of test I'm interested in to identify bottlenecks or inefficiencies. Next, I'll examine `CONFIG_KALLSYMS_SELFTEST`. This should provide me with another layer of testing, targeting the basic functionality and performance. It's also a boolean with `KALLSYMS` as a dependency. The default is 'n,' which indicates it's likely not critical for core functionality but provides valuable debugging/validation. I need to expand my scope to include where `kallsyms` is utilized in BPF-related syscalls, so I need to check `CONFIG_BPF_SYSCALL` which is the next logical step. I also know that `kprobes` often interact with `kallsyms` via tracefs, so I should look into `CONFIG_KPROBE_EVENTS`. This configuration probably enables the kprobe tracefs interface. Understanding the relationship between these options will give me a better understanding of how `kallsyms` is used, tested, and optimized, particularly in more modern use cases. |
| 44/2 | 2026/09/25 03:41 | tool | grepper |
0mArgs:{
"Expression": "config KPROBE_EVENTS"
}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"
} |
| 45/2 | 2026/09/25 03:41 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 56798 output: 39 thoughts: 197 Thoughts: **Investigating Kallsyms Performance Testing** Okay, let's dive into this. The goal is to understand the performance implications of `kallsyms`, so I should start with `CONFIG_TEST_KALLSYMS_PERF`. Looking at `lib/Kconfig.debug`, it's a boolean option dependent on `KALLSYMS`, as expected. So, enabling `TEST_KALLSYMS_PERF` should give me a controlled benchmark. The documentation says I can trigger the test by writing to `/sys/module/test_kallsyms_perf/parameters/run_test`, which then calls `run_kallsyms_benchmark()`. I'm guessing this function is where the relevant measurements are taken. It's likely measuring the overhead of symbol lookups by using `kallsyms_lookup_batch_start()` and `kallsyms_lookup_batch_end()`. Excellent, that seems like the most direct approach. Now, a related question: does `KALLSYMS_SELFTEST` also use the `kallsyms_lookup_batch_start()` during boot or when triggered? This could be a good comparison point, depending on the test type. So, let's take a look at `kernel/kallsyms_selftest.c`. Knowing how the selftest operates will help me see if I can leverage it or potentially compare its output to the benchmark output. I need to understand its lookup strategy to determine whether or not it performs the same function as the other benchmarks. |
| 46/2 | 2026/09/25 03:41 | tool | read-file |
0mArgs:{
"File": "kernel/kallsyms_selftest.c",
"FirstLine": 425,
"LineCount": 40
}Results: {
"Contents": " 425:\t\n 426:\tstatic int test_entry(void *p)\n 427:\t{\n 428:\t\tint ret;\n 429:\t\n 430:\t\tdo {\n 431:\t\t\tschedule_timeout(5 * HZ);\n 432:\t\t} while (system_state != SYSTEM_RUNNING);\n 433:\t\n 434:\t\tpr_info(\"start\\n\");\n 435:\t\tret = test_kallsyms_basic_function();\n 436:\t\tif (ret) {\n 437:\t\t\tpr_info(\"abort\\n\");\n 438:\t\t\treturn 0;\n 439:\t\t}\n 440:\t\n 441:\t\ttest_kallsyms_compression_ratio();\n 442:\t\ttest_perf_kallsyms_lookup_name();\n 443:\t\ttest_perf_kallsyms_on_each_symbol();\n 444:\t\ttest_perf_kallsyms_on_each_match_symbol();\n 445:\t\tpr_info(\"finish\\n\");\n 446:\t\n 447:\t\treturn 0;\n 448:\t}\n 449:\t\n 450:\tstatic int __init kallsyms_test_init(void)\n 451:\t{\n 452:\t\tstruct task_struct *t;\n 453:\t\n 454:\t\tt = kthread_run_on_cpu(test_entry, NULL, 0, \"kallsyms_test\");\n 455:\t\tif (IS_ERR(t)) {\n 456:\t\t\tpr_info(\"Create kallsyms selftest task failed\\n\");\n 457:\t\t\treturn PTR_ERR(t);\n 458:\t\t}\n 459:\t\n 460:\t\treturn 0;\n 461:\t}\n 462:\tlate_initcall(kallsyms_test_init);\n"
} |
| 47/2 | 2026/09/25 03:41 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 57892 output: 301 thoughts: 1689 Thoughts: **Focus Symbol Analysis and Justification** Okay, so we're looking at `CONFIG_KALLSYMS_SELFTEST`, and specifically at identifying the key functions for fuzzing. I need to make sure I'm following Rule 4, focusing on specific feature logic and entrypoints, while avoiding ubiquitous functions. First, let's examine the functions added or modified: within `kernel/kallsyms.c`, we have `kallsyms_lookup_batch_start`, `kallsyms_lookup_batch_end`, `kallsyms_build_offsets`, `kallsyms_lookup_names`, `kallsyms_lookup_name`, `kallsyms_on_each_match_symbol`, `kallsyms_strcmp_symbol`, `kallsyms_expand_symbol`, `kallsyms_get_symbol_type`, `get_symbol_offset`, `get_symbol_offset_marker`, `lookup_symbol_name`, and `sprint_symbol`. Then in `lib/test_kallsyms_perf.c`, there's `run_kallsyms_benchmark`. My first step is to filter out the static/inlined functions. I confirmed that `kallsyms_lookup_names` is static, which is worth considering as a FocusSymbol because its complexity may prevent the compiler from inlining it. `kallsyms_build_offsets` could be added if not inlined. `kallsyms_expand_symbol` is also static, but not inlined, which makes it another good candidate. `kallsyms_strcmp_symbol` is also static. Now, let's determine if the non-static functions are worth targeting. Looking at `kallsyms_lookup_name` and `kallsyms_on_each_match_symbol`, are they ubiquitous? No, thankfully. `kallsyms_lookup_name` is only called by specific subsystems like BPF, kprobes, and tracepoints. `kallsyms_on_each_match_symbol` is even more limited, only called by `trace_kprobe` and `livepatch`. So, both of these are definitely not generic and can be included. `kallsyms_lookup_batch_start` and `kallsyms_lookup_batch_end`, being new APIs, are definitely specific and relevant. `run_kallsyms_benchmark` is static and likely inlined, but still worth noting. Therefore, my final list of FocusSymbols should be: `kallsyms_lookup_batch_start`, `kallsyms_lookup_batch_end`, `kallsyms_lookup_names`, `kallsyms_strcmp_symbol`, `kallsyms_lookup_name`, and `kallsyms_on_each_match_symbol`. Considering the configurations: `KALLSYMS`, `TEST_KALLSYMS_PERF`, `KPROBE_EVENTS`, and `BPF_SYSCALL` are all relevant. In summary, this patch introduces a dynamic symbol offset table cache, refactors symbol expansion, adds `kallsyms_strcmp_symbol` for efficient comparison, and includes a performance test module. The modified code impacts core functionality, as well as being reachable via `/proc/kallsyms`, kprobes, trace events, and BPF. Thus, `WorthFuzzing` is unequivocally `true`, and I will now issue a `set-results` call. |
| 48/2 | 2026/09/25 03:42 | tool | set-results |
0mArgs:{
"EnableConfigs": [
"KALLSYMS",
"TEST_KALLSYMS_PERF",
"KPROBE_EVENTS",
"BPF_SYSCALL"
],
"FocusSymbols": [
"kallsyms_lookup_batch_start",
"kallsyms_lookup_batch_end",
"kallsyms_lookup_names",
"kallsyms_strcmp_symbol",
"kallsyms_lookup_name",
"kallsyms_on_each_match_symbol"
],
"Reasoning": "The patch refactors the core kallsyms symbol lookup and decoding subsystem. It implements a direct-comparison helper (kallsyms_strcmp_symbol) that parses compressed tokens against input strings, modifies kallsyms_expand_symbol and kallsyms_get_symbol_type, adds dynamic offset indexing with RCU and mutex synchronization (kallsyms_lookup_batch_start/end), and adds a new benchmark module (test_kallsyms_perf). These paths are reachable from user space via /proc/kallsyms reads, tracefs kprobe configuration (kprobe_events), BPF program loading with kfuncs/BTF resolution, and test module sysfs parameters. Refactored parsing logic and new synchronization primitives warrant fuzzing.",
"WorthFuzzing": true
}Results: {
"EnableConfigs": [
"KALLSYMS",
"TEST_KALLSYMS_PERF",
"KPROBE_EVENTS",
"BPF_SYSCALL"
],
"FocusSymbols": [
"kallsyms_lookup_batch_start",
"kallsyms_lookup_batch_end",
"kallsyms_lookup_names",
"kallsyms_strcmp_symbol",
"kallsyms_lookup_name",
"kallsyms_on_each_match_symbol"
],
"Reasoning": "The patch refactors the core kallsyms symbol lookup and decoding subsystem. It implements a direct-comparison helper (kallsyms_strcmp_symbol) that parses compressed tokens against input strings, modifies kallsyms_expand_symbol and kallsyms_get_symbol_type, adds dynamic offset indexing with RCU and mutex synchronization (kallsyms_lookup_batch_start/end), and adds a new benchmark module (test_kallsyms_perf). These paths are reachable from user space via /proc/kallsyms reads, tracefs kprobe configuration (kprobe_events), BPF program loading with kfuncs/BTF resolution, and test module sysfs parameters. Refactored parsing logic and new synchronization primitives warrant fuzzing.",
"WorthFuzzing": true
} |
| 49/1 | 2026/09/25 03:42 | action | If |
1mArgs:{
"WorthFuzzing": true
}Results: null |
| 50/2 | 2026/09/25 03:42 | agent | kmsan-evaluator |
1mModel:core Args: null Results: {
"KMSANReasoning": "The patch series optimizes symbol lookup in the kernel kallsyms subsystem by introducing direct in-place comparison against compressed symbols (`kallsyms_strcmp_symbol`), removing the temporary stack buffer (`namebuf`), and adding an optional transient dynamic offset index (`dyn_kallsyms_offsets`) managed via RCU for batch lookups.\n\nKMSAN vs KASAN analysis:\n1. No uninitialized memory or info-leaks: No kernel structures or data are exposed to user space. The stack buffer `namebuf` in `kallsyms_lookup_names()` was eliminated rather than added. The dynamically allocated offset array (`dyn_kallsyms_offsets`) created by `kallsyms_build_offsets()` allocates memory via `kvmalloc_array()` and fully populates every index from 0 through `kallsyms_num_syms - 1` prior to publishing the pointer via `rcu_assign_pointer()`.\n2. Applicability of other detectors: Any potential memory safety bugs introduced by this patch series would involve out-of-bounds reads into `kallsyms_names`, concurrency/lifetime issues (RCU grace periods, kvfree), or locking bugs in `dyn_kallsyms_mutex`. These issues are covered by KASAN and LOCKDEP.\n\nTherefore, this patch series does not pose uninitialized memory risks that would necessitate 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 01b29fa3a45ccf7bf7dca3ff0e9d96cad2a3c17e
Author: syz-cluster <triage@syzkaller.com>
Date: Fri Sep 25 03:39:15 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..35484361201f3 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,99 @@ 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 __rcu *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 = rcu_replace_pointer(dyn_kallsyms_offsets, NULL,
+ lockdep_is_held(&dyn_kallsyms_mutex));
+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 +280,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 +294,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 +312,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 +332,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..f6c3d5d82e5d0
--- /dev/null
+++ b/lib/test_kallsyms_perf.c
@@ -0,0 +1,341 @@
+// 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>
+#include <linux/mutex.h>
+#include <linux/minmax.h>
+
+#define BENCH_CHUNK_SIZE 4096
+
+static unsigned int num_iters = 100000;
+
+static int param_set_num_iters(const char *val, const struct kernel_param *kp)
+{
+ unsigned int n;
+ int ret;
+
+ ret = kstrtouint(val, 0, &n);
+ if (ret)
+ return ret;
+ if (!n)
+ return -EINVAL;
+
+ *((unsigned int *)kp->arg) = n;
+ return 0;
+}
+
+static const struct kernel_param_ops param_ops_num_iters = {
+ .set = param_set_num_iters,
+ .get = param_get_uint,
+};
+module_param_cb(num_iters, ¶m_ops_num_iters, &num_iters, 0644);
+MODULE_PARM_DESC(num_iters, "Number of iterations per microbenchmark (must be > 0)");
+
+static bool run_on_boot;
+module_param(run_on_boot, bool, 0444);
+MODULE_PARM_DESC(run_on_boot, "Run benchmark during boot (default: false)");
+
+static DEFINE_MUTEX(bench_lock);
+
+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, unsigned int iters,
+ u64 *avg_hit_ns, u64 *avg_miss_ns)
+{
+ u64 t0, t1, dt_hit = 0, dt_miss = 0;
+ 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) */
+ for (i = 0; i < iters; i += BENCH_CHUNK_SIZE) {
+ unsigned int chunk = min_t(unsigned int, BENCH_CHUNK_SIZE, iters - i);
+ unsigned int j;
+
+ cond_resched();
+ t0 = ktime_get_ns();
+ for (j = 0; j < chunk; j++) {
+ const char *sym = hit_symbols[(i + j) % nr_hits];
+
+ 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) */
+ for (i = 0; i < iters; i += BENCH_CHUNK_SIZE) {
+ unsigned int chunk = min_t(unsigned int, BENCH_CHUNK_SIZE, iters - i);
+ unsigned int j;
+
+ cond_resched();
+ t0 = ktime_get_ns();
+ for (j = 0; j < chunk; j++) {
+ const char *sym = miss_symbols[(i + j) % nr_misses];
+
+ 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, iters);
+ if (avg_miss_ns)
+ *avg_miss_ns = div_u64(dt_miss, iters);
+
+ pr_info("[%s] Name Search Hit: %llu ns/lookup (%llu ms total, %u iters)\n",
+ mode, div_u64(dt_hit, iters), div_u64(dt_hit, 1000000), iters);
+ pr_info("[%s] Name Search Miss: %llu ns/lookup (%llu ms total, %u iters)\n",
+ mode, div_u64(dt_miss, iters), div_u64(dt_miss, 1000000), iters);
+}
+
+static void run_address_lookup_bench(unsigned int iters)
+{
+ u64 t0, t1, dt_sprint = 0, dt_bldid = 0;
+ 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) */
+ for (i = 0; i < iters; i += BENCH_CHUNK_SIZE) {
+ unsigned int chunk = min_t(unsigned int, BENCH_CHUNK_SIZE, iters - i);
+ unsigned int j;
+
+ cond_resched();
+ t0 = ktime_get_ns();
+ for (j = 0; j < chunk; j++) {
+ unsigned long addr = addrs[(i + j) % nr_addrs];
+
+ sprint_symbol(symname, addr);
+ barrier_data(symname);
+ }
+ t1 = ktime_get_ns();
+ dt_sprint += t1 - t0;
+ }
+
+ /* 2. Address without offset (sprint_symbol_no_offset) */
+ for (i = 0; i < iters; i += BENCH_CHUNK_SIZE) {
+ unsigned int chunk = min_t(unsigned int, BENCH_CHUNK_SIZE, iters - i);
+ unsigned int j;
+
+ cond_resched();
+ t0 = ktime_get_ns();
+ for (j = 0; j < chunk; j++) {
+ unsigned long addr = addrs[(i + j) % nr_addrs];
+
+ 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, iters), div_u64(dt_sprint, 1000000), iters);
+ pr_info("sprint_symbol_no_offset: %llu ns/lookup (%llu ms total, %u iters)\n",
+ div_u64(dt_bldid, iters), div_u64(dt_bldid, 1000000), iters);
+}
+
+static void run_table_walk_bench(void)
+{
+ u64 t0, t1, dt_walk = 0;
+ unsigned long total_symbols = 0;
+ int iter = 50;
+ int i;
+
+ for (i = 0; i < iter; i++) {
+ total_symbols = 0;
+ cond_resched();
+ t0 = ktime_get_ns();
+ 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)
+{
+ unsigned int iters;
+ 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 = 0;
+
+ if (!mutex_trylock(&bench_lock)) {
+ pr_warn("Benchmark already running\n");
+ return -EBUSY;
+ }
+
+ iters = READ_ONCE(num_iters);
+ if (!iters) {
+ pr_err("num_iters must be non-zero\n");
+ ret = -EINVAL;
+ goto out;
+ }
+
+ pr_info("==================================================\n");
+ pr_info("Starting kallsyms performance benchmark (iters=%u)\n", iters);
+ pr_info("==================================================\n");
+
+ /* 1. Benchmark baseline unindexed marker scan */
+ run_name_lookup_bench("Unindexed (markers)", iters, &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", iters, &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(iters);
+ run_table_walk_bench();
+
+ pr_info("==================================================\n");
+ pr_info("kallsyms benchmark complete\n");
+ pr_info("==================================================\n");
+
+out:
+ mutex_unlock(&bench_lock);
+ return ret;
+}
+
+static int param_set_trigger(const char *val, const struct kernel_param *kp)
+{
+ if (system_state < SYSTEM_RUNNING) {
+ pr_warn("Early boot run ignored; use test_kallsyms_perf.run_on_boot=1 or trigger via sysfs\n");
+ return 0;
+ }
+ return run_kallsyms_benchmark();
+}
+
+static const struct kernel_param_ops param_ops_trigger = {
+ .set = param_set_trigger,
+};
+module_param_cb(run_test, ¶m_ops_trigger, NULL, 0200);
+MODULE_PARM_DESC(run_test, "Write 1 to trigger kallsyms benchmark run");
+
+static int __init test_kallsyms_init(void)
+{
+ if (run_on_boot)
+ return run_kallsyms_benchmark();
+ return 0;
+}
+late_initcall(test_kallsyms_init);
+
+MODULE_DESCRIPTION("Microbenchmark test module for kallsyms subsystem");
+MODULE_AUTHOR("Jim Cromie <jim.cromie@gmail.com>");
+MODULE_LICENSE("GPL");
|
| 51/3 | 2026/09/25 03:42 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 10727 output: 22 thoughts: 2700 Thoughts: **KMSAN Assessment of kallsyms Patch** Okay, let's break this down. The patch introduces optimizations to the kallsyms infrastructure, primarily focused on batch symbol lookups and performance improvements. My initial thought is to assess whether these changes introduce any uninitialized memory risks that would necessitate a KMSAN run. It's a key requirement that this isn't caught by the standard debugging tools we'd normally enable like KASAN or LOCKDEP. First, I've gone through each file changed methodically. The added header declarations in `kallsyms.h` are standard. The meat of the changes is in `kallsyms.c`. The introduction of `get_symbol_data`, refactoring symbol expansion functions to use it, and the batch lookup functions (`kallsyms_lookup_batch_start/end`) are all interesting. Specifically the optimized `kallsyms_strcmp_symbol` for comparing symbol names. It optimizes by using compressed entries in `kallsyms_names`. The important bit is the allocation of `dyn_kallsyms_offsets`. This uses `kvmalloc_array`, and I need to be *sure* all elements are initialized. The code does appear to initialize *every* element in the loop. The `get_symbol_offset` function uses `dyn_kallsyms_offsets`, and `pos` seems bound by the symbol array size. So that is not a problem. Now, my attention is caught by `kallsyms_strcmp_symbol`, because of the pointer arithmetic and string comparisons. The comparison logic relies on the kallsyms token table and involves incrementing both the input string (`name`) and the compressed symbol data pointer (`tptr`). The issue is if the input string (`name`) ends prematurely (i.e. is less than the length in the compressed format). I realize that with this function, the string may not be null-terminated to the kallsyms-internal string. I'm wondering if a malicious string can cause a read beyond the allocated buffer! The key is what if `name` is exhausted before `tptr`? It might be possible for `kallsyms_strcmp_symbol` to read past the end of the `name` buffer if the compressed symbol table entry is longer than the input string. This looks like a potential *read* from uninitialized memory! Now, *where* does this input string `name` come from? I need to trace the callers of `kallsyms_lookup_names` or the related `kallsyms_strcmp_symbol` to understand how the input buffer is constructed and if it can cause an issue. It looks like the caller provides the string, so a user controlled value, it is likely on the stack. Now let's find the callers and assess for an attack vector. |
| 52/3 | 2026/09/25 03:42 | tool | grepper |
0mArgs:{
"Expression": "kallsyms_lookup_names"
}Results: {
"Output": "kernel/kallsyms.c=283=static inline unsigned int get_symbol_seq(int index)\n--\nkernel/kallsyms.c-289-\nkernel/kallsyms.c:290:static int kallsyms_lookup_names(const char *name,\nkernel/kallsyms.c-291-\t\t\t\t unsigned int *start,\n--\nkernel/kallsyms.c=347=unsigned long kallsyms_lookup_name(const char *name)\n--\nkernel/kallsyms.c-355-\nkernel/kallsyms.c:356:\tret = kallsyms_lookup_names(name, \u0026i, NULL);\nkernel/kallsyms.c-357-\tif (!ret)\n--\nkernel/kallsyms.c=385=int kallsyms_on_each_match_symbol(int (*fn)(void *, unsigned long),\n--\nkernel/kallsyms.c-390-\nkernel/kallsyms.c:391:\tret = kallsyms_lookup_names(name, \u0026start, \u0026end);\nkernel/kallsyms.c-392-\tif (ret)\n--\nlib/test_kallsyms_perf.c=56=static const char * const hit_symbols[] = {\n--\nlib/test_kallsyms_perf.c-62-\t\"panic\",\nlib/test_kallsyms_perf.c:63:\t\"kallsyms_lookup_names\",\nlib/test_kallsyms_perf.c-64-\t\"vm_area_alloc\",\n"
} |
| 53/3 | 2026/09/25 03:42 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 14479 output: 22 thoughts: 1256 Thoughts: **Analyzing a Potential Vulnerability in kallsyms String Comparison** Okay, let's break this down systematically. I'm looking at a string comparison within `kallsyms`, and I'm trying to see if there's a potential out-of-bounds read or other vulnerability. My initial instinct is to play with edge cases and see if I can trick the comparison logic. First, I'm thinking about the scenario where the `name` string is shorter than the token being compared against. I'll focus on what happens if `name` is simply "a\0". If the first token starts with "abc", then `name[0]` matches `tptr[0]` (both 'a'), and the code increments both pointers. Then, in the next comparison, I see that when `name` increments to point to `'\0'`, `tptr` points to `b`. A non-zero difference is returned and the process ends immediately. The increment operation doesn't dereference an out-of-bounds pointer. So far, so good. Now, I'm thinking: what if `name` *starts* as '\0'? Then the comparison should immediately return. However, can `*name` ever be read after it is '\0'? In the first loop (`while (*tptr)`), if `*name` is '\0', then `diff = 0 - *tptr != 0` because `*tptr != 0` due to the `while` condition. The function returns immediately. In the second loop, similar logic applies, ensuring immediate return if `*name` is '\0'. It seems the check is sound. The critical thing I'm focused on is the `name++` within the comparison. The key here is to determine whether it *can* dereference beyond the intended boundary of `name`. I'm tracing the execution very carefully to confirm my understanding of how `name` is used. I'm thinking about the edge case where a token in `kallsyms_token_table` might be empty. If `tptr` becomes '\0' at the start, that might cause issues. However, the code's construction, specifically how `kallsyms_token_table` is built and how the loops work, seems to prevent any out-of-bounds read or dereference. I need to examine how the token table is constructed to be sure. My conclusion is that it can't be empty, and a comparison proceeds as expected. No vulnerability here. |
| 54/3 | 2026/09/25 03:42 | tool | grepper |
0mArgs:{
"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"
} |
| 55/3 | 2026/09/25 03:42 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 17476 output: 25 thoughts: 30 Thoughts: Okay, here's my summary, presented as a stream of thought: **Diving into `kallsyms.c`** Alright, time to get my hands dirty. Let's see... I need to understand how the kallsyms functionality is parsing those symbol tables. The logical starting point is the source code itself. Specifically, I need to check out `scripts/kallsyms.c`. I expect to find the token table definition in there. It's the key to understanding how the kernel's symbol data is parsed, and therefore how it's represented. I'm especially interested in getting the definition of the `kallsyms_token_table`, because that's where the crucial tokens and their meanings are defined. Understanding that table will give me a solid grasp of the parsing process. |
| 56/3 | 2026/09/25 03:42 | tool | grepper |
0mArgs:{
"Expression": "best_token",
"PathPrefix": "scripts/"
}Results: {
"Output": "scripts/kallsyms.c=505=static void compress_symbols(const unsigned char *str, int idx)\n--\nscripts/kallsyms.c-546-/* search the token with the maximum profit */\nscripts/kallsyms.c:547:static int find_best_token(void)\nscripts/kallsyms.c-548-{\n--\nscripts/kallsyms.c=564=static void optimize_result(void)\n--\nscripts/kallsyms.c-576-\t\t\t/* find the token with the best profit value */\nscripts/kallsyms.c:577:\t\t\tbest = find_best_token();\nscripts/kallsyms.c-578-\t\t\tif (token_profit[best] == 0)\n"
} |
| 57/3 | 2026/09/25 03:42 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 17910 output: 36 thoughts: 19 Thoughts: Okay, let's dive into this. Here's how I'd approach summarizing the prompt, given my assumed expertise: **Inspecting Token Initialization in `scripts/kallsyms.c`** Alright, so the task at hand is to investigate the initialization process of tokens within the `scripts/kallsyms.c` file. This immediately brings to mind several important aspects, likely centered around memory allocation, data structures, and the overall design of how these tokens are created and managed. I'll need to pinpoint the relevant section of the code, likely within the `main` or some related function, where the token structures are first brought into existence and then populated with data. I'll be looking for `malloc` calls, structure initializations (likely using `struct ksym` or something similar), and any associated size calculations. The key here will be understanding if there are any potential pitfalls, such as memory leaks, improper bounds checking, or initialization bugs that could lead to vulnerabilities or unexpected behavior later on. I'll be digging in to see if the allocation strategy is efficient, if there's any reuse of tokens, or if it's all recreated from scratch, as well as if there are any data structures or synchronization primitives involved to ensure proper access to the tokens from various execution paths. |
| 58/3 | 2026/09/25 03:42 | tool | read-file |
0mArgs:{
"File": "scripts/kallsyms.c",
"FirstLine": 400,
"LineCount": 40
}Results: {
"Contents": " 400:\t\t}\n 401:\t\tprintf(\".size kallsyms_names, . - kallsyms_names\\n\");\n 402:\t\tprintf(\"\\n\");\n 403:\t\n 404:\t\toutput_label(\"kallsyms_markers\");\n 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 435:\t\t\t\t\tfprintf(stderr, \"kallsyms failure: \"\n 436:\t\t\t\t\t\t\"relative symbol value %#llx out of range\\n\",\n 437:\t\t\t\t\t\ttable[i]-\u003eaddr);\n 438:\t\t\t\t\texit(EXIT_FAILURE);\n 439:\t\t\t\t}\n"
} |
| 59/3 | 2026/09/25 03:42 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 18898 output: 19 thoughts: 2822 Thoughts: **Analyzing kallsyms and Memory Safety** Okay, let's break this down systematically. I'm focusing on the `kallsyms_strcmp_symbol` function first, particularly after looking at its implementation. It's crucial to understand how this function, central to symbol lookups, interacts with the `kallsyms_token_table`. The critical observation here is about single-character tokens. If the first token in a symbol is a single character (e.g., just the symbol type like "T"), the `while (*tptr)` loop is bypassed due to the `+ 1` offset. This means `diff` isn't computed for that first character. However, the subsequent `while (--len)` loop *does* execute. It now correctly compares the rest of the tokens or returns if the token/symbol match. Importantly, if the symbol is just "T" and the input `name` is empty, then the function correctly returns 0. If `name` is "a", the comparison of `\0` with 'a' would return a non-zero, correctly. I've carefully considered the implications of the `name` argument (the string being looked up) and its relationship to the symbol table entries. The logic ensures that `name` is never read past its null terminator. The previous code paths also relied on `name` being a null-terminated C string, which is correct for how these functions are being used. It will behave just like `strcmp`, which is what's wanted. If the input `name` is shorter than the symbol, then the function correctly returns negative. If the input name is longer than the symbol, it correctly returns positive. I've also gone through the memory initialization and usage in the `kallsyms_build_offsets` function. The code initializes all elements in the `dyn_kallsyms_offsets` array, preventing any read of uninitialized memory. This is critical for RCU safety. Finally, regarding the changes, the removal of the stack-allocated `namebuf` in `kallsyms_lookup_names` is a net positive. It simplifies the code and reduces stack usage. The stack buffer in the original patch was removed, so there is no longer any reliance on it and the code is simplified. I've also examined the `test_kallsyms_perf.c` and haven't found any use of uninitialized memory there, which is what I wanted. In short, there is no uninitialized memory in the code. |
| 60/3 | 2026/09/25 03:43 | tool | grepper |
0mError:no matches Args: {
"Expression": "#define barrier_data"
}Results: {
"error": "no matches"
} |
| 61/3 | 2026/09/25 03:43 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 22293 output: 18 thoughts: 9 Thoughts: Okay, here's my attempt at summarizing the thought process, tailored for an expert audience, and written in the first person: **Finding the `barrier_data`** Alright, let's get down to brass tacks. The immediate goal is clear: I need to locate the `barrier_data`. That's the core focus right now. The term itself is straightforward, but its specific instantiation and form will define the subsequent analysis, and impact my understanding of the system's current state. Is it a variable, a data structure, a file, a database entry, or something else entirely? What context am I operating in here? Is this for debugging, code review, performance analysis, or something else? Understanding the context will help narrow down the search and refine the approach. I'll need to consider where I might expect to find this based on the existing code organization, or documentation. From my experience, there are several methods I could employ. I can start with a search through the codebase, using grep, or an IDE's search functionality, or I could utilize any debugging tools at my disposal. If there's an existing framework in place for tracking variables or data flow, I should leverage that. If the `barrier_data` is part of a larger system with a well-defined architecture, then looking at related component interfaces and data models is a likely first step. If there is documentation, which I will be sure to review, this should expedite the search significantly. The sooner I find it, the sooner I can start digging into its structure and properties. |
| 62/3 | 2026/09/25 03:43 | tool | grepper |
0mArgs:{
"Expression": "barrier_data\\("
}Results: {
"Output": "drivers/clk/renesas/clk-mstp.c=76=static int cpg_mstp_clock_endisable(struct clk_hw *hw, bool enable)\n--\ndrivers/clk/renesas/clk-mstp.c-96-\t\tcpg_mstp_read(group, group-\u003esmstpcr);\ndrivers/clk/renesas/clk-mstp.c:97:\t\tbarrier_data(group-\u003esmstpcr);\ndrivers/clk/renesas/clk-mstp.c-98-\t}\n--\ndrivers/clk/renesas/renesas-cpg-mssr.c=271=static int cpg_mstp_clock_endisable(struct clk_hw *hw, bool enable)\n--\ndrivers/clk/renesas/renesas-cpg-mssr.c-296-\t\treadb(priv-\u003epub.base0 + priv-\u003econtrol_regs[reg]);\ndrivers/clk/renesas/renesas-cpg-mssr.c:297:\t\tbarrier_data(priv-\u003epub.base0 + priv-\u003econtrol_regs[reg]);\ndrivers/clk/renesas/renesas-cpg-mssr.c-298-\n--\ndrivers/clk/renesas/renesas-cpg-mssr.c=718=static int cpg_mssr_reset_operate(struct reset_controller_dev *rcdev,\n--\ndrivers/clk/renesas/renesas-cpg-mssr.c-731-\treadl(priv-\u003epub.base0 + off);\ndrivers/clk/renesas/renesas-cpg-mssr.c:732:\tbarrier_data(priv-\u003epub.base0 + off);\ndrivers/clk/renesas/renesas-cpg-mssr.c-733-\n--\ndrivers/clk/renesas/renesas-cpg-mssr.c=1119=static int cpg_mssr_resume_noirq(struct device *dev)\n--\ndrivers/clk/renesas/renesas-cpg-mssr.c-1153-\t\t\treadb(priv-\u003epub.base0 + priv-\u003econtrol_regs[reg]);\ndrivers/clk/renesas/renesas-cpg-mssr.c:1154:\t\t\tbarrier_data(priv-\u003epub.base0 + priv-\u003econtrol_regs[reg]);\ndrivers/clk/renesas/renesas-cpg-mssr.c-1155-\t\t\tcontinue;\n--\ninclude/linux/compiler.h=15=void ftrace_likely_update(struct ftrace_likely_data *f, int val,\n--\ninclude/linux/compiler.h-101- */\ninclude/linux/compiler.h:102:# define barrier_data(ptr) __asm__ __volatile__(\"\": :\"r\"(ptr) :\"memory\")\ninclude/linux/compiler.h-103-#endif\n--\ninclude/linux/string.h=361=static inline void memzero_explicit(void *s, size_t count)\n--\ninclude/linux/string.h-363-\tmemset(s, 0, count);\ninclude/linux/string.h:364:\tbarrier_data(s);\ninclude/linux/string.h-365-}\n--\nlib/test_kallsyms_perf.c=168=static void run_address_lookup_bench(unsigned int iters)\n--\nlib/test_kallsyms_perf.c-198-\t\t\tsprint_symbol(symname, addr);\nlib/test_kallsyms_perf.c:199:\t\t\tbarrier_data(symname);\nlib/test_kallsyms_perf.c-200-\t\t}\n--\nlib/test_kallsyms_perf.c-215-\t\t\tsprint_symbol_no_offset(symname, addr);\nlib/test_kallsyms_perf.c:216:\t\t\tbarrier_data(symname);\nlib/test_kallsyms_perf.c-217-\t\t}\n--\nlib/tests/ffs_kunit.c=504=static noinline bool build_test_##func(void)\t\t\t\t\\\n--\nlib/tests/ffs_kunit.c-512-\t/* \"Consume\" the results so optimizer doesn't drop them. */\t\\\nlib/tests/ffs_kunit.c:513:\tbarrier_data(\u0026init_##func);\t\t\t\t\t\\\nlib/tests/ffs_kunit.c:514:\tbarrier_data(\u0026result_##func);\t\t\t\t\t\\\nlib/tests/ffs_kunit.c-515-\t\t\t\t\t\t\t\t\t\\\n"
} |
| 63/3 | 2026/09/25 03:43 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 23780 output: 328 thoughts: 1407 Thoughts: **Analysis of the Kallsyms Patch for Memory Safety** Okay, let's break this down. First, `barrier_data(ptr)` is just an `asm` statement; it doesn't introduce any memory safety concerns directly. The benchmark module, `test_kallsyms_perf.c`, is disabled by default and not relevant unless specifically enabled by syzkaller. No worries there. The real meat is in the `kallsyms` code. My immediate concern is, does this touch anything that can leak kernel data to userspace? Specifically, are there any `copy_to_user`, `put_user`, netlink interactions, ioctls, socket options, or BPF buffers? The answer is a resounding no. This patch doesn't seem to introduce or modify any kernel structures transmitted to user space. It also looks like it doesn't introduce any conditional logic that relies on uninitialized variables, or any complex data structure initializations where uninitialized fields could cause trouble. The dynamic allocation is `kvmalloc_array(kallsyms_num_syms, sizeof(u32), GFP_KERNEL)`. Critically, this array, `offsets`, is completely populated in a loop. It's fully initialized before any data is accessible. The removal of `namebuf` from `kallsyms_lookup_names()` also makes things simpler and safer. What risks *could* this patch introduce? Primarily, memory leaks/use-after-free/races related to RCU in `dyn_kallsyms_offsets`. However, the code uses `synchronize_rcu()` and `kvfree(offsets)`. Any use-after-free, race condition, or NULL dereference should be caught by KASAN or LOCKDEP. Then, there's the possibility of out-of-bounds reads in `kallsyms_strcmp_symbol()` or `get_symbol_data()`, but KASAN should also catch reads past `kallsyms_names`. Finally, locking bugs with `mutex_lock(&dyn_kallsyms_mutex)` inside `kallsyms_lookup_batch_start`/`end()` are checked by LOCKDEP. Now, let's apply the KMSAN criteria. Does it introduce or modify anything that sends kernel structures to userspace with uninitialized fields? Nope. Does it have any logic relying on uninitialized variables? Nope. Does it initialize complex data structures where uninitialized fields could be read later? Nope. Any changes to bounds checks, lengths, or logic that could expose uninitialized bytes? Nope. On the other hand, the code changes primarily risk out-of-bounds access, array overflows, NULL pointer dereferences, locking deadlocks, or use-after-free bugs. These are already covered by KASAN, LOCKDEP, or standard bug detectors. All stack and heap structures are fully initialized or zeroed before they are used. The patch does not introduce any risk of uninitialized memory usage or info-leaks. Therefore, `NeedsKMSAN=false` is correct. Let me just double-check the key files again: - `include/linux/kallsyms.h`: Prototyping and empty stubs. - `kernel/kallsyms.c`: Read-only data access with helpers. Dynamic offset array, initialized before being used, and RCU/mutex management. - `kernel/kallsyms_selftest.c`: Selftest code, no safety problems. - Benchmark module. The code is safe. **`NeedsKMSAN=false`.** Let's call `set-results`. |
| 64/3 | 2026/09/25 03:43 | tool | set-results |
0mArgs:{
"KMSANReasoning": "The patch series optimizes symbol lookup in the kernel kallsyms subsystem by introducing direct in-place comparison against compressed symbols (`kallsyms_strcmp_symbol`), removing the temporary stack buffer (`namebuf`), and adding an optional transient dynamic offset index (`dyn_kallsyms_offsets`) managed via RCU for batch lookups.\n\nKMSAN vs KASAN analysis:\n1. No uninitialized memory or info-leaks: No kernel structures or data are exposed to user space. The stack buffer `namebuf` in `kallsyms_lookup_names()` was eliminated rather than added. The dynamically allocated offset array (`dyn_kallsyms_offsets`) created by `kallsyms_build_offsets()` allocates memory via `kvmalloc_array()` and fully populates every index from 0 through `kallsyms_num_syms - 1` prior to publishing the pointer via `rcu_assign_pointer()`.\n2. Applicability of other detectors: Any potential memory safety bugs introduced by this patch series would involve out-of-bounds reads into `kallsyms_names`, concurrency/lifetime issues (RCU grace periods, kvfree), or locking bugs in `dyn_kallsyms_mutex`. These issues are covered by KASAN and LOCKDEP.\n\nTherefore, this patch series does not pose uninitialized memory risks that would necessitate a dedicated KMSAN fuzzing session.",
"NeedsKMSAN": false
}Results: {
"KMSANReasoning": "The patch series optimizes symbol lookup in the kernel kallsyms subsystem by introducing direct in-place comparison against compressed symbols (`kallsyms_strcmp_symbol`), removing the temporary stack buffer (`namebuf`), and adding an optional transient dynamic offset index (`dyn_kallsyms_offsets`) managed via RCU for batch lookups.\n\nKMSAN vs KASAN analysis:\n1. No uninitialized memory or info-leaks: No kernel structures or data are exposed to user space. The stack buffer `namebuf` in `kallsyms_lookup_names()` was eliminated rather than added. The dynamically allocated offset array (`dyn_kallsyms_offsets`) created by `kallsyms_build_offsets()` allocates memory via `kvmalloc_array()` and fully populates every index from 0 through `kallsyms_num_syms - 1` prior to publishing the pointer via `rcu_assign_pointer()`.\n2. Applicability of other detectors: Any potential memory safety bugs introduced by this patch series would involve out-of-bounds reads into `kallsyms_names`, concurrency/lifetime issues (RCU grace periods, kvfree), or locking bugs in `dyn_kallsyms_mutex`. These issues are covered by KASAN and LOCKDEP.\n\nTherefore, this patch series does not pose uninitialized memory risks that would necessitate a dedicated KMSAN fuzzing session.",
"NeedsKMSAN": false
} |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|