Linux s390 Architecture development
 help / color / mirror / Atom feed
From: Kees Cook <kees@kernel.org>
To: Michal Suchanek <msuchanek@suse.de>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Andy Lutomirski <luto@amacapital.net>,
	Will Drewry <wad@chromium.org>, Paul Walmsley <pjw@kernel.org>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Albert Ou <aou@eecs.berkeley.edu>,
	Alexandre Ghiti <alex@ghiti.fr>,
	linux-riscv@lists.infradead.org,
	Thomas Gleixner <tglx@kernel.org>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Shrikanth Hegde <sshegde@linux.ibm.com>,
	linuxppc-dev@lists.ozlabs.org,
	Huacai Chen <chenhuacai@kernel.org>,
	loongarch@lists.linux.dev, Sven Schnelle <svens@linux.ibm.com>,
	linux-s390@vger.kernel.org, x86@kernel.org,
	Mark Rutland <mark.rutland@arm.com>,
	Jinjie Ruan <ruanjinjie@huawei.com>,
	Magnus Lindholm <linmag7@gmail.com>,
	"Mukesh Kumar Chaurasiya (IBM)" <mkchauras@gmail.com>,
	Jonathan Corbet <corbet@lwn.net>, Radu Rendec <radu@rendec.net>,
	Renzo Davoli <renzo@cs.unibo.it>, Oleg Nesterov <oleg@redhat.com>
Subject: Re: [PATCH] seccomp: Fix syscall skip logic on ptrace
Date: Tue, 1 Sep 2026 11:34:31 -0700	[thread overview]
Message-ID: <202609011132.F4A3EB7103@keescook> (raw)
In-Reply-To: <al9NlZi20xHMvla2@kunlun.suse.cz>

On Tue, Jul 21, 2026 at 12:44:37PM +0200, Michal Suchanek wrote:
> seccomp takes a shortcut here. When the syscall number is re-read after
> ptrace and the sign bit is set in the syscall number the syscall is
> skipped right away.
> 
> This works fairly well on x86 where the return value of the syscall is
> preset before seccomp is processed.
> 
> However, on some architectures the syscall return value overlaps with
> the syscall number or syscall arguments, and as a result the return
> value cannot be preset in advance.
> 
> For these architectures seccomp needs to exit without flagging the
> syscall as skipped. Then processing of invalid syscall number in the
> architecture code should set the return value to -ENOSYS and skip the
> syscall.
> 
> This introduces a change: If the syscall number has the sign bit
> set, such as -1, previously the filter re-check would not be done, not
> applying the filter after trace. Now the re-check is done both for
> syscall nubers with and without sign bit set. This would only make a
> difference if the syscall number or the filter was changed by the
> tracer. Otherwise the filter would be resolved the first time around.
> 
> Signed-off-by: Michal Suchanek <msuchanek@suse.de>
> ---
>  kernel/seccomp.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/kernel/seccomp.c b/kernel/seccomp.c
> index 066909393c38..9e40a38aaedf 100644
> --- a/kernel/seccomp.c
> +++ b/kernel/seccomp.c
> @@ -1318,11 +1318,8 @@ static int __seccomp_filter(int this_syscall, const bool recheck_after_trace)
>  		 */
>  		if (fatal_signal_pending(current))
>  			goto skip;
> -		/* Check if the tracer forced the syscall to be skipped. */
> -		this_syscall = syscall_get_nr(current, current_pt_regs());
> -		if (this_syscall < 0)
> -			goto skip;
>  
> +		this_syscall = syscall_get_nr(current, current_pt_regs());
>  		/*
>  		 * Recheck the syscall, since it may have changed. This
>  		 * intentionally uses a NULL struct seccomp_data to force

Does the seccomp selftest still pass with this change? I _think_ it's
fine; this just induces more work on a tracer-induced skip path, which,
in theory, shouldn't be fast-path: kicking out to the tracer is going to
be the slowest part.

-- 
Kees Cook

  parent reply	other threads:[~2026-09-01 18:34 UTC|newest]

Thread overview: 110+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-07 19:05 [patch 00/18] entry: Consolidate and rework syscall entry handling Thomas Gleixner
2026-07-07 19:05 ` [patch 01/18] powerpc: Move stack randomization after syscall_enter_from_user_mode() Thomas Gleixner
2026-07-08 14:07   ` Shrikanth Hegde
2026-07-08 17:22   ` Radu Rendec
2026-07-09  1:20   ` Jinjie Ruan
2026-07-09 11:12   ` Philippe Mathieu-Daudé
2026-07-09 18:32   ` Mukesh Kumar Chaurasiya
2026-07-07 19:06 ` [patch 02/18] randomize_kstack: Provide add_random_kstack_offset_irqsoff() Thomas Gleixner
2026-07-08 17:24   ` Radu Rendec
2026-07-09  2:13   ` Jinjie Ruan
2026-07-09 16:23   ` Kees Cook
2026-07-09 18:34   ` Mukesh Kumar Chaurasiya
2026-07-07 19:06 ` [patch 03/18] entry: Provide [syscall_]enter_from_user_mode_randomize_stack() Thomas Gleixner
2026-07-08 17:26   ` Radu Rendec
2026-07-09  2:34   ` Jinjie Ruan
2026-07-09  3:46   ` Jinjie Ruan
2026-07-09 11:15   ` Philippe Mathieu-Daudé
2026-07-09 20:16   ` Mukesh Kumar Chaurasiya
2026-08-27 22:46   ` H. Peter Anvin
2026-08-29 21:12     ` Thomas Gleixner
2026-07-07 19:06 ` [patch 04/18] loongarch/syscall: Use syscall_enter_from_user_mode_randomize_stack() Thomas Gleixner
2026-07-08 18:37   ` Radu Rendec
2026-07-09  2:37   ` Jinjie Ruan
2026-07-09 11:15   ` Philippe Mathieu-Daudé
2026-07-09 18:40   ` Mukesh Kumar Chaurasiya
2026-07-07 19:06 ` [patch 05/18] powerpc/syscall: " Thomas Gleixner
2026-07-08 18:35   ` Radu Rendec
2026-07-09  2:38   ` Jinjie Ruan
2026-07-09 11:16   ` Philippe Mathieu-Daudé
2026-07-09 18:41   ` Mukesh Kumar Chaurasiya
2026-07-07 19:06 ` [patch 06/18] riscv/syscall: " Thomas Gleixner
2026-07-08 20:57   ` Radu Rendec
2026-07-09  2:38   ` Jinjie Ruan
2026-07-09 11:16   ` Philippe Mathieu-Daudé
2026-07-09 18:42   ` Mukesh Kumar Chaurasiya
2026-07-13  7:06   ` Guo Ren
2026-07-07 19:06 ` [patch 07/18] s390/syscall: Use enter_from_user_mode_randomize_stack() Thomas Gleixner
2026-07-08  6:47   ` Sven Schnelle
2026-07-08 20:57   ` Radu Rendec
2026-07-09  2:39   ` Jinjie Ruan
2026-07-09  2:46   ` Jinjie Ruan
2026-07-09 11:17     ` Philippe Mathieu-Daudé
2026-07-09 18:43   ` Mukesh Kumar Chaurasiya
2026-07-07 19:06 ` [patch 08/18] x86/syscall: Use [syscall_]enter_from_user_mode_randomize_stack() Thomas Gleixner
2026-07-08 20:59   ` Radu Rendec
2026-07-09  2:44   ` Jinjie Ruan
2026-07-09 11:18   ` Philippe Mathieu-Daudé
2026-07-09 18:45   ` Mukesh Kumar Chaurasiya
2026-07-07 19:06 ` [patch 09/18] entry: Remove syscall_enter_from_user_mode() Thomas Gleixner
2026-07-08 21:21   ` Radu Rendec
2026-07-08 22:08     ` Thomas Gleixner
2026-07-09  2:49   ` Jinjie Ruan
2026-07-09 18:49   ` Mukesh Kumar Chaurasiya
2026-07-07 19:06 ` [patch 10/18] entry: Use syscall number instead of rereading it Thomas Gleixner
2026-07-08 21:39   ` Radu Rendec
2026-07-09  2:55   ` Jinjie Ruan
2026-07-09 11:20   ` Philippe Mathieu-Daudé
2026-07-09 11:22     ` Philippe Mathieu-Daudé
2026-07-09 18:50   ` Mukesh Kumar Chaurasiya
2026-07-07 19:06 ` [patch 11/18] seccomp, treewide: Rename and convert __secure_computing() to return boolean Thomas Gleixner
2026-07-08  1:43   ` Jinjie Ruan
2026-07-08  9:15     ` Thomas Gleixner
2026-07-08 16:04       ` Oleg Nesterov
2026-07-08 21:49         ` Thomas Gleixner
2026-07-09 16:22   ` Kees Cook
2026-07-09 19:10   ` Mukesh Kumar Chaurasiya
2026-07-07 19:06 ` [patch 12/18] ptrace, treewide: Rename ptrace_report_syscall_entry() to ptrace_report_syscall_permit_entry() Thomas Gleixner
2026-07-08 15:46   ` Oleg Nesterov
2026-07-09  1:41   ` Jinjie Ruan
2026-07-09  8:41   ` Geert Uytterhoeven
2026-07-09 17:03   ` Radu Rendec
2026-07-09 19:22   ` Mukesh Kumar Chaurasiya
2026-07-10 10:42   ` Michal Suchánek
2026-07-10 11:16     ` Oleg Nesterov
2026-07-07 19:06 ` [patch 13/18] entry: Make trace_syscall_enter() return type bool Thomas Gleixner
2026-07-08 15:52   ` Michal Suchánek
2026-07-08 20:34     ` Thomas Gleixner
2026-07-08 23:14       ` Thomas Gleixner
2026-07-09 16:26         ` David Laight
2026-07-10 11:01       ` Michal Suchánek
2026-07-10 11:40         ` Oleg Nesterov
2026-07-10 12:32           ` Michal Suchánek
2026-07-10 12:52             ` Oleg Nesterov
2026-07-10 15:20               ` Michal Suchánek
2026-07-11 20:33         ` Thomas Gleixner
2026-07-14  8:20           ` Michal Suchánek
2026-07-07 19:06 ` [patch 14/18] entry: Make return type of syscall_trace_enter() bool Thomas Gleixner
2026-07-09 19:36   ` Mukesh Kumar Chaurasiya
2026-07-07 19:06 ` [patch 15/18] x86/entry: Make syscall functions static Thomas Gleixner
2026-07-09  1:47   ` Jinjie Ruan
2026-07-09 19:43   ` Mukesh Kumar Chaurasiya
2026-07-07 19:07 ` [patch 16/18] x86/entry: Get rid of the sys_ni_syscall() indirection Thomas Gleixner
2026-07-09  2:03   ` Jinjie Ruan
2026-07-07 19:07 ` [patch 17/18] x86/entry: Simplify the syscall number logic Thomas Gleixner
2026-07-07 19:07 ` [patch 18/18] entry, treewide: Make syscall_enter_from_user_mode[_work]() indicate syscall execution Thomas Gleixner
2026-07-08  5:21   ` Shrikanth Hegde
2026-07-08  9:16     ` Thomas Gleixner
2026-07-09 19:49   ` Mukesh Kumar Chaurasiya
2026-07-09 20:15 ` [patch 00/18] entry: Consolidate and rework syscall entry handling Mukesh Kumar Chaurasiya
2026-07-11 12:29 ` Magnus Lindholm
2026-07-19 11:25 ` Magnus Lindholm
2026-07-20 19:21   ` Thomas Gleixner
2026-07-20 22:01     ` Magnus Lindholm
2026-07-21  8:17       ` Thomas Gleixner
2026-07-21 10:44 ` [PATCH] seccomp: Fix syscall skip logic on ptrace Michal Suchanek
2026-07-21 11:05   ` sashiko-bot
2026-09-01 18:34   ` Kees Cook [this message]
2026-08-27 22:22 ` [patch 00/18] entry: Consolidate and rework syscall entry handling H. Peter Anvin
2026-08-31  8:50   ` Heiko Carstens
2026-08-31 19:57     ` H. Peter Anvin

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=202609011132.F4A3EB7103@keescook \
    --to=kees@kernel.org \
    --cc=alex@ghiti.fr \
    --cc=aou@eecs.berkeley.edu \
    --cc=chenhuacai@kernel.org \
    --cc=corbet@lwn.net \
    --cc=linmag7@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=loongarch@lists.linux.dev \
    --cc=luto@amacapital.net \
    --cc=mark.rutland@arm.com \
    --cc=mkchauras@gmail.com \
    --cc=mpe@ellerman.id.au \
    --cc=msuchanek@suse.de \
    --cc=oleg@redhat.com \
    --cc=palmer@dabbelt.com \
    --cc=pjw@kernel.org \
    --cc=radu@rendec.net \
    --cc=renzo@cs.unibo.it \
    --cc=ruanjinjie@huawei.com \
    --cc=sshegde@linux.ibm.com \
    --cc=svens@linux.ibm.com \
    --cc=tglx@kernel.org \
    --cc=wad@chromium.org \
    --cc=x86@kernel.org \
    /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