summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorAlexei Starovoitov <ast@kernel.org>2026-04-07 16:27:29 -0700
committerAlexei Starovoitov <ast@kernel.org>2026-04-07 16:28:13 -0700
commit656e835bb0f850bdb7a42bfb64a2495f4f4d2064 (patch)
treef43e4965c0a9517498c8087a6851341aaf8d47e3 /kernel
parenta4985a1755ec9e5aa5cfb89468ba4b51546b5eeb (diff)
parentcea4323f1cfe1d56dffcf98b5add1acd23aa91ed (diff)
Merge branch 'tracing-fix-kprobe-attachment-when-module-shadows-vmlinux-symbol'
Andrey Grodzovsky says: ==================== tracing: Fix kprobe attachment when module shadows vmlinux symbol When a kernel module exports a symbol with the same name as an existing vmlinux symbol, kprobe attachment fails with -EADDRNOTAVAIL because number_of_same_symbols() counts matches across both vmlinux and all loaded modules, returning a count greater than 1. This series takes a different approach from v1-v4, which implemented a libbpf-side fallback parsing /proc/kallsyms and retrying with the absolute address. That approach was rejected (Andrii Nakryiko, Ihor Solodrai) because ambiguous symbol resolution does not belong in libbpf. Following Ihor's suggestion, this series fixes the root cause in the kernel: when an unqualified symbol name is given and the symbol is found in vmlinux, prefer the vmlinux symbol and do not scan loaded modules. This makes the skeleton auto-attach path work transparently with no libbpf changes needed. Patch 1: Kernel fix - return vmlinux-only count from number_of_same_symbols() when the symbol is found in vmlinux, preventing module shadows from causing -EADDRNOTAVAIL. Patch 2: Selftests using bpf_fentry_shadow_test which exists in both vmlinux and bpf_testmod - tests unqualified (vmlinux) and MOD:SYM (module) attachment across all four attach modes, plus kprobe_multi with the duplicate symbol. Changes since v6 [1]: - Fix comment style: use /* on its own line instead of networking-style /* text on opener line (Alexei Starovoitov). [1] https://lore.kernel.org/bpf/20260407165145.1651061-1-andrey.grodzovsky@crowdstrike.com/ ==================== Link: https://patch.msgid.link/20260407203912.1787502-1-andrey.grodzovsky@crowdstrike.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/trace/trace_kprobe.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index a5dbb72528e0..058724c41c46 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -765,6 +765,14 @@ static unsigned int number_of_same_symbols(const char *mod, const char *func_nam
if (!mod)
kallsyms_on_each_match_symbol(count_symbols, func_name, &ctx.count);
+ /*
+ * If the symbol is found in vmlinux, use vmlinux resolution only.
+ * This prevents module symbols from shadowing vmlinux symbols
+ * and causing -EADDRNOTAVAIL for unqualified kprobe targets.
+ */
+ if (!mod && ctx.count > 0)
+ return ctx.count;
+
module_kallsyms_on_each_symbol(mod, count_mod_symbols, &ctx);
return ctx.count;