Skip to contentSkip to conversation

uprobes/x86: change error path for uprobe syscall

PATCH Applied Jiri Olsa 5 participants 9 messages Sep 5, 2025 – Sep 16, 2025

Subsystems (6)
x86 Kselftest BPF Tracing +2 more subsystems
lore
Share & tools
lore

Jiri Olsa

author reviewer
#0 lore raw

cover uprobes/x86: change error path for uprobe syscall

hi,
as suggested by Andrii [1] it'd be helpful for uprobe syscall detection to return error value for the !in_uprobe_trampoline check instead of forcing SIGILL.

This way we could just call uprobe syscall and based on return value we will find out if the kernel supports it.

Alejandro,
I included the full man page change from [2], because IIUC this was not applied yet, and as usual I butchered the wording, so I'd appreciate your review on that.

thanks,
jirka

[1] https://lore.kernel.org/bpf/CAEf4BzaxtW_W1M94e3q0Qw4vM_heHqU7zFeH-fFHOQBwy5+7LQ@mail.gmail.com/
[2] https://lore.kernel.org/bpf/[email protected]/
---
Jiri Olsa (2):
uprobes/x86: Return error from uprobe syscall when not called from trampoline selftests/bpf: Fix uprobe_sigill test for uprobe syscall error value

 arch/x86/kernel/uprobes.c                               |  2 +-
 tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c | 34 ++++++----------------------------
 2 files changed, 7 insertions(+), 29 deletions(-)

Jiri Olsa (1):
man2: Add uprobe syscall page

 man/man2/uprobe.2    |  1 +
 man/man2/uretprobe.2 | 42 +++++++++++++++++++++++++++++-------------
 2 files changed, 30 insertions(+), 13 deletions(-)
 create mode 100644 man/man2/uprobe.2
author reviewer
#1 lore raw

PATCH 1/3 uprobes/x86: Return error from uprobe syscall when not called from trampoline

Currently uprobe syscall handles all errors with forcing SIGILL to current process. As suggested by Andrii it'd be helpful for uprobe syscall detection to return error value for the !in_uprobe_trampoline check.

This way we could just call uprobe syscall and based on return value we will find out if the kernel has it.

---
 arch/x86/kernel/uprobes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/uprobes.c +1 -1
index 0a8c0a4a5423..845aeaf36b8d 100644
@@ -810,7 +810,7 @@ SYSCALL_DEFINE0(uprobe)
 
 	/* Allow execution only from uprobe trampolines. */
 	if (!in_uprobe_trampoline(regs->ip))
-		goto sigill;
+		return -ENXIO;
 
 	err = copy_from_user(&args, (void __user *)regs->sp, sizeof(args));
 	if (err)
Signature · 1 line
2.51.0
maintainer Acked-by on v1 1/3
#2 lore raw

Re: [PATCH perf/core 1/3] uprobes/x86: Return error from uprobe syscall when not called from trampoline

Quoted 20 lines · Jiri Olsa

Currently uprobe syscall handles all errors with forcing SIGILL to current process. As suggested by Andrii it'd be helpful for uprobe syscall detection to return error value for the !in_uprobe_trampoline check.

This way we could just call uprobe syscall and based on return value we will find out if the kernel has it.

---
 arch/x86/kernel/uprobes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/uprobes.c +0 -0
index 0a8c0a4a5423..845aeaf36b8d 100644

arch/x86/kernel/uprobes.c SYSCALL_DEFINE0(uprobe) · line 813

Quoted 5 lines
arch/x86/kernel/uprobes.c +1 -1
@@ -810,7 +810,7 @@ SYSCALL_DEFINE0(uprobe)
 
 	/* Allow execution only from uprobe trampolines. */
 	if (!in_uprobe_trampoline(regs->ip))
-		goto sigill;
+		return -ENXIO;

I agree.

merge bot Applied
#3 lore raw

[tip: perf/core] uprobes/x86: Return error from uprobe syscall when not called from trampoline

In reply to Jiri Olsa
The following commit has been merged into the perf/core branch of tip:

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     d3aeb6d97b22272bb4783c6d4309d81bb0a4527c
Gitweb:        https://git.kernel.org/tip/d3aeb6d97b22272bb4783c6d4309d81bb0a4527c
Author:        Jiri Olsa <[email protected]>
AuthorDate:    Fri, 05 Sep 2025 22:57:29 +02:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Mon, 15 Sep 2025 13:46:29 +02:00

uprobes/x86: Return error from uprobe syscall when not called from trampoline

Currently uprobe syscall handles all errors with forcing SIGILL to current process. As suggested by Andrii it'd be helpful for uprobe syscall detection to return error value for the !in_uprobe_trampoline check.

This way we could just call uprobe syscall and based on return value we will find out if the kernel has it.

---
 arch/x86/kernel/uprobes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/uprobes.c +1 -1
index 0a8c0a4..845aeaf 100644
@@ -810,7 +810,7 @@ SYSCALL_DEFINE0(uprobe)
 
 	/* Allow execution only from uprobe trampolines. */
 	if (!in_uprobe_trampoline(regs->ip))
-		goto sigill;
+		return -ENXIO;
 
 	err = copy_from_user(&args, (void __user *)regs->sp, sizeof(args));
 	if (err)
author reviewer
#4 lore raw

PATCH 2/3 selftests/bpf: Fix uprobe_sigill test for uprobe syscall error value

In reply to Jiri Olsa

The uprobe syscall now returns -ENXIO errno when called outside kernel trampoline, fixing the current sigill test to reflect that and renaming it to uprobe_error.

