Re: [PATCH] rseq: Clear yield state when syscall entry aborts
From: Thomas Gleixner
Date: Fri Dec 04 2026 - 08:10:34 EST
On Wed, Dec 02 2026 at 08:50, Shawn Shao wrote:
> 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
I agree, but...
> 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();
... adding this unholy mess to cure that is not justified.
It's sufficient to do wipe out stale state when the next slice extension
is granted because it's arguable that rseq_sched_yield() only provides a
valid result when invoked in the related section if and only if the
granted bit is observed, i.e.:
start:
rseq->slice_ctrl.request = 1;
critical_section();
rseq->slice_ctrl.request = 0;
if (rseq->slice_ctrl.granted)
rseq_slice_yield();
end:
Any invocation after #end is bogus to begin with. So in case that
rseq_slice_yield() is invoked and a tracer aborts the syscall after
recording yielded, then the only requirement is that the next sequence
which requests a slice extension and observes granted at the end get's
the correct information.
Something like the below plus an update to the documentation which
explains the validity rules of rseq_slice_yield().
No?
Thanks,
tglx
---
--- a/include/linux/rseq_entry.h
+++ b/include/linux/rseq_entry.h
@@ -174,6 +174,9 @@ static __always_inline bool __rseq_grant
rseq_stat_inc(rseq_stats.s_granted);
curr->rseq.slice.state.granted = true;
+ /* Wipe out stale state caused by a tracer aborting rseq_slice_yield() */
+ curr->rseq.slice.yielded = false;
+
/* Store expiry time for arming the timer on the way out */
curr->rseq.slice.expires = data_race(rseq_slice_ext_nsecs) + ktime_get_mono_fast_ns();
/*