]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
selftests/bpf: Add uprobe_multi path_fd fail tests
authorJiri Olsa <jolsa@kernel.org>
Thu, 11 Jun 2026 11:42:29 +0000 (13:42 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Mon, 15 Jun 2026 00:24:26 +0000 (17:24 -0700)
Adding tests to attach_api_fails suite to make sure we fail
wrong setup for path_fd usage.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Link: https://lore.kernel.org/r/20260611114230.950379-7-jolsa@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c

index ffcf3c92f047458afb93a0de7e877c4494d116be..f0baf5738b751b925d7f6f722364f1c5d657d7f3 100644 (file)
@@ -537,7 +537,37 @@ static void test_attach_api_fails(void)
        link_fd = bpf_link_create(prog_fd, 0, BPF_TRACE_UPROBE_MULTI, &opts);
        if (!ASSERT_ERR(link_fd, "link_fd"))
                goto cleanup;
-       ASSERT_EQ(link_fd, -EINVAL, "pid_is_wrong");
+       if (!ASSERT_EQ(link_fd, -EINVAL, "pid_is_wrong"))
+               goto cleanup;
+
+       /* wrong path_fd */
+       LIBBPF_OPTS_RESET(opts,
+               .uprobe_multi.path = NULL,
+               .uprobe_multi.path_fd = -1,
+               .uprobe_multi.flags = BPF_F_UPROBE_MULTI_PATH_FD,
+               .uprobe_multi.offsets = (unsigned long *)&offset,
+               .uprobe_multi.cnt = 1,
+       );
+
+       link_fd = bpf_link_create(prog_fd, 0, BPF_TRACE_UPROBE_MULTI, &opts);
+       if (!ASSERT_ERR(link_fd, "link_fd"))
+               goto cleanup;
+       if (!ASSERT_EQ(link_fd, -EBADF, "path_fd_is_wrong"))
+               goto cleanup;
+
+       /* path and path_fd both set with BPF_F_UPROBE_MULTI_PATH_FD flag */
+       LIBBPF_OPTS_RESET(opts,
+               .uprobe_multi.path = path,
+               .uprobe_multi.path_fd = 1,
+               .uprobe_multi.flags = BPF_F_UPROBE_MULTI_PATH_FD,
+               .uprobe_multi.offsets = (unsigned long *)&offset,
+               .uprobe_multi.cnt = 1,
+       );
+
+       link_fd = bpf_link_create(prog_fd, 0, BPF_TRACE_UPROBE_MULTI, &opts);
+       if (!ASSERT_ERR(link_fd, "link_fd"))
+               goto cleanup;
+       ASSERT_EQ(link_fd, -EINVAL, "path_and_path_fd_together");
 
 cleanup:
        if (link_fd >= 0)