All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rseq: Clear yield state when syscall entry aborts
@ 2026-12-02  8:50 Shawn Shao
  2026-12-04 13:10 ` Thomas Gleixner
  0 siblings, 1 reply; 4+ messages in thread
From: Shawn Shao @ 2026-12-02  8:50 UTC (permalink / raw)
  To: tglx, peterz, mathieu.desnoyers
  Cc: Andy Lutomirski, Paul E. McKenney, Boqun Feng, Dmitry Vyukov,
	linux-kernel

rseq_syscall_enter_work() can set the yield result before ptrace and seccomp
policy checks run. If either check prevents the syscall from being dispatched,
the syscall body does not consume that result. A later rseq_slice_yield() can
then return a stale success.

Clear the one-shot result when syscall entry rejects the call, and when ptrace
changes the syscall number so the yield body cannot consume the original
result. The normal rseq_slice_yield() path continues to consume its result in
the syscall body.

The time-slice extension is opt-in. This is a correctness issue in the return
value; the reproducer does not demonstrate memory corruption or a privilege
boundary bypass.

Fixes: dd0a04606937 ("rseq: Implement syscall entry work for time slice extensions")
Signed-off-by: Shawn Shao <shawnq1@163.com>

---
Testing:
- x86-64 bzImage build with CONFIG_RSEQ_SLICE_EXTENSION=y passed.
- The x86-64 syscall-entry object compiled with CONFIG_RSEQ_SLICE_EXTENSION
  disabled.
- On the unpatched kernel, three fresh QEMU TCG boots returned 1 from the
  allowed yield after the preceding seccomp-denied yield, with slice_ctrl=0.
- With the patch, two fresh boots returned 0 for that sequence.
- The patched no-grant control passed 10,000 denied/allowed pairs and returned
  0; the live-grant control retained the expected return value of 1.
- git apply --check and checkpatch.pl --strict passed; checkpatch reported
  0 errors and 0 warnings.

Reproducer and results:
https://gist.github.com/shaos26/525e502547c0fd673e93067aed7f6d88
console output: https://gist.githubusercontent.com/shaos26/525e502547c0fd673e93067aed7f6d88/raw/d7eb70ad659d30fc8a4ae012515270b9a8148ff3/console-output.txt
kernel config: https://gist.githubusercontent.com/shaos26/525e502547c0fd673e93067aed7f6d88/raw/2ef579c9651051d222d532a9d339d3fccb7a985a/kernel-config.txt
PoC: https://gist.githubusercontent.com/shaos26/525e502547c0fd673e93067aed7f6d88/raw/a2a99144687e987376c8b045b3f29eeb5098c88d/poc.c
initramfs init: https://gist.githubusercontent.com/shaos26/525e502547c0fd673e93067aed7f6d88/raw/97e031180a22a2c59c037d6b01f872a50dbd7895/init
initramfs builder: https://gist.githubusercontent.com/shaos26/525e502547c0fd673e93067aed7f6d88/raw/32d33092bc0c0920a6389bf98e0ddab8b5c6eeec/build-initramfs.sh
QEMU runner: https://gist.githubusercontent.com/shaos26/525e502547c0fd673e93067aed7f6d88/raw/5d44df3440bbfb04518763279006a9ad8144731b/run-qemu.sh
reproduction steps: https://gist.githubusercontent.com/shaos26/525e502547c0fd673e93067aed7f6d88/raw/d123a444579160125457b3c7e39a7e2cec5b8c01/reproduction.md
reproduction wrapper: https://gist.githubusercontent.com/shaos26/525e502547c0fd673e93067aed7f6d88/raw/40a5c2d5fe81024f4020b146240d010f575463dc/reproduce.sh
patch file: https://gist.githubusercontent.com/shaos26/525e502547c0fd673e93067aed7f6d88/raw/8a1710df3bfb7155cc0f13e25bb872c0134558df/fix.patch

 include/linux/entry-common.h | 14 +++++++++++++-
 include/linux/rseq.h         |  2 ++
 kernel/rseq.c                |  5 +++++
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/include/linux/entry-common.h b/include/linux/entry-common.h
index 15278416f8860..557d55cb8cd34 100644
--- a/include/linux/entry-common.h
+++ b/include/linux/entry-common.h
@@ -140,15 +140,27 @@ static __always_inline bool syscall_trace_enter(struct pt_regs *regs, unsigned l
 static __always_inline bool syscall_enter_from_user_mode_work(struct pt_regs *regs, long *syscall)
 {
 	unsigned long work = READ_ONCE(current_thread_info()->syscall_work);
+	long syscall_nr;
 
 	if (!(work & SYSCALL_WORK_ENTER))
 		return true;
 
-	if (unlikely(!syscall_trace_enter(regs, work, *syscall)))
+	syscall_nr = *syscall;
+
+	/*
+	 * rseq entry work can prepare a yield result before ptrace or seccomp
+	 * decides whether to invoke the syscall.
+	 */
+	if (unlikely(!syscall_trace_enter(regs, work, *syscall))) {
+		rseq_syscall_enter_clear_yielded();
 		return false;
+	}
 
 	/* Reread the syscall number as it might have been modified */
 	*syscall = syscall_get_nr(current, regs);
+	/* A changed syscall number cannot consume the original yield result. */
+	if (unlikely(*syscall != syscall_nr))
+		rseq_syscall_enter_clear_yielded();
 
 	return true;
 }
diff --git a/include/linux/rseq.h b/include/linux/rseq.h
index 7ef79b25e714b..0971ace23ee73 100644
--- a/include/linux/rseq.h
+++ b/include/linux/rseq.h
@@ -192,9 +192,11 @@ static inline void rseq_syscall(struct pt_regs *regs) { }
 
 #ifdef CONFIG_RSEQ_SLICE_EXTENSION
 void rseq_syscall_enter_work(long syscall);
+void rseq_syscall_enter_clear_yielded(void);
 int rseq_slice_extension_prctl(unsigned long arg2, unsigned long arg3);
 #else /* CONFIG_RSEQ_SLICE_EXTENSION */
 static inline void rseq_syscall_enter_work(long syscall) { }
+static inline void rseq_syscall_enter_clear_yielded(void) { }
 static inline int rseq_slice_extension_prctl(unsigned long arg2, unsigned long arg3)
 {
 	return -ENOTSUPP;
diff --git a/kernel/rseq.c b/kernel/rseq.c
index e75e3a5e312c8..90e9eddeeb140 100644
--- a/kernel/rseq.c
+++ b/kernel/rseq.c
@@ -743,6 +743,11 @@ void rseq_syscall_enter_work(long syscall)
 		force_sig(SIGSEGV);
 }
 
+void rseq_syscall_enter_clear_yielded(void)
+{
+	current->rseq.slice.yielded = 0;
+}
+
 int rseq_slice_extension_prctl(unsigned long arg2, unsigned long arg3)
 {
 	switch (arg2) {


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

end of thread, other threads:[~2026-12-05 20:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02  8:50 [PATCH] rseq: Clear yield state when syscall entry aborts Shawn Shao
2026-12-04 13:10 ` Thomas Gleixner
2026-12-05  3:39   ` [PATCH v2] rseq: Clear stale yield state on slice grant Shawn Shao
2026-12-05 20:00     ` [tip: core/rseq] " tip-bot2 for Shawn Shao

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.