]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests/bpf: Add test for attaching uprobe with long event names
authorFeng Yang <yangfeng@kylinos.cn>
Thu, 17 Apr 2025 01:48:47 +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 uprobe/uretprobe 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-3-yangfeng59949@163.com
tools/testing/selftests/bpf/prog_tests/attach_probe.c

index 329c7862b52d3aa2f5d27a78b1d3e58322369446..9b7f36f39c325e60834f894573e774797b8f111a 100644 (file)
@@ -122,6 +122,52 @@ cleanup:
        test_attach_probe_manual__destroy(skel);
 }
 
+/* attach uprobe/uretprobe long event name testings */
+static void test_attach_uprobe_long_event_name(void)
+{
+       DECLARE_LIBBPF_OPTS(bpf_uprobe_opts, uprobe_opts);
+       struct bpf_link *uprobe_link, *uretprobe_link;
+       struct test_attach_probe_manual *skel;
+       ssize_t uprobe_offset;
+       char path[PATH_MAX] = {0};
+
+       skel = test_attach_probe_manual__open_and_load();
+       if (!ASSERT_OK_PTR(skel, "skel_kprobe_manual_open_and_load"))
+               return;
+
+       uprobe_offset = get_uprobe_offset(&trigger_func);
+       if (!ASSERT_GE(uprobe_offset, 0, "uprobe_offset"))
+               goto cleanup;
+
+       if (!ASSERT_GT(readlink("/proc/self/exe", path, PATH_MAX - 1), 0, "readlink"))
+               goto cleanup;
+
+       /* manual-attach uprobe/uretprobe */
+       uprobe_opts.attach_mode = PROBE_ATTACH_MODE_LEGACY;
+       uprobe_opts.ref_ctr_offset = 0;
+       uprobe_opts.retprobe = false;
+       uprobe_link = bpf_program__attach_uprobe_opts(skel->progs.handle_uprobe,
+                                                     0 /* self pid */,
+                                                     path,
+                                                     uprobe_offset,
+                                                     &uprobe_opts);
+       if (!ASSERT_OK_PTR(uprobe_link, "attach_uprobe_long_event_name"))
+               goto cleanup;
+       skel->links.handle_uprobe = uprobe_link;
+
+       uprobe_opts.retprobe = true;
+       uretprobe_link = bpf_program__attach_uprobe_opts(skel->progs.handle_uretprobe,
+                                                        -1 /* any pid */,
+                                                        path,
+                                                        uprobe_offset, &uprobe_opts);
+       if (!ASSERT_OK_PTR(uretprobe_link, "attach_uretprobe_long_event_name"))
+               goto cleanup;
+       skel->links.handle_uretprobe = uretprobe_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;
@@ -323,6 +369,9 @@ void test_attach_probe(void)
        if (test__start_subtest("uprobe-ref_ctr"))
                test_uprobe_ref_ctr(skel);
 
+       if (test__start_subtest("uprobe-long_name"))
+               test_attach_uprobe_long_event_name();
+
 cleanup:
        test_attach_probe__destroy(skel);
        ASSERT_EQ(uprobe_ref_ctr, 0, "uprobe_ref_ctr_cleanup");