public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH bpf-next 0/2] libbpf: Handle duplicate kprobe symbols
@ 2026-02-18 22:56 Andrey Grodzovsky
  2026-02-18 22:56 ` [RFC PATCH bpf-next 1/2] libbpf: Handle duplicate kprobe symbols in attach_kprobe_opts Andrey Grodzovsky
  2026-02-18 22:56 ` [RFC PATCH bpf-next 2/2] selftests/bpf: Add tests for duplicate kprobe symbol handling Andrey Grodzovsky
  0 siblings, 2 replies; 10+ messages in thread
From: Andrey Grodzovsky @ 2026-02-18 22:56 UTC (permalink / raw)
  To: bpf; +Cc: ast, daniel, andrii, jolsa, linux-open-source

When a kernel module exports a symbol with the same name as an existing
vmlinux symbol, kprobe attachment via bpf_program__attach_kprobe_opts()
fails with EADDRNOTAVAIL (perf_event_open path) or EINVAL (legacy tracefs
path). The kernel rejects the ambiguous symbol name because it cannot
determine which address to probe.

This is a practical problem: out-of-tree modules may inadvertently
duplicate vmlinux symbol names, and the current libbpf behavior provides
no recovery path — the attachment simply fails.

This series adds a fallback mechanism in libbpf that retries attachment
using the absolute kernel address instead of the symbol name when the
initial attempt fails due to duplicate symbols.

The approach:
  1. Enhance libbpf_kallsyms_parse() to extract module names from
     /proc/kallsyms entries (format: "addr type name [module]"),
     passing them to callbacks via a new module_name parameter.
  2. On EADDRNOTAVAIL/EINVAL failure, look up the function address
     in /proc/kallsyms, filtering to vmlinux-only text symbols.
     If the vmlinux symbol itself is ambiguous (same name, different
     addresses), reject with an error.
  3. Retry the probe attachment with func_name=NULL and the resolved
     address as the offset, bypassing the kernel's symbol lookup
     entirely.

This works because perf_event_open with config1=0 (no symbol name)
and config2=address performs a direct address-based probe without
any kallsyms validation. The legacy tracefs path uses the "0xADDR"
format which similarly avoids symbol resolution.

Patch 1 implements the core libbpf changes.
Patch 2 adds selftests with a test module (bpf_testmod_dup_sym.ko)
that creates a duplicate syscall wrapper symbol, validating all four
kprobe attachment modes (default, legacy, perf_event_open, link).

Andrey Grodzovsky (2):
  libbpf: Handle duplicate kprobe symbols in attach_kprobe_opts
  selftests/bpf: Add tests for duplicate kprobe symbol handling

 tools/lib/bpf/libbpf.c                        | 150 ++++++++++++++++--
 tools/testing/selftests/bpf/Makefile          |   2 +-
 .../selftests/bpf/prog_tests/attach_probe.c   |  63 ++++++++
 .../testing/selftests/bpf/test_kmods/Makefile |   2 +-
 .../bpf/test_kmods/bpf_testmod_dup_sym.c      |  45 ++++++
 5 files changed, 243 insertions(+), 19 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/test_kmods/bpf_testmod_dup_sym.c

-- 
2.34.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-02-24 13:06 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-18 22:56 [RFC PATCH bpf-next 0/2] libbpf: Handle duplicate kprobe symbols Andrey Grodzovsky
2026-02-18 22:56 ` [RFC PATCH bpf-next 1/2] libbpf: Handle duplicate kprobe symbols in attach_kprobe_opts Andrey Grodzovsky
2026-02-18 23:31   ` bot+bpf-ci
2026-02-19  0:28   ` Emil Tsalapatis
2026-02-19 21:57     ` [External] " Andrey Grodzovsky
2026-02-18 22:56 ` [RFC PATCH bpf-next 2/2] selftests/bpf: Add tests for duplicate kprobe symbol handling Andrey Grodzovsky
2026-02-23  9:19   ` Jiri Olsa
2026-02-23 18:56     ` [External] " Andrey Grodzovsky
2026-02-24 10:54       ` Jiri Olsa
2026-02-24 13:06         ` Jiri Olsa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox