Skip to content

Handle duplicate kprobe symbols#11253

Closed
kernel-patches-daemon-bpf[bot] wants to merge 2 commits intobpf-next_basefrom
series/1060295=>bpf-next
Closed

Handle duplicate kprobe symbols#11253
kernel-patches-daemon-bpf[bot] wants to merge 2 commits intobpf-next_basefrom
series/1060295=>bpf-next

Conversation

@kernel-patches-daemon-bpf
Copy link

Pull request for series with
subject: Handle duplicate kprobe symbols
version: 5
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=1060295

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 309d880
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1060295
version: 5

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 44dd647
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1060295
version: 5

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 05c9b2e
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1060295
version: 5

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 4faa189
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1060295
version: 5

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 748f9c6
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1060295
version: 5

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).

Implement a fallback mechanism that, on such failures, resolves the
vmlinux address through /proc/kallsyms - filtering out module symbols -
and retries probe attachment using the absolute address, bypassing
kernel symbol name validation.

Changes:
- Restructure libbpf_kallsyms_parse() to accept a bool skip_if_module
  parameter that filters module symbols before invoking the callback.
- Add find_kaddr_cb() callback and find_kaddr_ctx struct to resolve
  vmlinux text symbol addresses from /proc/kallsyms.
- Detect duplicate symbol errors (-EADDRNOTAVAIL for perf_event_open,
  -EINVAL for legacy tracefs) and retry with resolved KADDR.
- Fix NULL pointer in gen_probe_legacy_event_name() when using absolute
  address by passing func_name instead of optional_func_name.
- Fix NULL pointer in pr_warn() calls within
  perf_event_kprobe_open_legacy() by using ternary fallback.
- Fix memory leak of legacy_probe buffer on retry path.

Signed-off-by: Andrey Grodzovsky <andrey.grodzovsky@crowdstrike.com>
Add bpf_testmod_dup_sym.ko test module that creates a duplicate
nanosleep symbols to test kprobe attachment when a module exports
a symbol with the same name as a vmlinux symbol.

Add test_attach_probe_dup_sym() to attach_probe tests that loads
the duplicate symbol module and validates kprobe attachment across
all four attach modes: auto-attach, explicit symbol, legacy with
offset, and perf_event_open with offset.

Signed-off-by: Andrey Grodzovsky <andrey.grodzovsky@crowdstrike.com>
Reviewed-by: Emil Tsalapatis <emil@etsalapatis.com>
@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 6dd780f
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1060295
version: 5

@kernel-patches-daemon-bpf
Copy link
Author

At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=1060295 expired. Closing PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant