mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3 0/2] powerpc/syscall: Fix the return value of skipped syscalls
@ 2026-10-30  8:49 Renzo Davoli
  2026-10-30  8:49 ` [PATCH v3 1/2] powerpc/syscall: Remove TIF_SYSCALL_RET Renzo Davoli
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Renzo Davoli @ 2026-10-30  8:49 UTC (permalink / raw)
  To: Madhavan Srinivasan, Michael Ellerman
  Cc: Renzo Davoli, Nicholas Piggin, Christophe Leroy, Ritesh Harjani,
	Michal Suchánek, Mukesh Kumar Chaurasiya, Shrikanth Hegde,
	Thomas Gleixner, Oleg Nesterov, Dmitry V . Levin,
	Thomas Bogendoerfer, Andrew Morton, linuxppc-dev, linux-kernel

When ptrace or seccomp skip a system call on powerpc, the return value
they set is lost or the tracer is affected:

 - syscall_set_return_value() sets TIF_SYSCALL_RET on current, which is
   the tracer when called through PTRACE_SET_SYSCALL_INFO, so the next
   system call of the tracer is silently skipped (1/2);

 - system_call_exception() returns syscall_get_error() for a skipped
   system call, which is 0 for any non-error value, so a success value
   set by a tracer or by a SECCOMP_RET_USER_NOTIF listener is replaced
   with 0 (2/2).

Both problems are in v7.3.  1/2 does not apply as is to v7.3, which
still has the two separate TIF_SYSCALL_RET checks from before commit
66236558dfac ("powerpc/syscall: Avoid atomic test_and_clear_thread_flag
on fast path"); the code it leaves behind is the same, and 2/2 then
applies on top.

Tested on QEMU pseries (TCG, -cpu power9), ppc64le guest config, on
mainline 734bef548a96, with ppc_skip_repro.c [1] (a tracer sets the
return value with PTRACE_SET_SYSCALL_INFO and then makes a system call;
a tracer skips a system call at a PTRACE_EVENT_SECCOMP stop with
PTRACE_POKEUSER, with both "sc" and "scv 0") and with the ptrace and
seccomp selftests:

                                           mainline    + 1/2       + 2/2
  tracer syscall after SET_SYSCALL_INFO    not run     correct     correct
  skipped syscall, success value, sc/scv   returns 0   returns 0   correct
  skipped syscall, error value, sc/scv     correct     correct     correct
  selftests/ptrace set_syscall_info        FAIL        pass        pass
  selftests/seccomp/seccomp_bpf (*)        14 FAIL     14 FAIL     all pass

  failing in mainline and with 1/2 only:
  user_notification_{basic,child_pid_ns,sibling_pid_ns,fault_recv,addfd,
  addfd_opath,addfd_rlimit,addfd_send_interrupted,sync,fifo,
  wait_killable}, TRACE_syscall.seccomp.syscall_faked,
  notification_restart.{killable,both}.after_receive

(*) not counting user_notification_wait_killable_after_reply (100000
    notifications with a 1 ms itimer), which hits the 30 s harness
    timeout under emulation on all three kernels.

Build-tested with W=1: ppc64le guest config, ppc64_defconfig (BE),
pmac32_defconfig.

Changes in v3:
- Split in two patches, one per Fixes: tag: 1/2 removes TIF_SYSCALL_RET
  (suggested by Michal), 2/2 fixes the return value.
- 2/2 returns syscall_get_error() ?: regs->gpr[3] instead of
  regs->gpr[3], so the error path is unchanged (suggested by Mukesh).
- Applies unchanged to current mainline (d89e1d186ec9).
- Link to v2:
  https://lore.kernel.org/lkml/20261023180735.853655-1-renzo@cs.unibo.it/

Changes in v2:
- Rebased on mainline 734bef548a96, after commit 66236558dfac.
- Link to v1:
  https://lore.kernel.org/lkml/20261018151539.440213-1-renzo@cs.unibo.it/

[1] https://lore.kernel.org/lkml/ato6Tq0aKdqqdqyJ@cs.unibo.it/

Renzo Davoli (2):
  powerpc/syscall: Remove TIF_SYSCALL_RET
  powerpc/syscall: Return the preset value of skipped syscalls

 arch/powerpc/include/asm/syscall.h     |  6 ------
 arch/powerpc/include/asm/thread_info.h |  1 -
 arch/powerpc/kernel/syscall.c          | 13 +++++++++----
 3 files changed, 9 insertions(+), 11 deletions(-)


base-commit: d89e1d186ec9271bf78e62771779e9fc03bf0fc3
-- 
2.55.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v3 1/2] powerpc/syscall: Remove TIF_SYSCALL_RET
  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 ` Renzo Davoli
  2026-10-30  8:49 ` [PATCH v3 2/2] powerpc/syscall: Return the preset value of skipped syscalls Renzo Davoli
  2026-11-19 10:34 ` [PATCH v3 0/2] powerpc/syscall: Fix the return " Renzo Davoli
  2 siblings, 0 replies; 5+ messages in thread
