From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F327A424D41 for ; Wed, 15 Jul 2026 13:16:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784121400; cv=none; b=Hlz7Wn7ckNtnK8rAZtQ8VlWu28DtixOBVZL31gTlONkJvdnnWR87LCRUNMRe1ZO3IR68fZZaktFT0GSNbQByJlW4OXGMXjgcIGIRlnpULChlzTQJ0Ygd9ZB3esXFfIbJswGE+cG5X/yO5sP2PHOcfD3e/E6gg5IJH/CRU627SYU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784121400; c=relaxed/simple; bh=i9on92yeviHbyd+FvH6I2YLkCuwXsZPEXSPhBwo1nIk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=glgQpyNkp+3EP7B1MvV9IXcirrUiLAk3URtzwhFCYrAMBUx7v/QUjezvHHaEVHMBxgwOmKzV9ClaCnCab110b6dvb3+xjTL0fXPvDXj/Ox0gIiKov9UE23yH7UGnN3Q16lVmmUkL+zwXiDqyn19jA2YJEyJSYFTsvRKmQXHR6mU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=S3pNjOUR; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="S3pNjOUR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 698F41F00A3A; Wed, 15 Jul 2026 13:16:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1784121394; bh=H5199GC69OdVHFe2ZYfzY6fpsLwmA9JkeWcsxv1LcTI=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=S3pNjOURqGtTxDulVO2+hJDkGcGs+SKhp6y212/7Smgi7QJiv1nlFsXAST08kDsoU 51JU+oWdGguVOS78WsY87DFYH3jPiO16V9+JOMXmh2Oc5uwdhSstL6qbqGYAOnzwb0 3XY70YI/6MRtyzQtInoxrxq+cuQQDY2YRlCFaRIs6mrec69yy1jOekBb8EMvDUkpFX cbEoKBk6FjCiXmP4Cu9lcAjW16UNtgGlrQ+eAFNz+pbyOVOQnXfwWUGYZ+CGYEXkf5 EqMBb9p9TAHCzYTKHowQ/NWXqKOTkTgmY4sFvhEqVoQh1xCpqrmTYUSgGkxPXNPFG5 7eWxQZ0ajdiOA== Date: Wed, 15 Jul 2026 14:16:29 +0100 From: Will Deacon To: Jinjie Ruan Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Kees Cook , Mark Rutland , Yiqi Sun , Catalin Marinas Subject: Re: [PATCH] arm64: syscall: Ensure saved x0 is kept in-sync with tracer updates Message-ID: References: <20260714143600.23853-1-will@kernel.org> <55b6734e-39b9-40bb-93ae-b869f17476d5@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <55b6734e-39b9-40bb-93ae-b869f17476d5@huawei.com> Hi Jinjie, Thank you for having a look at this. We're nearly there! On Wed, Jul 15, 2026 at 07:39:43PM +0800, Jinjie Ruan wrote: > On 7/14/2026 10:35 PM, Will Deacon wrote: > > diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c > > index 4d08598e2891..57e8c6714d44 100644 > > --- a/arch/arm64/kernel/ptrace.c > > +++ b/arch/arm64/kernel/ptrace.c > > @@ -2417,12 +2432,21 @@ int syscall_trace_enter(struct pt_regs *regs) > > ret = report_syscall_entry(regs); > > if (ret || (flags & _TIF_SYSCALL_EMU)) > > return NO_SYSCALL; > > + > > + /* > > + * Ensure ptrace changes to x0 are visible to seccomp > > + * ptrace exits (SECCOMP_RET_TRACE). > > + */ > > After delving into the seccomp code, I believe the comments are not > quite accurate, I think SECCOMP_RET_TRACE not return to here. > > maybe, > > /* > * Ensure ptrace changes to x0 during a regular syscall-enter-stop > * (PTRACE_SYSCALL) are visible to subsequent seccomp and audit > * checking. > */ Yes, that's better. Seccomp BPF filters will get passed whatever comes back from syscall_get_arguments(), so mentioning SECCOMP_RET_TRACE is confusing here. > > + update_syscall_orig_x0_after_ptrace(regs); > > } > > > > /* Do the secure computing after ptrace; failures should be fast. */ > > if (secure_computing() == -1) > > return NO_SYSCALL; > > > > + /* Ensure seccomp updates to x0 are visible to audit. */ > > This comment is also not quite accurate, it implies that Seccomp itself > (such as SECCOMP_RET_ERRNO) modifies x0, but in this scenario, the audit > is not executed, because __seccomp_filter() skip the syscall. > > 1279 >-------switch (action) { > 1280 >-------case SECCOMP_RET_ERRNO: > 1281 >------->-------/* Set low-order bits as an errno, capped at > MAX_ERRNO. */ > 1282 >------->-------if (data > MAX_ERRNO) > 1283 >------->------->-------data = MAX_ERRNO; > 1284 >------->-------syscall_set_return_value(current, current_pt_regs(), > 1285 >------->------->------->------->------- -data, 0); > 1286 >------->-------goto skip; > ^^^^^^^^^^^^^<- we skip the syscall if > SECCOMP_RET_ERRNO changes x0 > > > Here what we actually need to synchronize is the tracer's modification > of x0 in the SECCOMP_RET_TRACE path, the SECCOMP_RET_TRACE logic > notifies the tracer, the tracer modifies x0 and modifies the system call > number to a legal value and so we can continue the latter audit. Right, the 'SECCOMP_RET_TRACE' example should be in _this_ comment, not the previous one. > /* > * Ensure tracer changes to x0 during SECCOMP_RET_TRACE processing > * are visible to later trace and audit. > */ I'll tweak that, as I don't think the tracing part matters (it doesn't see orig_x0 afaict) and I'd like to be very clear that this is down to the secure_computing() call. So it becomes: /* * Ensure tracer changes to x0 during seccomp ptrace exit processing * (SECCOMP_RET_TRACE) are visible to audit. */ Will