The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@kernel.org>
To: Shawn Shao <shawnq1@163.com>,
	peterz@infradead.org, mathieu.desnoyers@efficios.com
Cc: Andy Lutomirski <luto@kernel.org>,
	"Paul E. McKenney" <paulmck@kernel.org>,
	Boqun Feng <boqun@kernel.org>, Dmitry Vyukov <dvyukov@google.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] rseq: Clear yield state when syscall entry aborts
Date: Fri, 04 Dec 2026 14:10:25 +0100	[thread overview]
Message-ID: <87o6b1mbsu.ffs@fw13> (raw)
In-Reply-To: <20261202085026.1020727-1-shawnq1@163.com>

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();
 	/*



      reply	other threads:[~2026-12-04 13:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  8:50 [PATCH] rseq: Clear yield state when syscall entry aborts Shawn Shao
2026-12-04 13:10 ` Thomas Gleixner [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=87o6b1mbsu.ffs@fw13 \
    --to=tglx@kernel.org \
    --cc=boqun@kernel.org \
    --cc=dvyukov@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=shawnq1@163.com \
    /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