From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796389829; b=LO+231tQV4zL5DYq0SoUV+XTe8qe0eV5YSOLCoSlRPgbP9DATh4FxpK4SRRmtmoRO2y2 vLVDMh3e9YSfLJepan9u3WcyjEXGRvUzbCQKakV9BVK9J7jyI+UaDqNWHL2Lo4GNguC4E 12QWkEPe4Cl1171F/bRN2QfF/hGu0Yyb8yaWDZzQWFFmm+OxYlxSVdH4T/E/OVyxsgsZD zU2oJRKchadUvmiJtll8OPDjJ0B5jp5sYHxgKWExTMM9Swd/YtUWZzAEIJo82zgMUJZg+ zeE4MhC2zhJ1eSNzRaNa4ktmZc7zSktypBGzo0lG1L2P9dyZAPAfLHeLFq6XNw7Pd6g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796389829; h=Received:DKIM-Signature:From:To:Cc:Subject:In-Reply-To:References: Date:Message-ID:MIME-Version:Content-Type; bh=Ylfp/RsO5nYDRpS8tV85v07Vf5QvqcJfP/IBK6nxjyQ=; b=kfRAkSiE0fMQd+JH53IIhPhlnof9+OeKfgl/05GRyqe2EgaXfKCBI+wXpv+N/exZ6KLK 0FkxJ5ixu7X3D1OtOBKWssqfc1neUIzj9eslG1kxM46IObjlMckaxbopGv8yqZVWx5yZ2 h0f24TSKgDA0iMA1Pti0qLSHd/INIW/oFEklMIIbRvrALu2WHu2zFDIvaHtH4+kX/seGo aclY3ZBKIkmlNJJUqQ1wijI9bbiwKeawqAd3R5puHxMTo1AmRQJoP7ZNkeUkz+2u3cTmb tkYwlyFWZ9Ark52qViQiAfpuzyMq/cB4E5nNkI0yNYneJx+1H9tLBjIjDBCJXE0b/Kg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="BQ/Y4LNs"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 64BD8606A322 for ; Fri, 4 Dec 2026 13:10:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=BQ/Y4LNs Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2757B1F000C2; Fri, 4 Dec 2026 13:10:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796389828; bh=Ylfp/RsO5nYDRpS8tV85v07Vf5QvqcJfP/IBK6nxjyQ=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=BQ/Y4LNsFVFGBvDlYMyb0WrVuOycvJRpuMFX6EKA9tU9j7T0P7bNW4F8QmFAzAncA lXmi0q+uQQ9IueLPZQ2g/2SHEMQzpcZ7+yZEEKXImslouDp5W4WpqJAdFaSw8W/h8K vnzk/Cp+DpSU4BL1pXkGZJOPrmVOMGwK0r/O1UoH1DVK2fFQUlsgA8t90BBfv5wE8L G07XjNyae0Dn4JlK3ZadgTYlRU+5l7jBGurzezOhUEVgGwfzdFBjUCk6uDset/PtJn XvA5ZddG/Xs4eJ6yeg/4MJqDERspO+yiLrkQ7pmBz67+yRVxNmY+b+hEbgxV63rdNT nyt0yiAU4pxog== From: Thomas Gleixner To: Shawn Shao , peterz@infradead.org, mathieu.desnoyers@efficios.com Cc: Andy Lutomirski , "Paul E. McKenney" , Boqun Feng , Dmitry Vyukov , linux-kernel@vger.kernel.org Subject: Re: [PATCH] rseq: Clear yield state when syscall entry aborts In-Reply-To: <20261202085026.1020727-1-shawnq1@163.com> References: <20261202085026.1020727-1-shawnq1@163.com> Date: Fri, 04 Dec 2026 14:10:25 +0100 Message-ID: <87o6b1mbsu.ffs@fw13> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain 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(); /*