FAILED: patch "[PATCH] entry: Fix seccomp bypass after ptrace with TSYNC" failed to apply to 6.6-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 6.6-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y
git checkout FETCH_HEAD
git cherry-pick -x 4a3591287fb7f808e209b4974ed337f609a2006b
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026090330-squeak-freehand-d54a@gregkh' --subject-prefix 'PATCH 6.6.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 4a3591287fb7f808e209b4974ed337f609a2006b Mon Sep 17 00:00:00 2001
From: Jinjie Ruan <[email protected]>
Date: Mon, 13 Jul 2026 10:57:12 +0800
Subject: [PATCH] entry: Fix seccomp bypass after ptrace with TSYNC
Sashiko review pointed out the following issue.
If a thread is stopped in syscall_trace_enter() for ptrace, another thread can install a seccomp filter with SECCOMP_FILTER_FLAG_TSYNC (e.g., via seccomp_attach_filter()). This will successfully set SYSCALL_WORK_SECCOMP on the stopped thread, but syscall_trace_enter() evaluates a cached 'work' variable sampled on entry. Consequently, the subsequent check for SYSCALL_WORK_SECCOMP misses the newly assigned flag, and the filter is silently bypassed.
This race condition could allow an unprivileged process to execute a prohibited system call (e.g., execve) that the newly installed filter was intended to block, especially since the tracer might have modified the system call number during the ptrace stop.
Fix this by re-reading the syscall_work flags after ptrace handling, so that any new SYSCALL_WORK_SECCOMP flag set by another thread via TSYNC during the ptrace stop is observed before the subsequent seccomp check.
include/linux/entry-common.h +3 -0
@@ -97,6 +97,9 @@ static __always_inline long syscall_trace_enter(struct pt_regs *regs, unsigned lif (!arch_ptrace_report_syscall_permit_entry (regs) || (work &SYSCALL_WORK_SYSCALL_EMU ))return -1L ; + +/* ptrace might have changed work flags */ + work =READ_ONCE (current_thread_info ()->syscall_work); }/* Do seccomp after ptrace, to catch any tracer changes. */
Sasha Levin
maintainerPATCH 1/5 entry: Split generic entry into generic exception and syscall entry
From: Jinjie Ruan <[email protected]>
[ Upstream commit a70e9f647f501e36a6a092888b1ea7386b7c5664 ]
Currently CONFIG_GENERIC_ENTRY enables both the generic exception entry logic and the generic syscall entry logic, which are otherwise loosely coupled.
Introduce separate config options for these so that architectures can select the two independently. This will make it easier for architectures to migrate to generic entry code.
[Linus Walleij: rebase onto v6.16-rc1]
Stable-dep-of: 4a3591287fb7 ("entry: Fix seccomp bypass after ptrace with TSYNC")
--- MAINTAINERS | 1 + arch/Kconfig | 9 + include/linux/entry-common.h | 410 ++++++++----------------------- include/linux/irq-entry-common.h | 393 +++++++++++++++++++++++++++++ kernel/entry/Makefile | 3 +- kernel/entry/common.c | 262 +------------------- kernel/entry/syscall-common.c | 78 ++++++ kernel/sched/core.c | 8 +- 8 files changed, 596 insertions(+), 568 deletions(-) create mode 100644 include/linux/irq-entry-common.h create mode 100644 kernel/entry/syscall-common.c
MAINTAINERS +1 -0
@@ -8687,6 +8687,7 @@ S: Maintained T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git core/entry F: include/linux/entry-common.h F: include/linux/entry-kvm.h +F: include/linux/irq-entry-common.h F: kernel/entry/ GENERIC GPIO I2C DRIVER
arch/Kconfig +9 -0
@@ -55,8 +55,17 @@ config HOTPLUG_PARALLEL bool select HOTPLUG_SPLIT_STARTUP +config GENERIC_IRQ_ENTRY + bool + +config GENERIC_SYSCALL + bool + depends on GENERIC_IRQ_ENTRY + config GENERIC_ENTRY bool + select GENERIC_IRQ_ENTRY + select GENERIC_SYSCALL config KPROBES bool "Kprobes"
include/linux/entry-common.h +99 -311
463 lines not on this page · raw message
include/linux/irq-entry-common.h new file +393 -0
393 lines not on this page · raw message
kernel/entry/Makefile +2 -1
@@ -9,5 +9,6 @@ KCOV_INSTRUMENT := n CFLAGS_REMOVE_common.o = -fstack-protector -fstack-protector-strong CFLAGS_common.o += -fno-stack-protector -obj-$(CONFIG_GENERIC_ENTRY) += common.o syscall_user_dispatch.o +obj-$(CONFIG_GENERIC_IRQ_ENTRY) += common.o +obj-$(CONFIG_GENERIC_SYSCALL) += syscall-common.o syscall_user_dispatch.o obj-$(CONFIG_KVM_XFER_TO_GUEST_WORK) += kvm.o
kernel/entry/common.c +10 -252
291 lines not on this page · raw message
kernel/entry/syscall-common.c new file +78 -0
78 lines not on this page · raw message
kernel/sched/core.c +4 -4
@@ -66,8 +66,8 @@#include <linux/workqueue_api.h> #ifdef CONFIG_PREEMPT_DYNAMIC -# ifdef CONFIG_GENERIC_ENTRY -# include <linux/entry-common.h> +# ifdef CONFIG_GENERIC_IRQ_ENTRY +# include <linux/irq-entry-common.h> # endif #endif
@@ -8677,8 +8677,8 @@ EXPORT_SYMBOL(__cond_resched_rwlock_write);#ifdef CONFIG_PREEMPT_DYNAMIC -#ifdef CONFIG_GENERIC_ENTRY -#include <linux/entry-common.h> +#ifdef CONFIG_GENERIC_IRQ_ENTRY +#include <linux/irq-entry-common.h> #endif /*
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/5 entry: Remove syscall_enter_from_user_mode_prepare()
From: Thomas Gleixner <[email protected]>
[ Upstream commit 54a5ab56242f96555999aaa41228f77b4a76e386 ]
Open code the only user in the x86 syscall code and reduce the zoo of functions.
[ sashal: Reduced backport -- upstream 54a5ab56242f9 touches 3 file(s), this
backport carries 3. Not backported here:
arch/x86/entry/syscall_32.c
This note is generated from the file lists only; see the resolution record for the reasoning. ]
Stable-dep-of: 4a3591287fb7 ("entry: Fix seccomp bypass after ptrace with TSYNC")
--- arch/x86/entry/common.c | 3 ++- include/linux/entry-common.h | 26 +++++--------------------- kernel/entry/syscall-common.c | 8 -------- 3 files changed, 7 insertions(+), 30 deletions(-)
arch/x86/entry/common.c +2 -1
@@ -236,9 +236,10 @@ static noinstr bool __do_fast_syscall_32(struct pt_regs *regs)* fetch EBP before invoking any of the syscall entry work * functions. */ -syscall_enter_from_user_mode_prepare (regs); +enter_from_user_mode (regs);instrumentation_begin (); +local_irq_enable ();/* Fetch EBP from where the vDSO stashed it. */ if (IS_ENABLED (CONFIG_X86_64 )) {/*
include/linux/entry-common.h +5 -21
@@ -89,23 +89,6 @@ static __always_inline long syscall_trace_enter(struct pt_regs *regs, long syscareturn syscall_enter_audit (regs, syscall, work); } -/** -* syscall_enter_from_user_mode_prepare - Establish state and enable interrupts -* @regs: Pointer to currents pt_regs -* -* Invoked from architecture specific syscall entry code with interrupts -* disabled. The calling code has to be non-instrumentable. When the -* function returns all state is correct, interrupts are enabled and the -* subsequent functions can be instrumented. -* -* This handles lockdep, RCU (context tracking) and tracing state, i.e. -* the functionality provided by enter_from_user_mode(). -* -* This is invoked when there is extra architecture specific functionality -* to be done between establishing state and handling user mode entry work. -*/ -void syscall_enter_from_user_mode_prepare (struct pt_regs *regs); -/** * syscall_enter_from_user_mode_work - Check and handle work before invoking * a syscall
@@ -113,8 +96,8 @@ void syscall_enter_from_user_mode_prepare(struct pt_regs *regs);* @syscall: The syscall number * * Invoked from architecture specific syscall entry code with interrupts -* enabled after invoking syscall_enter_from_user_mode_prepare() and extra -* architecture specific work. +* enabled after invoking enter_from_user_mode(), enabling interrupts and +* extra architecture specific work. * * Returns: The original or a modified syscall number *
@@ -150,8 +133,9 @@ static __always_inline long syscall_enter_from_user_mode_work(struct pt_regs *re* function returns all state is correct, interrupts are enabled and the * subsequent functions can be instrumented. * -* This is combination of syscall_enter_from_user_mode_prepare() and -* syscall_enter_from_user_mode_work(). +* This is the combination of enter_from_user_mode() and +* syscall_enter_from_user_mode_work() to be used when there is no +* architecture specific work to be done between the two. * * Returns: The original or a modified syscall number. See * syscall_enter_from_user_mode_work() for further explanation.
kernel/entry/syscall-common.c +0 -8
@@ -29,14 +29,6 @@ long syscall_enter_audit(struct pt_regs *regs, long syscall,return syscall; } -noinstr void syscall_enter_from_user_mode_prepare(struct pt_regs *regs) -{ -enter_from_user_mode (regs); -instrumentation_begin (); -local_irq_enable (); -instrumentation_end (); -} -/* * If SYSCALL_EMU is set, then the only reason to report is when * SINGLESTEP is set (i.e. PTRACE_SYSEMU_SINGLESTEP). This syscall
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 5/5 entry: Fix seccomp bypass after ptrace with TSYNC
In reply to Sasha LevinFrom: Jinjie Ruan <[email protected]>
[ Upstream commit 4a3591287fb7f808e209b4974ed337f609a2006b ]
Sashiko review pointed out the following issue.
If a thread is stopped in syscall_trace_enter() for ptrace, another thread can install a seccomp filter with SECCOMP_FILTER_FLAG_TSYNC (e.g., via seccomp_attach_filter()). This will successfully set SYSCALL_WORK_SECCOMP on the stopped thread, but syscall_trace_enter() evaluates a cached 'work' variable sampled on entry. Consequently, the subsequent check for SYSCALL_WORK_SECCOMP misses the newly assigned flag, and the filter is silently bypassed.
This race condition could allow an unprivileged process to execute a prohibited system call (e.g., execve) that the newly installed filter was intended to block, especially since the tracer might have modified the system call number during the ptrace stop.
Fix this by re-reading the syscall_work flags after ptrace handling, so that any new SYSCALL_WORK_SECCOMP flag set by another thread via TSYNC during the ptrace stop is observed before the subsequent seccomp check.
--- include/linux/entry-common.h | 3 +++ 1 file changed, 3 insertions(+)
include/linux/entry-common.h +3 -0
@@ -74,6 +74,9 @@ static __always_inline long syscall_trace_enter(struct pt_regs *regs,if (!arch_ptrace_report_syscall_permit_entry (regs) || (work &SYSCALL_WORK_SYSCALL_EMU ))return -1L ; + +/* ptrace might have changed work flags */ + work =READ_ONCE (current_thread_info ()->syscall_work); }/* Do seccomp after ptrace, to catch any tracer changes. */
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/5 entry: Clean up header
In reply to Sasha LevinFrom: Thomas Gleixner <[email protected]>
[ Upstream commit 5204be16790f305febbf331d0ec2cead7978b3c3 ]
Clean up the include ordering, kernel-doc and other trivialities before making further changes.
Stable-dep-of: 4a3591287fb7 ("entry: Fix seccomp bypass after ptrace with TSYNC")
--- include/linux/entry-common.h | 5 +++-- include/linux/irq-entry-common.h | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-)
include/linux/entry-common.h +3 -2
@@ -3,11 +3,11 @@#define __LINUX_ENTRYCOMMON_H#include <linux/irq-entry-common.h> +#include <linux/livepatch.h> #include <linux/ptrace.h> +#include <linux/resume_user_mode.h> #include <linux/seccomp.h> #include <linux/sched.h> -#include <linux/livepatch.h> -#include <linux/resume_user_mode.h> #include <asm/entry-common.h> #include <asm/syscall.h>
@@ -33,6 +33,7 @@ SYSCALL_WORK_SYSCALL_AUDIT | \ SYSCALL_WORK_SYSCALL_USER_DISPATCH | \ ARCH_SYSCALL_WORK_ENTER) +#define SYSCALL_WORK_EXIT (SYSCALL_WORK_SYSCALL_TRACEPOINT | \ SYSCALL_WORK_SYSCALL_TRACE | \ SYSCALL_WORK_SYSCALL_AUDIT | \
include/linux/irq-entry-common.h +2 -0
@@ -54,6 +54,7 @@ static __always_inline void arch_enter_from_user_mode(struct pt_regs *regs) {}/** * enter_from_user_mode - Establish state when coming from user mode +* @regs: Pointer to currents pt_regs * * Syscall/interrupt entry disables interrupts, but user mode is traced as * interrupts enabled. Also with NO_HZ_FULL RCU might be idle.
@@ -340,6 +341,7 @@ irqentry_state_t noinstr irqentry_enter(struct pt_regs *regs);* Conditional reschedule with additional sanity checks. */ void raw_irqentry_exit_cond_resched (void ); +#ifdef CONFIG_PREEMPT_DYNAMIC #if defined(CONFIG_HAVE_PREEMPT_DYNAMIC_CALL )#define irqentry_exit_cond_resched_dynamic_enabled raw_irqentry_exit_cond_resched
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 4/5 entry: Remove unused syscall argument from syscall_trace_enter()
In reply to Sasha LevinFrom: Jinjie Ruan <[email protected]>
[ Upstream commit 03150a9f84b328f5c724b8ed9ff8600c2d7e2d7b ]
The 'syscall' argument of syscall_trace_enter() is immediately overwritten before any real use and serves only as a local variable, so drop the parameter.
No functional change intended.
[ sashal: Reduced backport -- upstream 03150a9f84b32 touches 2 file(s), this
backport carries 1. Not backported here:
kernel/entry/syscall-common.c
This note is generated from the file lists only; see the resolution record for the reasoning. ]
Stable-dep-of: 4a3591287fb7 ("entry: Fix seccomp bypass after ptrace with TSYNC")
--- include/linux/entry-common.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
include/linux/entry-common.h +3 -3
@@ -54,10 +54,10 @@ bool syscall_user_dispatch(struct pt_regs *regs);long syscall_enter_audit (struct pt_regs *regs,long syscall,unsigned long work); -static __always_inline long syscall_trace_enter (struct pt_regs *regs,long syscall, +static __always_inline long syscall_trace_enter (struct pt_regs *regs,unsigned long work) { -long ret =0 ; +long syscall, ret =0 ;/* * Handle Syscall User Dispatch. This must comes first, since
@@ -117,7 +117,7 @@ static __always_inline long syscall_enter_from_user_mode_work(struct pt_regs *reunsigned long work =READ_ONCE (current_thread_info ()->syscall_work);if (work &SYSCALL_WORK_ENTER ) - syscall =syscall_trace_enter (regs, syscall, work); + syscall =syscall_trace_enter (regs, work);return syscall; }
Signature · 1 line
2.53.0