Skip to content

Commit b511436

Browse files
andrey-grodzovskygregkh
authored andcommitted
bpf: Prefer vmlinux symbols over module symbols for unqualified kprobes
[ Upstream commit 1870ddc ] When an unqualified kprobe target exists in both vmlinux and a loaded module, number_of_same_symbols() returns a count greater than 1, causing kprobe attachment to fail with -EADDRNOTAVAIL even though the vmlinux symbol is unambiguous. When no module qualifier is given and the symbol is found in vmlinux, return the vmlinux-only count without scanning loaded modules. This preserves the existing behavior for all other cases: - Symbol only in a module: vmlinux count is 0, falls through to module scan as before. - Symbol qualified with MOD:SYM: mod != NULL, unchanged path. - Symbol ambiguous within vmlinux itself: count > 1 is returned as-is. Fixes: 926fe78 ("tracing/kprobes: Fix symbol counting logic by looking at modules as well") Fixes: 9d86160 ("tracing/kprobes: Add symbol counting check when module loads") Suggested-by: Ihor Solodrai <ihor.solodrai@linux.dev> Acked-by: Jiri Olsa <jolsa@kernel.org> Acked-by: Ihor Solodrai <ihor.solodrai@linux.dev> Signed-off-by: Andrey Grodzovsky <andrey.grodzovsky@crowdstrike.com> Link: https://lore.kernel.org/r/20260407203912.1787502-2-andrey.grodzovsky@crowdstrike.com Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 99dbab7 commit b511436

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

kernel/trace/trace_kprobe.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,14 @@ static unsigned int number_of_same_symbols(const char *mod, const char *func_nam
765765
if (!mod)
766766
kallsyms_on_each_match_symbol(count_symbols, func_name, &ctx.count);
767767

768+
/*
769+
* If the symbol is found in vmlinux, use vmlinux resolution only.
770+
* This prevents module symbols from shadowing vmlinux symbols
771+
* and causing -EADDRNOTAVAIL for unqualified kprobe targets.
772+
*/
773+
if (!mod && ctx.count > 0)
774+
return ctx.count;
775+
768776
module_kallsyms_on_each_symbol(mod, count_mod_symbols, &ctx);
769777

770778
return ctx.count;

0 commit comments

Comments
 (0)