[PATCH bpf-next v6 0/2] tracing: Fix kprobe attachment when module shadows vmlinux symbol

Andrey Grodzovsky
2026-04-07T16:52:13Z

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-v5, 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,
and because it did not cover the kprobe_multi path.

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 v5 [1]:
- Selftest: use existing bpf_fentry_shadow_test (vmlinux + bpf_testmod)
instead of a new bpf_testmod_dup_sym.ko test module (Jiri Olsa).
- Selftest: add MOD:SYM qualification test for module shadow attachment
(Jiri Olsa).
- Selftest: add kprobe_multi dup_sym test in kprobe_multi_test.c
(Jiri Olsa).

[1] https://lore.kernel.org/bpf/20260406193158.754498-1-andrey.grodzovsky@crowdstrike.com/

Andrey Grodzovsky (2):
tracing: Prefer vmlinux symbols over module symbols for unqualified
kprobes
selftests/bpf: Add tests for kprobe attachment with duplicate symbols

kernel/trace/trace_kprobe.c | 7 ++
.../selftests/bpf/prog_tests/attach_probe.c | 68 +++++++++++++++++++
.../bpf/prog_tests/kprobe_multi_test.c | 39 +++++++++++
3 files changed, 114 insertions(+)

--
2.34.1