]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests/bpf: Add test for attaching kprobe with long event names
authorFeng Yang <yangfeng@kylinos.cn>
Thu, 17 Apr 2025 01:48:48 +0000 (09:48 +0800)
committerAndrii Nakryiko <andrii@kernel.org>
Wed, 23 Apr 2025 00:13:37 +0000 (17:13 -0700)
This test verifies that attaching kprobe/kretprobe with long event names
does not trigger EINVAL errors.

Signed-off-by: Feng Yang <yangfeng@kylinos.cn>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20250417014848.59321-4-yangfeng59949@163.com
tools/testing/selftests/bpf/prog_tests/attach_probe.c
tools/testing/selftests/bpf/test_kmods/bpf_testmod.c

index 9b7f36f39c325e60834f894573e774797b8f111a..cabc51c2ca6bd5c6d291e44c27e7ad923b3e455f 100644 (file)
@@ -168,6 +168,39 @@ cleanup:
        test_attach_probe_manual__destroy(skel);
 }
 
+/* attach kprobe/kretprobe long event name testings */
+static void test_attach_kprobe_long_event_name(void)
+{
+       DECLARE_LIBBPF_OPTS(bpf_kprobe_opts, kprobe_opts);
+       struct bpf_link *kprobe_link, *kretprobe_link;
+       struct test_attach_probe_manual *skel;
+
+       skel = test_attach_probe_manual__open_and_load();
+       if (!ASSERT_OK_PTR(skel, "skel_kprobe_manual_open_and_load"))
+               return;
+
+       /* manual-attach kprobe/kretprobe */
+       kprobe_opts.attach_mode = PROBE_ATTACH_MODE_LEGACY;
+       kprobe_opts.retprobe = false;
+       kprobe_link = bpf_program__attach_kprobe_opts(skel->progs.handle_kprobe,
+                                                     "bpf_testmod_looooooooooooooooooooooooooooooong_name",
+                                                     &kprobe_opts);
+       if (!ASSERT_OK_PTR(kprobe_link, "attach_kprobe_long_event_name"))
+               goto cleanup;
+       skel->links.handle_kprobe = kprobe_link;
+
+       kprobe_opts.retprobe = true;
+       kretprobe_link = bpf_program__attach_kprobe_opts(skel->progs.handle_kretprobe,
+                                                        "bpf_testmod_looooooooooooooooooooooooooooooong_name",
+                                                        &kprobe_opts);
+       if (!ASSERT_OK_PTR(kretprobe_link, "attach_kretprobe_long_event_name"))
+               goto cleanup;
+       skel->links.handle_kretprobe = kretprobe_link;
+
+cleanup:
+       test_attach_probe_manual__destroy(skel);
+}
+
 static void test_attach_probe_auto(struct test_attach_probe *skel)
 {
        struct bpf_link *uprobe_err_link;
@@ -371,6 +404,8 @@ void test_attach_probe(void)
 
        if (test__start_subtest("uprobe-long_name"))
                test_attach_uprobe_long_event_name();
+       if (test__start_subtest("kprobe-long_name"))
+               test_attach_kprobe_long_event_name();
 
 cleanup:
        test_attach_probe__destroy(skel);
index f38eaf0d35efa712ec288f06983c86b02c0d3e0e..2e54b95ad898a4bdc073d1608f46550f91b48f97 100644 (file)
@@ -134,6 +134,10 @@ bpf_testmod_test_arg_ptr_to_struct(struct bpf_testmod_struct_arg_1 *a) {
        return bpf_testmod_test_struct_arg_result;
 }
 
+__weak noinline void bpf_testmod_looooooooooooooooooooooooooooooong_name(void)
+{
+}
+
 __bpf_kfunc void
 bpf_testmod_test_mod_kfunc(int i)
 {