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 83D45342532 for ; Tue, 14 Jul 2026 13:56:43 +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=1784037404; cv=none; b=aIvO4MfcLunI94W7TS6U1eiqM/UEiEcH05RH2bZsGNHUH7cHCKMhUo9py+QZekQJLfKrQpbAcTmjj57nQCAtisOPNl/NRm6RGHpslBO62iF7L2tsaeaWewyBnq7VVCKrXcUwUFFbubJySmec/zgjto2MNeme846bUElC/DgxwdI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784037404; c=relaxed/simple; bh=GtsF4rXmVZu/HY16jT6oQjbac4makq5T/g9cCP8rlVg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=DicaUlWnOpDfXlYlDuApwdnsd42wr4zFmTEm/Tts70FeHMWUMlFQGrblgTcSPBqsA9t1SHLmic7r5/L1+RqkCyIsmXhfFyoiv+wBta9Ffq6XNnuoH4R5qs0qcUrW86AfC6LX7XkkLDgTH9APrkpyJ3rM2VbKARtDFIIxwWpp0d4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZAx4bJzN; 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="ZAx4bJzN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 944121F000E9; Tue, 14 Jul 2026 13:56:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1784037403; bh=XvENzWPT8BIDQ2LQGKoQLGSHRTQAQieNQdFR+KeOugA=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=ZAx4bJzNzAjHRolKxVz6IF1lmI9TASLuutiBBNHkPe5sZ9McOlDR4Qj/gFVCngBZR lRwCP5p3vlfy7xy1BLW2kHfzOtclnZqUzKWma9XgCqhHuLccl8is2VUwfTxfqjnX5j 5RS6YEtJ24ya06dY0hovHhA/8FSNzN2xPYjZ4gY7o3Gksnr4Abn8nutlfvf0MujD3M byRvi0qhNTqUg87wjdKdGsNRz8RI4058ZbsXI+yhhHPYG3FoQh6F9oYwMPw1YYFEh0 AKgJsOMO8byI6WY3WN06hRsmGj9jqGNJ7FzRgBU4ljUn0msiUS5U4sI9CdYxRPAvpD 3LBeONprKuCRg== Date: Tue, 14 Jul 2026 14:56:37 +0100 From: Will Deacon To: Jinjie Ruan Cc: Catalin Marinas , Yiqi Sun , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, rmk+kernel@armlinux.org.uk, kees@kernel.org, mark.rutland@arm.com Subject: Re: [PATCH v2] arm64: ptrace: use live x0 for seccomp and audit after ptrace Message-ID: References: <20260529065444.1336608-1-sunyiqixm@gmail.com> <2f435bab0d61d0bf8fbaa54203525aae8e8f5371.1782384161.git.sunyiqixm@gmail.com> <1610f167-1af0-4d20-877c-b362b9b49d94@huawei.com> <1d55c62e-7c08-4b2b-a009-b770c5ac13bc@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: <1d55c62e-7c08-4b2b-a009-b770c5ac13bc@huawei.com> On Tue, Jul 14, 2026 at 11:20:20AM +0800, Jinjie Ruan wrote: > > > On 7/13/2026 10:07 PM, Will Deacon wrote: > > On Mon, Jul 13, 2026 at 03:49:18PM +0800, Jinjie Ruan wrote: > >> On 7/1/2026 1:29 AM, Catalin Marinas wrote: > >>> I think we need to keep orig_x0 as our original arg0 throughout the > >>> kernel and just fix the tracer path to sync it on the syscall entry. It > >>> doesn't unclutter the code but it shouldn't break the ABI either (unless > >>> someone relied on the ptrace change x0 and not being noticed by > >>> seccomp). Something like below: > >>> > >>> ----------------8<----------------------------- > >>> diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c > >>> index 4d08598e2891..cd21b301e154 100644 > >>> --- a/arch/arm64/kernel/ptrace.c > >>> +++ b/arch/arm64/kernel/ptrace.c > >>> @@ -2417,6 +2417,18 @@ int syscall_trace_enter(struct pt_regs *regs) > >>> ret = report_syscall_entry(regs); > >>> if (ret || (flags & _TIF_SYSCALL_EMU)) > >>> return NO_SYSCALL; > >>> + /* > >>> + * Keep orig_x0 authoritative so that seccomp (via > >>> + * syscall_get_arguments()), audit and the restart path all > >>> + * see the same first argument the syscall is dispatched with, > >>> + * even if it has been updated by a tracer. Skip this for > >>> + * NO_SYSCALL (set either by the user or the tracer) as > >>> + * regs[0] holds the return value (see the comment in > >>> + * el0_svc_common()). For compat, orig_r0 is provided directly > >>> + * through GPR index 17. > >>> + */ > >>> + if (!is_compat_task() && regs->syscallno != NO_SYSCALL) > >>> + regs->orig_x0 = regs->regs[0]; > >> > >> Can we place this fix in report_syscall_entry()? The generic entry > >> framework has already reserved the function > >> arch_ptrace_report_syscall_permit_entry() for architecture-specific > >> customization, so switching to it might be more convenient. > > > > Hmm, your comment prompted me to look at this some more and now I'm > > unsure that the seccomp handling is correct, even with the fix above. > > Hi Will, > > It seems that this issue can be reproduced itself and Catalin's patch > can fix the original question. I'm not disputing that it fixes the reported issue, but I don't think it's complete. > I used DeepSeek to help write the following test method and script, > which can successfully reproduce the issue. I also have similar testcases for this, thanks. I'll send a patch shortly. Will