LinuxPPC-Dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Renzo Davoli <renzo@cs.unibo.it>
To: Madhavan Srinivasan <maddy@linux.ibm.com>,
	Michael Ellerman <mpe@ellerman.id.au>
Cc: "Renzo Davoli" <renzo@cs.unibo.it>,
	"Nicholas Piggin" <npiggin@gmail.com>,
	"Christophe Leroy" <chleroy@kernel.org>,
	"Ritesh Harjani" <ritesh.list@gmail.com>,
	"Michal Suchánek" <msuchanek@suse.de>,
	"Mukesh Kumar Chaurasiya" <mkchauras@gmail.com>,
	"Shrikanth Hegde" <sshegde@linux.ibm.com>,
	"Thomas Gleixner" <tglx@kernel.org>,
	"Oleg Nesterov" <oleg@redhat.com>,
	"Dmitry V . Levin" <ldv@strace.io>,
	"Thomas Bogendoerfer" <tsbogend@alpha.franken.de>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: [PATCH v3 2/2] powerpc/syscall: Return the preset value of skipped syscalls
Date: Fri, 30 Oct 2026 09:49:25 +0100	[thread overview]
Message-ID: <20261030084926.1068384-3-renzo@cs.unibo.it> (raw)
In-Reply-To: <20261030084926.1068384-1-renzo@cs.unibo.it>

When ptrace or seccomp skip a system call, r3 (and CR0.SO for "sc")
already hold its return value, set either through
syscall_set_return_value() or directly by a tracer, e.g. with
PTRACE_POKEUSER at a PTRACE_EVENT_SECCOMP stop.

Since commit 05c033db7e9a ("entry, treewide: Make
syscall_enter_from_user_mode[_work]() indicate syscall execution"),
system_call_exception() returns syscall_get_error() for a skipped system
call.  syscall_get_error() is 0 for any non-error value, so a success
value is replaced with 0: the value set by a tracer, or the val of a
SECCOMP_RET_USER_NOTIF response.  Among others, the seccomp_bpf
user_notification_* and TRACE_syscall.seccomp.syscall_faked selftests
fail.

Return the error from syscall_get_error() if there is one, and the value
in r3 otherwise.  The error path is unchanged, and a success value is
returned as it was before the conversion to GENERIC_ENTRY, when
system_call_exception() returned regs->gpr[3] for a skipped system call.

Fixes: 05c033db7e9a ("entry, treewide: Make syscall_enter_from_user_mode[_work]() indicate syscall execution")
Cc: stable@vger.kernel.org # v7.3
Suggested-by: Mukesh Kumar Chaurasiya (IBM) <mkchauras@gmail.com>
Assisted-by: claude-opus-5-5
Signed-off-by: Renzo Davoli <renzo@cs.unibo.it>
---
 arch/powerpc/kernel/syscall.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/kernel/syscall.c b/arch/powerpc/kernel/syscall.c
index f7412556a9e8..7b35b895b70c 100644
--- a/arch/powerpc/kernel/syscall.c
+++ b/arch/powerpc/kernel/syscall.c
@@ -19,7 +19,14 @@ notrace long system_call_exception(struct pt_regs *regs, unsigned long r0)
 	syscall_fn f;
 
 	if (unlikely(!syscall_enter_from_user_mode_randomize_stack(regs, &r0))) {
-		return syscall_get_error(current, regs);
+		/*
+		 * The syscall was skipped by seccomp or ptrace. r3 (and CR0.SO
+		 * for "sc") already hold the return value, set either through
+		 * syscall_set_return_value() or directly by the tracer. Hand
+		 * it back in the form syscall_exit_prepare() expects: -errno
+		 * on failure, else the value in r3.
+		 */
+		return syscall_get_error(current, regs) ?: regs->gpr[3];
 	}
 
 	if (unlikely(r0 >= NR_syscalls)) {
-- 
2.55.0



      parent reply	other threads:[~2026-10-30  8:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-30  8:49 [PATCH v3 0/2] powerpc/syscall: Fix the return value of skipped syscalls Renzo Davoli
2026-10-30  8:49 ` [PATCH v3 1/2] powerpc/syscall: Remove TIF_SYSCALL_RET Renzo Davoli
2026-10-30  8:49 ` Renzo Davoli [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261030084926.1068384-3-renzo@cs.unibo.it \
    --to=renzo@cs.unibo.it \
    --cc=akpm@linux-foundation.org \
    --cc=chleroy@kernel.org \
    --cc=ldv@strace.io \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.ibm.com \
    --cc=mkchauras@gmail.com \
    --cc=mpe@ellerman.id.au \
    --cc=msuchanek@suse.de \
    --cc=npiggin@gmail.com \
    --cc=oleg@redhat.com \
    --cc=ritesh.list@gmail.com \
    --cc=sshegde@linux.ibm.com \
    --cc=stable@vger.kernel.org \
    --cc=tglx@kernel.org \
    --cc=tsbogend@alpha.franken.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox