]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
selftests/bpf: Add uprobe syscall sigill signal test
authorJiri Olsa <jolsa@kernel.org>
Sun, 20 Jul 2025 11:21:26 +0000 (13:21 +0200)
committerPeter Zijlstra <peterz@infradead.org>
Thu, 21 Aug 2025 18:09:24 +0000 (20:09 +0200)
Make sure that calling uprobe syscall from outside uprobe trampoline
results in sigill signal.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20250720112133.244369-17-jolsa@kernel.org
tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c

index 3d27c8bc019e6a0eb14da5b87ca1f19db47a42a1..02e98cba5cc69848fe21dcfb2e7c9426c1a91e81 100644 (file)
@@ -735,6 +735,40 @@ cleanup:
        ASSERT_FALSE(USDT_SEMA_IS_ACTIVE(race), "race_semaphore");
 }
 
+#ifndef __NR_uprobe
+#define __NR_uprobe 336
+#endif
+
+static void test_uprobe_sigill(void)
+{
+       int status, err, pid;
+
+       pid = fork();
+       if (!ASSERT_GE(pid, 0, "fork"))
+               return;
+       /* child */
+       if (pid == 0) {
+               asm volatile (
+                       "pushq %rax\n"
+                       "pushq %rcx\n"
+                       "pushq %r11\n"
+                       "movq $" __stringify(__NR_uprobe) ", %rax\n"
+                       "syscall\n"
+                       "popq %r11\n"
+                       "popq %rcx\n"
+                       "retq\n"
+               );
+               exit(0);
+       }
+
+       err = waitpid(pid, &status, 0);
+       ASSERT_EQ(err, pid, "waitpid");
+
+       /* verify the child got killed with SIGILL */
+       ASSERT_EQ(WIFSIGNALED(status), 1, "WIFSIGNALED");
+       ASSERT_EQ(WTERMSIG(status), SIGILL, "WTERMSIG");
+}
+
 static void __test_uprobe_syscall(void)
 {
        if (test__start_subtest("uretprobe_regs_equal"))
@@ -755,6 +789,8 @@ static void __test_uprobe_syscall(void)
                test_uprobe_usdt();
        if (test__start_subtest("uprobe_race"))
                test_uprobe_race();
+       if (test__start_subtest("uprobe_sigill"))
+               test_uprobe_sigill();
 }
 #else
 static void __test_uprobe_syscall(void)