All of lore.kernel.org
 help / color / mirror / Atom feed
From: Will Deacon <will@kernel.org>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Zhao Gongyi <zhaogongyi@bytedance.com>,
	catalin.marinas@arm.com, mark.rutland@arm.com,
	ruanjinjie@huawei.com, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] arm64: ptrace: don't warn on missing siginfo in a group-stop
Date: Wed, 4 Nov 2026 14:05:12 +0000	[thread overview]
Message-ID: <aus7mMS4tXAzPCSi@willie-the-truck> (raw)
In-Reply-To: <attf9KALBQyOGyco@redhat.com>

Hey Oleg,

On Fri, Oct 23, 2026 at 03:24:04PM +0200, Oleg Nesterov wrote:
> On 10/23, Zhao Gongyi wrote:
> >
> > --- a/arch/arm64/kernel/ptrace.c
> > +++ b/arch/arm64/kernel/ptrace.c
> > @@ -573,10 +573,6 @@ static void update_syscall_orig_x0_after_ptrace(struct task_struct *target)
> >  	if (regs->syscallno == NO_SYSCALL)
> >  		return;
> >
> > -	/* We should only be called when target is in a ptrace stop */
> > -	if (WARN_ON_ONCE(!info))
> > -		return;
> > -
> >  	/*
> >  	 * For compat tasks, orig_r0 is provided directly through GPR index
> >  	 * 17.
> > @@ -588,7 +584,7 @@ static void update_syscall_orig_x0_after_ptrace(struct task_struct *target)
> >  	 * Don't update orig_x0 for a syscall-exit-stop, as x0 now contains the
> >  	 * return value of the system call.
> >  	 */
> > -	if ((info->si_code & ~0x80) == SIGTRAP &&
> > +	if (info && (info->si_code & ~0x80) == SIGTRAP &&
> >  	    target->ptrace_message == PTRACE_EVENTMSG_SYSCALL_EXIT) {
> >  		return;
> 
> LGTM, but I don't understand this arm-specific code.

Welcome to the club :)

The original rationale is described in e057b9477232 ("arm64: syscall:
Ensure saved x0 is kept in-sync with tracer updates"), so hopefully that
helps to set the scene. The crux of the problem is that the x0 register
on arm64 is used both for the first argument of a system call but also
for the return value, which causes difficulties for things like syscall
restarting, syscall skipping and syscall reporting in /proc/<pid>/syscall.

We handle that by keeping the original argument value in a shadow variable,
orig_x0, in the pt_regs and using that to implement the problematic
mechanisms above, including the accessors used by seccomp in asm/syscall.h.

The bug was (a) that we only copied x0 into orig_x0 early on the syscall
path (el0_svc_common()), which meant that tracer updates to x0 would not
be visible to seccomp filters and (b) that we passed x0 to the syscall,
which meant that the unchecked value was used as the first argument.

My initial fix (in e057b9477232) tried to copy x0 back into orig_x0
after tracer updates on the syscall entry path, however this didn't work
with some of the more complicated seccomp interactions (involving BPF
programs and SECCOMP_RET_TRACE) and so commit 88b839ce497c ("arm64: ptrace:
Keep 'orig_x0' in-sync with x0 on syscall entry") took a different
approach of updating orig_x0 at a lower-level, whenever x0 is written
by ptrace *and* we're on the syscall entry path. The latter check is
really a "we're not on the syscall exit path" so that we can handle the
seccomp case.

So that's the mess we're in and I'm all ears if there's a cleaner way to
sort it out without breaking anything that relies on the fragile semantics
we already have.

Cheers,

Will


  parent reply	other threads:[~2026-11-04 14:05 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-23 11:07 [PATCH v2] arm64: ptrace: don't warn on missing siginfo in a group-stop Zhao Gongyi
2026-10-23 13:24 ` Oleg Nesterov
2026-10-24 14:50   ` Zhao Gongyi
2026-10-24 15:09     ` Oleg Nesterov
2026-11-04 14:05   ` Will Deacon [this message]
2026-10-26 18:32 ` Catalin Marinas
2026-11-02  7:42   ` Jinjie Ruan
2026-11-02  7:54   ` Jinjie Ruan
2026-11-02  8:45     ` Zhao Gongyi
2026-11-02 11:31       ` Oleg Nesterov
2026-11-04 13:41   ` Will Deacon

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=aus7mMS4tXAzPCSi@willie-the-truck \
    --to=will@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=oleg@redhat.com \
    --cc=ruanjinjie@huawei.com \
    --cc=zhaogongyi@bytedance.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.