* [PATCH] powerpc/syscall: Fix seccomp errno handling with GENERIC_ENTRY
@ 2026-06-24 17:15 Mukesh Kumar Chaurasiya (IBM)
2026-06-24 17:44 ` Michal Suchánek
` (4 more replies)
0 siblings, 5 replies; 12+ messages in thread
From: Mukesh Kumar Chaurasiya (IBM) @ 2026-06-24 17:15 UTC (permalink / raw)
To: maddy, mpe, npiggin, chleroy, sshegde, mkchauras, kees,
mark.rutland, mkchauras, ryan.roberts, linuxppc-dev, linux-kernel
Cc: Michal Suchánek
After enabling GENERIC_ENTRY on PowerPC, seccomp filters using
SCMP_ACT_ERRNO without an explicit errnoRet value return ENOSYS
(Function not implemented) instead of the expected EPERM (Operation
not permitted).
The issue occurs in system_call_exception() when syscall_enter_from_user_mode()
returns -1 to indicate the syscall should be skipped (e.g., blocked by seccomp).
The current code treats this -1 as a syscall number and compares it against
NR_syscalls. Since -1 (when cast to unsigned long) is greater than NR_syscalls,
the code incorrectly returns -ENOSYS, overwriting the errno that seccomp
already set via syscall_set_return_value().
The generic entry code in syscall_trace_enter() calls __secure_computing(),
which sets the appropriate errno in regs->gpr[3] and returns -1 to signal
that the syscall should be skipped. However, the PowerPC syscall handler
was not checking for this -1 return value before validating the syscall
number.
Fix this by explicitly checking if syscall_enter_from_user_mode() returns
-1 and returning the value already set in regs->gpr[3] (the errno from
seccomp) before performing the syscall number validation.
This aligns PowerPC's behavior with other architectures using GENERIC_ENTRY
and restores correct seccomp errno handling.
Fixes: bee25f97ad24 ("powerpc: Enable GENERIC_ENTRY feature")
Reported-by: Michal Suchánek <msuchanek@suse.de>
Signed-off-by: Mukesh Kumar Chaurasiya (IBM) <mkchauras@gmail.com>
---
arch/powerpc/kernel/syscall.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/arch/powerpc/kernel/syscall.c b/arch/powerpc/kernel/syscall.c
index a9da2af6efa8..5b58c8d396c8 100644
--- a/arch/powerpc/kernel/syscall.c
+++ b/arch/powerpc/kernel/syscall.c
@@ -22,6 +22,10 @@ notrace long system_call_exception(struct pt_regs *regs, unsigned long r0)
add_random_kstack_offset();
r0 = syscall_enter_from_user_mode(regs, r0);
+ /* Seccomp or ptrace may have set return value, skip syscall */
+ if (unlikely(r0 == -1L))
+ return regs->gpr[3];
+
if (unlikely(r0 >= NR_syscalls)) {
if (unlikely(trap_is_unsupported_scv(regs))) {
/* Unsupported scv vector */
--
2.54.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH] powerpc/syscall: Fix seccomp errno handling with GENERIC_ENTRY
2026-06-24 17:15 [PATCH] powerpc/syscall: Fix seccomp errno handling with GENERIC_ENTRY Mukesh Kumar Chaurasiya (IBM)
@ 2026-06-24 17:44 ` Michal Suchánek
2026-06-26 5:54 ` Michal Suchánek
` (3 subsequent siblings)
4 siblings, 0 replies; 12+ messages in thread
From: Michal Suchánek @ 2026-06-24 17:44 UTC (permalink / raw)
To: Mukesh Kumar Chaurasiya (IBM)
Cc: maddy, mpe, npiggin, chleroy, sshegde, mkchauras, kees,
mark.rutland, ryan.roberts, linuxppc-dev, linux-kernel
On Wed, Jun 24, 2026 at 10:45:20PM +0530, Mukesh Kumar Chaurasiya (IBM) wrote:
> After enabling GENERIC_ENTRY on PowerPC, seccomp filters using
> SCMP_ACT_ERRNO without an explicit errnoRet value return ENOSYS
> (Function not implemented) instead of the expected EPERM (Operation
> not permitted).
>
> The issue occurs in system_call_exception() when syscall_enter_from_user_mode()
> returns -1 to indicate the syscall should be skipped (e.g., blocked by seccomp).
> The current code treats this -1 as a syscall number and compares it against
> NR_syscalls. Since -1 (when cast to unsigned long) is greater than NR_syscalls,
> the code incorrectly returns -ENOSYS, overwriting the errno that seccomp
> already set via syscall_set_return_value().
>
> The generic entry code in syscall_trace_enter() calls __secure_computing(),
> which sets the appropriate errno in regs->gpr[3] and returns -1 to signal
> that the syscall should be skipped. However, the PowerPC syscall handler
> was not checking for this -1 return value before validating the syscall
> number.
>
> Fix this by explicitly checking if syscall_enter_from_user_mode() returns
> -1 and returning the value already set in regs->gpr[3] (the errno from
> seccomp) before performing the syscall number validation.
>
> This aligns PowerPC's behavior with other architectures using GENERIC_ENTRY
> and restores correct seccomp errno handling.
>
> Fixes: bee25f97ad24 ("powerpc: Enable GENERIC_ENTRY feature")
> Reported-by: Michal Suchánek <msuchanek@suse.de>
Tested-by: Michal Suchánek <msuchanek@suse.de>
Thanks
Michal
> Signed-off-by: Mukesh Kumar Chaurasiya (IBM) <mkchauras@gmail.com>
> ---
> arch/powerpc/kernel/syscall.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/arch/powerpc/kernel/syscall.c b/arch/powerpc/kernel/syscall.c
> index a9da2af6efa8..5b58c8d396c8 100644
> --- a/arch/powerpc/kernel/syscall.c
> +++ b/arch/powerpc/kernel/syscall.c
> @@ -22,6 +22,10 @@ notrace long system_call_exception(struct pt_regs *regs, unsigned long r0)
> add_random_kstack_offset();
> r0 = syscall_enter_from_user_mode(regs, r0);
>
> + /* Seccomp or ptrace may have set return value, skip syscall */
> + if (unlikely(r0 == -1L))
> + return regs->gpr[3];
> +
> if (unlikely(r0 >= NR_syscalls)) {
> if (unlikely(trap_is_unsupported_scv(regs))) {
> /* Unsupported scv vector */
> --
> 2.54.0
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] powerpc/syscall: Fix seccomp errno handling with GENERIC_ENTRY
2026-06-24 17:15 [PATCH] powerpc/syscall: Fix seccomp errno handling with GENERIC_ENTRY Mukesh Kumar Chaurasiya (IBM)
2026-06-24 17:44 ` Michal Suchánek
@ 2026-06-26 5:54 ` Michal Suchánek
2026-06-29 4:50 ` Mukesh Kumar Chaurasiya
2026-06-26 7:50 ` Kees Cook
` (2 subsequent siblings)
4 siblings, 1 reply; 12+ messages in thread
From: Michal Suchánek @ 2026-06-26 5:54 UTC (permalink / raw)
To: Mukesh Kumar Chaurasiya (IBM)
Cc: maddy, mpe, npiggin, chleroy, sshegde, mkchauras, kees,
mark.rutland, ryan.roberts, linuxppc-dev, linux-kernel
Hello,
On Wed, Jun 24, 2026 at 10:45:20PM +0530, Mukesh Kumar Chaurasiya (IBM) wrote:
> After enabling GENERIC_ENTRY on PowerPC, seccomp filters using
> SCMP_ACT_ERRNO without an explicit errnoRet value return ENOSYS
> (Function not implemented) instead of the expected EPERM (Operation
> not permitted).
>
> The issue occurs in system_call_exception() when syscall_enter_from_user_mode()
> returns -1 to indicate the syscall should be skipped (e.g., blocked by seccomp).
> The current code treats this -1 as a syscall number and compares it against
> NR_syscalls. Since -1 (when cast to unsigned long) is greater than NR_syscalls,
> the code incorrectly returns -ENOSYS, overwriting the errno that seccomp
> already set via syscall_set_return_value().
>
> The generic entry code in syscall_trace_enter() calls __secure_computing(),
> which sets the appropriate errno in regs->gpr[3] and returns -1 to signal
> that the syscall should be skipped. However, the PowerPC syscall handler
> was not checking for this -1 return value before validating the syscall
> number.
>
> Fix this by explicitly checking if syscall_enter_from_user_mode() returns
> -1 and returning the value already set in regs->gpr[3] (the errno from
> seccomp) before performing the syscall number validation.
>
> This aligns PowerPC's behavior with other architectures using GENERIC_ENTRY
> and restores correct seccomp errno handling.
>
> Fixes: bee25f97ad24 ("powerpc: Enable GENERIC_ENTRY feature")
> Reported-by: Michal Suchánek <msuchanek@suse.de>
> Signed-off-by: Mukesh Kumar Chaurasiya (IBM) <mkchauras@gmail.com>
> ---
> arch/powerpc/kernel/syscall.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/arch/powerpc/kernel/syscall.c b/arch/powerpc/kernel/syscall.c
> index a9da2af6efa8..5b58c8d396c8 100644
> --- a/arch/powerpc/kernel/syscall.c
> +++ b/arch/powerpc/kernel/syscall.c
> @@ -22,6 +22,10 @@ notrace long system_call_exception(struct pt_regs *regs, unsigned long r0)
> add_random_kstack_offset();
> r0 = syscall_enter_from_user_mode(regs, r0);
>
> + /* Seccomp or ptrace may have set return value, skip syscall */
> + if (unlikely(r0 == -1L))
> + return regs->gpr[3];
this should use syscall_get_error instead of accessing the register
value directly. The error is represented differently in the scv and
non-scv case, and for non-scv case this will return wrong value.
Thanks
Michal
> +
> if (unlikely(r0 >= NR_syscalls)) {
> if (unlikely(trap_is_unsupported_scv(regs))) {
> /* Unsupported scv vector */
> --
> 2.54.0
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] powerpc/syscall: Fix seccomp errno handling with GENERIC_ENTRY
2026-06-24 17:15 [PATCH] powerpc/syscall: Fix seccomp errno handling with GENERIC_ENTRY Mukesh Kumar Chaurasiya (IBM)
2026-06-24 17:44 ` Michal Suchánek
2026-06-26 5:54 ` Michal Suchánek
@ 2026-06-26 7:50 ` Kees Cook
2026-06-26 14:30 ` Christophe Leroy (CS GROUP)
2026-06-26 14:31 ` Christophe Leroy (CS GROUP)
2026-06-29 13:31 ` Michal Suchánek
4 siblings, 1 reply; 12+ messages in thread
From: Kees Cook @ 2026-06-26 7:50 UTC (permalink / raw)
To: Mukesh Kumar Chaurasiya (IBM)
Cc: maddy, mpe, npiggin, chleroy, sshegde, mkchauras, mark.rutland,
ryan.roberts, linuxppc-dev, linux-kernel, Michal Suchánek
On Wed, Jun 24, 2026 at 10:45:20PM +0530, Mukesh Kumar Chaurasiya (IBM) wrote:
> After enabling GENERIC_ENTRY on PowerPC, seccomp filters using
> SCMP_ACT_ERRNO without an explicit errnoRet value return ENOSYS
> (Function not implemented) instead of the expected EPERM (Operation
> not permitted).
Was this noticed by the seccomp_bpf kselftest? (If not, I'd love a
regression test added for this case...)
-Kees
--
Kees Cook
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] powerpc/syscall: Fix seccomp errno handling with GENERIC_ENTRY
2026-06-26 7:50 ` Kees Cook
@ 2026-06-26 14:30 ` Christophe Leroy (CS GROUP)
0 siblings, 0 replies; 12+ messages in thread
From: Christophe Leroy (CS GROUP) @ 2026-06-26 14:30 UTC (permalink / raw)
To: Kees Cook, Mukesh Kumar Chaurasiya (IBM)
Cc: maddy, mpe, npiggin, sshegde, mkchauras, mark.rutland,
ryan.roberts, linuxppc-dev, linux-kernel, Michal Suchánek
Le 26/06/2026 à 09:50, Kees Cook a écrit :
> On Wed, Jun 24, 2026 at 10:45:20PM +0530, Mukesh Kumar Chaurasiya (IBM) wrote:
>> After enabling GENERIC_ENTRY on PowerPC, seccomp filters using
>> SCMP_ACT_ERRNO without an explicit errnoRet value return ENOSYS
>> (Function not implemented) instead of the expected EPERM (Operation
>> not permitted).
>
> Was this noticed by the seccomp_bpf kselftest? (If not, I'd love a
> regression test added for this case...)
>
Was reported here:
https://lore.kernel.org/all/ajpp-_XnbF3UTM_E@kunlun.suse.cz/
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] powerpc/syscall: Fix seccomp errno handling with GENERIC_ENTRY
2026-06-24 17:15 [PATCH] powerpc/syscall: Fix seccomp errno handling with GENERIC_ENTRY Mukesh Kumar Chaurasiya (IBM)
` (2 preceding siblings ...)
2026-06-26 7:50 ` Kees Cook
@ 2026-06-26 14:31 ` Christophe Leroy (CS GROUP)
2026-06-29 4:54 ` Mukesh Kumar Chaurasiya
2026-06-29 13:31 ` Michal Suchánek
4 siblings, 1 reply; 12+ messages in thread
From: Christophe Leroy (CS GROUP) @ 2026-06-26 14:31 UTC (permalink / raw)
To: Mukesh Kumar Chaurasiya (IBM), maddy, mpe, npiggin, sshegde,
mkchauras, kees, mark.rutland, ryan.roberts, linuxppc-dev,
linux-kernel
Cc: Michal Suchánek
Le 24/06/2026 à 19:15, Mukesh Kumar Chaurasiya (IBM) a écrit :
> After enabling GENERIC_ENTRY on PowerPC, seccomp filters using
> SCMP_ACT_ERRNO without an explicit errnoRet value return ENOSYS
> (Function not implemented) instead of the expected EPERM (Operation
> not permitted).
>
> The issue occurs in system_call_exception() when syscall_enter_from_user_mode()
> returns -1 to indicate the syscall should be skipped (e.g., blocked by seccomp).
> The current code treats this -1 as a syscall number and compares it against
> NR_syscalls. Since -1 (when cast to unsigned long) is greater than NR_syscalls,
> the code incorrectly returns -ENOSYS, overwriting the errno that seccomp
> already set via syscall_set_return_value().
>
> The generic entry code in syscall_trace_enter() calls __secure_computing(),
> which sets the appropriate errno in regs->gpr[3] and returns -1 to signal
> that the syscall should be skipped. However, the PowerPC syscall handler
> was not checking for this -1 return value before validating the syscall
> number.
>
> Fix this by explicitly checking if syscall_enter_from_user_mode() returns
> -1 and returning the value already set in regs->gpr[3] (the errno from
> seccomp) before performing the syscall number validation.
>
> This aligns PowerPC's behavior with other architectures using GENERIC_ENTRY
> and restores correct seccomp errno handling.
>
> Fixes: bee25f97ad24 ("powerpc: Enable GENERIC_ENTRY feature")
> Reported-by: Michal Suchánek <msuchanek@suse.de>
Closes: https://lore.kernel.org/all/ajpp-_XnbF3UTM_E@kunlun.suse.cz/
> Signed-off-by: Mukesh Kumar Chaurasiya (IBM) <mkchauras@gmail.com>
> ---
> arch/powerpc/kernel/syscall.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/arch/powerpc/kernel/syscall.c b/arch/powerpc/kernel/syscall.c
> index a9da2af6efa8..5b58c8d396c8 100644
> --- a/arch/powerpc/kernel/syscall.c
> +++ b/arch/powerpc/kernel/syscall.c
> @@ -22,6 +22,10 @@ notrace long system_call_exception(struct pt_regs *regs, unsigned long r0)
> add_random_kstack_offset();
> r0 = syscall_enter_from_user_mode(regs, r0);
>
> + /* Seccomp or ptrace may have set return value, skip syscall */
> + if (unlikely(r0 == -1L))
Is it really needed to add the L after 1 ?
> + return regs->gpr[3];
> +
> if (unlikely(r0 >= NR_syscalls)) {
> if (unlikely(trap_is_unsupported_scv(regs))) {
> /* Unsupported scv vector */
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] powerpc/syscall: Fix seccomp errno handling with GENERIC_ENTRY
2026-06-26 5:54 ` Michal Suchánek
@ 2026-06-29 4:50 ` Mukesh Kumar Chaurasiya
0 siblings, 0 replies; 12+ messages in thread
From: Mukesh Kumar Chaurasiya @ 2026-06-29 4:50 UTC (permalink / raw)
To: Michal Suchánek
Cc: maddy, mpe, npiggin, chleroy, sshegde, mkchauras, kees,
mark.rutland, ryan.roberts, linuxppc-dev, linux-kernel
On Fri, Jun 26, 2026 at 07:54:08AM +0200, Michal Suchánek wrote:
> Hello,
>
> On Wed, Jun 24, 2026 at 10:45:20PM +0530, Mukesh Kumar Chaurasiya (IBM) wrote:
> > After enabling GENERIC_ENTRY on PowerPC, seccomp filters using
> > SCMP_ACT_ERRNO without an explicit errnoRet value return ENOSYS
> > (Function not implemented) instead of the expected EPERM (Operation
> > not permitted).
> >
> > The issue occurs in system_call_exception() when syscall_enter_from_user_mode()
> > returns -1 to indicate the syscall should be skipped (e.g., blocked by seccomp).
> > The current code treats this -1 as a syscall number and compares it against
> > NR_syscalls. Since -1 (when cast to unsigned long) is greater than NR_syscalls,
> > the code incorrectly returns -ENOSYS, overwriting the errno that seccomp
> > already set via syscall_set_return_value().
> >
> > The generic entry code in syscall_trace_enter() calls __secure_computing(),
> > which sets the appropriate errno in regs->gpr[3] and returns -1 to signal
> > that the syscall should be skipped. However, the PowerPC syscall handler
> > was not checking for this -1 return value before validating the syscall
> > number.
> >
> > Fix this by explicitly checking if syscall_enter_from_user_mode() returns
> > -1 and returning the value already set in regs->gpr[3] (the errno from
> > seccomp) before performing the syscall number validation.
> >
> > This aligns PowerPC's behavior with other architectures using GENERIC_ENTRY
> > and restores correct seccomp errno handling.
> >
> > Fixes: bee25f97ad24 ("powerpc: Enable GENERIC_ENTRY feature")
> > Reported-by: Michal Suchánek <msuchanek@suse.de>
> > Signed-off-by: Mukesh Kumar Chaurasiya (IBM) <mkchauras@gmail.com>
> > ---
> > arch/powerpc/kernel/syscall.c | 4 ++++
> > 1 file changed, 4 insertions(+)
> >
> > diff --git a/arch/powerpc/kernel/syscall.c b/arch/powerpc/kernel/syscall.c
> > index a9da2af6efa8..5b58c8d396c8 100644
> > --- a/arch/powerpc/kernel/syscall.c
> > +++ b/arch/powerpc/kernel/syscall.c
> > @@ -22,6 +22,10 @@ notrace long system_call_exception(struct pt_regs *regs, unsigned long r0)
> > add_random_kstack_offset();
> > r0 = syscall_enter_from_user_mode(regs, r0);
> >
> > + /* Seccomp or ptrace may have set return value, skip syscall */
> > + if (unlikely(r0 == -1L))
> > + return regs->gpr[3];
>
> this should use syscall_get_error instead of accessing the register
> value directly. The error is represented differently in the scv and
> non-scv case, and for non-scv case this will return wrong value.
>
> Thanks
>
> Michal
>
Yeah, Thanks.
Will send out a new version.
Regards,
Mukesh
> > +
> > if (unlikely(r0 >= NR_syscalls)) {
> > if (unlikely(trap_is_unsupported_scv(regs))) {
> > /* Unsupported scv vector */
> > --
> > 2.54.0
> >
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] powerpc/syscall: Fix seccomp errno handling with GENERIC_ENTRY
2026-06-26 14:31 ` Christophe Leroy (CS GROUP)
@ 2026-06-29 4:54 ` Mukesh Kumar Chaurasiya
0 siblings, 0 replies; 12+ messages in thread
From: Mukesh Kumar Chaurasiya @ 2026-06-29 4:54 UTC (permalink / raw)
To: Christophe Leroy (CS GROUP)
Cc: maddy, mpe, npiggin, sshegde, mkchauras, kees, mark.rutland,
ryan.roberts, linuxppc-dev, linux-kernel, Michal Suchánek
On Fri, Jun 26, 2026 at 04:31:47PM +0200, Christophe Leroy (CS GROUP) wrote:
>
>
> Le 24/06/2026 à 19:15, Mukesh Kumar Chaurasiya (IBM) a écrit :
> > After enabling GENERIC_ENTRY on PowerPC, seccomp filters using
> > SCMP_ACT_ERRNO without an explicit errnoRet value return ENOSYS
> > (Function not implemented) instead of the expected EPERM (Operation
> > not permitted).
> >
> > The issue occurs in system_call_exception() when syscall_enter_from_user_mode()
> > returns -1 to indicate the syscall should be skipped (e.g., blocked by seccomp).
> > The current code treats this -1 as a syscall number and compares it against
> > NR_syscalls. Since -1 (when cast to unsigned long) is greater than NR_syscalls,
> > the code incorrectly returns -ENOSYS, overwriting the errno that seccomp
> > already set via syscall_set_return_value().
> >
> > The generic entry code in syscall_trace_enter() calls __secure_computing(),
> > which sets the appropriate errno in regs->gpr[3] and returns -1 to signal
> > that the syscall should be skipped. However, the PowerPC syscall handler
> > was not checking for this -1 return value before validating the syscall
> > number.
> >
> > Fix this by explicitly checking if syscall_enter_from_user_mode() returns
> > -1 and returning the value already set in regs->gpr[3] (the errno from
> > seccomp) before performing the syscall number validation.
> >
> > This aligns PowerPC's behavior with other architectures using GENERIC_ENTRY
> > and restores correct seccomp errno handling.
> >
> > Fixes: bee25f97ad24 ("powerpc: Enable GENERIC_ENTRY feature")
> > Reported-by: Michal Suchánek <msuchanek@suse.de>
>
> Closes: https://lore.kernel.org/all/ajpp-_XnbF3UTM_E@kunlun.suse.cz/
>
> > Signed-off-by: Mukesh Kumar Chaurasiya (IBM) <mkchauras@gmail.com>
> > ---
> > arch/powerpc/kernel/syscall.c | 4 ++++
> > 1 file changed, 4 insertions(+)
> >
> > diff --git a/arch/powerpc/kernel/syscall.c b/arch/powerpc/kernel/syscall.c
> > index a9da2af6efa8..5b58c8d396c8 100644
> > --- a/arch/powerpc/kernel/syscall.c
> > +++ b/arch/powerpc/kernel/syscall.c
> > @@ -22,6 +22,10 @@ notrace long system_call_exception(struct pt_regs *regs, unsigned long r0)
> > add_random_kstack_offset();
> > r0 = syscall_enter_from_user_mode(regs, r0);
> > + /* Seccomp or ptrace may have set return value, skip syscall */
> > + if (unlikely(r0 == -1L))
>
> Is it really needed to add the L after 1 ?
>
I guess it's not needed, but syscall_trace_enter is returning -1L, and i
wanted to keep it consistent to that.
Regards,
Mukesh
> > + return regs->gpr[3];
> > +
> > if (unlikely(r0 >= NR_syscalls)) {
> > if (unlikely(trap_is_unsupported_scv(regs))) {
> > /* Unsupported scv vector */
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] powerpc/syscall: Fix seccomp errno handling with GENERIC_ENTRY
2026-06-24 17:15 [PATCH] powerpc/syscall: Fix seccomp errno handling with GENERIC_ENTRY Mukesh Kumar Chaurasiya (IBM)
` (3 preceding siblings ...)
2026-06-26 14:31 ` Christophe Leroy (CS GROUP)
@ 2026-06-29 13:31 ` Michal Suchánek
2026-06-29 17:02 ` Mukesh Kumar Chaurasiya
4 siblings, 1 reply; 12+ messages in thread
From: Michal Suchánek @ 2026-06-29 13:31 UTC (permalink / raw)
To: Mukesh Kumar Chaurasiya (IBM)
Cc: maddy, mpe, npiggin, chleroy, sshegde, mkchauras, kees,
mark.rutland, ryan.roberts, linuxppc-dev, linux-kernel
Hello,
there is yet another bug identified.
When the initial syscall number is -1 the new condition bypasses setting
the ENOSYS below in if (unlikely(r0 >= NR_syscalls)) and returns 0.
perl -MPOSIX -e '$!=0; my $r = syscall(-1, 0); print "ret=$r errno=".($!+0)." ($!)\n"'
Normally the result is
ret=-1 errno=38 (Function not implemented)
but with this patch the result is
ret=0 errno=0 ()
fixup below.
On Wed, Jun 24, 2026 at 10:45:20PM +0530, Mukesh Kumar Chaurasiya (IBM) wrote:
> After enabling GENERIC_ENTRY on PowerPC, seccomp filters using
> SCMP_ACT_ERRNO without an explicit errnoRet value return ENOSYS
> (Function not implemented) instead of the expected EPERM (Operation
> not permitted).
>
> The issue occurs in system_call_exception() when syscall_enter_from_user_mode()
> returns -1 to indicate the syscall should be skipped (e.g., blocked by seccomp).
> The current code treats this -1 as a syscall number and compares it against
> NR_syscalls. Since -1 (when cast to unsigned long) is greater than NR_syscalls,
> the code incorrectly returns -ENOSYS, overwriting the errno that seccomp
> already set via syscall_set_return_value().
>
> The generic entry code in syscall_trace_enter() calls __secure_computing(),
> which sets the appropriate errno in regs->gpr[3] and returns -1 to signal
> that the syscall should be skipped. However, the PowerPC syscall handler
> was not checking for this -1 return value before validating the syscall
> number.
>
> Fix this by explicitly checking if syscall_enter_from_user_mode() returns
> -1 and returning the value already set in regs->gpr[3] (the errno from
> seccomp) before performing the syscall number validation.
>
> This aligns PowerPC's behavior with other architectures using GENERIC_ENTRY
> and restores correct seccomp errno handling.
>
> Fixes: bee25f97ad24 ("powerpc: Enable GENERIC_ENTRY feature")
> Reported-by: Michal Suchánek <msuchanek@suse.de>
> Signed-off-by: Mukesh Kumar Chaurasiya (IBM) <mkchauras@gmail.com>
> ---
> arch/powerpc/kernel/syscall.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/arch/powerpc/kernel/syscall.c b/arch/powerpc/kernel/syscall.c
> index a9da2af6efa8..5b58c8d396c8 100644
> --- a/arch/powerpc/kernel/syscall.c
> +++ b/arch/powerpc/kernel/syscall.c
> @@ -22,6 +22,10 @@ notrace long system_call_exception(struct pt_regs *regs, unsigned long r0)
unsigned long r0_initial = r0;
> add_random_kstack_offset();
> r0 = syscall_enter_from_user_mode(regs, r0);
>
> + /* Seccomp or ptrace may have set return value, skip syscall */
> + if (unlikely(r0 == -1L)
&& (r0_initial != -1L))
> + return regs->gpr[3];
> +
> if (unlikely(r0 >= NR_syscalls)) {
> if (unlikely(trap_is_unsupported_scv(regs))) {
> /* Unsupported scv vector */
Thanks
Michal
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] powerpc/syscall: Fix seccomp errno handling with GENERIC_ENTRY
2026-06-29 13:31 ` Michal Suchánek
@ 2026-06-29 17:02 ` Mukesh Kumar Chaurasiya
2026-06-29 17:07 ` Michal Suchánek
0 siblings, 1 reply; 12+ messages in thread
From: Mukesh Kumar Chaurasiya @ 2026-06-29 17:02 UTC (permalink / raw)
To: Michal Suchánek
Cc: maddy, mpe, npiggin, chleroy, sshegde, mkchauras, kees,
mark.rutland, ryan.roberts, linuxppc-dev, linux-kernel
On Mon, Jun 29, 2026 at 03:31:36PM +0200, Michal Suchánek wrote:
> Hello,
>
> there is yet another bug identified.
>
> When the initial syscall number is -1 the new condition bypasses setting
> the ENOSYS below in if (unlikely(r0 >= NR_syscalls)) and returns 0.
>
> perl -MPOSIX -e '$!=0; my $r = syscall(-1, 0); print "ret=$r errno=".($!+0)." ($!)\n"'
>
> Normally the result is
>
> ret=-1 errno=38 (Function not implemented)
>
> but with this patch the result is
>
> ret=0 errno=0 ()
>
> fixup below.
>
> On Wed, Jun 24, 2026 at 10:45:20PM +0530, Mukesh Kumar Chaurasiya (IBM) wrote:
> > After enabling GENERIC_ENTRY on PowerPC, seccomp filters using
> > SCMP_ACT_ERRNO without an explicit errnoRet value return ENOSYS
> > (Function not implemented) instead of the expected EPERM (Operation
> > not permitted).
> >
> > The issue occurs in system_call_exception() when syscall_enter_from_user_mode()
> > returns -1 to indicate the syscall should be skipped (e.g., blocked by seccomp).
> > The current code treats this -1 as a syscall number and compares it against
> > NR_syscalls. Since -1 (when cast to unsigned long) is greater than NR_syscalls,
> > the code incorrectly returns -ENOSYS, overwriting the errno that seccomp
> > already set via syscall_set_return_value().
> >
> > The generic entry code in syscall_trace_enter() calls __secure_computing(),
> > which sets the appropriate errno in regs->gpr[3] and returns -1 to signal
> > that the syscall should be skipped. However, the PowerPC syscall handler
> > was not checking for this -1 return value before validating the syscall
> > number.
> >
> > Fix this by explicitly checking if syscall_enter_from_user_mode() returns
> > -1 and returning the value already set in regs->gpr[3] (the errno from
> > seccomp) before performing the syscall number validation.
> >
> > This aligns PowerPC's behavior with other architectures using GENERIC_ENTRY
> > and restores correct seccomp errno handling.
> >
> > Fixes: bee25f97ad24 ("powerpc: Enable GENERIC_ENTRY feature")
> > Reported-by: Michal Suchánek <msuchanek@suse.de>
> > Signed-off-by: Mukesh Kumar Chaurasiya (IBM) <mkchauras@gmail.com>
> > ---
> > arch/powerpc/kernel/syscall.c | 4 ++++
> > 1 file changed, 4 insertions(+)
> >
> > diff --git a/arch/powerpc/kernel/syscall.c b/arch/powerpc/kernel/syscall.c
> > index a9da2af6efa8..5b58c8d396c8 100644
> > --- a/arch/powerpc/kernel/syscall.c
> > +++ b/arch/powerpc/kernel/syscall.c
> > @@ -22,6 +22,10 @@ notrace long system_call_exception(struct pt_regs *regs, unsigned long r0)
> unsigned long r0_initial = r0;
> > add_random_kstack_offset();
> > r0 = syscall_enter_from_user_mode(regs, r0);
> >
> > + /* Seccomp or ptrace may have set return value, skip syscall */
> > + if (unlikely(r0 == -1L)
> && (r0_initial != -1L))
> > + return regs->gpr[3];
> > +
> > if (unlikely(r0 >= NR_syscalls)) {
> > if (unlikely(trap_is_unsupported_scv(regs))) {
> > /* Unsupported scv vector */
>
> Thanks
>
> Michal
What do you think about this diff?
This seems much cleaner.
diff --git a/arch/powerpc/kernel/syscall.c b/arch/powerpc/kernel/syscall.c
index a9da2af6efa8..a6c89052e8c5 100644
--- a/arch/powerpc/kernel/syscall.c
+++ b/arch/powerpc/kernel/syscall.c
@@ -20,8 +20,6 @@ notrace long system_call_exception(struct pt_regs *regs, unsigned long r0)
syscall_fn f;
add_random_kstack_offset();
- r0 = syscall_enter_from_user_mode(regs, r0);
-
if (unlikely(r0 >= NR_syscalls)) {
if (unlikely(trap_is_unsupported_scv(regs))) {
/* Unsupported scv vector */
@@ -30,6 +28,11 @@ notrace long system_call_exception(struct pt_regs *regs, unsigned long r0)
}
return -ENOSYS;
}
+ r0 = syscall_enter_from_user_mode(regs, r0);
+
+ /* Seccomp or ptrace may have set return value, skip syscall */
+ if (unlikely(r0 == -1L))
+ return syscall_get_error(current, regs);
/* May be faster to do array_index_nospec? */
barrier_nospec();
Regards,
Mukesh
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH] powerpc/syscall: Fix seccomp errno handling with GENERIC_ENTRY
2026-06-29 17:02 ` Mukesh Kumar Chaurasiya
@ 2026-06-29 17:07 ` Michal Suchánek
2026-06-29 17:14 ` Mukesh Kumar Chaurasiya
0 siblings, 1 reply; 12+ messages in thread
From: Michal Suchánek @ 2026-06-29 17:07 UTC (permalink / raw)
To: Mukesh Kumar Chaurasiya
Cc: maddy, mpe, npiggin, chleroy, sshegde, mkchauras, kees,
mark.rutland, ryan.roberts, linuxppc-dev, linux-kernel
On Mon, Jun 29, 2026 at 10:32:47PM +0530, Mukesh Kumar Chaurasiya wrote:
> On Mon, Jun 29, 2026 at 03:31:36PM +0200, Michal Suchánek wrote:
> > Hello,
> >
> > there is yet another bug identified.
> >
> > When the initial syscall number is -1 the new condition bypasses setting
> > the ENOSYS below in if (unlikely(r0 >= NR_syscalls)) and returns 0.
> >
> > perl -MPOSIX -e '$!=0; my $r = syscall(-1, 0); print "ret=$r errno=".($!+0)." ($!)\n"'
> >
> > Normally the result is
> >
> > ret=-1 errno=38 (Function not implemented)
> >
> > but with this patch the result is
> >
> > ret=0 errno=0 ()
> >
> > fixup below.
> >
> > On Wed, Jun 24, 2026 at 10:45:20PM +0530, Mukesh Kumar Chaurasiya (IBM) wrote:
> > > After enabling GENERIC_ENTRY on PowerPC, seccomp filters using
> > > SCMP_ACT_ERRNO without an explicit errnoRet value return ENOSYS
> > > (Function not implemented) instead of the expected EPERM (Operation
> > > not permitted).
> > >
> > > The issue occurs in system_call_exception() when syscall_enter_from_user_mode()
> > > returns -1 to indicate the syscall should be skipped (e.g., blocked by seccomp).
> > > The current code treats this -1 as a syscall number and compares it against
> > > NR_syscalls. Since -1 (when cast to unsigned long) is greater than NR_syscalls,
> > > the code incorrectly returns -ENOSYS, overwriting the errno that seccomp
> > > already set via syscall_set_return_value().
> > >
> > > The generic entry code in syscall_trace_enter() calls __secure_computing(),
> > > which sets the appropriate errno in regs->gpr[3] and returns -1 to signal
> > > that the syscall should be skipped. However, the PowerPC syscall handler
> > > was not checking for this -1 return value before validating the syscall
> > > number.
> > >
> > > Fix this by explicitly checking if syscall_enter_from_user_mode() returns
> > > -1 and returning the value already set in regs->gpr[3] (the errno from
> > > seccomp) before performing the syscall number validation.
> > >
> > > This aligns PowerPC's behavior with other architectures using GENERIC_ENTRY
> > > and restores correct seccomp errno handling.
> > >
> > > Fixes: bee25f97ad24 ("powerpc: Enable GENERIC_ENTRY feature")
> > > Reported-by: Michal Suchánek <msuchanek@suse.de>
> > > Signed-off-by: Mukesh Kumar Chaurasiya (IBM) <mkchauras@gmail.com>
> > > ---
> > > arch/powerpc/kernel/syscall.c | 4 ++++
> > > 1 file changed, 4 insertions(+)
> > >
> > > diff --git a/arch/powerpc/kernel/syscall.c b/arch/powerpc/kernel/syscall.c
> > > index a9da2af6efa8..5b58c8d396c8 100644
> > > --- a/arch/powerpc/kernel/syscall.c
> > > +++ b/arch/powerpc/kernel/syscall.c
> > > @@ -22,6 +22,10 @@ notrace long system_call_exception(struct pt_regs *regs, unsigned long r0)
> > unsigned long r0_initial = r0;
> > > add_random_kstack_offset();
> > > r0 = syscall_enter_from_user_mode(regs, r0);
> > >
> > > + /* Seccomp or ptrace may have set return value, skip syscall */
> > > + if (unlikely(r0 == -1L)
> > && (r0_initial != -1L))
> > > + return regs->gpr[3];
> > > +
> > > if (unlikely(r0 >= NR_syscalls)) {
> > > if (unlikely(trap_is_unsupported_scv(regs))) {
> > > /* Unsupported scv vector */
> >
> > Thanks
> >
> > Michal
>
> What do you think about this diff?
> This seems much cleaner.
>
> diff --git a/arch/powerpc/kernel/syscall.c b/arch/powerpc/kernel/syscall.c
> index a9da2af6efa8..a6c89052e8c5 100644
> --- a/arch/powerpc/kernel/syscall.c
> +++ b/arch/powerpc/kernel/syscall.c
> @@ -20,8 +20,6 @@ notrace long system_call_exception(struct pt_regs *regs, unsigned long r0)
> syscall_fn f;
>
> add_random_kstack_offset();
> - r0 = syscall_enter_from_user_mode(regs, r0);
> -
> if (unlikely(r0 >= NR_syscalls)) {
> if (unlikely(trap_is_unsupported_scv(regs))) {
> /* Unsupported scv vector */
> @@ -30,6 +28,11 @@ notrace long system_call_exception(struct pt_regs *regs, unsigned long r0)
> }
> return -ENOSYS;
> }
> + r0 = syscall_enter_from_user_mode(regs, r0);
> +
> + /* Seccomp or ptrace may have set return value, skip syscall */
> + if (unlikely(r0 == -1L))
> + return syscall_get_error(current, regs);
>
This will skip the check for NR_syscalls for whatever is returned from
syscall_enter_from_user_mode other than -1. To me it is not clear if
invalid syscall can be generated by one of the modifications done in
syscall_enter_from_user_mode.
Thanks
Michal
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] powerpc/syscall: Fix seccomp errno handling with GENERIC_ENTRY
2026-06-29 17:07 ` Michal Suchánek
@ 2026-06-29 17:14 ` Mukesh Kumar Chaurasiya
0 siblings, 0 replies; 12+ messages in thread
From: Mukesh Kumar Chaurasiya @ 2026-06-29 17:14 UTC (permalink / raw)
To: Michal Suchánek
Cc: maddy, mpe, npiggin, chleroy, sshegde, mkchauras, kees,
mark.rutland, ryan.roberts, linuxppc-dev, linux-kernel
On Mon, Jun 29, 2026 at 07:07:21PM +0200, Michal Suchánek wrote:
> On Mon, Jun 29, 2026 at 10:32:47PM +0530, Mukesh Kumar Chaurasiya wrote:
> > On Mon, Jun 29, 2026 at 03:31:36PM +0200, Michal Suchánek wrote:
> > > Hello,
> > >
> > > there is yet another bug identified.
> > >
> > > When the initial syscall number is -1 the new condition bypasses setting
> > > the ENOSYS below in if (unlikely(r0 >= NR_syscalls)) and returns 0.
> > >
> > > perl -MPOSIX -e '$!=0; my $r = syscall(-1, 0); print "ret=$r errno=".($!+0)." ($!)\n"'
> > >
> > > Normally the result is
> > >
> > > ret=-1 errno=38 (Function not implemented)
> > >
> > > but with this patch the result is
> > >
> > > ret=0 errno=0 ()
> > >
> > > fixup below.
> > >
> > > On Wed, Jun 24, 2026 at 10:45:20PM +0530, Mukesh Kumar Chaurasiya (IBM) wrote:
> > > > After enabling GENERIC_ENTRY on PowerPC, seccomp filters using
> > > > SCMP_ACT_ERRNO without an explicit errnoRet value return ENOSYS
> > > > (Function not implemented) instead of the expected EPERM (Operation
> > > > not permitted).
> > > >
> > > > The issue occurs in system_call_exception() when syscall_enter_from_user_mode()
> > > > returns -1 to indicate the syscall should be skipped (e.g., blocked by seccomp).
> > > > The current code treats this -1 as a syscall number and compares it against
> > > > NR_syscalls. Since -1 (when cast to unsigned long) is greater than NR_syscalls,
> > > > the code incorrectly returns -ENOSYS, overwriting the errno that seccomp
> > > > already set via syscall_set_return_value().
> > > >
> > > > The generic entry code in syscall_trace_enter() calls __secure_computing(),
> > > > which sets the appropriate errno in regs->gpr[3] and returns -1 to signal
> > > > that the syscall should be skipped. However, the PowerPC syscall handler
> > > > was not checking for this -1 return value before validating the syscall
> > > > number.
> > > >
> > > > Fix this by explicitly checking if syscall_enter_from_user_mode() returns
> > > > -1 and returning the value already set in regs->gpr[3] (the errno from
> > > > seccomp) before performing the syscall number validation.
> > > >
> > > > This aligns PowerPC's behavior with other architectures using GENERIC_ENTRY
> > > > and restores correct seccomp errno handling.
> > > >
> > > > Fixes: bee25f97ad24 ("powerpc: Enable GENERIC_ENTRY feature")
> > > > Reported-by: Michal Suchánek <msuchanek@suse.de>
> > > > Signed-off-by: Mukesh Kumar Chaurasiya (IBM) <mkchauras@gmail.com>
> > > > ---
> > > > arch/powerpc/kernel/syscall.c | 4 ++++
> > > > 1 file changed, 4 insertions(+)
> > > >
> > > > diff --git a/arch/powerpc/kernel/syscall.c b/arch/powerpc/kernel/syscall.c
> > > > index a9da2af6efa8..5b58c8d396c8 100644
> > > > --- a/arch/powerpc/kernel/syscall.c
> > > > +++ b/arch/powerpc/kernel/syscall.c
> > > > @@ -22,6 +22,10 @@ notrace long system_call_exception(struct pt_regs *regs, unsigned long r0)
> > > unsigned long r0_initial = r0;
> > > > add_random_kstack_offset();
> > > > r0 = syscall_enter_from_user_mode(regs, r0);
> > > >
> > > > + /* Seccomp or ptrace may have set return value, skip syscall */
> > > > + if (unlikely(r0 == -1L)
> > > && (r0_initial != -1L))
> > > > + return regs->gpr[3];
> > > > +
> > > > if (unlikely(r0 >= NR_syscalls)) {
> > > > if (unlikely(trap_is_unsupported_scv(regs))) {
> > > > /* Unsupported scv vector */
> > >
> > > Thanks
> > >
> > > Michal
> >
> > What do you think about this diff?
> > This seems much cleaner.
> >
> > diff --git a/arch/powerpc/kernel/syscall.c b/arch/powerpc/kernel/syscall.c
> > index a9da2af6efa8..a6c89052e8c5 100644
> > --- a/arch/powerpc/kernel/syscall.c
> > +++ b/arch/powerpc/kernel/syscall.c
> > @@ -20,8 +20,6 @@ notrace long system_call_exception(struct pt_regs *regs, unsigned long r0)
> > syscall_fn f;
> >
> > add_random_kstack_offset();
> > - r0 = syscall_enter_from_user_mode(regs, r0);
> > -
> > if (unlikely(r0 >= NR_syscalls)) {
> > if (unlikely(trap_is_unsupported_scv(regs))) {
> > /* Unsupported scv vector */
> > @@ -30,6 +28,11 @@ notrace long system_call_exception(struct pt_regs *regs, unsigned long r0)
> > }
> > return -ENOSYS;
> > }
> > + r0 = syscall_enter_from_user_mode(regs, r0);
> > +
> > + /* Seccomp or ptrace may have set return value, skip syscall */
> > + if (unlikely(r0 == -1L))
> > + return syscall_get_error(current, regs);
> >
>
> This will skip the check for NR_syscalls for whatever is returned from
> syscall_enter_from_user_mode other than -1. To me it is not clear if
> invalid syscall can be generated by one of the modifications done in
> syscall_enter_from_user_mode.
>
> Thanks
>
> Michal
The possible return values for syscall_enter_from_user_mode are either
`gpr[0]` or -1. If we have an invalid syscall it'll be handled by the
`r0 >= NR_syscalls` check. I think functionally there should be no
issues.
Regards,
Mukesh
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2026-06-29 17:14 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-24 17:15 [PATCH] powerpc/syscall: Fix seccomp errno handling with GENERIC_ENTRY Mukesh Kumar Chaurasiya (IBM)
2026-06-24 17:44 ` Michal Suchánek
2026-06-26 5:54 ` Michal Suchánek
2026-06-29 4:50 ` Mukesh Kumar Chaurasiya
2026-06-26 7:50 ` Kees Cook
2026-06-26 14:30 ` Christophe Leroy (CS GROUP)
2026-06-26 14:31 ` Christophe Leroy (CS GROUP)
2026-06-29 4:54 ` Mukesh Kumar Chaurasiya
2026-06-29 13:31 ` Michal Suchánek
2026-06-29 17:02 ` Mukesh Kumar Chaurasiya
2026-06-29 17:07 ` Michal Suchánek
2026-06-29 17:14 ` Mukesh Kumar Chaurasiya
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox