Linux s390 Architecture development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Renzo Davoli" <renzo@cs.unibo.it>
Cc: linux-s390@vger.kernel.org, "Heiko Carstens" <hca@linux.ibm.com>,
	"Vasily Gorbik" <gor@linux.ibm.com>,
	"Alexander Gordeev" <agordeev@linux.ibm.com>,
	"Christian Borntraeger" <borntraeger@linux.ibm.com>
Subject: Re: [PATCH v11 2/3] ptrace: add PTRACE_SET_SYSCALL_INFO syscall skipping support
Date: Sat, 14 Nov 2026 18:44:27 +0000	[thread overview]
Message-ID: <sashiko-outbox-214908@kernel.org> (raw)
In-Reply-To: <20261114181923.370930-3-renzo@cs.unibo.it>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] ptrace: ptrace_set_syscall_info_seccomp_skip() breaks syscall
  skip on powerpc
--

commit 18172201986e4a2acbcbbd3f1822583db8925569
Author: Renzo Davoli <renzo@cs.unibo.it>

ptrace: add PTRACE_SET_SYSCALL_INFO syscall skipping support

This commit extends PTRACE_SET_SYSCALL_INFO to allow a tracer to skip a
system call at a PTRACE_SYSCALL_INFO_SECCOMP stop by changing the operation
to PTRACE_SYSCALL_INFO_EXIT and specifying the return value.

> diff --git a/kernel/ptrace.c b/kernel/ptrace.c
> index 3f2fe68ccb140..ab6f5dab02238 100644
> --- a/kernel/ptrace.c
> +++ b/kernel/ptrace.c

[ ... ]

> @@ -1119,12 +1128,35 @@ ptrace_set_syscall_info_exit(struct task_struct *child, struct pt_regs *regs,
>  	return 0;
>  }
>  
> +/*
> + * Skip the system call at a PTRACE_SYSCALL_INFO_SECCOMP stop and set its
> + * return value as specified by info->exit.
> + *
> + * The skip request is passed to seccomp out of band instead of by setting
> + * the system call number to -1: on some architectures the syscall number,
> + * or the register seccomp reads it from, shares a register with the return
> + * value, and on others -1 cannot be represented as a syscall number.
> + */
> +static int
> +ptrace_set_syscall_info_seccomp_skip(struct task_struct *child,
> +				     struct pt_regs *regs,
> +				     struct ptrace_syscall_info *info)
> +{
> +	int ret = ptrace_set_syscall_info_exit(child, regs, info);
> +
> +	if (!ret)
> +		seccomp_ptrace_skip_syscall(child);
> +
> +	return ret;
> +}

[Severity: High]
Does calling ptrace_set_syscall_info_exit() from the tracer while the tracee
is stopped at PTRACE_EVENT_SECCOMP break both the tracer and the tracee on
powerpc?

ptrace_set_syscall_info_exit() calls syscall_set_return_value(child, regs,
...), which on powerpc sets TIF_SYSCALL_RET on current rather than on task:

arch/powerpc/include/asm/syscall.h:syscall_set_return_value() {
    ...
	/*
	 * We are returning from the syscall, so anything that
	 * depends on the regs being in the entry state is now invalid.
	 */
	set_thread_flag(TIF_SYSCALL_RET);
}

Because ptrace_set_syscall_info_seccomp_skip() runs in the tracer's task
context, TIF_SYSCALL_RET is set on the tracer.  On the tracer's next system
call (such as PTRACE_GET_SYSCALL_INFO or PTRACE_CONT),
system_call_exception() sees TIF_SYSCALL_RET set, clears it, and returns
syscall_get_error(current, regs) (0) without executing the system call:

arch/powerpc/kernel/syscall.c:system_call_exception() {
    ...
	if (unlikely(!syscall_enter_from_user_mode_randomize_stack(regs, &r0) ||
			test_thread_flag(TIF_SYSCALL_RET))) {
		clear_thread_flag(TIF_SYSCALL_RET);
		return syscall_get_error(current, regs);
	}
    ...
}

In addition, when the tracee resumes from the skipped seccomp stop,
syscall_enter_from_user_mode_randomize_stack() returns false and
system_call_exception() returns syscall_get_error(current, regs), which
syscall_exit_prepare() writes into regs->gpr[3].  When info->exit.is_error is
0, syscall_get_error() returns 0, overwriting any non-error return value set
by the tracer in regs->gpr[3].

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261114181923.370930-1-renzo@cs.unibo.it?part=2

  reply	other threads:[~2026-11-14 18:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-14 18:19 [PATCH v11 0/3] PTRACE_SET_SYSCALL_INFO: add support for seccomp syscall skipping Renzo Davoli
2026-11-14 18:19 ` [PATCH v11 1/3] seccomp: let the tracer skip a syscall independently of its number Renzo Davoli
2026-11-14 18:40   ` sashiko-bot
2026-11-14 18:19 ` [PATCH v11 2/3] ptrace: add PTRACE_SET_SYSCALL_INFO syscall skipping support Renzo Davoli
2026-11-14 18:44   ` sashiko-bot [this message]
2026-11-14 18:19 ` [PATCH v11 3/3] selftests/ptrace: add a test case for PTRACE_SET_SYSCALL_INFO syscall skipping Renzo Davoli
2026-11-14 18:27   ` sashiko-bot

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=sashiko-outbox-214908@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=linux-s390@vger.kernel.org \
    --cc=renzo@cs.unibo.it \
    --cc=sashiko-reviews@lists.linux.dev \
    /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