uprobes/x86: change error path for uprobe syscall
Jiri Olsa
reviewercover 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
Jiri Olsa
reviewerPATCH 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
@@ -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
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.
Suggested-by Andrii Nakryiko <[email protected]>Acked-by Andrii Nakryiko <[email protected]>Signed-off-by Jiri Olsa <[email protected]>--- arch/x86/kernel/uprobes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kernel/uprobes.c +0
-0
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.
[tip: perf/core] uprobes/x86: Return error from uprobe syscall when not called from trampoline
In reply to Jiri OlsaThe 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
@@ -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)
Jiri Olsa
reviewerPATCH 2/3 selftests/bpf: Fix uprobe_sigill test for uprobe syscall error value
In reply to Jiri OlsaThe 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
@@ -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 ) { - asmvolatile ( -"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
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
-ENXIOerrno when called outside kernel trampoline, fixing the current sigill test to reflect that and renaming it touprobe_error.Signed-off-by Jiri Olsa <[email protected]>--- .../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@@ -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 ) { - asmvolatile ( -"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
[tip: perf/core] selftests/bpf: Fix uprobe_sigill test for uprobe syscall error value
In reply to Jiri OlsaThe 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
@@ -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 ) { - asmvolatile ( -"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" ))
Jiri Olsa
reviewerPATCH 3/3 man2: Add uprobe syscall page
In reply to Jiri OlsaChanging uretprobe syscall man page to be shared with new uprobe syscall man 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
man/man2/uprobe.2 new file +1 -0
@@ -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
Peter Zijlstra
maintainerQuoted 7 lines · Jiri Olsa
Jiri Olsa (2):
uprobes/x86: Return error from uprobe syscall when not called from trampoline selftests/bpf: Fixuprobe_sigilltest for uprobe syscall error valuearch/x86/kernel/uprobes.c | 2 +- tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c | 34 ++++++---------------------------- 2 files changed, 7 insertions(+), 29 deletions(-)
Thanks!