LinuxPPC-Dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [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

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