mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] arm64: ptrace: don't warn on missing siginfo in a group-stop
@ 2026-10-23 11:07 Zhao Gongyi
  2026-10-23 13:24 ` Oleg Nesterov
  0 siblings, 1 reply; 4+ messages in thread
From: Zhao Gongyi @ 2026-10-23 11:07 UTC (permalink / raw)
  To: catalin.marinas, will
  Cc: mark.rutland, oleg, ruanjinjie, linux-arm-kernel, linux-kernel,
	Zhao Gongyi

PTRACE_ATTACH to a group-stopped child can enter do_jobctl_trap(),
which calls ptrace_stop() without siginfo. If the tracer writes
NT_ARM_SYSTEM_CALL, system_call_set() can change syscallno from
NO_SYSCALL before calling update_syscall_orig_x0_after_ptrace(). The
WARN_ON_ONCE(!info) then fires, although this is a valid ptrace stop.

Remove the warning and guard the syscall-exit-stop check against a
missing siginfo. Keep recognizing both SIGTRAP and SIGTRAP | 0x80:
syscall-exit-stops use either value depending on whether the tracer
enabled PTRACE_O_TRACESYSGOOD. With no siginfo, allow the final
assignment to synchronize orig_x0 from x0.

Fixes: 88b839ce497c ("arm64: ptrace: Keep 'orig_x0' in-sync with x0 on syscall entry")
Cc: stable@vger.kernel.org
Signed-off-by: Zhao Gongyi <zhaogongyi@bytedance.com>
---
Changes since v1:
- Remove the warning and early return, as suggested by Oleg.
- Keep recognizing syscall-exit-stops with or without PTRACE_O_TRACESYSGOOD.

v1: https://lore.kernel.org/r/20261016024536.18938-1-zhaogongyi@bytedance.com

Tested on arm64 KVM at af32da41b032 with this v2 applied.
At a group-stop, PTRACE_GETSIGINFO returned -EINVAL and an
NT_ARM_SYSTEM_CALL write succeeded. Syscall-entry and seccomp
x0 rewrites worked. At syscall-exit-stops, NT_PRSTATUS writes succeeded
with and without PTRACE_O_TRACESYSGOOD (si_code 133 and 5,
respectively). No kernel warnings occurred.

 arch/arm64/kernel/ptrace.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c
index f743cbec1..22fb9eeed 100644
--- 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;
 	}

base-commit: 24a19b953e2a3d0ea5a8c4951a0ab8f32720c907
-- 
2.39.5 (Apple Git-154)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] arm64: ptrace: don't warn on missing siginfo in a group-stop
  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
  0 siblings, 1 reply; 4+ messages in thread
From: Oleg Nesterov @ 2026-10-23 13:24 UTC (permalink / raw)
  To: Zhao Gongyi
  Cc: catalin.marinas, will, mark.rutland, ruanjinjie,
	linux-arm-kernel, linux-kernel

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.

And... Do we need to check target->last_siginfo at all?

ptrace_signal() -> ptrace_stop() path sets ->ptrace_message = 0.

In all other cases: if info != NULL, then .si_code == target->exit_code.
ptrace_event(event) users always use event != 0 and != 0x80.

So it seems that we can just do

	if ((target->exit_code & ~0x80) == SIGTRAP &&
	    target->ptrace_message == PTRACE_EVENTMSG_SYSCALL_EXIT)

?

I'll recheck... If I am right, perhaps it makes sense to simplify
ptrace_get_syscall_info_op().

Anyway, up to you.

Oleg.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] arm64: ptrace: don't warn on missing siginfo in a group-stop
  2026-10-23 13:24 ` Oleg Nesterov
@ 2026-10-24 14:50   ` Zhao Gongyi
  2026-10-24 15:09     ` Oleg Nesterov
  0 siblings, 1 reply; 4+ messages in thread
From: Zhao Gongyi @ 2026-10-24 14:50 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: catalin.marinas, will, mark.rutland, ruanjinjie,
	linux-arm-kernel, linux-kernel

On 10/23/26 9:24 PM, 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.
> 
> And... Do we need to check target->last_siginfo at all?
> 
> ptrace_signal() -> ptrace_stop() path sets ->ptrace_message = 0.
> 
> In all other cases: if info != NULL, then .si_code == target->exit_code.
> ptrace_event(event) users always use event != 0 and != 0x80.
> 
> So it seems that we can just do
> 
> 	if ((target->exit_code & ~0x80) == SIGTRAP &&
> 	    target->ptrace_message == PTRACE_EVENTMSG_SYSCALL_EXIT)
> 
> ?
> 
> I'll recheck... If I am right, perhaps it makes sense to simplify
> ptrace_get_syscall_info_op().
> 

Hi Oleg,

Thanks for the review. I checked target->exit_code when the tracer calls 
PTRACE_SETREGSET after waitpid(). It
was 0 at syscall-exit-stops both with and without PTRACE_O_TRACESYSGOOD: 
wait_task_stopped() clears it when
reporting the stop. last_siginfo still held the corresponding si_code (5 
or 133).

I also used temporary kernel logging to check orig_x0 before and after 
writing a distinct value to x0 at each
stop. orig_x0 remained unchanged in both cases. Using exit_code in this 
condition would instead fall through
and copy the new x0 into orig_x0.

So I think we should keep the last_siginfo check in v2. The same 
exit_code lifetime also seems relevant to
ptrace_get_syscall_info_op() after waitpid().

Thanks,
Gongyi

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] arm64: ptrace: don't warn on missing siginfo in a group-stop
  2026-10-24 14:50   ` Zhao Gongyi
@ 2026-10-24 15:09     ` Oleg Nesterov
  0 siblings, 0 replies; 4+ messages in thread
From: Oleg Nesterov @ 2026-10-24 15:09 UTC (permalink / raw)
  To: Zhao Gongyi
  Cc: catalin.marinas, will, mark.rutland, ruanjinjie,
	linux-arm-kernel, linux-kernel

On 10/24, Zhao Gongyi wrote:
>
> On 10/23/26 9:24 PM, Oleg Nesterov wrote:
> >
> > So it seems that we can just do
> >
> > 	if ((target->exit_code & ~0x80) == SIGTRAP &&
> > 	    target->ptrace_message == PTRACE_EVENTMSG_SYSCALL_EXIT)
> >
> > ?
> >
> > I'll recheck... If I am right, perhaps it makes sense to simplify
> > ptrace_get_syscall_info_op().
> >
>
> Hi Oleg,
>
> Thanks for the review. I checked target->exit_code when the tracer calls
> PTRACE_SETREGSET after waitpid().

Aaaaah, I forgot that wait_task_stopped() obviously clears ->exit_code ;)

Zhao, sorry for noise and thanks for correcting me!

And let me repeat, you patch LGTM. But I don't think I can ACK it, I don't
understand this arm-specific code.

Thanks!

Oleg.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-10-24 15:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®