Make sure that calling uprobe syscall from outside uprobe trampoline
results in sigill signal.

Signed-off-by: Jiri Olsa <jo...@kernel.org>
---
 .../selftests/bpf/prog_tests/uprobe_syscall.c | 36 +++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c 
b/tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c
index 3f320da4ac46..c5894ddc5b5e 100644
--- a/tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c
+++ b/tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c
@@ -631,6 +631,40 @@ static void test_uprobe_race(void)
                pthread_join(threads[i], NULL);
 }
 
+#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"))
@@ -649,6 +683,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)
-- 
2.48.1


Reply via email to