From: Renzo Davoli @ 2026-10-30  8:49 UTC (permalink / raw)
  To: Madhavan Srinivasan, Michael Ellerman
  Cc: Renzo Davoli, Nicholas Piggin, Christophe Leroy, Ritesh Harjani,
	Michal Suchánek, Mukesh Kumar Chaurasiya, Shrikanth Hegde,
	Thomas Gleixner, Oleg Nesterov, Dmitry V . Levin,
	Thomas Bogendoerfer, Andrew Morton, linuxppc-dev, linux-kernel,
	stable

Commit 69cb2be898be ("powerpc/syscall: Fix syscall skip handling for
seccomp and ptrace") added TIF_SYSCALL_RET, set by
syscall_set_return_value(), so that system_call_exception() skips a
system call whose return value has already been set.

The flag is set with set_thread_flag(), i.e. on current rather than on
the task passed to syscall_set_return_value().  When the caller is a
tracer, as with PTRACE_SET_SYSCALL_INFO and op ==
PTRACE_SYSCALL_INFO_EXIT, the flag ends up on the tracer, and the next
system call of the tracer is silently not executed.  Setting it on the
right task would not be enough either: at a syscall-exit stop the flag
would then skip the next system call of the tracee.

The flag is not needed anymore.  Commit 05c033db7e9a ("entry, treewide:
Make syscall_enter_from_user_mode[_work]() indicate syscall execution")
made syscall_enter_from_user_mode_randomize_stack() return false when
ptrace or seccomp skip the system call, and every in-kernel caller of
syscall_set_return_value() on the syscall entry path (SECCOMP_RET_ERRNO,
SECCOMP_RET_TRACE without a tracer, SECCOMP_RET_USER_NOTIF) also makes
it return false.  A system call with an invalid number, including
syscall(-1), still gets -ENOSYS.

Remove the flag.

Fixes: 69cb2be898be ("powerpc/syscall: Fix syscall skip handling for seccomp and ptrace")
Cc: stable@vger.kernel.org # v7.3
Suggested-by: Michal Suchánek <msuchanek@suse.de>
Assisted-by: claude-opus-5-5
Signed-off-by: Renzo Davoli <renzo@cs.unibo.it>
---
 arch/powerpc/include/asm/syscall.h     | 6 ------
 arch/powerpc/include/asm/thread_info.h | 1 -
 arch/powerpc/kernel/syscall.c          | 4 +---
 3 files changed, 1 insertion(+), 10 deletions(-)

diff --git a/arch/powerpc/include/asm/syscall.h b/arch/powerpc/include/asm/syscall.h
index 32be22b995cc..4b3c52ed6e9d 100644
--- a/arch/powerpc/include/asm/syscall.h
+++ b/arch/powerpc/include/asm/syscall.h
@@ -98,12 +98,6 @@ static inline void syscall_set_return_value(struct task_struct *task,
 			regs->gpr[3] = val;
 		}
 	}
-	/*
-	 * Mark that a return value has been explicitly set by seccomp or
-	 * ptrace so that system_call_exception() can skip the syscall
-	 * unconditionally, even when the user requested syscall(-1).
-	 */
-	set_thread_flag(TIF_SYSCALL_RET);
 }
 
 static inline void syscall_get_arguments(struct task_struct *task,
diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
index 1e069a2e7ce8..0487e94d3416 100644
--- a/arch/powerpc/include/asm/thread_info.h
+++ b/arch/powerpc/include/asm/thread_info.h
@@ -120,7 +120,6 @@ void arch_setup_new_exec(void);
 #endif
 #define TIF_POLLING_NRFLAG	19	/* true if poll_idle() is polling TIF_NEED_RESCHED */
 #define TIF_32BIT		20	/* 32 bit binary */
-#define TIF_SYSCALL_RET		21	/* syscall error value set */
 
 /* as above, but as bit values */
 #define _TIF_SYSCALL_TRACE	(1<<TIF_SYSCALL_TRACE)
diff --git a/arch/powerpc/kernel/syscall.c b/arch/powerpc/kernel/syscall.c
index 8529827d697f..f7412556a9e8 100644
--- a/arch/powerpc/kernel/syscall.c
+++ b/arch/powerpc/kernel/syscall.c
@@ -18,9 +18,7 @@ notrace long system_call_exception(struct pt_regs *regs, unsigned long r0)
 	long ret;
 	syscall_fn f;
 
-	if (unlikely(!syscall_enter_from_user_mode_randomize_stack(regs, &r0) ||
-			test_thread_flag(TIF_SYSCALL_RET))) {
-		clear_thread_flag(TIF_SYSCALL_RET);
+	if (unlikely(!syscall_enter_from_user_mode_randomize_stack(regs, &r0))) {
 		return syscall_get_error(current, regs);
 	}
 
-- 
2.55.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v3 2/2] powerpc/syscall: Return the preset value of skipped syscalls
  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
  2026-11-19 10:34 ` [PATCH v3 0/2] powerpc/syscall: Fix the return " Renzo Davoli
  2 siblings, 0 replies; 5+ messages in thread
From: Renzo Davoli @ 2026-10-30  8:49 UTC (permalink / raw)
  To: Madhavan Srinivasan, Michael Ellerman
  Cc: Renzo Davoli, Nicholas Piggin, Christophe Leroy, Ritesh Harjani,
	Michal Suchánek, Mukesh Kumar Chaurasiya, Shrikanth Hegde,
	Thomas Gleixner, Oleg Nesterov, Dmitry V . Levin,
	Thomas Bogendoerfer, Andrew Morton, linuxppc-dev, linux-kernel,
	stable

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3 0/2] powerpc/syscall: Fix the return value of skipped syscalls
  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 ` [PATCH v3 2/2] powerpc/syscall: Return the preset value of skipped syscalls Renzo Davoli
@ 2026-11-19 10:34 ` Renzo Davoli
  2 siblings, 0 replies; 5+ messages in thread
From: Renzo Davoli @ 2026-11-19 10:34 UTC (permalink / raw)
  To: Madhavan Srinivasan, Michael Ellerman
  Cc: Nicholas Piggin, Christophe Leroy, Ritesh Harjani,
	Michal Suchánek, Mukesh Kumar Chaurasiya, Shrikanth Hegde,
	Thomas Gleixner, Oleg Nesterov, Dmitry V . Levin,
	Thomas Bogendoerfer, Andrew Morton, linuxppc-dev, linux-kernel

On Fri, Oct 30, 2026 at 09:49:23AM +0100, Renzo Davoli wrote:
> When ptrace or seccomp skip a system call on powerpc, the return value
> they set is lost or the tracer is affected:

Hi Madhavan, Michael,

gentle ping on this series.

It fixes a bug already present in mainline: on powerpc a return value
set via PTRACE_SET_SYSCALL_INFO for a skipped system call is lost, and
syscall_set_return_value() sets TIF_SYSCALL_RET on the tracer instead
of the tracee. This currently breaks the set_syscall_info selftest
and seccomp_bpf user_notification_basic on ppc64le.

The series still applies to current mainline. Please let me know if
anything needs to be changed, or if I should resend it.

Thanks,
renzo

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v3 0/2] powerpc/syscall: Fix the return value of skipped syscalls
@ 2026-10-30  8:17 Renzo Davoli
  0 siblings, 0 replies; 5+ messages in thread
From: Renzo Davoli @ 2026-10-30  8:17 UTC (permalink / raw)
  To: Madhavan Srinivasan, Michael Ellerman
  Cc: Renzo Davoli, Nicholas Piggin, Christophe Leroy, Ritesh Harjani,
	Michal Suchánek, Mukesh Kumar Chaurasiya, Shrikanth Hegde,
	Thomas Gleixner, Oleg Nesterov, Dmitry V . Levin,
	Thomas Bogendoerfer, Andrew Morton, linuxppc-dev, linux-kernel

When ptrace or seccomp skip a system call on powerpc, the return value
they set is lost or the tracer is affected:

 - syscall_set_return_value() sets TIF_SYSCALL_RET on current, which is
   the tracer when called through PTRACE_SET_SYSCALL_INFO, so the next
   system call of the tracer is silently skipped (1/2);

 - system_call_exception() returns syscall_get_error() for a skipped
   system call, which is 0 for any non-error value, so a success value
   set by a tracer or by a SECCOMP_RET_USER_NOTIF listener is replaced
   with 0 (2/2).

Both problems are in v7.3.  1/2 does not apply as is to v7.3, which
still has the two separate TIF_SYSCALL_RET checks from before commit
66236558dfac ("powerpc/syscall: Avoid atomic test_and_clear_thread_flag
on fast path"); the code it leaves behind is the same, and 2/2 then
applies on top.

Tested on QEMU pseries (TCG, -cpu power9), ppc64le guest config, on
mainline 734bef548a96, with ppc_skip_repro.c [1] (a tracer sets the
return value with PTRACE_SET_SYSCALL_INFO and then makes a system call;
a tracer skips a system call at a PTRACE_EVENT_SECCOMP stop with
PTRACE_POKEUSER, with both "sc" and "scv 0") and with the ptrace and
seccomp selftests:

                                           mainline    + 1/2       + 2/2
  tracer syscall after SET_SYSCALL_INFO    not run     correct     correct
  skipped syscall, success value, sc/scv   returns 0   returns 0   correct
  skipped syscall, error value, sc/scv     correct     correct     correct
  selftests/ptrace set_syscall_info        FAIL        pass        pass
  selftests/seccomp/seccomp_bpf (*)        14 FAIL     14 FAIL     all pass

  failing in mainline and with 1/2 only:
  user_notification_{basic,child_pid_ns,sibling_pid_ns,fault_recv,addfd,
  addfd_opath,addfd_rlimit,addfd_send_interrupted,sync,fifo,
  wait_killable}, TRACE_syscall.seccomp.syscall_faked,
  notification_restart.{killable,both}.after_receive

(*) not counting user_notification_wait_killable_after_reply (100000
    notifications with a 1 ms itimer), which hits the 30 s harness
    timeout under emulation on all three kernels.

Build-tested with W=1: ppc64le guest config, ppc64_defconfig (BE),
pmac32_defconfig.

Changes in v3:
- Split in two patches, one per Fixes: tag: 1/2 removes TIF_SYSCALL_RET
  (suggested by Michal), 2/2 fixes the return value.
- 2/2 returns syscall_get_error() ?: regs->gpr[3] instead of
  regs->gpr[3], so the error path is unchanged (suggested by Mukesh).
- Applies unchanged to current mainline (d89e1d186ec9).
- Link to v2:
  https://lore.kernel.org/lkml/20261023180735.853655-1-renzo@cs.unibo.it/

Changes in v2:
- Rebased on mainline 734bef548a96, after commit 66236558dfac.
- Link to v1:
  https://lore.kernel.org/lkml/20261018151539.440213-1-renzo@cs.unibo.it/

[1] https://lore.kernel.org/lkml/ato6Tq0aKdqqdqyJ@cs.unibo.it/

Renzo Davoli (2):
  powerpc/syscall: Remove TIF_SYSCALL_RET
  powerpc/syscall: Return the preset value of skipped syscalls

 arch/powerpc/include/asm/syscall.h     |  6 ------
 arch/powerpc/include/asm/thread_info.h |  1 -
 arch/powerpc/kernel/syscall.c          | 13 +++++++++----
 3 files changed, 9 insertions(+), 11 deletions(-)


base-commit: d89e1d186ec9271bf78e62771779e9fc03bf0fc3
-- 
2.55.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-19 10:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH v3 2/2] powerpc/syscall: Return the preset value of skipped syscalls Renzo Davoli
2026-11-19 10:34 ` [PATCH v3 0/2] powerpc/syscall: Fix the return " Renzo Davoli
  -- strict thread matches above, loose matches on Subject: below --
2026-10-30  8:17 Renzo Davoli

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®