---
 .../selftests/bpf/prog_tests/uprobe_syscall.c | 34 ++++---------------
 1 file changed, 6 insertions(+), 28 deletions(-)
tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c +6 -28
index 5da0b49eeaca..6d75ede16e7c 100644
@@ -757,34 +757,12 @@ static void test_uprobe_race(void)
 #define __NR_uprobe 336
 #endif
 
-static void test_uprobe_sigill(void)
+static void test_uprobe_error(void)
 {
-	int status, err, pid;
+	long err = syscall(__NR_uprobe);
 
-	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");
+	ASSERT_EQ(err, -1, "error");
+	ASSERT_EQ(errno, ENXIO, "errno");
 }
 
 static void __test_uprobe_syscall(void)
@@ -805,8 +783,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();
+	if (test__start_subtest("uprobe_error"))
+		test_uprobe_error();
 	if (test__start_subtest("uprobe_regs_equal"))
 		test_uprobe_regs_equal(false);
 	if (test__start_subtest("regs_change"))
Signature · 1 line
2.51.0
Acked-by on v1 2/3
#5 lore raw

Re: [PATCH perf/core 2/3] selftests/bpf: Fix uprobe_sigill test for uprobe syscall error value

Quoted 10 lines · Jiri Olsa

The uprobe syscall now returns -ENXIO errno when called outside kernel trampoline, fixing the current sigill test to reflect that and renaming it to uprobe_error.

---
 .../selftests/bpf/prog_tests/uprobe_syscall.c | 34 ++++---------------
 1 file changed, 6 insertions(+), 28 deletions(-)
Quoted 57 lines
tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c +6 -29
index 5da0b49eeaca..6d75ede16e7c 100644
@@ -757,34 +757,12 @@ static void test_uprobe_race(void)
 #define __NR_uprobe 336
 #endif
 
-static void test_uprobe_sigill(void)
+static void test_uprobe_error(void)
 {
-       int status, err, pid;
+       long err = syscall(__NR_uprobe);
 
-       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");
+       ASSERT_EQ(err, -1, "error");
+       ASSERT_EQ(errno, ENXIO, "errno");
 }
 
 static void __test_uprobe_syscall(void)
@@ -805,8 +783,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();
+       if (test__start_subtest("uprobe_error"))
+               test_uprobe_error();
        if (test__start_subtest("uprobe_regs_equal"))
                test_uprobe_regs_equal(false);
        if (test__start_subtest("regs_change"))
--

2.51.0

merge bot Applied
#6 lore raw

[tip: perf/core] selftests/bpf: Fix uprobe_sigill test for uprobe syscall error value

In reply to Jiri Olsa
The following commit has been merged into the perf/core branch of tip:

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     6d48436560e91be858158e227f21aab71698814e
Gitweb:        https://git.kernel.org/tip/6d48436560e91be858158e227f21aab71698814e
Author:        Jiri Olsa <[email protected]>
AuthorDate:    Fri, 05 Sep 2025 22:57:30 +02:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Mon, 15 Sep 2025 13:46:29 +02:00

selftests/bpf: Fix uprobe_sigill test for uprobe syscall error value

The uprobe syscall now returns -ENXIO errno when called outside kernel trampoline, fixing the current sigill test to reflect that and renaming it to uprobe_error.

---
 tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c | 34 +-------
 1 file changed, 6 insertions(+), 28 deletions(-)
tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c +6 -28
index 5da0b49..6d75ede 100644
@@ -757,34 +757,12 @@ cleanup:
 #define __NR_uprobe 336
 #endif
 
-static void test_uprobe_sigill(void)
+static void test_uprobe_error(void)
 {
-	int status, err, pid;
+	long err = syscall(__NR_uprobe);
 
-	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");
+	ASSERT_EQ(err, -1, "error");
+	ASSERT_EQ(errno, ENXIO, "errno");
 }
 
 static void __test_uprobe_syscall(void)
@@ -805,8 +783,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();
+	if (test__start_subtest("uprobe_error"))
+		test_uprobe_error();
 	if (test__start_subtest("uprobe_regs_equal"))
 		test_uprobe_regs_equal(false);
 	if (test__start_subtest("regs_change"))
author reviewer
#7 lore raw

PATCH 3/3 man2: Add uprobe syscall page

In reply to Jiri Olsa

Changing uretprobe syscall man page to be shared with new uprobe syscall man page.

Cc Alejandro Colomar <[email protected]>
---
 man/man2/uprobe.2    |  1 +
 man/man2/uretprobe.2 | 42 +++++++++++++++++++++++++++++-------------
 2 files changed, 30 insertions(+), 13 deletions(-)
 create mode 100644 man/man2/uprobe.2
man/man2/uprobe.2 new file +1 -0
new file mode 100644
index 000000000000..ea5ccf901591
@@ -0,0 +1 @@
+.so man2/uretprobe.2
man/man2/uretprobe.2 +29 -13

75 lines not on this page · raw message

Signature · 1 line
2.51.0
maintainer
#8 lore raw
In reply to Jiri Olsa
Quoted 7 lines · Jiri Olsa

Jiri Olsa (2):
uprobes/x86: Return error from uprobe syscall when not called from trampoline selftests/bpf: Fix uprobe_sigill test for uprobe syscall error value

 arch/x86/kernel/uprobes.c                               |  2 +-
 tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c | 34 ++++++----------------------------
 2 files changed, 7 insertions(+), 29 deletions(-)

Thanks!