From: Will Deacon <will@kernel.org>
To: Jinjie Ruan <ruanjinjie@huawei.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>,
Yiqi Sun <sunyiqixm@gmail.com>,
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
Date: Mon, 13 Jul 2026 15:07:01 +0100 [thread overview]
Message-ID: <alTxBVLJmQ7-ZnSS@willie-the-truck> (raw)
In-Reply-To: <1610f167-1af0-4d20-877c-b362b9b49d94@huawei.com>
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.
If the seccomp filters return SECCOMP_RET_TRACE, we'll do another ptrace
exit but we won't re-sync orig_x0, so audit could see a stale value. So
I think we might need something like the diff below, which looks like it
might be a pain for the generic entry code.
Will
--->8
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
@@ -2408,6 +2408,21 @@ static void report_syscall_exit(struct pt_regs *regs)
}
}
+static void update_syscall_orig_x0_after_ptrace(struct pt_regs *regs)
+{
+ /*
+ * 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()) and can be unwound using syscall_rollback().
+ * For compat tasks, orig_r0 is provided directly through GPR index 17.
+ */
+ if (!is_compat_task() && regs->syscallno != NO_SYSCALL)
+ regs->orig_x0 = regs->regs[0];
+}
+
int syscall_trace_enter(struct pt_regs *regs)
{
unsigned long flags = read_thread_flags();
@@ -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).
+ */
+ 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. */
+ update_syscall_orig_x0_after_ptrace(regs);
+
if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
trace_sys_enter(regs, regs->syscallno);
next prev parent reply other threads:[~2026-07-13 14:54 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-29 6:54 [PATCH] fix: arm64: syscall: use live x0 for syscall_get_arguments() arg0 Yiqi Sun
2026-06-01 12:43 ` Will Deacon
2026-06-03 9:07 ` Yiqi Sun
2026-06-19 16:05 ` Will Deacon
2026-06-25 10:45 ` [PATCH v2] arm64: ptrace: use live x0 for seccomp and audit after ptrace Yiqi Sun
2026-06-25 11:11 ` Yiqi Sun
2026-06-25 11:30 ` Yiqi Sun
2026-06-29 13:09 ` Will Deacon
2026-06-30 17:29 ` Catalin Marinas
2026-07-01 8:47 ` Catalin Marinas
2026-07-10 14:04 ` Will Deacon
2026-07-13 7:49 ` Jinjie Ruan
2026-07-13 14:07 ` Will Deacon [this message]
2026-07-14 3:20 ` Jinjie Ruan
2026-07-14 13:56 ` Will Deacon
2026-07-13 6:59 ` [PATCH] fix: arm64: syscall: use live x0 for syscall_get_arguments() arg0 Jinjie Ruan
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=alTxBVLJmQ7-ZnSS@willie-the-truck \
--to=will@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=kees@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=rmk+kernel@armlinux.org.uk \
--cc=ruanjinjie@huawei.com \
--cc=sunyiqixm@gmail.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