From: Jiri Olsa <olsajiri@gmail.com>
To: Andrey Grodzovsky <andrey.grodzovsky@crowdstrike.com>
Cc: bpf@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
rostedt@goodmis.org, mhiramat@kernel.org,
ihor.solodrai@linux.dev, emil@etsalapatis.com,
linux-open-source@crowdstrike.com
Subject: Re: [RFC PATCH bpf-next v5 2/2] selftests/bpf: Add tests for duplicate kprobe symbol handling
Date: Tue, 7 Apr 2026 14:59:23 +0200 [thread overview]
Message-ID: <adT_q0MzIOOj9yL3@krava> (raw)
In-Reply-To: <20260406193158.754498-3-andrey.grodzovsky@crowdstrike.com>
On Mon, Apr 06, 2026 at 03:31:58PM -0400, Andrey Grodzovsky wrote:
SNIP
> +static void test_attach_probe_dup_sym(enum probe_attach_mode attach_mode)
> +{
> + DECLARE_LIBBPF_OPTS(bpf_kprobe_opts, kprobe_opts);
> + struct bpf_link *kprobe_link, *kretprobe_link;
> + struct test_attach_probe_manual *skel;
> + int err;
> +
> + /* Load module with duplicate symbol */
> + err = load_module("bpf_testmod_dup_sym.ko", false);
> + if (!ASSERT_OK(err, "load_bpf_testmod_dup_sym")) {
> + test__skip();
> + return;
> + }
> +
> + skel = test_attach_probe_manual__open_and_load();
> + if (!ASSERT_OK_PTR(skel, "skel_dup_sym_open_and_load"))
> + goto unload_module;
> +
> + /* manual-attach kprobe/kretprobe with duplicate symbol present */
> + kprobe_opts.attach_mode = attach_mode;
> + kprobe_opts.retprobe = false;
> + kprobe_link = bpf_program__attach_kprobe_opts(skel->progs.handle_kprobe,
> + SYS_NANOSLEEP_KPROBE_NAME,
> + &kprobe_opts);
> + if (!ASSERT_OK_PTR(kprobe_link, "attach_kprobe_dup_sym"))
> + goto cleanup;
> + skel->links.handle_kprobe = kprobe_link;
> +
> + kprobe_opts.retprobe = true;
> + kretprobe_link = bpf_program__attach_kprobe_opts(skel->progs.handle_kretprobe,
> + SYS_NANOSLEEP_KPROBE_NAME,
> + &kprobe_opts);
maybe add tests for attaching the shadow module function as well?
> diff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod_dup_sym.c b/tools/testing/selftests/bpf/test_kmods/bpf_testmod_dup_sym.c
> new file mode 100644
> index 000000000000..0e12f68afe3a
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod_dup_sym.c
> @@ -0,0 +1,48 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/* Copyright (c) 2025 CrowdStrike */
> +/* Test module for duplicate kprobe symbol handling */
> +#include <linux/init.h>
> +#include <linux/module.h>
> +#include <linux/kernel.h>
> +
> +/* Duplicate symbol to test kprobe attachment with duplicate symbols.
> + * This creates a duplicate of the syscall wrapper used in attach_probe tests.
> + * The libbpf fix should handle this by preferring the vmlinux symbol.
> + * This function should NEVER be called - kprobes should attach to vmlinux version.
> + */
> +#ifdef __x86_64__
> +int __x64_sys_nanosleep(void);
> +noinline int __x64_sys_nanosleep(void)
> +#elif defined(__s390x__)
> +int __s390x_sys_nanosleep(void);
> +noinline int __s390x_sys_nanosleep(void)
> +#elif defined(__aarch64__)
> +int __arm64_sys_nanosleep(void);
> +noinline int __arm64_sys_nanosleep(void)
> +#elif defined(__riscv)
> +int __riscv_sys_nanosleep(void);
> +noinline int __riscv_sys_nanosleep(void)
> +#else
> +int sys_nanosleep(void);
> +noinline int sys_nanosleep(void)
> +#endif
could we use module_fentry_shadow instead? it's in kernel and in bpf_testmod
for fentry shadowing test.. it's not executed via test_run but it could be
added or we just don't run it
jirka
> +{
> + WARN_ONCE(1, "bpf_testmod_dup_sym: dummy nanosleep symbol called - this should never execute!\n");
> + return -EINVAL;
> +}
> +
> +static int __init bpf_testmod_dup_sym_init(void)
> +{
> + return 0;
> +}
> +
> +static void __exit bpf_testmod_dup_sym_exit(void)
> +{
> +}
> +
> +module_init(bpf_testmod_dup_sym_init);
> +module_exit(bpf_testmod_dup_sym_exit);
> +
> +MODULE_AUTHOR("Andrey Grodzovsky");
> +MODULE_DESCRIPTION("BPF selftest duplicate symbol module");
> +MODULE_LICENSE("GPL");
> --
> 2.34.1
>
prev parent reply other threads:[~2026-04-07 12:59 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-06 19:31 [RFC PATCH bpf-next v5 0/2] tracing: Fix kprobe attachment when module shadows vmlinux symbol Andrey Grodzovsky
2026-04-06 19:31 ` [RFC PATCH bpf-next v5 1/2] tracing: Prefer vmlinux symbols over module symbols for unqualified kprobes Andrey Grodzovsky
2026-04-06 20:15 ` bot+bpf-ci
2026-04-07 12:59 ` Jiri Olsa
2026-04-07 12:59 ` Jiri Olsa
2026-04-06 19:31 ` [RFC PATCH bpf-next v5 2/2] selftests/bpf: Add tests for duplicate kprobe symbol handling Andrey Grodzovsky
2026-04-07 12:59 ` Jiri Olsa [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=adT_q0MzIOOj9yL3@krava \
--to=olsajiri@gmail.com \
--cc=andrey.grodzovsky@crowdstrike.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=linux-open-source@crowdstrike.com \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox