arm64: entry: Convert to Generic Entry
Subsystems (21)
v16 cover arm64: entry: Convert to Generic Entry
This is the 16th iteration of the patch series. I would like to express my sincere gratitude to everyone who has contributed to the reviews and testing across the previous versions, which helped significantly refine this work.
Currently, architectures such as x86, Riscv, Loongarch use the Generic Entry, which significantly eases maintenance burden and improves code elegance. Given that arm64 has already successfully adopted the Generic IRQ Entry in commit b3cf07851b6c ("arm64: entry: Switch to generic IRQ entry"), it is now the right time to completely convert arm64 to the Generic Entry infrastructure.
The objective of this series is to bring arm64 in line with other major architectures, reducing duplicated boilerplate code and simplifying the sharing of future improvements in entry/exit paths, such as "Syscall User Dispatch" and "rseq time slice extension" optimizations.
This patch set is rebased on v7.2-rc1. It contains the foundational updates required for arm64. Following the suggestion from Linus Walleij, these patches are being submitted separately for inclusion via the arm64 tree.
Performance benchmarks were conducted on a "Kunpeng HIP09" platform with kernel auditing enabled. The results are detailed below:
1. perf bench syscall usec/op (-ve is improvement)
| Syscall | Base | Generic Entry | change % |
| ------- | ----------- | ------------- | -------- |
| basic | 0.223 | 0.218 | -2.25 |
| execve | 799.564 | 787.849 | -1.47 |
| fork | 1088.503 | 1096.920 | +0.77 |
| getpgid | 0.218 | 0.122 | -0.47 |2. perf bench syscall ops/sec (+ve is improvement)
| Syscall | Base | Generic Entry| change % |
| ------- | -------- | ------------ | -------- |
| basic | 4475386 | 4578820 | +2.31 |
| execve | 1250 | 1269 | +1.54 |
| fork | 918 | 911 | -0.74 |
| getpgid | 4587781 | 4607488 | +0.43 |Overall, the syscall performance remains largely neutral, with minor variations ranging from a 0.8% regression to a 2.3% improvement, which is within normal measurement tolerance.
Tested successfully on "Kunpeng HIP09" using the following test cases:
- stress-ng: CPU, Virtual Memory, Syscall, and Interrupt stress tests.
- hackbench: Evaluated in both thread and pipe modes.
- kselftests (ptrace): get_syscall_info, set_syscall_info, peeksiginfo.
- kselftests (breakpoints): breakpoint_test_arm64.
- kselftests (arm64/abi): syscall-abi and ptrace.
- kselftests (arm64/fp): fp-ptrace, sve-ptrace, and za-ptrace.
- kselftests (vDSO): vdso_test_getrandom.
- Ptrace stress test: tracing stress-ng system calls under load.
- Pseudo-NMI load test using perf.
Changes in v16:
- Rebased on v7.2-rc1.
- Convert __secure_computing() to return boolean as Thomas suggested.
- Introduce a weak vesion for arch_syscall_is_vdso_sigreturn()
to simplify the code.
- Split out the implementation of arch_syscall_is_vdso_sigreturn()
into a separate patch to facilitate reviewing.
- Break down the syscall_exit_to_user_mode_work() refactoring into
5 smaller, bite-sized patches for easier review and justification.
- Update the comment and commit message as Ada suggeted.
- Clarify patch titles and align title prefixes for consistency.
- Collect Reviewed-by and Tesed-by.
- Link to v15: https://lore.kernel.org/all/[email protected]/
Changes in v15:
- Rebased on v7.1-rc1 and Mark's fix patch in [1].
- Solve issues Sashiko AI pointed out, "Fix potential syscall truncation in syscall_trace_enter()".
- Make syscall_exit_to_user_mode_work() __always_inline to keep the fast-path performance as Sashiko pointed out.
Changes in v14:
- Initialize ret = 0 in syscall_trace_enter().
- Split into two patch sets as Linus Walleij suggested, so this patch set
can be applied separately to the arm64 tree.
- Rebased on arm64 for-next/core branch.
- Collect Reviewed-by and Acked-by.
- Link to v13 resend: https://lore.kernel.org/all/[email protected]/
Changes in v13 resend:
- Fix exit_to_user_mode_prepare_legacy() issues.
- Also move TIF_SINGLESTEP to generic TIF infrastructure for loongarch.
- Use generic TIF bits for arm64 and moving TIF_SINGLESTEP to
generic TIF for related architectures separately.
- Refactor syscall_trace_enter/exit() to accept flags and Use syscall_get_nr() helper separately.
- Tested with slice_test for rseq optimizations.
- Add acked-by.
- Link to v13: https://lore.kernel.org/all/[email protected]/
Changes in v13:
- Rebased on v7.0-rc3, so drop the firt applied arm64 patch.
- Use generic TIF bits to enables RSEQ optimization.
- Update most of the commit message to make it more clear.
- Link to v12: https://lore.kernel.org/all/[email protected]/
Changes in v12:
- Rebased on "sched/core", so remove the four generic entry patches.
- Move "Expand secure_computing() in place" and
"Use syscall_get_arguments() helper" patch forward, which will group all non-functional cleanups at the front.
- Adjust the explanation for moving rseq_syscall() before audit_syscall_exit().
- Link to v11: https://lore.kernel.org/all/[email protected]/
Changes in v11:
- Remove unused syscall in syscall_trace_enter().
- Update and provide a detailed explanation of the differences after
moving rseq_syscall() before audit_syscall_exit().
- Rebased on arm64 (for-next/entry), and remove the first applied 3 patchs.
- syscall_exit_to_user_mode_work() for arch reuse instead of adding
new syscall_exit_to_user_mode_work_prepare() helper.
- Link to v10: https://lore.kernel.org/all/[email protected]/
Changes in v10:
- Rebased on v6.19-rc1, rename syscall_exit_to_user_mode_prepare() to syscall_exit_to_user_mode_work_prepare() to avoid conflict.
- Also inline syscall_trace_enter().
- Support aarch64 for sud_benchmark.
- Update and correct the commit message.
- Add Reviewed-by.
- Link to v9: https://lore.kernel.org/all/[email protected]/
Changes in v9:
- Move "Return early for ptrace_report_syscall_entry() error" patch ahead to make it not introduce a regression.
- Not check _TIF_SECCOMP/SYSCALL_EMU for syscall_exit_work() in
a separate patch.
- Do not report_syscall_exit() for PTRACE_SYSEMU_SINGLESTEP in a separate patch.
- Add two performance patch to improve the arm64 performance.
- Add Reviewed-by.
- Link to v8: https://lore.kernel.org/all/[email protected]/
Changes in v8:
- Rename "report_syscall_enter()" to "report_syscall_entry()".
- Add ptrace_save_reg() to avoid duplication.
- Remove unused _TIF_WORK_MASK in a standalone patch.
- Align syscall_trace_enter() return value with the generic version.
- Use "scno" instead of regs->syscallno in el0_svc_common().
- Move rseq_syscall() ahead in a standalone patch to clarify it clearly.
- Rename "syscall_trace_exit()" to "syscall_exit_work()".
- Keep the goto in el0_svc_common().
- No argument was passed to __secure_computing() and check -1 not -1L.
- Remove "Add has_syscall_work() helper" patch.
- Move "Add syscall_exit_to_user_mode_prepare() helper" patch later.
- Add miss header for asm/entry-common.h.
- Update the implementation of arch_syscall_is_vdso_sigreturn().
- Add "ARCH_SYSCALL_WORK_EXIT" to be defined as "SECCOMP | SYSCALL_EMU" to keep the behaviour unchanged.
- Add more testcases test.
- Add Reviewed-by.
- Update the commit message.
- Link to v7: https://lore.kernel.org/all/[email protected]/
Jinjie Ruan (18):
seccomp: Convert __secure_computing() to return boolean
syscall_user_dispatch: Introduce a weak fallback for
arch_syscall_is_vdso_sigreturn()
arm64: ptrace: Pass thread flags to syscall_trace_enter/exit()
arm64: ptrace: Use syscall_get_nr() helper for syscall_trace_enter()
arm64: ptrace: Expand secure_computing() in place
arm64: ptrace: Use syscall_get_arguments() helper for audit
arm64: ptrace: Protect rseq_syscall() from tracer PC modifications
arm64: ptrace: Rename syscall_trace_exit() to syscall_exit_work()
arm64: syscall: Rework the syscall exit path in el0_svc_common()
arm64: ptrace: Extract syscall_exit_to_user_mode_work() helper
arm64: ptrace: Align syscall exit work semantics with generic entry
arm64: syscall: Use exit-specific flags check in el0_svc_common()
arm64: syscall: Simplify el0_svc_common() syscall exit path
arm64: syscall: Simplify syscall exit path in el0_svc_common()
arm64: ptrace: Skip syscall exit reporting for
PTRACE_SYSEMU_SINGLESTEP
arm64: entry: Convert to generic entry
arm64: Inline el0_svc_common()
arm64: vdso: Expose sigreturn address on vdso to the kernel
arch/alpha/kernel/ptrace.c | 2 +- arch/arm/kernel/ptrace.c | 2 +- arch/arm64/Kconfig | 2 +- arch/arm64/include/asm/elf.h | 1 + arch/arm64/include/asm/entry-common.h | 76 +++++++++++++++++ arch/arm64/include/asm/syscall.h | 4 +- arch/arm64/include/asm/thread_info.h | 16 +--- arch/arm64/kernel/debug-monitors.c | 8 ++ arch/arm64/kernel/ptrace.c | 115 -------------------------- arch/arm64/kernel/signal.c | 2 +- arch/arm64/kernel/syscall.c | 30 ++----- arch/arm64/kernel/vdso.c | 16 ++++ arch/csky/kernel/ptrace.c | 2 +- arch/loongarch/include/asm/syscall.h | 5 -- arch/m68k/kernel/ptrace.c | 2 +- arch/mips/kernel/ptrace.c | 2 +- arch/parisc/kernel/ptrace.c | 2 +- arch/powerpc/include/asm/syscall.h | 5 -- arch/riscv/include/asm/syscall.h | 5 -- arch/s390/include/asm/syscall.h | 5 -- arch/sh/kernel/ptrace_32.c | 2 +- arch/um/kernel/skas/syscall.c | 2 +- arch/x86/entry/vsyscall/vsyscall_64.c | 2 +- arch/xtensa/kernel/ptrace.c | 3 +- include/linux/entry-common.h | 7 +- include/linux/seccomp.h | 10 +-- include/linux/syscall_user_dispatch.h | 1 + kernel/entry/syscall_user_dispatch.c | 5 ++ kernel/seccomp.c | 34 ++++---- 29 files changed, 154 insertions(+), 214 deletions(-)
Signature · 1 line
2.34.1
PATCH v16 1/18 seccomp: Convert __secure_computing() to return boolean
The return value of __secure_computing() currently uses 0 to indicate that a system call should be allowed, and -1 to indicate that it should be blocked/killed. This 0/-1 pattern is non-intuitive for a security check function and makes the control flow at the call sites less readable.
Furthermore, any potential future changes to these return values would require a high-risk, error-prone audit of all its users across different architectures.
Sanitize this logic by converting the return type of __secure_computing() to a proper boolean, where 'true' explicitly means 'allow' and 'false' means 'fail/deny'.
Update all the two dozen or so call sites across the tree to align with this new boolean semantic. No functional changes are intended, as the callers still return -1 to the lower-level assembly entry code upon seccomp denial.
--- arch/alpha/kernel/ptrace.c | 2 +- arch/arm/kernel/ptrace.c | 2 +- arch/arm64/kernel/ptrace.c | 2 +- arch/csky/kernel/ptrace.c | 2 +- arch/m68k/kernel/ptrace.c | 2 +- arch/mips/kernel/ptrace.c | 2 +- arch/parisc/kernel/ptrace.c | 2 +- arch/sh/kernel/ptrace_32.c | 2 +- arch/um/kernel/skas/syscall.c | 2 +- arch/x86/entry/vsyscall/vsyscall_64.c | 2 +- arch/xtensa/kernel/ptrace.c | 3 +-- include/linux/entry-common.h | 7 +++--- include/linux/seccomp.h | 10 ++++---- kernel/seccomp.c | 34 +++++++++++++-------------- 14 files changed, 36 insertions(+), 38 deletions(-)
arch/alpha/kernel/ptrace.c +1 -1
@@ -387,7 +387,7 @@ asmlinkage unsigned long syscall_trace_enter(void)* If this fails, seccomp may already have set up the return value * (e.g. SECCOMP_RET_ERRNO / TRACE). */ -if (secure_computing () ==-1 ) { +if (!secure_computing ()) {if (regs->r19 ==0 && regs->r0 == (unsigned long )-1 )syscall_set_return_value (current, regs, -ENOSYS ,0 );syscall_set_nr (current, regs,-1 );
arch/arm/kernel/ptrace.c +1 -1
@@ -855,7 +855,7 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)/* Do seccomp after ptrace; syscall may have changed. */ #ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER -if (secure_computing () ==-1 ) +if (!secure_computing ())return -1 ;#else /* XXX: remove this once OABI gets fixed */
arch/arm64/kernel/ptrace.c +1 -1
@@ -2420,7 +2420,7 @@ int syscall_trace_enter(struct pt_regs *regs) }/* Do the secure computing after ptrace; failures should be fast. */ -if (secure_computing () ==-1 ) +if (!secure_computing ())return NO_SYSCALL ;if (test_thread_flag (TIF_SYSCALL_TRACEPOINT ))
arch/csky/kernel/ptrace.c +1 -1
@@ -323,7 +323,7 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)if (ptrace_report_syscall_entry (regs))return -1 ; -if (secure_computing () ==-1 ) +if (!secure_computing ())return -1 ;if (test_thread_flag (TIF_SYSCALL_TRACEPOINT ))
arch/m68k/kernel/ptrace.c +1 -1
@@ -281,7 +281,7 @@ asmlinkage int syscall_trace_enter(void)if (test_thread_flag (TIF_SYSCALL_TRACE )) ret =ptrace_report_syscall_entry (task_pt_regs (current)); -if (secure_computing () ==-1 ) +if (!secure_computing ())return -1 ;return ret;
arch/mips/kernel/ptrace.c +1 -1
@@ -1328,7 +1328,7 @@ asmlinkage long syscall_trace_enter(struct pt_regs *regs)return -1 ; } -if (secure_computing ()) +if (!secure_computing ())return -1 ;if (unlikely (test_thread_flag (TIF_SYSCALL_TRACEPOINT )))
arch/parisc/kernel/ptrace.c +1 -1
@@ -351,7 +351,7 @@ long do_syscall_trace_enter(struct pt_regs *regs) }/* Do the secure computing check after ptrace. */ -if (secure_computing () ==-1 ) +if (!secure_computing ())return -1 ;#ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
arch/sh/kernel/ptrace_32.c +1 -1
@@ -460,7 +460,7 @@ asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)return -1 ; } -if (secure_computing () ==-1 ) +if (!secure_computing ())return -1 ;if (unlikely (test_thread_flag (TIF_SYSCALL_TRACEPOINT )))
arch/um/kernel/skas/syscall.c +1 -1
@@ -27,7 +27,7 @@ void handle_syscall(struct uml_pt_regs *r) goto out;/* Do the seccomp check after ptrace; failures should be fast. */ -if (secure_computing () ==-1 ) +if (!secure_computing ()) goto out; syscall =UPT_SYSCALL_NR (r);
arch/x86/entry/vsyscall/vsyscall_64.c +1 -1
@@ -198,7 +198,7 @@ static bool __emulate_vsyscall(struct pt_regs *regs, unsigned long address) regs->orig_ax = syscall_nr; regs->ax = -ENOSYS ; tmp =secure_computing (); -if ((!tmp && regs->orig_ax != syscall_nr) || regs->ip != address) { +if ((tmp && regs->orig_ax != syscall_nr) || regs->ip != address) {warn_bad_vsyscall (KERN_DEBUG , regs,"seccomp tried to change syscall nr or ip" );force_exit_sig (SIGSYS );
arch/xtensa/kernel/ptrace.c +1 -2
@@ -553,8 +553,7 @@ int do_syscall_trace_enter(struct pt_regs *regs)return 0 ; } -if (regs->syscall ==NO_SYSCALL || -secure_computing () ==-1 ) { +if (regs->syscall ==NO_SYSCALL || !secure_computing ()) {do_syscall_trace_leave (regs);return 0 ; }
include/linux/entry-common.h +3 -4
@@ -100,9 +100,8 @@ static __always_inline long syscall_trace_enter(struct pt_regs *regs, unsigned l/* Do seccomp after ptrace, to catch any tracer changes. */ if (work &SYSCALL_WORK_SECCOMP ) { - ret =__secure_computing (); -if (ret ==-1L ) -return ret; +if (!__secure_computing ()) +return -1L ; }/* Either of the above might have changed the syscall number */
@@ -113,7 +112,7 @@ static __always_inline long syscall_trace_enter(struct pt_regs *regs, unsigned lsyscall_enter_audit (regs, syscall); -return ret ? : syscall; +return syscall; }/**
include/linux/seccomp.h +5 -5
@@ -22,14 +22,14 @@#include <linux/atomic.h> #include <asm/seccomp.h> -extern int __secure_computing (void ); +extern bool __secure_computing (void );#ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER -static inline int secure_computing (void ) +static inline bool secure_computing (void ) {if (unlikely (test_syscall_work (SECCOMP )))return __secure_computing (); -return 0 ; +return true; }#else extern void secure_computing_strict (int this_syscall);
@@ -50,11 +50,11 @@ static inline int seccomp_mode(struct seccomp *s)struct seccomp_data ;#ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER -static inline int secure_computing (void ) {return 0 ; } +static inline bool secure_computing (void ) {return true; }#else static inline void secure_computing_strict (int this_syscall) {return ; }#endif -static inline int __secure_computing (void ) {return 0 ; } +static inline bool __secure_computing (void ) {return true; }static inline long prctl_get_seccomp (void ) {
kernel/seccomp.c +17 -17
@@ -1100,12 +1100,12 @@ void secure_computing_strict(int this_syscall) else BUG(); } -int __secure_computing (void ) +bool __secure_computing (void ) {int this_syscall =syscall_get_nr (current,current_pt_regs ());secure_computing_strict (this_syscall); -return 0 ; +return true; }#else
@@ -1256,7 +1256,7 @@ static int seccomp_do_user_notification(int this_syscall,return -1 ; } -static int __seccomp_filter (int this_syscall,const bool recheck_after_trace) +static bool __seccomp_filter (int this_syscall,const bool recheck_after_trace) {u32 filter_ret, action;struct seccomp_data sd;
@@ -1294,7 +1294,7 @@ static int __seccomp_filter(int this_syscall, const bool recheck_after_trace)case SECCOMP_RET_TRACE :/* We've been put in this state by the ptracer already. */ if (recheck_after_trace) -return 0 ; +return true;/* ENOSYS these calls if there is no tracer attached. */ if (!ptrace_event_enabled (current,PTRACE_EVENT_SECCOMP )) {
@@ -1330,19 +1330,19 @@ static int __seccomp_filter(int this_syscall, const bool recheck_after_trace)* a skip would have already been reported. */ if (__seccomp_filter (this_syscall, true)) -return -1 ; +return false; -return 0 ; +return true;case SECCOMP_RET_USER_NOTIF :if (seccomp_do_user_notification (this_syscall, match, &sd)) goto skip; -return 0 ; +return true;case SECCOMP_RET_LOG :seccomp_log (this_syscall,0 , action, true); -return 0 ; +return true;case SECCOMP_RET_ALLOW :/*
@@ -1350,7 +1350,7 @@ static int __seccomp_filter(int this_syscall, const bool recheck_after_trace)* this action since SECCOMP_RET_ALLOW is the starting * state in seccomp_run_filters(). */ -return 0 ; +return true;case SECCOMP_RET_KILL_THREAD :case SECCOMP_RET_KILL_PROCESS :
@@ -1367,46 +1367,46 @@ static int __seccomp_filter(int this_syscall, const bool recheck_after_trace) } else {do_exit (SIGSYS ); } -return -1 ;/* skip the syscall go directly to signal handling */ +return false;/* skip the syscall go directly to signal handling */ }unreachable (); skip:seccomp_log (this_syscall,0 , action, match ? match->log : false); -return -1 ; +return false; }#else -static int __seccomp_filter (int this_syscall,const bool recheck_after_trace) +static bool __seccomp_filter (int this_syscall,const bool recheck_after_trace) {BUG (); -return -1 ; +return false; }#endif -int __secure_computing (void ) +bool __secure_computing (void ) {int mode = current->seccomp.mode;int this_syscall;if (IS_ENABLED (CONFIG_CHECKPOINT_RESTORE ) &&unlikely (current->ptrace &PT_SUSPEND_SECCOMP )) -return 0 ; +return true; this_syscall =syscall_get_nr (current,current_pt_regs ());switch (mode) {case SECCOMP_MODE_STRICT :__secure_computing_strict (this_syscall);/* may call do_exit */ -return 0 ; +return true;case SECCOMP_MODE_FILTER :return __seccomp_filter (this_syscall, false);/* Surviving SECCOMP_RET_KILL_* must be proactively impossible. */ case SECCOMP_MODE_DEAD :WARN_ON_ONCE (1 );do_exit (SIGKILL ); -return -1 ; +return false;default :BUG (); }
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v16 01/18] seccomp: Convert __secure_computing() to return boolean
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Critical] Incomplete conversion of secure_computing() return semantics in x86 vsyscall emulation causes…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Critical] Incomplete conversion of secure_computing() return semantics in x86 vsyscall emulation causes allowed vsyscalls to be incorrectly skipped and blocked vsyscalls to be executed.
- [Critical] Inverted seccomp evaluation logic for tracer-modified syscalls in SECCOMP_RET_TRACE allows ptracers to bypass seccomp and execute blocked system calls. --
commit f5bc8c5696220b369255d486da26d273d661d2fa
Author: Jinjie Ruan <[email protected]>
seccomp: Convert __secure_computing() to return boolean
The return value of __secure_computing() currently uses 0 to indicate that a system call should be allowed, and -1 to indicate that it should be blocked/killed. This 0/-1 pattern is non-intuitive for a security check function and makes the control flow at the call sites less readable.
Quoted 13 lines
arch/x86/entry/vsyscall/vsyscall_64.c +1
-1@@ -198,7 +198,7 @@ static bool __emulate_vsyscall(struct pt_regs *regs, unsigned long address) regs->orig_ax = syscall_nr; regs->ax = -ENOSYS ; tmp =secure_computing (); -if ((!tmp && regs->orig_ax != syscall_nr) || regs->ip != address) { +if ((tmp && regs->orig_ax != syscall_nr) || regs->ip != address) {warn_bad_vsyscall (KERN_DEBUG , regs,"seccomp tried to change syscall nr or ip" );force_exit_sig (SIGSYS );
arch/x86/entry/vsyscall/vsyscall_64.c
Quoted 5 lines
arch/x86/entry/vsyscall/vsyscall_64.c +0
-0return true; } regs->orig_ax =-1 ;if (tmp) goto do_ret;/* skip requested */
[Severity: Critical]
Since secure_computing() now returns true when allowing a system call, doesn't this check skip the emulation for allowed vsyscalls and execute the blocked ones instead?
[ ... ]
Quoted 4 lines
kernel/seccomp.c +0
-0
[ ... ]
kernel/seccomp.c static int __seccomp_filter(int this_syscall, const bool recheck_after_trace) · line 1335
Quoted 9 lines
kernel/seccomp.c +2
-2@@ -1330,19 +1330,19 @@ static int __seccomp_filter(int this_syscall, const bool recheck_after_trace)* a skip would have already been reported. */ if (__seccomp_filter (this_syscall, true)) -return -1 ; +return false; -return 0 ; +return true;
[Severity: Critical]
Is this logic inverted for tracer-modified syscalls in SECCOMP_RET_TRACE?
__seccomp_filter() now returns true on allow and false on deny. If the nested __seccomp_filter() call evaluates the modified syscall and returns true (allow), the if condition evaluates to true and it returns false (deny).
Conversely, if it returns false (deny), it bypasses the if condition and returns true (allow).
Could a ptracer bypass the seccomp sandbox entirely by changing the syscall to a prohibited one, which would then be incorrectly allowed here?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH v16 01/18] seccomp: Convert __secure_computing() to return boolean
In reply to Jinjie RuanHi Jinjie,
Quoted 9 lines · Jinjie Ruan
The return value of
__secure_computing()currently uses 0 to indicate that a system call should be allowed, and -1 to indicate that it should be blocked/killed. This 0/-1 pattern is non-intuitive for a security check function and makes the control flow at the call sites less readable.Furthermore, any potential future changes to these return values would require a high-risk, error-prone audit of all its users across different architectures.
Quoted 8 lines
Sanitize this logic by converting the return type of
__secure_computing()to a proper boolean, where 'true' explicitly means 'allow' and 'false' means 'fail/deny'.Update all the two dozen or so call sites across the tree to align with this new boolean semantic. No functional changes are intended, as the callers still return -1 to the lower-level assembly entry code upon seccomp denial.
Would it be relevant to mention that this fixes the unsound return value of syscall_trace_enter() in generic entry, which motivated the patch initially[0] ?
Quoted 18 lines
Suggested-by Thomas Gleixner <[email protected]>Signed-off-by Jinjie Ruan <[email protected]>--- arch/alpha/kernel/ptrace.c | 2 +- arch/arm/kernel/ptrace.c | 2 +- arch/arm64/kernel/ptrace.c | 2 +- arch/csky/kernel/ptrace.c | 2 +- arch/m68k/kernel/ptrace.c | 2 +- arch/mips/kernel/ptrace.c | 2 +- arch/parisc/kernel/ptrace.c | 2 +- arch/sh/kernel/ptrace_32.c | 2 +- arch/um/kernel/skas/syscall.c | 2 +- arch/x86/entry/vsyscall/vsyscall_64.c | 2 +- arch/xtensa/kernel/ptrace.c | 3 +-- include/linux/entry-common.h | 7 +++--- include/linux/seccomp.h | 10 ++++---- kernel/seccomp.c | 34 +++++++++++++-------------- 14 files changed, 36 insertions(+), 38 deletions(-)
This is missing an update to the Kconfig documentation, a possible suggestion :
arch/Kconfig +1 -1
@@ -637,7 +637,7 @@ config HAVE_ARCH_SECCOMP_FILTER - syscall_set_return_value() - SIGSYS siginfo_t support - secure_computing is called from a ptrace_event()-safe context - - secure_computing return value is checked and a return value of -1 + - secure_computing return value is checked and if false results in the system call being skipped immediately. - seccomp syscall wired up - if !HAVE_SPARSE_SYSCALL_NR, have SECCOMP_ARCH_NATIVE,
Quoted 18 lines
[...]
include/linux/entry-common.h +2
-3@@ -100,9 +100,8 @@ static __always_inline long syscall_trace_enter(struct pt_regs *regs, unsigned l/* Do seccomp after ptrace, to catch any tracer changes. */ if (work &SYSCALL_WORK_SECCOMP ) { - ret =__secure_computing (); -if (ret ==-1L ) -return ret; +if (!__secure_computing ()) +return -1L ; }/* Either of the above might have changed the syscall number */
include/linux/entry-common.h static __always_inline long syscall_trace_enter(struct pt_regs *regs, unsigned l · line 116
Quoted 7 lines
include/linux/entry-common.h +1
-1@@ -113,7 +112,7 @@ static __always_inline long syscall_trace_enter(struct pt_regs *regs, unsigned lsyscall_enter_audit (regs, syscall); -return ret ? : syscall; +return syscall; }
Otherwise this feels like a more appropriate change with regards to "safeguarding against new secure_computing() return value" !
With the updated Kconfig :
Thanks,
Ada
Re: [PATCH v16 01/18] seccomp: Convert __secure_computing() to return boolean
Quoted 17 lines · Ada Couprie Diaz
Hi Jinjie,
Quoted 14 lines · Jinjie Ruan
The return value of
__secure_computing()currently uses 0 to indicate that a system call should be allowed, and -1 to indicate that it should be blocked/killed. This 0/-1 pattern is non-intuitive for a security check function and makes the control flow at the call sites less readable.Furthermore, any potential future changes to these return values would require a high-risk, error-prone audit of all its users across different architectures.
Sanitize this logic by converting the return type of
__secure_computing()to a proper boolean, where 'true' explicitly means 'allow' and 'false' means 'fail/deny'.
Quoted 7 lines
Quoted 4 lines
Update all the two dozen or so call sites across the tree to align with this new boolean semantic. No functional changes are intended, as the callers still return -1 to the lower-level assembly entry code upon seccomp denial.
Would it be relevant to mention that this fixes the unsound return value of
syscall_trace_enter()in generic entry, which motivated the patch initially[0] ?
That's a very good point. It's definitely worth mentioning
Quoted 19 lines
Quoted 17 lines
Suggested-by Thomas Gleixner <[email protected]>Signed-off-by Jinjie Ruan <[email protected]>---
arch/alpha/kernel/ptrace.c | 2 +-
arch/arm/kernel/ptrace.c | 2 +-
arch/arm64/kernel/ptrace.c | 2 +-arch/csky/kernel/ptrace.c | 2 +- arch/m68k/kernel/ptrace.c | 2 +- arch/mips/kernel/ptrace.c | 2 +-arch/parisc/kernel/ptrace.c | 2 +- arch/sh/kernel/ptrace_32.c | 2 +- arch/um/kernel/skas/syscall.c | 2 +-
arch/x86/entry/vsyscall/vsyscall_64.c| 2 +- arch/xtensa/kernel/ptrace.c | 3 +-- include/linux/entry-common.h | 7 +++--- include/linux/seccomp.h | 10 ++++---- kernel/seccomp.c | 34 +++++++++++++--------------Quoted 1 line
14 files changed, 36 insertions(+), 38 deletions(-)
Quoted 2 lines
This is missing an update to the
Kconfigdocumentation, a possible suggestion :
Will update it.
Quoted 53 lines
arch/Kconfig +0
-0@@ -637,7 +637,7 @@ config HAVE_ARCH_SECCOMP_FILTER - syscall_set_return_value()- SIGSYS
siginfo_tsupport
-secure_computingis called from a ptrace_event()-safe context - -secure_computingreturn value is checked and a return value of -1
+ -secure_computingreturn value is checked and if false results in the system call being skipped immediately.
- seccomp syscall wired up
- if !HAVE_SPARSE_SYSCALL_NR, haveSECCOMP_ARCH_NATIVE,Quoted 17 lines
[...]
include/linux/entry-common.h +0
-0@@ -100,9 +100,8 @@ static __always_inline longsyscall_trace_enter(struct
pt_regs*regs, unsigned l
/* Do seccomp after ptrace, to catch any tracer changes. */ if (work &SYSCALL_WORK_SECCOMP) {
- ret =__secure_computing();
- if (ret == -1L)
- return ret;
+ if (!__secure_computing())
+ return -1L;
}
/* Either of the above might have changed the syscall number */include/linux/entry-common.h +0
-0@@ -113,7 +112,7 @@ static __always_inline longQuoted 6 lines
syscall_trace_enter(struct
pt_regs*regs, unsigned lsyscall_enter_audit(regs, syscall); - return ret ? : syscall;
+ return syscall;
}
[...]Otherwise this feels like a more appropriate change with regards to "safeguarding against new
secure_computing()return value" !With the updated
Kconfig:Reviewed-by Ada Couprie Diaz <[email protected]>Thanks,
Ada[0]: https://lore.kernel.org/r/20260511092103.1974980-2-
[email protected]
Re: [PATCH v16 01/18] seccomp: Convert __secure_computing() to return boolean
In reply to Jinjie RuanQuoted 107 lines · Jinjie Ruan
The return value of
__secure_computing()currently uses 0 to indicate that a system call should be allowed, and -1 to indicate that it should be blocked/killed. This 0/-1 pattern is non-intuitive for a security check function and makes the control flow at the call sites less readable.Furthermore, any potential future changes to these return values would require a high-risk, error-prone audit of all its users across different architectures.
Sanitize this logic by converting the return type of
__secure_computing()to a proper boolean, where 'true' explicitly means 'allow' and 'false' means 'fail/deny'.Update all the two dozen or so call sites across the tree to align with this new boolean semantic. No functional changes are intended, as the callers still return -1 to the lower-level assembly entry code upon seccomp denial.
Suggested-by Thomas Gleixner <[email protected]>Signed-off-by Jinjie Ruan <[email protected]>--- arch/alpha/kernel/ptrace.c | 2 +- arch/arm/kernel/ptrace.c | 2 +- arch/arm64/kernel/ptrace.c | 2 +- arch/csky/kernel/ptrace.c | 2 +- arch/m68k/kernel/ptrace.c | 2 +- arch/mips/kernel/ptrace.c | 2 +- arch/parisc/kernel/ptrace.c | 2 +- arch/sh/kernel/ptrace_32.c | 2 +- arch/um/kernel/skas/syscall.c | 2 +- arch/x86/entry/vsyscall/vsyscall_64.c | 2 +- arch/xtensa/kernel/ptrace.c | 3 +-- include/linux/entry-common.h | 7 +++--- include/linux/seccomp.h | 10 ++++---- kernel/seccomp.c | 34 +++++++++++++-------------- 14 files changed, 36 insertions(+), 38 deletions(-)arch/alpha/kernel/ptrace.c +1
-1@@ -387,7 +387,7 @@ asmlinkage unsigned long syscall_trace_enter(void)* If this fails, seccomp may already have set up the return value * (e.g. SECCOMP_RET_ERRNO / TRACE). */ -if (secure_computing () ==-1 ) { +if (!secure_computing ()) {if (regs->r19 ==0 && regs->r0 == (unsigned long )-1 )syscall_set_return_value (current, regs, -ENOSYS ,0 );syscall_set_nr (current, regs,-1 );arch/arm/kernel/ptrace.c +1
-1@@ -855,7 +855,7 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)/* Do seccomp after ptrace; syscall may have changed. */ #ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER -if (secure_computing () ==-1 ) +if (!secure_computing ())return -1 ;#else /* XXX: remove this once OABI gets fixed */ arch/arm64/kernel/ptrace.c +1
-1@@ -2420,7 +2420,7 @@ int syscall_trace_enter(struct pt_regs *regs) }/* Do the secure computing after ptrace; failures should be fast. */ -if (secure_computing () ==-1 ) +if (!secure_computing ())return NO_SYSCALL ;if (test_thread_flag (TIF_SYSCALL_TRACEPOINT ))arch/csky/kernel/ptrace.c +1
-1@@ -323,7 +323,7 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)if (ptrace_report_syscall_entry (regs))return -1 ; -if (secure_computing () ==-1 ) +if (!secure_computing ())return -1 ;if (test_thread_flag (TIF_SYSCALL_TRACEPOINT ))arch/m68k/kernel/ptrace.c +1
-1@@ -281,7 +281,7 @@ asmlinkage int syscall_trace_enter(void)if (test_thread_flag (TIF_SYSCALL_TRACE )) ret =ptrace_report_syscall_entry (task_pt_regs (current)); -if (secure_computing () ==-1 ) +if (!secure_computing ())return -1 ;return ret;arch/mips/kernel/ptrace.c +0
-0
arch/mips/kernel/ptrace.c asmlinkage long syscall_trace_enter(struct pt_regs *regs) · line 1332
Quoted 6 lines
arch/mips/kernel/ptrace.c +1
-1@@ -1328,7 +1328,7 @@ asmlinkage long syscall_trace_enter(struct pt_regs *regs)return -1 ; } -if (secure_computing ()) +if (!secure_computing ())return -1 ;
Hello,
I am not fond of this logic inversion. The boolean is meaningless in itself.
Previously -1 was used to indicate that the syscall was filtered but you chose to invert the logic choosing true to mean syscall was not filtered.
You could choose true to mean that syscall was fitered avoiding this inversion.
Sashiko points out some places in existing code where it supposedly explodes which might or might not be true but any in-flight patches that use secure_computing would also be affected.
Also please document what the value actually means. I do not see that added as part of these series. As either interpretation of the boolean value is equally valid it needs to be documented which one was chosen.
While there is a code comment in one of the functions that secure_computing() calls I could not find any documentation for the return value of secure_computing.
This could add a kernel-doc comment while touching the code anyway
https://www.kernel.org/doc/html/v7.2-rc1/doc-guide/kernel-doc.html
Thanks
Michal
Quoted 257 lines
arch/mips/kernel/ptrace.c +0
-0if (unlikely (test_thread_flag (TIF_SYSCALL_TRACEPOINT )))arch/parisc/kernel/ptrace.c +1
-1@@ -351,7 +351,7 @@ long do_syscall_trace_enter(struct pt_regs *regs) }/* Do the secure computing check after ptrace. */ -if (secure_computing () ==-1 ) +if (!secure_computing ())return -1 ;#ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS arch/sh/kernel/ptrace_32.c +1
-1@@ -460,7 +460,7 @@ asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)return -1 ; } -if (secure_computing () ==-1 ) +if (!secure_computing ())return -1 ;if (unlikely (test_thread_flag (TIF_SYSCALL_TRACEPOINT )))arch/um/kernel/skas/syscall.c +1
-1@@ -27,7 +27,7 @@ void handle_syscall(struct uml_pt_regs *r) goto out;/* Do the seccomp check after ptrace; failures should be fast. */ -if (secure_computing () ==-1 ) +if (!secure_computing ()) goto out; syscall =UPT_SYSCALL_NR (r);arch/x86/entry/vsyscall/vsyscall_64.c +1
-1@@ -198,7 +198,7 @@ static bool __emulate_vsyscall(struct pt_regs *regs, unsigned long address) regs->orig_ax = syscall_nr; regs->ax = -ENOSYS ; tmp =secure_computing (); -if ((!tmp && regs->orig_ax != syscall_nr) || regs->ip != address) { +if ((tmp && regs->orig_ax != syscall_nr) || regs->ip != address) {warn_bad_vsyscall (KERN_DEBUG , regs,"seccomp tried to change syscall nr or ip" );force_exit_sig (SIGSYS );arch/xtensa/kernel/ptrace.c +1
-2@@ -553,8 +553,7 @@ int do_syscall_trace_enter(struct pt_regs *regs)return 0 ; } -if (regs->syscall ==NO_SYSCALL || -secure_computing () ==-1 ) { +if (regs->syscall ==NO_SYSCALL || !secure_computing ()) {do_syscall_trace_leave (regs);return 0 ; }include/linux/entry-common.h +3
-4@@ -100,9 +100,8 @@ static __always_inline long syscall_trace_enter(struct pt_regs *regs, unsigned l/* Do seccomp after ptrace, to catch any tracer changes. */ if (work &SYSCALL_WORK_SECCOMP ) { - ret =__secure_computing (); -if (ret ==-1L ) -return ret; +if (!__secure_computing ()) +return -1L ; }/* Either of the above might have changed the syscall number */ @@ -113,7 +112,7 @@ static __always_inline long syscall_trace_enter(struct pt_regs *regs, unsigned lsyscall_enter_audit (regs, syscall); -return ret ? : syscall; +return syscall; }/** include/linux/seccomp.h +5
-5@@ -22,14 +22,14 @@#include <linux/atomic.h> #include <asm/seccomp.h> -extern int __secure_computing (void ); +extern bool __secure_computing (void );#ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER -static inline int secure_computing (void ) +static inline bool secure_computing (void ) {if (unlikely (test_syscall_work (SECCOMP )))return __secure_computing (); -return 0 ; +return true; }#else extern void secure_computing_strict (int this_syscall);@@ -50,11 +50,11 @@ static inline int seccomp_mode(struct seccomp *s)struct seccomp_data ;#ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER -static inline int secure_computing (void ) {return 0 ; } +static inline bool secure_computing (void ) {return true; }#else static inline void secure_computing_strict (int this_syscall) {return ; }#endif -static inline int __secure_computing (void ) {return 0 ; } +static inline bool __secure_computing (void ) {return true; }static inline long prctl_get_seccomp (void ) {kernel/seccomp.c +17
-17@@ -1100,12 +1100,12 @@ void secure_computing_strict(int this_syscall) else BUG(); } -int __secure_computing (void ) +bool __secure_computing (void ) {int this_syscall =syscall_get_nr (current,current_pt_regs ());secure_computing_strict (this_syscall); -return 0 ; +return true; }#else @@ -1256,7 +1256,7 @@ static int seccomp_do_user_notification(int this_syscall,return -1 ; } -static int __seccomp_filter (int this_syscall,const bool recheck_after_trace) +static bool __seccomp_filter (int this_syscall,const bool recheck_after_trace) {u32 filter_ret, action;struct seccomp_data sd;@@ -1294,7 +1294,7 @@ static int __seccomp_filter(int this_syscall, const bool recheck_after_trace)case SECCOMP_RET_TRACE :/* We've been put in this state by the ptracer already. */ if (recheck_after_trace) -return 0 ; +return true;/* ENOSYS these calls if there is no tracer attached. */ if (!ptrace_event_enabled (current,PTRACE_EVENT_SECCOMP )) {@@ -1330,19 +1330,19 @@ static int __seccomp_filter(int this_syscall, const bool recheck_after_trace)* a skip would have already been reported. */ if (__seccomp_filter (this_syscall, true)) -return -1 ; +return false; -return 0 ; +return true;case SECCOMP_RET_USER_NOTIF :if (seccomp_do_user_notification (this_syscall, match, &sd)) goto skip; -return 0 ; +return true;case SECCOMP_RET_LOG :seccomp_log (this_syscall,0 , action, true); -return 0 ; +return true;case SECCOMP_RET_ALLOW :/* @@ -1350,7 +1350,7 @@ static int __seccomp_filter(int this_syscall, const bool recheck_after_trace)* this action since SECCOMP_RET_ALLOW is the starting * state in seccomp_run_filters(). */ -return 0 ; +return true;case SECCOMP_RET_KILL_THREAD :case SECCOMP_RET_KILL_PROCESS :@@ -1367,46 +1367,46 @@ static int __seccomp_filter(int this_syscall, const bool recheck_after_trace) } else {do_exit (SIGSYS ); } -return -1 ;/* skip the syscall go directly to signal handling */ +return false;/* skip the syscall go directly to signal handling */ }unreachable (); skip:seccomp_log (this_syscall,0 , action, match ? match->log : false); -return -1 ; +return false; }#else -static int __seccomp_filter (int this_syscall,const bool recheck_after_trace) +static bool __seccomp_filter (int this_syscall,const bool recheck_after_trace) {BUG (); -return -1 ; +return false; }#endif -int __secure_computing (void ) +bool __secure_computing (void ) {int mode = current->seccomp.mode;int this_syscall;if (IS_ENABLED (CONFIG_CHECKPOINT_RESTORE ) &&unlikely (current->ptrace &PT_SUSPEND_SECCOMP )) -return 0 ; +return true; this_syscall =syscall_get_nr (current,current_pt_regs ());switch (mode) {case SECCOMP_MODE_STRICT :__secure_computing_strict (this_syscall);/* may call do_exit */ -return 0 ; +return true;case SECCOMP_MODE_FILTER :return __seccomp_filter (this_syscall, false);/* Surviving SECCOMP_RET_KILL_* must be proactively impossible. */ case SECCOMP_MODE_DEAD :WARN_ON_ONCE (1 );do_exit (SIGKILL ); -return -1 ; +return false;default :BUG (); }Signature · 1 line
2.34.1
Thomas Gleixner
maintainerRe: [PATCH v16 01/18] seccomp: Convert __secure_computing() to return boolean
Quoted 7 lines · Michal Suchánek
arch/mips/kernel/ptrace.c asmlinkage long syscall_trace_enter(struct pt_regs *regs) · line 1332
Quoted 3 lines · Jinjie Ruan
arch/mips/kernel/ptrace.c +1
-1-if (secure_computing ()) +if (!secure_computing ())return -1 ;Hello,
Quoted 8 lines
I am not fond of this logic inversion. The boolean is meaningless in itself.
Previously -1 was used to indicate that the syscall was filtered but you chose to invert the logic choosing true to mean syscall was not filtered.
You could choose true to mean that syscall was fitered avoiding this inversion.
That's just wrong. Boolean logic makes more sense with having (!condition()). Just because the old 0/-1 nonsense had it the other way round does not mean it has to stay that way.
Quoted 2 lines
Sashiko points out some places in existing code where it supposedly explodes which might or might not be true
The vsyscall one is correct, but that's a bug like any other one and should be caught in review.
The blurb about bypass is AI halluzination nonsense.
Quoted 2 lines
but any in-flight patches that use
secure_computingwould also be affected.
Maintainers know how to deal with collisions of that kind. Stop making problems up.
Mark Rutland
reviewerRe: [PATCH v16 01/18] seccomp: Convert __secure_computing() to return boolean
Quoted 14 lines · Thomas Gleixner
Quoted 13 lines · Michal Suchánek
arch/mips/kernel/ptrace.c asmlinkage long syscall_trace_enter(struct pt_regs *regs) · line 1332
Quoted 3 lines · Jinjie Ruan
arch/mips/kernel/ptrace.c +1
-1-if (secure_computing ()) +if (!secure_computing ())return -1 ;Hello,
I am not fond of this logic inversion. The boolean is meaningless in itself.
Previously -1 was used to indicate that the syscall was filtered but you chose to invert the logic choosing true to mean syscall was not filtered.
Quoted 6 lines
Quoted 2 lines
You could choose true to mean that syscall was fitered avoiding this inversion.
That's just wrong. Boolean logic makes more sense with having (!condition()). Just because the old 0/-1 nonsense had it the other way round does not mean it has to stay that way.
100% agreed!
Bikeshedding below; sorry.
I think the bigger problem is just that secure_computing() is a terrible name that does not express the intended semantic -- it's not clear whether "secure computing" means "seccomp permit the syscall" or "seccomp is enabled and some special rules now apply" or something else entirely.
If we're changing the return type, it might be worth renaming the function something like:
seccomp_permits_syscall()
... so for the code quoted at the start of the mail, we'd have:
if (!seccomp_permits_syscall()) return -1;
... or for arm64, where we have NO_SYSCALL:
if (!seccomp_permits_syscall())
return NO_SYSCALL.
Thomas, any thoughts on that?
It's also odd that seccomp aquires the syscall number itself via , rather than than being passed down explicitly by the arch code. That completely obscures what seccomp is doing, vs having:
if (!seccomp_permis_syscall(syscall)) ...
... but I guess that saves some duplication in the ptrace code.
Mark.
Re: [PATCH v16 01/18] seccomp: Convert __secure_computing() to return boolean
Quoted 32 lines · Mark Rutland
Quoted 14 lines · Thomas Gleixner
Quoted 13 lines · Michal Suchánek
arch/mips/kernel/ptrace.c asmlinkage long syscall_trace_enter(struct pt_regs *regs) · line 1332
Quoted 3 lines · Jinjie Ruan
arch/mips/kernel/ptrace.c +1
-1-if (secure_computing ()) +if (!secure_computing ())return -1 ;Hello,
I am not fond of this logic inversion. The boolean is meaningless in itself.
Previously -1 was used to indicate that the syscall was filtered but you chose to invert the logic choosing true to mean syscall was not filtered.
Quoted 6 lines
Quoted 2 lines
You could choose true to mean that syscall was fitered avoiding this inversion.
That's just wrong. Boolean logic makes more sense with having (!condition()). Just because the old 0/-1 nonsense had it the other way round does not mean it has to stay that way.
100% agreed!
Bikeshedding below; sorry.
I think the bigger problem is just that
secure_computing()is a terrible name that does not express the intended semantic -- it's not clear whether "secure computing" means "seccomp permit the syscall" or "seccomp is enabled and some special rules now apply" or something else entirely.
Quoted 4 lines
If we're changing the return type, it might be worth renaming the function something like:
seccomp_permits_syscall()
Then not only it is clear which way the boolean value should be interpreted, it also pervents the accidental inversion of existing calls. Overall great.
Thanks
Michal
Re: [PATCH v16 01/18] seccomp: Convert __secure_computing() to return boolean
Quoted 30 lines · Michal Suchánek
Quoted 29 lines · Mark Rutland
Quoted 10 lines · Thomas Gleixner
Quoted 9 lines · Michal Suchánek
arch/mips/kernel/ptrace.c asmlinkage long syscall_trace_enter(struct pt_regs *regs) · line 1332
Quoted 3 lines · Jinjie Ruan
arch/mips/kernel/ptrace.c +1
-1-if (secure_computing ()) +if (!secure_computing ())return -1 ;Hello,
I am not fond of this logic inversion. The boolean is meaningless in itself.
Quoted 8 lines
Quoted 5 lines
Previously -1 was used to indicate that the syscall was filtered but you chose to invert the logic choosing true to mean syscall was not filtered.
You could choose true to mean that syscall was fitered avoiding this inversion.
That's just wrong. Boolean logic makes more sense with having (!condition()). Just because the old 0/-1 nonsense had it the other way round does not mean it has to stay that way.
100% agreed!
Bikeshedding below; sorry.
I think the bigger problem is just that
secure_computing()is a terrible name that does not express the intended semantic -- it's not clear whether "secure computing" means "seccomp permit the syscall" or "seccomp is enabled and some special rules now apply" or something else entirely.
Quoted 7 lines
Quoted 4 lines
If we're changing the return type, it might be worth renaming the function something like:
seccomp_permits_syscall()Then not only it is clear which way the boolean value should be interpreted, it also pervents the accidental inversion of existing calls. Overall great.
Totally agreed, if we have the opportunity to rename a completely undescriptive function name like "secure_computing" we should take it.
- Kevin
Thomas Gleixner
maintainerRe: [PATCH v16 01/18] seccomp: Convert __secure_computing() to return boolean
Quoted 11 lines · Kevin Brodsky
Quoted 7 lines · Michal Suchánek
Quoted 4 lines
If we're changing the return type, it might be worth renaming the function something like:
seccomp_permits_syscall()Then not only it is clear which way the boolean value should be interpreted, it also pervents the accidental inversion of existing calls. Overall great.
Totally agreed, if we have the opportunity to rename a completely undescriptive function name like "
secure_computing" we should take it.
Absolutely no objections from my side on that.
H. Peter Anvin
reviewerRe: [PATCH v16 01/18] seccomp: Convert __secure_computing() to return boolean
Quoted 6 lines · Thomas Gleixner
Quoted 5 lines · Kevin Brodsky
Quoted 4 lines · Michal Suchánek
Quoted 4 lines
If we're changing the return type, it might be worth renaming the function something like:
seccomp_permits_syscall()
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
Then not only it is clear which way the boolean value should be interpreted, it also pervents the accidental inversion of existing calls. Overall great.
Totally agreed, if we have the opportunity to rename a completely undescriptive function name like "
secure_computing" we should take it.Absolutely no objections from my side on that.
Hell yes.
Re: [PATCH v16 01/18] seccomp: Convert __secure_computing() to return boolean
In reply to Mark RutlandQuoted 8 lines · Mark Rutland
Bikeshedding below; sorry.
I think the bigger problem is just that
secure_computing()is a terrible name that does not express the intended semantic -- it's not clear whether "secure computing" means "seccomp permit the syscall" or "seccomp is enabled and some special rules now apply" or something else entirely.
Quoted 4 lines
If we're changing the return type, it might be worth renaming the function something like:
seccomp_permits_syscall()
Yeah that's way better, let's do this.
(I also had problems with this function!!)
Rusty Russel's API design manifesto tells us to do this:
https://gist.github.com/mjball/9cd028ac793ae8b351df1379f1e721f9
Yours,
Linus Walleij
PATCH v16 2/18 syscall_user_dispatch: Introduce a weak fallback for arch_syscall_is_vdso_sigreturn()
In reply to Jinjie RuanCurrently, multiple architectures (LoongArch, RISC-V, S390, Powerpc) provide identical stubs for arch_syscall_is_vdso_sigreturn() that simply return false. This results in redundant boilerplate code across the tree.
Introduce a default __weak implementation of arch_syscall_is_vdso_sigreturn() directly in syscall_user_dispatch.c that returns false. This allows architectures that do not utilize a vDSO sigreturn to entirely drop their redundant inline definitions.
Architectures requiring a specialized check (such as x86) will continue to override this fallback with their strong symbol definitions.
Clean up the redundant implementations in loongarch, riscv, s390 and powerpc.
--- arch/loongarch/include/asm/syscall.h | 5 ----- arch/powerpc/include/asm/syscall.h | 5 ----- arch/riscv/include/asm/syscall.h | 5 ----- arch/s390/include/asm/syscall.h | 5 ----- include/linux/syscall_user_dispatch.h | 1 + kernel/entry/syscall_user_dispatch.c | 5 +++++ 6 files changed, 6 insertions(+), 20 deletions(-)
arch/loongarch/include/asm/syscall.h +0 -5
@@ -85,9 +85,4 @@ static inline int syscall_get_arch(struct task_struct *task) #endif } -static inline bool arch_syscall_is_vdso_sigreturn (struct pt_regs *regs) -{ -return false; -} -#endif /* __ASM_LOONGARCH_SYSCALL_H */
arch/powerpc/include/asm/syscall.h +0 -5
@@ -139,9 +139,4 @@ static inline int syscall_get_arch(struct task_struct *task) else return AUDIT_ARCH_PPC64; } - -static inline bool arch_syscall_is_vdso_sigreturn (struct pt_regs *regs) -{ -return false; -}#endif /* _ASM_SYSCALL_H */
arch/riscv/include/asm/syscall.h +0 -5
@@ -112,11 +112,6 @@ static inline void syscall_handler(struct pt_regs *regs, ulong syscall) regs->a0 =fn (regs); } -static inline bool arch_syscall_is_vdso_sigreturn (struct pt_regs *regs) -{ -return false; -} -asmlinkage long sys_riscv_flush_icache (uintptr_t ,uintptr_t ,uintptr_t ); asmlinkage long sys_riscv_hwprobe(struct riscv_hwprobe *, size_t, size_t,
arch/s390/include/asm/syscall.h +0 -5
@@ -89,11 +89,6 @@ static inline int syscall_get_arch(struct task_struct *task)return AUDIT_ARCH_S390X ; } -static inline bool arch_syscall_is_vdso_sigreturn (struct pt_regs *regs) -{ -return false; -} -#define SYSCALL_FMT_0 #define SYSCALL_FMT_1 , "0" (r2)#define SYSCALL_FMT_2 , "d" (r3) SYSCALL_FMT_1
include/linux/syscall_user_dispatch.h +1 -0
@@ -10,6 +10,7 @@#ifdef CONFIG_GENERIC_ENTRY +bool arch_syscall_is_vdso_sigreturn (struct pt_regs *regs);int set_syscall_user_dispatch (unsigned long mode,unsigned long offset,unsigned long len,char __user *selector);
kernel/entry/syscall_user_dispatch.c +5 -0
@@ -32,6 +32,11 @@ static void trigger_sigsys(struct pt_regs *regs)force_sig_info (&info); } +bool __weak arch_syscall_is_vdso_sigreturn (struct pt_regs *regs) +{ +return false; +} +bool syscall_user_dispatch (struct pt_regs *regs) {struct syscall_user_dispatch *sd = ¤t->syscall_dispatch;
Signature · 1 line
2.34.1
Re: [PATCH v16 02/18] syscall_user_dispatch: Introduce a weak fallback for arch_syscall_is_vdso_sigreturn()
Quoted 117 lines · Jinjie Ruan
Currently, multiple architectures (LoongArch, RISC-V, S390, Powerpc) provide identical stubs for
arch_syscall_is_vdso_sigreturn()that simply return false. This results in redundant boilerplate code across the tree.Introduce a default
__weakimplementation ofarch_syscall_is_vdso_sigreturn()directly insyscall_user_dispatch.cthat returns false. This allows architectures that do not utilize a vDSO sigreturn to entirely drop their redundant inline definitions.Architectures requiring a specialized check (such as x86) will continue to override this fallback with their strong symbol definitions.
Clean up the redundant implementations in loongarch, riscv, s390 and powerpc.
Cc Thomas Gleixner <[email protected]>Signed-off-by Jinjie Ruan <[email protected]>--- arch/loongarch/include/asm/syscall.h | 5 ----- arch/powerpc/include/asm/syscall.h | 5 ----- arch/riscv/include/asm/syscall.h | 5 ----- arch/s390/include/asm/syscall.h | 5 ----- include/linux/syscall_user_dispatch.h | 1 + kernel/entry/syscall_user_dispatch.c | 5 +++++ 6 files changed, 6 insertions(+), 20 deletions(-)arch/loongarch/include/asm/syscall.h +0
-5@@ -85,9 +85,4 @@ static inline int syscall_get_arch(struct task_struct *task) #endif } -static inline bool arch_syscall_is_vdso_sigreturn (struct pt_regs *regs) -{ -return false; -} -#endif /* __ASM_LOONGARCH_SYSCALL_H */ arch/powerpc/include/asm/syscall.h +0
-5@@ -139,9 +139,4 @@ static inline int syscall_get_arch(struct task_struct *task) else return AUDIT_ARCH_PPC64; } - -static inline bool arch_syscall_is_vdso_sigreturn (struct pt_regs *regs) -{ -return false; -}#endif /* _ASM_SYSCALL_H */ arch/riscv/include/asm/syscall.h +0
-5@@ -112,11 +112,6 @@ static inline void syscall_handler(struct pt_regs *regs, ulong syscall) regs->a0 =fn (regs); } -static inline bool arch_syscall_is_vdso_sigreturn (struct pt_regs *regs) -{ -return false; -} -asmlinkage long sys_riscv_flush_icache (uintptr_t ,uintptr_t ,uintptr_t ); asmlinkage long sys_riscv_hwprobe(struct riscv_hwprobe *, size_t, size_t,arch/s390/include/asm/syscall.h +0
-5@@ -89,11 +89,6 @@ static inline int syscall_get_arch(struct task_struct *task)return AUDIT_ARCH_S390X ; } -static inline bool arch_syscall_is_vdso_sigreturn (struct pt_regs *regs) -{ -return false; -} -#define SYSCALL_FMT_0 #define SYSCALL_FMT_1 , "0" (r2)#define SYSCALL_FMT_2 , "d" (r3) SYSCALL_FMT_1include/linux/syscall_user_dispatch.h +1
-0@@ -10,6 +10,7 @@#ifdef CONFIG_GENERIC_ENTRY +bool arch_syscall_is_vdso_sigreturn (struct pt_regs *regs);int set_syscall_user_dispatch (unsigned long mode,unsigned long offset,unsigned long len,char __user *selector);kernel/entry/syscall_user_dispatch.c +5
-0@@ -32,6 +32,11 @@ static void trigger_sigsys(struct pt_regs *regs)force_sig_info (&info); } +bool __weak arch_syscall_is_vdso_sigreturn (struct pt_regs *regs) +{ +return false; +} +bool syscall_user_dispatch (struct pt_regs *regs) {struct syscall_user_dispatch *sd = ¤t->syscall_dispatch;Signature · 1 line
2.34.1
Build and boot tested on ppc with P11 LPAR. LGTM.
Mark Rutland
reviewerRe: [PATCH v16 02/18] syscall_user_dispatch: Introduce a weak fallback for arch_syscall_is_vdso_sigreturn()
In reply to Jinjie RuanQuoted 15 lines · Jinjie Ruan
Currently, multiple architectures (LoongArch, RISC-V, S390, Powerpc) provide identical stubs for
arch_syscall_is_vdso_sigreturn()that simply return false. This results in redundant boilerplate code across the tree.Introduce a default
__weakimplementation ofarch_syscall_is_vdso_sigreturn()directly insyscall_user_dispatch.cthat returns false. This allows architectures that do not utilize a vDSO sigreturn to entirely drop their redundant inline definitions.Architectures requiring a specialized check (such as x86) will continue to override this fallback with their strong symbol definitions.
Clean up the redundant implementations in loongarch, riscv, s390 and powerpc.
kernel/entry/syscall_user_dispatch.c static void trigger_sigsys(struct pt_regs *regs) · line 38
Quoted 4 lines
kernel/entry/syscall_user_dispatch.c +4
-0+bool __weak arch_syscall_is_vdso_sigreturn (struct pt_regs *regs) +{ +return false; +}
If we need this, please make it:
#ifndef arch_syscall_is_vdso_sigreturn
static inline bool arch_syscall_is_vdso_sigreturn(struct pt_regs *regs)
{
return false;
}#endif
... and require that architectures which need this provide a CPP definition.
The use of __weak is generally problematic, as it prevents the compiler form being able to elide code, and gets in the way of symbol resolution. It's perfectly fine to require that architectures need to provide a CPP definition alongside their own implementation of this function.
That said, as per my comment on v15, I'd prefer that for now we DO NOT enable syscall user dispatch on arm64, and we first make it possible for architecture to express whether or not they support that, even if they use GENERIC_ENTRY. That might mean this patch isn't necessary right now.
[1] https://lore.kernel.org/linux-arm-kernel/[email protected]/
Mark.
Re: [PATCH v16 02/18] syscall_user_dispatch: Introduce a weak fallback for arch_syscall_is_vdso_sigreturn()
Quoted 38 lines · Mark Rutland
Quoted 15 lines · Jinjie Ruan
Currently, multiple architectures (LoongArch, RISC-V, S390, Powerpc) provide identical stubs for
arch_syscall_is_vdso_sigreturn()that simply return false. This results in redundant boilerplate code across the tree.Introduce a default
__weakimplementation ofarch_syscall_is_vdso_sigreturn()directly insyscall_user_dispatch.cthat returns false. This allows architectures that do not utilize a vDSO sigreturn to entirely drop their redundant inline definitions.Architectures requiring a specialized check (such as x86) will continue to override this fallback with their strong symbol definitions.
Clean up the redundant implementations in loongarch, riscv, s390 and powerpc.
kernel/entry/syscall_user_dispatch.c static void trigger_sigsys(struct pt_regs *regs) · line 38
Quoted 4 lines
kernel/entry/syscall_user_dispatch.c +4
-0+bool __weak arch_syscall_is_vdso_sigreturn (struct pt_regs *regs) +{ +return false; +}If we need this, please make it:
#ifndef
arch_syscall_is_vdso_sigreturn
static inline boolarch_syscall_is_vdso_sigreturn(struct pt_regs *regs){ return false; }#endif
... and require that architectures which need this provide a CPP definition.
The use of
__weakis generally problematic, as it prevents the compiler form being able to elide code, and gets in the way of symbol resolution. It's perfectly fine to require that architectures need to provide a CPP definition alongside their own implementation of this function.
Quoted 4 lines
That said, as per my comment on v15, I'd prefer that for now we DO NOT enable syscall user dispatch on arm64, and we first make it possible for architecture to express whether or not they support that, even if they use
GENERIC_ENTRY. That might mean this patch isn't necessary right now.
That sounds good. First, focus on switching to generic entry, without having to implement syscall user dispatch immediately.
Quoted 5 lines
[1] https://lore.kernel.org/linux-arm-kernel/[email protected]/
Mark.
PATCH v16 3/18 arm64: ptrace: Pass thread flags to syscall_trace_enter/exit()
In reply to Jinjie RuanRefactor syscall_trace_enter() and syscall_trace_exit() to move thread flag reading to the caller. This aligns arm64's syscall trace enter/exit function signature with generic entry framework.
[Changes]
1. Function signature changes:
- syscall_trace_enter(regs) → syscall_trace_enter(regs, flags)
- syscall_trace_exit(regs) → syscall_trace_exit(regs, flags)
2. Move flags reading to caller:
- Previously: read_thread_flags() called inside each function.
- Now: caller (like el0_svc_common) passes flags as parameter.
3. Update syscall.c:
- el0_svc_common() now passes flags to tracing functions and re-fetches flags before entry/exit to handle potential TIF updates.
[Why this matters]
- Aligns arm64 with the generic entry interface.
- Makes future migration to generic entry framework smoother.
No functional changes intended.
--- arch/arm64/include/asm/syscall.h | 4 ++-- arch/arm64/kernel/ptrace.c | 7 ++----- arch/arm64/kernel/syscall.c | 5 +++-- 3 files changed, 7 insertions(+), 9 deletions(-)
arch/arm64/include/asm/syscall.h +2 -2
@@ -120,7 +120,7 @@ static inline int syscall_get_arch(struct task_struct *task) return AUDIT_ARCH_AARCH64; } -int syscall_trace_enter (struct pt_regs *regs); -void syscall_trace_exit (struct pt_regs *regs); +int syscall_trace_enter (struct pt_regs *regs,unsigned long flags); +void syscall_trace_exit (struct pt_regs *regs,unsigned long flags);#endif /* __ASM_SYSCALL_H */
arch/arm64/kernel/ptrace.c +2 -5
@@ -2408,9 +2408,8 @@ static void report_syscall_exit(struct pt_regs *regs) } } -int syscall_trace_enter (struct pt_regs *regs) +int syscall_trace_enter (struct pt_regs *regs,unsigned long flags) { -unsigned long flags =read_thread_flags ();int ret;if (flags & (_TIF_SYSCALL_EMU | _TIF_SYSCALL_TRACE)) {
@@ -2432,10 +2431,8 @@ int syscall_trace_enter(struct pt_regs *regs)return regs->syscallno; } -void syscall_trace_exit (struct pt_regs *regs) +void syscall_trace_exit (struct pt_regs *regs,unsigned long flags) { -unsigned long flags =read_thread_flags (); -audit_syscall_exit (regs);if (flags & _TIF_SYSCALL_TRACEPOINT)
arch/arm64/kernel/syscall.c +3 -2
@@ -113,7 +113,7 @@ static void el0_svc_common(struct pt_regs *regs, int scno, int sc_nr,*/ if (scno ==NO_SYSCALL )syscall_set_return_value (current, regs, -ENOSYS ,0 ); - scno =syscall_trace_enter (regs); + scno =syscall_trace_enter (regs,read_thread_flags ());if (scno ==NO_SYSCALL ) goto trace_exit; }
@@ -132,7 +132,8 @@ static void el0_svc_common(struct pt_regs *regs, int scno, int sc_nr, } trace_exit: -syscall_trace_exit (regs); + flags =read_thread_flags (); +syscall_trace_exit (regs, flags); }void do_el0_svc (struct pt_regs *regs)
Signature · 1 line
2.34.1
PATCH v16 4/18 arm64: ptrace: Use syscall_get_nr() helper for syscall_trace_enter()
In reply to Jinjie RuanUse syscall_get_nr() to get syscall number for syscall_trace_enter(). This aligns arm64's internal tracing logic with the generic entry framework.
[Changes]
1. Use syscall_get_nr() helper:
- Replace direct regs->syscallno access with syscall_get_nr(current, regs).
- This helper is functionally equivalent to direct access on arm64.
2. Re-read syscall number after tracepoint:
- Re-fetch the syscall number after trace_sys_enter() as it may have been modified by BPF or ftrace probes, matching generic entry behavior.
[Why this matters]
- Aligns arm64 with the generic entry interface.
- Makes future migration to generic entry framework smoother.
- Properly handles syscall number modifications by tracers.
- Uses standard architecture-independent helpers.
No functional changes intended.
--- arch/arm64/kernel/ptrace.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
arch/arm64/kernel/ptrace.c +15 -4
@@ -2410,6 +2410,7 @@ static void report_syscall_exit(struct pt_regs *regs)int syscall_trace_enter (struct pt_regs *regs,unsigned long flags) { +long syscall;int ret;if (flags & (_TIF_SYSCALL_EMU | _TIF_SYSCALL_TRACE)) {
@@ -2422,13 +2423,23 @@ int syscall_trace_enter(struct pt_regs *regs, unsigned long flags)if (!secure_computing ())return NO_SYSCALL ; -if (test_thread_flag (TIF_SYSCALL_TRACEPOINT )) -trace_sys_enter (regs, regs->syscallno); +/* Either of the above might have changed the syscall number */ + syscall =syscall_get_nr (current, regs); -audit_syscall_entry (regs->syscallno, regs->orig_x0, regs->regs[1 ], +if (test_thread_flag (TIF_SYSCALL_TRACEPOINT )) { +trace_sys_enter (regs, syscall); + +/* +* Probes or BPF hooks in the tracepoint may have changed the +* system call number as well. +*/ + syscall =syscall_get_nr (current, regs); + } + +audit_syscall_entry (syscall, regs->orig_x0, regs->regs[1 ], regs->regs[2 ], regs->regs[3 ]); -return regs->syscallno; +return syscall; }void syscall_trace_exit (struct pt_regs *regs,unsigned long flags)
Signature · 1 line
2.34.1
PATCH v16 5/18 arm64: ptrace: Expand secure_computing() in place
In reply to Jinjie RuanRefactor syscall_trace_enter() by open-coding the seccomp check to align with the generic entry framework.
[Background]
The generic entry implementation expands the seccomp check in-place instead of using the secure_computing() wrapper. It directly tests SYSCALL_WORK_SECCOMP and calls the underlying __secure_computing() function to handle syscall filtering.
[Changes]
1. Open-code seccomp check:
- Instead of calling the secure_computing() wrapper, explicitly check the 'flags' parameter for _TIF_SECCOMP.
- Call __secure_computing() directly if the flag is set.
[Why this matters]
- Aligns the arm64 syscall path with the generic entry implementation, simplifying future migration to the generic entry framework.
- No functional changes are intended; seccomp behavior remains identical.
--- arch/arm64/kernel/ptrace.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
arch/arm64/kernel/ptrace.c +4 -2
@@ -2420,8 +2420,10 @@ int syscall_trace_enter(struct pt_regs *regs, unsigned long flags) }/* Do the secure computing after ptrace; failures should be fast. */ -if (!secure_computing ()) -return NO_SYSCALL ; +if (flags & _TIF_SECCOMP) { +if (!__secure_computing ()) +return NO_SYSCALL ; + }/* Either of the above might have changed the syscall number */ syscall =syscall_get_nr (current, regs);
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v16 05/18] arm64: ptrace: Expand secure_computing() in place
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Open-coding the seccomp check using a cached `flags` variable creates a Time-of-Check to…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Open-coding the seccomp check using a cached flags variable creates a Time-of-Check to Time-of-Use (TOCTOU) vulnerability during ptrace stops, allowing a seccomp filter installed via TSYNC to be bypassed. --
commit 138e96f2aef98ac6348b34ceeb3157f77bd0f2f7
Author: Jinjie Ruan <[email protected]>
arm64: ptrace: Expand secure_computing() in place
This commit refactors syscall_trace_enter() by open-coding the seccomp check to align with the generic entry framework. It explicitly checks the flags parameter for _TIF_SECCOMP instead of calling the wrapper.
Quoted 5 lines
arch/arm64/kernel/ptrace.c +0
-0@@ -2420,8 +2420,10 @@ int syscall_trace_enter(struct pt_regs *regs, unsigned long flags)
[ ... ]
arch/arm64/kernel/ptrace.c int syscall_trace_enter(struct pt_regs *regs, unsigned long flags) · line 2426
Quoted 7 lines
arch/arm64/kernel/ptrace.c +4
-2/* Do the secure computing after ptrace; failures should be fast. */ -if (!secure_computing ()) -return NO_SYSCALL ; +if (flags & _TIF_SECCOMP) { +if (!__secure_computing ()) +return NO_SYSCALL ; + }
[Severity: High]
Does checking the cached 'flags' argument here instead of dynamically reading the thread flags create a race condition?
If the current thread stops for ptrace earlier in syscall_trace_enter(), and another thread installs a filter via seccomp with SECCOMP_FILTER_FLAG_TSYNC while this thread is stopped, the newly set _TIF_SECCOMP flag wouldn't be reflected in the local 'flags' variable.
Could this allow an unprivileged process to bypass a newly installed seccomp filter for the current syscall, especially since the tracer might modify the syscall number (e.g., to execve) during the ptrace stop?
As an additional detail, the generic entry code in include/linux/entry-common.h seems to exhibit the same pattern by checking a cached 'work' variable passed into syscall_trace_enter().
Quoted 3 lines
arch/arm64/kernel/ptrace.c +0
-0/* Either of the above might have changed the syscall number */ syscall =syscall_get_nr (current, regs);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
PATCH v16 6/18 arm64: ptrace: Use syscall_get_arguments() helper for audit
In reply to Jinjie RuanExtract syscall_enter_audit() helper and use syscall_get_arguments() to get syscall arguments, matching the generic entry implementation.
The new code:
- Checks audit_context() first to avoid unnecessary memcpy when audit is not active.
- Uses syscall_get_arguments() helper instead of directly accessing regs fields.
- Is now exactly equivalent to generic entry's syscall_enter_audit().
No functional changes.
--- arch/arm64/kernel/ptrace.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
arch/arm64/kernel/ptrace.c +11 -2
@@ -2408,6 +2408,16 @@ static void report_syscall_exit(struct pt_regs *regs) } } +static inline void syscall_enter_audit (struct pt_regs *regs,long syscall) +{ +if (unlikely (audit_context ())) { +unsigned long args[6 ]; + +syscall_get_arguments (current, regs, args); +audit_syscall_entry (syscall, args[0 ], args[1 ], args[2 ], args[3 ]); + } +} +int syscall_trace_enter (struct pt_regs *regs,unsigned long flags) {long syscall;
@@ -2438,8 +2448,7 @@ int syscall_trace_enter(struct pt_regs *regs, unsigned long flags) syscall =syscall_get_nr (current, regs); } -audit_syscall_entry (syscall, regs->orig_x0, regs->regs[1 ], - regs->regs[2 ], regs->regs[3 ]); +syscall_enter_audit (regs, syscall);return syscall; }
Signature · 1 line
2.34.1
PATCH v16 7/18 arm64: ptrace: Protect rseq_syscall() from tracer PC modifications
In reply to Jinjie RuanMove the rseq_syscall() check earlier in the syscall exit path to ensure it operates on the original instruction pointer (regs->pc) before any potential modification by a tracer.
[Background]
When CONFIG_DEBUG_RSEQ is enabled, rseq_syscall() verifies that a system call was not executed within an rseq critical section by examining regs->pc. If a violation is detected, it triggers a SIGSEGV.
[Problem]
Currently, arm64 invokes rseq_syscall() after report_syscall_exit(). However, during report_syscall_exit(), a ptrace tracer can modify the task's instruction pointer via PTRACE_SETREGSET (with NT_PRSTATUS). This leads to an inconsistency where rseq may analyze a post-trace PC instead of the actual PC at the time of syscall exit.
[Why this matters]
The rseq check is intended to validate the execution context of the syscall itself. Analyzing a tracer-modified PC can lead to incorrect detection or missed violations. Moving the check earlier ensures rseq sees the authentic state of the task.
[Alignment]
This change aligns arm64 with:
- Generic entry, which calls rseq_syscall() first.
- arm32 implementation, which also performs the check before audit.
[Impact]
There is no functional change to signal delivery; SIGSEGV will still be processed in arm64_exit_to_user_mode() at the end of the exit path.
--- arch/arm64/kernel/ptrace.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/kernel/ptrace.c +2 -2
@@ -2455,6 +2455,8 @@ int syscall_trace_enter(struct pt_regs *regs, unsigned long flags)void syscall_trace_exit (struct pt_regs *regs,unsigned long flags) { +rseq_syscall (regs); +audit_syscall_exit (regs);if (flags & _TIF_SYSCALL_TRACEPOINT)
@@ -2462,8 +2464,6 @@ void syscall_trace_exit(struct pt_regs *regs, unsigned long flags)if (flags & (_TIF_SYSCALL_TRACE | _TIF_SINGLESTEP))report_syscall_exit (regs); - -rseq_syscall (regs); }/*
Signature · 1 line
2.34.1
PATCH v16 8/18 arm64: ptrace: Rename syscall_trace_exit() to syscall_exit_work()
In reply to Jinjie RuanIn preparation for moving arm64 over to the generic entry code, rename syscall_trace_exit() to syscall_exit_work(). The renamed function checks and prevents illegal system calls inside user-space rseq critical sections, while also handling tracing, auditing, and ptrace reporting.
No functional changes.
--- arch/arm64/include/asm/syscall.h | 2 +- arch/arm64/kernel/ptrace.c | 2 +- arch/arm64/kernel/syscall.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
arch/arm64/include/asm/syscall.h +1 -1
@@ -121,6 +121,6 @@ static inline int syscall_get_arch(struct task_struct *task) }int syscall_trace_enter (struct pt_regs *regs,unsigned long flags); -void syscall_trace_exit (struct pt_regs *regs,unsigned long flags); +void syscall_exit_work (struct pt_regs *regs,unsigned long flags);#endif /* __ASM_SYSCALL_H */
arch/arm64/kernel/ptrace.c +1 -1
@@ -2453,7 +2453,7 @@ int syscall_trace_enter(struct pt_regs *regs, unsigned long flags)return syscall; } -void syscall_trace_exit (struct pt_regs *regs,unsigned long flags) +void syscall_exit_work (struct pt_regs *regs,unsigned long flags) {rseq_syscall (regs);
arch/arm64/kernel/syscall.c +1 -1
@@ -133,7 +133,7 @@ static void el0_svc_common(struct pt_regs *regs, int scno, int sc_nr, trace_exit: flags =read_thread_flags (); -syscall_trace_exit (regs, flags); +syscall_exit_work (regs, flags); }void do_el0_svc (struct pt_regs *regs)
Signature · 1 line
2.34.1
PATCH v16 9/18 arm64: syscall: Rework the syscall exit path in el0_svc_common()
In reply to Jinjie RuanIn preparation for moving arm64 over to the generic entry code, restructure the fast-path syscall exit sequence within el0_svc_common().
Invert the nested conditional flags check so that when syscall work is pending or single-stepping is active, the corresponding exit work can be dispatched directly from within the fast-path bailout block. This clarifies the separation between the fast and slow exit paths, facilitating a cleaner transition to the generic entry state machine in subsequent patches.
No functional changes.
--- arch/arm64/kernel/syscall.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
arch/arm64/kernel/syscall.c +5 -2
@@ -127,8 +127,11 @@ static void el0_svc_common(struct pt_regs *regs, int scno, int sc_nr,*/ if (!has_syscall_work (flags) && !IS_ENABLED (CONFIG_DEBUG_RSEQ )) { flags =read_thread_flags (); -if (!has_syscall_work (flags) && !(flags & _TIF_SINGLESTEP)) -return ; +if (has_syscall_work (flags) || flags & _TIF_SINGLESTEP) { + flags =read_thread_flags (); +syscall_exit_work (regs, flags); + } +return ; } trace_exit:
Signature · 1 line
2.34.1
PATCH v16 10/18 arm64: ptrace: Extract syscall_exit_to_user_mode_work() helper
In reply to Jinjie RuanIn preparation for moving arm64 over to the generic entry code, extract the core syscall exit tracing logic into a new inline helper, syscall_exit_to_user_mode_work().
This new helper encapsulates the thread flags retrieval and syscall exit processing, unifying the exit invocation paths across both the fast-path bailout block and the slow-path trace_exit fallback in el0_svc_common(). This restructuring significantly streamlines the architecture for the upcoming transition to the generic entry framework.
No functional changes.
--- arch/arm64/include/asm/syscall.h | 7 +++++++ arch/arm64/kernel/syscall.c | 9 +++------ 2 files changed, 10 insertions(+), 6 deletions(-)
arch/arm64/include/asm/syscall.h +7 -0
@@ -123,4 +123,11 @@ static inline int syscall_get_arch(struct task_struct *task)int syscall_trace_enter (struct pt_regs *regs,unsigned long flags);void syscall_exit_work (struct pt_regs *regs,unsigned long flags); +static __always_inline void syscall_exit_to_user_mode_work(struct pt_regs *regs) +{ +unsigned long flags =read_thread_flags (); + +syscall_exit_work (regs, flags); +} +#endif /* __ASM_SYSCALL_H */
arch/arm64/kernel/syscall.c +3 -6
@@ -127,16 +127,13 @@ static void el0_svc_common(struct pt_regs *regs, int scno, int sc_nr,*/ if (!has_syscall_work (flags) && !IS_ENABLED (CONFIG_DEBUG_RSEQ )) { flags =read_thread_flags (); -if (has_syscall_work (flags) || flags & _TIF_SINGLESTEP) { - flags =read_thread_flags (); -syscall_exit_work (regs, flags); - } +if (has_syscall_work (flags) || flags & _TIF_SINGLESTEP) +syscall_exit_to_user_mode_work (regs);return ; } trace_exit: - flags =read_thread_flags (); -syscall_exit_work (regs, flags); +syscall_exit_to_user_mode_work (regs); }void do_el0_svc (struct pt_regs *regs)
Signature · 1 line
2.34.1
PATCH v16 11/18 arm64: ptrace: Align syscall exit work semantics with generic entry
In reply to Jinjie RuanStreamline syscall_exit_to_user_mode_work() to align arm64's syscall exit behavior with the generic entry framework.
[Rationale]
1. Unconditional RSEQ Execution: Relocate rseq_syscall() from the slow-path helper to the very beginning of syscall_exit_to_user_mode_work(). This ensures that RSEQ validation executes unconditionally across all exit scenarios, preventing it from being incorrectly bypassed on fast paths when CONFIG_DEBUG_RSEQ is active.
2. Centralized Exit Work Gating: Introduce the _TIF_SYSCALL_EXIT_WORK mask to aggregate exit thread flags and gate the execution of syscall_exit_work().
Gating audit_syscall_exit() behind this exit-time check introduces no functional changes. The SYSCALL_AUDIT flag and its context are statically allocated via audit_alloc() at fork time and only freed via audit_free() at do_exit(). Since the flag remains persistent and static throughout syscall execution, checking _TIF_SYSCALL_AUDIT in the mask is fully equivalent to evaluating audit_context() inside audit_syscall_exit().
[Changes]
- Introduce the _TIF_SYSCALL_EXIT_WORK mask to bundle exit-specific flags.
- Relocate rseq_syscall() to run unconditionally on the outermost layer.
- Gate syscall_exit_work() via the new aggregated flag check to mirror the generic entry loop behavior.
No functional changes intended.
--- arch/arm64/include/asm/syscall.h | 6 +++++- arch/arm64/include/asm/thread_info.h | 3 +++ arch/arm64/kernel/ptrace.c | 3 --- 3 files changed, 8 insertions(+), 4 deletions(-)
arch/arm64/include/asm/syscall.h +5 -1
@@ -8,6 +8,7 @@#include <uapi/linux/audit.h> #include <linux/compat.h> #include <linux/err.h> +#include <linux/rseq.h> typedef long (*syscall_fn_t )(const struct pt_regs *regs);
@@ -127,7 +128,10 @@ static __always_inline void syscall_exit_to_user_mode_work(struct pt_regs *regs) {unsigned long flags =read_thread_flags (); -syscall_exit_work (regs, flags); +rseq_syscall (regs); + +if (unlikely (flags & _TIF_SYSCALL_EXIT_WORK) || flags & _TIF_SINGLESTEP) +syscall_exit_work (regs, flags); }#endif /* __ASM_SYSCALL_H */
arch/arm64/include/asm/thread_info.h +3 -0
@@ -112,6 +112,9 @@ void arch_setup_new_exec(void); _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \ _TIF_SYSCALL_EMU) +#define _TIF_SYSCALL_EXIT_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \ + _TIF_SYSCALL_TRACEPOINT) +#ifdef CONFIG_SHADOW_CALL_STACK #define INIT_SCS \ .scs_base = init_shadow_call_stack, \
arch/arm64/kernel/ptrace.c +0 -3
@@ -28,7 +28,6 @@#include <linux/hw_breakpoint.h> #include <linux/regset.h> #include <linux/elf.h> -#include <linux/rseq.h> #include <asm/compat.h> #include <asm/cpufeature.h>
@@ -2455,8 +2454,6 @@ int syscall_trace_enter(struct pt_regs *regs, unsigned long flags)void syscall_exit_work (struct pt_regs *regs,unsigned long flags) { -rseq_syscall (regs); -audit_syscall_exit (regs);if (flags & _TIF_SYSCALL_TRACEPOINT)
Signature · 1 line
2.34.1
PATCH v16 12/18 arm64: syscall: Use exit-specific flags check in el0_svc_common()
In reply to Jinjie RuanUse exit-specific _TIF_SYSCALL_EXIT_WORK mask to filter out entry-only flags during the system call exit path checks. This aligns arm64 with the generic entry framework's SYSCALL_WORK_EXIT semantics.
[Rationale]
The current syscall exit path re-evaluates the thread flags using the global _TIF_SYSCALL_WORK mask. However, _TIF_SYSCALL_WORK includes flags that are strictly relevant to system call entry processing:
1. _TIF_SECCOMP: Seccomp filtering (__secure_computing()) only runs on entry. There is no seccomp callback for syscall exit.
2. _TIF_SYSCALL_EMU: In PTRACE_SYSEMU mode, the syscall is intercepted and skipped on entry. Since the syscall is never fully executed, reporting a separate syscall exit stop is unnecessary.
[Changes]
- _TIF_SYSCALL_EXIT_WORK: A new mask containing only flags requiring exit-time processing: _TIF_SYSCALL_TRACE, _TIF_SYSCALL_AUDIT, and _TIF_SYSCALL_TRACEPOINT.
- Optimize re-evaluation check: Use _TIF_SYSCALL_EXIT_WORK inside the el0_svc_common() fast-path block to prevent redundant exit work execution when entry-only flags fluctuate or are synchronously modified under the hood. The outermost gating maintains _TIF_SYSCALL_WORK to preserve architectural entry-exit symmetry for tracers.
- Cleanup: Remove the has_syscall_work() helper as it is no longer needed, supporting direct flag comparison to clearly distinguish between entry and exit mandates.
[Impact]
Unnecessary exit tracing and auditing processing are safely bypassed when entry-specific flags fluctuate during the fast-path re-check block. This safely streamlines the syscall exit sequence to mirror the generic entry loop behaviors without breaking debugger expectations.
No functional changes intended
--- arch/arm64/kernel/syscall.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
arch/arm64/kernel/syscall.c +3 -8
@@ -54,11 +54,6 @@ static void invoke_syscall(struct pt_regs *regs, unsigned int scno,syscall_set_return_value (current, regs,0 , ret); } -static inline bool has_syscall_work (unsigned long flags) -{ -return unlikely (flags & _TIF_SYSCALL_WORK); -} -static void el0_svc_common (struct pt_regs *regs,int scno,int sc_nr,const syscall_fn_t syscall_table[]) {
@@ -95,7 +90,7 @@ static void el0_svc_common(struct pt_regs *regs, int scno, int sc_nr,return ; } -if (has_syscall_work (flags)) { +if (unlikely (flags & _TIF_SYSCALL_WORK)) {/* * The de-facto standard way to skip a system call using ptrace * is to set the system call to -1 (NO_SYSCALL) and set x0 to a
@@ -125,9 +120,9 @@ static void el0_svc_common(struct pt_regs *regs, int scno, int sc_nr,* check again. However, if we were tracing entry, then we always trace * exit regardless, as the old entry assembly did. */ -if (!has_syscall_work (flags) && !IS_ENABLED (CONFIG_DEBUG_RSEQ )) { +if (!(unlikely (flags & _TIF_SYSCALL_WORK)) && !IS_ENABLED (CONFIG_DEBUG_RSEQ )) { flags =read_thread_flags (); -if (has_syscall_work (flags) || flags & _TIF_SINGLESTEP) +if (unlikely (flags & _TIF_SYSCALL_EXIT_WORK) || flags & _TIF_SINGLESTEP)syscall_exit_to_user_mode_work (regs);return ; }
Signature · 1 line
2.34.1
PATCH v16 13/18 arm64: syscall: Simplify el0_svc_common() syscall exit path
In reply to Jinjie RuanRemove the redundant nested conditional check within the system call exit path of el0_svc_common() to streamline the exit sequence.
When entering this fast-path block, CONFIG_DEBUG_RSEQ is guaranteed to be disabled. Under this constraint, the code logic inside the block becomes completely identical to the evaluation performed within syscall_exit_to_user_mode_work(). Therefore, invoking the inline helper directly achieves full logical equivalence while eliminating duplicate code nesting.
No functional changes.
--- arch/arm64/kernel/syscall.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
arch/arm64/kernel/syscall.c +1 -3
@@ -121,9 +121,7 @@ static void el0_svc_common(struct pt_regs *regs, int scno, int sc_nr,* exit regardless, as the old entry assembly did. */ if (!(unlikely (flags & _TIF_SYSCALL_WORK)) && !IS_ENABLED (CONFIG_DEBUG_RSEQ )) { - flags =read_thread_flags (); -if (unlikely (flags & _TIF_SYSCALL_EXIT_WORK) || flags & _TIF_SINGLESTEP) -syscall_exit_to_user_mode_work (regs); +syscall_exit_to_user_mode_work (regs);return ; }
Signature · 1 line
2.34.1
PATCH v16 14/18 arm64: syscall: Simplify syscall exit path in el0_svc_common()
In reply to Jinjie RuanRemove the redundant conditional fast-path check within el0_svc_common() as both branches now execute the exact the same syscall_exit_to_user_mode_work().
Since both the conditional fast-path and the fallback slow-path now uniformly invoke syscall_exit_to_user_mode_work(), this explicit conditional branch is entirely redundant regardless of whether the evaluation is true or false. Removing it collapses the duplicated logic into a single, unconditional path.
No functional changes.
--- arch/arm64/kernel/syscall.c | 11 ----------- 1 file changed, 11 deletions(-)
arch/arm64/kernel/syscall.c +0 -11
@@ -114,17 +114,6 @@ static void el0_svc_common(struct pt_regs *regs, int scno, int sc_nr, }invoke_syscall (regs, scno, sc_nr, syscall_table); - -/* -* The tracing status may have changed under our feet, so we have to -* check again. However, if we were tracing entry, then we always trace -* exit regardless, as the old entry assembly did. -*/ -if (!(unlikely (flags & _TIF_SYSCALL_WORK)) && !IS_ENABLED (CONFIG_DEBUG_RSEQ )) { -syscall_exit_to_user_mode_work (regs); -return ; - } - trace_exit:syscall_exit_to_user_mode_work (regs); }
Signature · 1 line
2.34.1
PATCH v16 15/18 arm64: ptrace: Skip syscall exit reporting for PTRACE_SYSEMU_SINGLESTEP
In reply to Jinjie RuanAlign the syscall exit reporting logic with the generic entry framework by skipping the exit stop when PTRACE_SYSEMU_SINGLESTEP is in effect.
[Rationale]
When a tracer uses PTRACE_SYSEMU_SINGLESTEP, both _TIF_SYSCALL_EMU and _TIF_SINGLESTEP flags are set. Currently, arm64 reports a syscall exit stop whenever _TIF_SINGLESTEP is set, regardless of the emulation state.
However, as per the generic entry implementation (see include/linux/entry-common.h):
"If SYSCALL_EMU is set, then the only reason to report is when SINGLESTEP is set (i.e. PTRACE_SYSEMU_SINGLESTEP). This syscall instruction has been already reported in syscall_trace_enter()."
Since PTRACE_SYSEMU intercepts and skips the actual syscall execution, reporting a subsequent exit stop is redundant and inconsistent with the expected behavior of emulated system calls.
[Changes]
- Introduce report_single_step(): Add a helper to encapsulate the logic for deciding whether to report a single-step stop at syscall exit. It returns false if _TIF_SYSCALL_EMU is set, ensuring the emulated syscall does not trigger a duplicate report.
- Update syscall_exit_work(): Use the new helper to determine the stepping state instead of directly checking _TIF_SINGLESTEP.
[Impact]
- PTRACE_SINGLESTEP: Continues to report exit stops for actual instructions.
- PTRACE_SYSEMU: Continues to skip exit stops.
- PTRACE_SYSEMU_SINGLESTEP: Now correctly skips the redundant exit stop, aligning arm64 with the generic entry infrastructure.
--- arch/arm64/kernel/ptrace.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
arch/arm64/kernel/ptrace.c +12 -1
@@ -2452,14 +2452,25 @@ int syscall_trace_enter(struct pt_regs *regs, unsigned long flags)return syscall; } +static inline bool report_single_step (unsigned long flags) +{ +if (flags & _TIF_SYSCALL_EMU) +return false; + +return flags & _TIF_SINGLESTEP; +} +void syscall_exit_work (struct pt_regs *regs,unsigned long flags) { +bool step; +audit_syscall_exit (regs);if (flags & _TIF_SYSCALL_TRACEPOINT)trace_sys_exit (regs,syscall_get_return_value (current, regs)); -if (flags & (_TIF_SYSCALL_TRACE | _TIF_SINGLESTEP)) + step =report_single_step (flags); +if (step || flags & _TIF_SYSCALL_TRACE)report_syscall_exit (regs); }
Signature · 1 line
2.34.1
PATCH v16 16/18 arm64: entry: Convert to generic entry
In reply to Jinjie RuanImplement the generic entry framework for arm64 to handle system call entry and exit. This follows the migration of x86, RISC-V, and LoongArch, consolidating architecture-specific syscall tracing and auditing into the common kernel entry infrastructure, making it easier to enable advanced features on arm64, such as "Syscall User Dispatch" and "rseq time slice extension" optimization.
[Background]
Arm64 has already adopted generic IRQ entry. Completing the conversion to the generic syscall entry framework reduces architectural divergence, simplifies maintenance, and allows arm64 to automatically benefit from improvements in the common entry code.
[Changes]
1. Kconfig and Infrastructure:
- Select GENERIC_ENTRY and remove GENERIC_IRQ_ENTRY (now implied).
- Migrate struct thread_info to use the syscall_work field instead of TIF flags for syscall-related tasks.
2. Thread Info and Flags:
- Remove definitions for TIF_SYSCALL_TRACE, TIF_SYSCALL_AUDIT, TIF_SYSCALL_TRACEPOINT, TIF_SECCOMP, and TIF_SYSCALL_EMU.
- Replace _TIF_SYSCALL_WORK and _TIF_SYSCALL_EXIT_WORK with the generic SYSCALL_WORK bitmask.
- Map single-step state to SYSCALL_EXIT_TRAP in debug-monitors.c.
3. Architecture-Specific Hooks (asm/entry-common.h):
- Implement arch_ptrace_report_syscall_entry() and _exit() by porting the existing arm64 logic to the generic interface.
4. Cleanup and Refactoring:
- Remove redundant arm64-specific syscall tracing functions from ptrace.c, including syscall_trace_enter(), syscall_exit_work(), and related audit/step helpers.
- Update el0_svc_common() in syscall.c to use the generic syscall_work checks and entry/exit call sites.
[Why this matters]
- Unified Interface: Aligns arm64 with the modern kernel entry standard.
- Improved Maintainability: Bug fixes in kernel/entry/common.c now apply to arm64 automatically.
- Feature Readiness: Simplifies the implementation of future cross-architecture syscall features.
[Compatibility]
This conversion maintains full ABI compatibility with existing userspace. The ptrace register-saving behavior, seccomp filtering, and syscall tracing semantics remain identical to the previous implementation.
Additionally, since arm64 now does not select HAVE_GENERIC_TIF_BITS, there is no functional change regarding rseq management, as those generic entry pathways remain a no-op for this architecture."
--- arch/arm64/Kconfig | 2 +- arch/arm64/include/asm/entry-common.h | 76 ++++++++++++++ arch/arm64/include/asm/syscall.h | 13 --- arch/arm64/include/asm/thread_info.h | 19 +--- arch/arm64/kernel/debug-monitors.c | 8 ++ arch/arm64/kernel/ptrace.c | 142 -------------------------- arch/arm64/kernel/signal.c | 2 +- arch/arm64/kernel/syscall.c | 7 +- 8 files changed, 92 insertions(+), 177 deletions(-)
arch/arm64/Kconfig +1 -1
@@ -128,9 +128,9 @@ config ARM64 select GENERIC_CPU_DEVICES select GENERIC_CPU_VULNERABILITIES select GENERIC_EARLY_IOREMAP + select GENERIC_ENTRY select GENERIC_IDLE_POLL_SETUP select GENERIC_IOREMAP - select GENERIC_IRQ_ENTRY select GENERIC_IRQ_IPI select GENERIC_IRQ_KEXEC_CLEAR_VM_FORWARD select GENERIC_IRQ_PROBE
arch/arm64/include/asm/entry-common.h +76 -0
94 lines not on this page · raw message
arch/arm64/include/asm/syscall.h +0 -13
@@ -121,17 +121,4 @@ static inline int syscall_get_arch(struct task_struct *task) return AUDIT_ARCH_AARCH64; } -int syscall_trace_enter (struct pt_regs *regs,unsigned long flags); -void syscall_exit_work (struct pt_regs *regs,unsigned long flags); - -static __always_inline void syscall_exit_to_user_mode_work(struct pt_regs *regs) -{ -unsigned long flags =read_thread_flags (); - -rseq_syscall (regs); - -if (unlikely (flags & _TIF_SYSCALL_EXIT_WORK) || flags & _TIF_SINGLESTEP) -syscall_exit_work (regs, flags); -} -#endif /* __ASM_SYSCALL_H */
arch/arm64/include/asm/thread_info.h +1 -18
@@ -46,6 +46,7 @@ struct thread_info {u64 mpam_partid_pmg;#endif u32 cpu; +unsigned long syscall_work;/* SYSCALL_WORK_ flags */ };#define thread_saved_pc (tsk) \
@@ -68,11 +69,6 @@ void arch_setup_new_exec(void);#define TIF_UPROBE 5/* uprobe breakpoint or singlestep */ #define TIF_MTE_ASYNC_FAULT 6/* MTE Asynchronous Tag Check Fault */ #define TIF_NOTIFY_SIGNAL 7/* signal notifications exist */ -#define TIF_SYSCALL_TRACE 8/* syscall trace active */ -#define TIF_SYSCALL_AUDIT 9/* syscall auditing */ -#define TIF_SYSCALL_TRACEPOINT 10/* syscall tracepoint for ftrace */ -#define TIF_SECCOMP 11/* syscall secure computing */ -#define TIF_SYSCALL_EMU 12/* syscall emulation active */ #define TIF_PATCH_PENDING 13/* pending live patching update */ #define TIF_MEMDIE 18/* is terminating due to OOM killer */ #define TIF_FREEZE 19
@@ -94,27 +90,14 @@ void arch_setup_new_exec(void);#define _TIF_NEED_RESCHED_LAZY (1 << TIF_NEED_RESCHED_LAZY)#define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)#define _TIF_FOREIGN_FPSTATE (1 << TIF_FOREIGN_FPSTATE) -#define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE) -#define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT) -#define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT) -#define _TIF_SECCOMP (1 << TIF_SECCOMP) -#define _TIF_SYSCALL_EMU (1 << TIF_SYSCALL_EMU)#define _TIF_PATCH_PENDING (1 << TIF_PATCH_PENDING)#define _TIF_UPROBE (1 << TIF_UPROBE) -#define _TIF_SINGLESTEP (1 << TIF_SINGLESTEP)#define _TIF_32BIT (1 << TIF_32BIT)#define _TIF_SVE (1 << TIF_SVE)#define _TIF_MTE_ASYNC_FAULT (1 << TIF_MTE_ASYNC_FAULT)#define _TIF_NOTIFY_SIGNAL (1 << TIF_NOTIFY_SIGNAL)#define _TIF_TSC_SIGSEGV (1 << TIF_TSC_SIGSEGV) -#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \ - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \ - _TIF_SYSCALL_EMU) - -#define _TIF_SYSCALL_EXIT_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \ - _TIF_SYSCALL_TRACEPOINT) -#ifdef CONFIG_SHADOW_CALL_STACK #define INIT_SCS \ .scs_base = init_shadow_call_stack, \
arch/arm64/kernel/debug-monitors.c +8 -0
@@ -385,11 +385,19 @@ void user_enable_single_step(struct task_struct *task)if (!test_and_set_ti_thread_flag (ti,TIF_SINGLESTEP ))set_regs_spsr_ss (task_pt_regs (task)); + +/* +* Ensure that the generic entry code triggers a trap once stepping +* out of a system call prior to executing any user instruction, +* as the generic entry code does not natively check for TIF_SINGLESTEP. +*/ +set_task_syscall_work (task,SYSCALL_EXIT_TRAP ); }NOKPROBE_SYMBOL (user_enable_single_step);void user_disable_single_step (struct task_struct *task) {clear_ti_thread_flag (task_thread_info (task),TIF_SINGLESTEP ); +clear_task_syscall_work (task,SYSCALL_EXIT_TRAP ); }NOKPROBE_SYMBOL (user_disable_single_step);
arch/arm64/kernel/ptrace.c +0 -142
169 lines not on this page · raw message
arch/arm64/kernel/signal.c +1 -1
@@ -8,8 +8,8 @@#include <linux/cache.h> #include <linux/compat.h> +#include <linux/entry-common.h> #include <linux/errno.h> -#include <linux/irq-entry-common.h> #include <linux/kernel.h> #include <linux/signal.h> #include <linux/freezer.h>
arch/arm64/kernel/syscall.c +5 -2
@@ -2,6 +2,7 @@#include <linux/compiler.h> #include <linux/context_tracking.h> +#include <linux/entry-common.h> #include <linux/errno.h> #include <linux/nospec.h> #include <linux/ptrace.h>
@@ -58,6 +59,7 @@ static void el0_svc_common(struct pt_regs *regs, int scno, int sc_nr, const syscall_fn_t syscall_table[]) {unsigned long flags =read_thread_flags (); +unsigned long work; regs->orig_x0 = regs->regs[0 ]; regs->syscallno = scno;
@@ -90,7 +92,8 @@ static void el0_svc_common(struct pt_regs *regs, int scno, int sc_nr,return ; } -if (unlikely (flags & _TIF_SYSCALL_WORK)) { + work =READ_ONCE (current_thread_info ()->syscall_work); +if (unlikely (work &SYSCALL_WORK_ENTER )) {/* * The de-facto standard way to skip a system call using ptrace * is to set the system call to -1 (NO_SYSCALL) and set x0 to a
@@ -108,7 +111,7 @@ static void el0_svc_common(struct pt_regs *regs, int scno, int sc_nr,*/ if (scno ==NO_SYSCALL )syscall_set_return_value (current, regs, -ENOSYS ,0 ); - scno =syscall_trace_enter (regs,read_thread_flags ()); + scno =syscall_trace_enter (regs, work);if (scno ==NO_SYSCALL ) goto trace_exit; }
Signature · 1 line
2.34.1
PATCH v16 17/18 arm64: Inline el0_svc_common()
In reply to Jinjie RuanAfter converting arm64 to Generic Entry framework, the compiler no longer inlines el0_svc_common() into its caller do_el0_svc(). This introduces a small but measurable overhead in the critical system call path.
Manually forcing el0_svc_common() to be inlined restores the performance. Benchmarking with perf bench syscall basic on a Kunpeng 920 platform (based on v6.19-rc1) shows a ~1% performance uplift.
Inlining this function reduces function prologue/epilogue overhead and allows for better compiler optimization in the hot system call dispatch path.
| Metric | W/O this patch | With this patch | Change | | ---------- | -------------- | --------------- | --------- | | Total time | 2.195 [sec] | 2.171 [sec] | ↓1.1% | | usecs/op | 0.219575 | 0.217192 | ↓1.1% | | ops/sec | 4,554,260 | 4,604,225 | ↑1.1% |
--- arch/arm64/kernel/syscall.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/kernel/syscall.c +2 -2
@@ -55,8 +55,8 @@ static void invoke_syscall(struct pt_regs *regs, unsigned int scno,syscall_set_return_value (current, regs,0 , ret); } -static void el0_svc_common (struct pt_regs *regs,int scno,int sc_nr, -const syscall_fn_t syscall_table[]) +static __always_inline void el0_svc_common(struct pt_regs *regs, int scno, int sc_nr, +const syscall_fn_t syscall_table[]) {unsigned long flags =read_thread_flags ();unsigned long work;
Signature · 1 line
2.34.1
PATCH v16 18/18 arm64: vdso: Expose sigreturn address on vdso to the kernel
In reply to Jinjie RuanSyscall User Dispatch (SUD) requires the signal trampoline code to not be intercepted. This is necessary to support returning with a locked selector while avoiding infinite recursion back into the signal handler.
Implement arch_syscall_is_vdso_sigreturn() for arm64 to support this exclusion mechanism. For native 64-bit tasks, it checks whether the current PC matches the 'svc #0' instruction inside the vDSO sigreturn trampoline.
SYM_CODE_START(__kernel_rt_sigreturn)
mov x8, #__NR_rt_sigreturn
svc #0
SYM_CODE_END(__kernel_rt_sigreturn)
For COMPAT tasks, it verifies if the instruction falls within the architecture's 'sigpage' range, allowing the kernel to safely bypass dispatching syscalls originating from these areas back to userspace.
--- arch/arm64/include/asm/elf.h | 1 + arch/arm64/kernel/vdso.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+)
arch/arm64/include/asm/elf.h +1 -0
@@ -185,6 +185,7 @@ do { \struct linux_binprm ;extern int arch_setup_additional_pages (struct linux_binprm *bprm,int uses_interp); +extern bool arch_syscall_is_vdso_sigreturn (struct pt_regs *regs);/* 1GB of VA */ #ifdef CONFIG_COMPAT
arch/arm64/kernel/vdso.c +16 -0
@@ -343,3 +343,19 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)return ret; } + +bool arch_syscall_is_vdso_sigreturn (struct pt_regs *regs) +{ +unsigned long sigtramp; + +#ifdef CONFIG_COMPAT +if (is_compat_task ()) { +unsigned long sigpage = (unsigned long )current->mm->context.sigpage; + +return regs->pc >= sigpage && regs->pc < (sigpage +PAGE_SIZE ); + } +#endif + sigtramp = (unsigned long )VDSO_SYMBOL (current->mm->context.vdso, sigtramp); + +return regs->pc == (sigtramp +8 ); +}
Signature · 1 line
2.34.1
Re: [PATCH v16 18/18] arm64: vdso: Expose sigreturn address on vdso to the kernel
Hi Jinjie,
Quoted 3 lines · Jinjie Ruan
Syscall User Dispatch (SUD) requires the signal trampoline code to not be intercepted. This is necessary to support returning with a locked selector while avoiding infinite recursion back into the signal handler.
Thanks for splitting this out, I find it is much clearer that way !
However, this should definitely be earlier in the series
As I mentioned in my comment in v15, Syscall User Dispatch only depends on CONFIG_GENERIC_ENTRY, so enabling generic entry for arm64 in patch 16 also enables Syscall User Dispatch.
Given that this series adds a weak default function returning false for arch_syscall_is_vdso_sigreturn() before enabling generic entry for arm64 in patch 16, patch 16 and 17 have a potentially broken SUD enabled, as we do not check for those sigreturns yet.
I think shuffling this patch back just before converting to generic entry should be OK !
Quoted 9 lines
Implement
arch_syscall_is_vdso_sigreturn()for arm64 to support this exclusion mechanism. For native 64-bit tasks, it checks whether the current PC matches the 'svc #0' instruction inside the vDSO sigreturn trampoline.
SYM_CODE_START(__kernel_rt_sigreturn)
mov x8, #__NR_rt_sigreturn
svc #0
SYM_CODE_END(__kernel_rt_sigreturn)
Maybe add arch/arm64/kernel/vdso/sigreturn.S to mention where this snippet comes from ?
Quoted 4 lines
For COMPAT tasks, it verifies if the instruction falls within the architecture's 'sigpage' range, allowing the kernel to safely bypass dispatching syscalls originating from these areas back to userspace.
I think this might benefit from a bit more details or clarity on the "why" of the COMPAT handling : there is a vDSO page for COMPAT tasks, but COMPAT signal handlers have their own dedicated page, sigpage, which serves the same purpose and is handled similarly, so it needs to be checked as well.
Hopefully that is correct... Would you find that relevant information to add ? Pinging @Kevin Brodsky on that as well.
Quoted 7 lines
Suggested-by Kevin Brodsky <[email protected]>Suggested-by kemal <[email protected]>Signed-off-by Jinjie Ruan <[email protected]>--- arch/arm64/include/asm/elf.h | 1 + arch/arm64/kernel/vdso.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+)
Otherwise this looks good to me, great to have more context with the change !
Thanks,
Ada
Re: [PATCH v16 18/18] arm64: vdso: Expose sigreturn address on vdso to the kernel
Quoted 16 lines · Ada Couprie Diaz
Hi Jinjie,
Quoted 4 lines · Jinjie Ruan
Syscall User Dispatch (SUD) requires the signal trampoline code to not be intercepted. This is necessary to support returning with a locked selector
while avoiding infinite recursion back into the signal handler.Thanks for splitting this out, I find it is much clearer that way !
However, this should definitely be earlier in the series
As I mentioned in my comment in v15, Syscall User Dispatch only depends onCONFIG_GENERIC_ENTRY, so enabling generic entry for arm64 in patch 16 also enables Syscall User Dispatch.
Quoted 7 lines
Given that this series adds a weak default function returning false for
arch_syscall_is_vdso_sigreturn()before enabling generic entry for arm64 in patch 16, patch 16 and 17 have a potentially broken SUD enabled, as we do not check for those sigreturns yet.I think shuffling this patch back just before converting to generic entry should be OK !
As Mark suggested, we can decouple the generic entry and syscall_user_dispatch features. First, we can focus on switching to the generic entry, and then implement syscall_user_dispatch.
Quoted 23 lines
Quoted 11 lines
Implement
arch_syscall_is_vdso_sigreturn()for arm64 to support this exclusion mechanism. For native 64-bit tasks, it checks whether the current
PC matches the 'svc #0' instruction inside the vDSO sigreturn trampoline.SYM_CODE_START(__kernel_rt_sigreturn)
mov x8, #__NR_rt_sigreturn
svc #0
SYM_CODE_END(__kernel_rt_sigreturn)Maybe add
arch/arm64/kernel/vdso/sigreturn.Sto mention where this snippet comes from ?Quoted 4 lines
For COMPAT tasks, it verifies if the instruction falls within the architecture's 'sigpage' range, allowing the kernel to safely bypass dispatching syscalls originating from these areas back to userspace.
I think this might benefit from a bit more details or clarity on the "why" of the COMPAT handling : there is a vDSO page for COMPAT tasks, but COMPAT signal handlers have their own dedicated page,
sigpage, which serves the same purpose and is handled similarly, so it needs to be checked as well.
Quoted 3 lines
Hopefully that is correct... Would you find that relevant information to add ?
Pinging @Kevin Brodsky on that as well.
Thank you for the review. The related information needs to be improved.
Quoted 16 lines
Quoted 8 lines
Suggested-by Kevin Brodsky <[email protected]>Suggested-by kemal <[email protected]>Signed-off-by Jinjie Ruan <[email protected]>---
arch/arm64/include/asm/elf.h| 1 + arch/arm64/kernel/vdso.c | 16 ++++++++++++++++2 files changed, 17 insertions(+)Otherwise this looks good to me, great to have more context with the change !
Thanks,
Ada
Re: [PATCH v16 18/18] arm64: vdso: Expose sigreturn address on vdso to the kernel
In reply to Jinjie RuanQuoted 30 lines · Jinjie Ruan
Syscall User Dispatch (SUD) requires the signal trampoline code to not be intercepted. This is necessary to support returning with a locked selector while avoiding infinite recursion back into the signal handler.
Implement
arch_syscall_is_vdso_sigreturn()for arm64 to support this exclusion mechanism. For native 64-bit tasks, it checks whether the current PC matches the 'svc #0' instruction inside the vDSO sigreturn trampoline.
SYM_CODE_START(__kernel_rt_sigreturn)
mov x8, #__NR_rt_sigreturn
svc #0
SYM_CODE_END(__kernel_rt_sigreturn)For COMPAT tasks, it verifies if the instruction falls within the architecture's 'sigpage' range, allowing the kernel to safely bypass dispatching syscalls originating from these areas back to userspace.
Suggested-by Kevin Brodsky <[email protected]>Suggested-by kemal <[email protected]>Signed-off-by Jinjie Ruan <[email protected]>--- arch/arm64/include/asm/elf.h | 1 + arch/arm64/kernel/vdso.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+)arch/arm64/include/asm/elf.h +0
-0
arch/arm64/include/asm/elf.h do { \ · line 188
Quoted 4 lines
arch/arm64/include/asm/elf.h +1
-0@@ -185,6 +185,7 @@ do { \struct linux_binprm ;extern int arch_setup_additional_pages (struct linux_binprm *bprm,int uses_interp); +extern bool arch_syscall_is_vdso_sigreturn (struct pt_regs *regs);
A header for that?
Quoted 15 lines
arch/arm64/include/asm/elf.h +0
-0/* 1GB of VA */ #ifdef CONFIG_COMPAT arch/arm64/kernel/vdso.c +5
-0@@ -343,3 +343,19 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)return ret; } + +bool arch_syscall_is_vdso_sigreturn (struct pt_regs *regs) +{ +unsigned long sigtramp; +
arch/arm64/kernel/vdso.c int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) · line 360
Quoted 10 lines
arch/arm64/kernel/vdso.c +10
-0+#ifdef CONFIG_COMPAT +if (is_compat_task ()) { +unsigned long sigpage = (unsigned long )current->mm->context.sigpage; + +return regs->pc >= sigpage && regs->pc < (sigpage +PAGE_SIZE ); + } +#endif + sigtramp = (unsigned long )VDSO_SYMBOL (current->mm->context.vdso, sigtramp); + +return regs->pc == (sigtramp +8 );
Instead of hardcoding 'sigtramp + 8' you could add a new label to the 'svc #0' instruction and use that with VDSO_SYMBOL().
Thomas
Re: [PATCH v16 18/18] arm64: vdso: Expose sigreturn address on vdso to the kernel
Quoted 26 lines · Thomas Weißschuh
Quoted 25 lines · Jinjie Ruan
Syscall User Dispatch (SUD) requires the signal trampoline code to not be intercepted. This is necessary to support returning with a locked selector while avoiding infinite recursion back into the signal handler.
Implement
arch_syscall_is_vdso_sigreturn()for arm64 to support this exclusion mechanism. For native 64-bit tasks, it checks whether the current PC matches the 'svc #0' instruction inside the vDSO sigreturn trampoline.
SYM_CODE_START(__kernel_rt_sigreturn)
mov x8, #__NR_rt_sigreturn
svc #0
SYM_CODE_END(__kernel_rt_sigreturn)For COMPAT tasks, it verifies if the instruction falls within the architecture's 'sigpage' range, allowing the kernel to safely bypass dispatching syscalls originating from these areas back to userspace.
Suggested-by Kevin Brodsky <[email protected]>Suggested-by kemal <[email protected]>Signed-off-by Jinjie Ruan <[email protected]>--- arch/arm64/include/asm/elf.h | 1 + arch/arm64/kernel/vdso.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+)
Quoted 11 lines
arch/arm64/include/asm/elf.h do { \ · line 188
Quoted 9 lines
arch/arm64/include/asm/elf.h +1
-0@@ -185,6 +185,7 @@ do { \struct linux_binprm ;extern int arch_setup_additional_pages (struct linux_binprm *bprm,int uses_interp); +extern bool arch_syscall_is_vdso_sigreturn (struct pt_regs *regs);A header for that?
Sure, it need a cleanup, as currently, there is no syscall_user_dispatch header file related to the architecture.
Quoted 21 lines
Quoted 21 lines
arch/arm64/include/asm/elf.h +0
-0/* 1GB of VA */ #ifdef CONFIG_COMPAT arch/arm64/kernel/vdso.c +10
-0@@ -343,3 +343,19 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)return ret; } + +bool arch_syscall_is_vdso_sigreturn (struct pt_regs *regs) +{ +unsigned long sigtramp; + +#ifdef CONFIG_COMPAT +if (is_compat_task ()) { +unsigned long sigpage = (unsigned long )current->mm->context.sigpage; + +return regs->pc >= sigpage && regs->pc < (sigpage +PAGE_SIZE );
Quoted 8 lines
arch/arm64/kernel/vdso.c int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) · line 360
Quoted 5 lines
arch/arm64/kernel/vdso.c +5
-0+ } +#endif + sigtramp = (unsigned long )VDSO_SYMBOL (current->mm->context.vdso, sigtramp); + +return regs->pc == (sigtramp +8 );Instead of hardcoding 'sigtramp + 8' you could add a new label to the 'svc #0' instruction and use that with
VDSO_SYMBOL().
It seems that the modification of __kernel_rt_sigreturn() is not recommended
Quoted 3 lines
Thomas
Re: [PATCH v16 18/18] arm64: vdso: Expose sigreturn address on vdso to the kernel
Quoted 2 lines · Jinjie Ruan
Quoted 1 line · Thomas Weißschuh
On Mon, Jun 29, 2026 at 09:06:16PM +0800, Jinjie Ruan wrote:
(..)
Quoted 27 lines
Quoted 18 lines
Quoted 18 lines
arch/arm64/kernel/vdso.c +10
-0@@ -343,3 +343,19 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)return ret; } + +bool arch_syscall_is_vdso_sigreturn (struct pt_regs *regs) +{ +unsigned long sigtramp; + +#ifdef CONFIG_COMPAT +if (is_compat_task ()) { +unsigned long sigpage = (unsigned long )current->mm->context.sigpage; + +return regs->pc >= sigpage && regs->pc < (sigpage +PAGE_SIZE );Quoted 8 lines
arch/arm64/kernel/vdso.c int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) · line 360
Quoted 5 lines
arch/arm64/kernel/vdso.c +5
-0+ } +#endif + sigtramp = (unsigned long )VDSO_SYMBOL (current->mm->context.vdso, sigtramp); + +return regs->pc == (sigtramp +8 );Instead of hardcoding 'sigtramp + 8' you could add a new label to the 'svc #0' instruction and use that with
VDSO_SYMBOL().
Quoted 1 line
It seems that the modification of
__kernel_rt_sigreturn()is not recommended
For the changes to the object code of the function this is obvious and well explained in the comments.
Such a label however would not change the object code of the function. In fact it would not change any bit whatsoever in the final vDSO, save for a new build ID.
Thomas
Re: [PATCH v16 18/18] arm64: vdso: Expose sigreturn address on vdso to the kernel
Quoted 32 lines · Thomas Weißschuh
Quoted 2 lines · Jinjie Ruan
Quoted 1 line · Thomas Weißschuh
On Mon, Jun 29, 2026 at 09:06:16PM +0800, Jinjie Ruan wrote:
(..)
Quoted 27 lines
Quoted 26 lines
Quoted 13 lines
arch/arm64/kernel/vdso.c +5
-0@@ -343,3 +343,19 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)return ret; } + +bool arch_syscall_is_vdso_sigreturn (struct pt_regs *regs) +{ +unsigned long sigtramp; +arch/arm64/kernel/vdso.c int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) · line 360
Quoted 10 lines
arch/arm64/kernel/vdso.c +10
-0+#ifdef CONFIG_COMPAT +if (is_compat_task ()) { +unsigned long sigpage = (unsigned long )current->mm->context.sigpage; + +return regs->pc >= sigpage && regs->pc < (sigpage +PAGE_SIZE ); + } +#endif + sigtramp = (unsigned long )VDSO_SYMBOL (current->mm->context.vdso, sigtramp); + +return regs->pc == (sigtramp +8 );Instead of hardcoding 'sigtramp + 8' you could add a new label to the 'svc #0' instruction and use that with
VDSO_SYMBOL().
Quoted 8 lines
Quoted 1 line
It seems that the modification of
__kernel_rt_sigreturn()is not recommendedFor the changes to the object code of the function this is obvious and well explained in the comments.
Such a label however would not change the object code of the function. In fact it would not change any bit whatsoever in the final vDSO, save for a new build ID.
Yes, and using labels is easier to maintain than hardcoding offsets directly.
Similar to the code below?
arch/arm64/Kconfig +1 -0
@@ -86,6 +86,7 @@ config ARM64 select ARCH_SUPPORTS_SCHED_SMT select ARCH_SUPPORTS_SCHED_CLUSTER select ARCH_SUPPORTS_SCHED_MC + select ARCH_SUPPORTS_SYSCALL_USER_DISPATCH select ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH select ARCH_WANT_COMPAT_IPC_PARSE_VERSION if COMPAT select ARCH_WANT_DEFAULT_BPF_JIT
arch/arm64/include/asm/elf.h +0 -0
@@ -293,6 +293,7 @@ static inline int arch_check_elf(void *ehdr, bool
has_interp,
return 0;
}
+extern bool arch_syscall_is_vdso_sigreturn(struct pt_regs *regs);
#endif /* !__ASSEMBLER__ */
#endif
arch/arm64/kernel/vdso.c +0 -0
@@ -343,3 +343,19 @@ int arch_setup_additional_pages(struct linux_binprm
*bprm, int uses_interp)
return ret;
}
+
+bool arch_syscall_is_vdso_sigreturn(struct pt_regs *regs) +{
+ unsigned long sigtramp;
+
+#ifdef CONFIG_COMPAT
+ if (is_compat_task()) {
+ unsigned long sigpage = (unsigned
long)current->mm->context.sigpage;
+
+ return regs->pc >= sigpage && regs->pc < (sigpage +PAGE_SIZE);
+ }
+#endif
+ sigtramp = (unsigned long)VDSO_SYMBOL(current->mm->context.vdso,sigreturn_landing_pad);
+
+ return regs->pc == sigtramp;
+}
(quoted diff) +0 -0
b/arch/arm64/kernel/vdso/sigreturn.S
index 0e18729abc3b..8d2d413ff45e 100644
arch/arm64/kernel/vdso/sigreturn.S +1 -0
@@ -73,6 +73,7 @@ SYM_CODE_START(__kernel_rt_sigreturn) mov x8, #__NR_rt_sigreturn // PLEASE DO NOT MODIFY svc #0 + SYM_INNER_LABEL(__sigreturn_landing_pad, SYM_L_GLOBAL) // PLEASE DO NOT MODIFY // .cfi_endproc SYM_CODE_END(__kernel_rt_sigreturn)
(quoted diff) +0 -0
b/arch/arm64/kernel/vdso/vdso.lds.S
index 52314be29191..5fee2927e4c5 100644
arch/arm64/kernel/vdso/vdso.lds.S +2 -0
@@ -104,6 +104,7 @@ VERSION __kernel_clock_gettime; __kernel_clock_getres; __kernel_getrandom; + __sigreturn_landing_pad; local: *; }; }
@@ -112,3 +113,4 @@ VERSION * Make the sigreturn code visible to the kernel. */ VDSO_sigtramp = __kernel_rt_sigreturn; +VDSO_sigreturn_landing_pad = __sigreturn_landing_pad;
Quoted 4 lines
Thomas
Re: [PATCH v16 18/18] arm64: vdso: Expose sigreturn address on vdso to the kernel
Quoted 38 lines · Jinjie Ruan
Quoted 37 lines · Thomas Weißschuh
Quoted 2 lines · Jinjie Ruan
Quoted 1 line · Thomas Weißschuh
On Mon, Jun 29, 2026 at 09:06:16PM +0800, Jinjie Ruan wrote:
(..)
Quoted 27 lines
Quoted 18 lines
Quoted 18 lines
arch/arm64/kernel/vdso.c +10
-0@@ -343,3 +343,19 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)return ret; } + +bool arch_syscall_is_vdso_sigreturn (struct pt_regs *regs) +{ +unsigned long sigtramp; + +#ifdef CONFIG_COMPAT +if (is_compat_task ()) { +unsigned long sigpage = (unsigned long )current->mm->context.sigpage; + +return regs->pc >= sigpage && regs->pc < (sigpage +PAGE_SIZE );Quoted 8 lines
arch/arm64/kernel/vdso.c int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) · line 360
Quoted 5 lines
arch/arm64/kernel/vdso.c +5
-0+ } +#endif + sigtramp = (unsigned long )VDSO_SYMBOL (current->mm->context.vdso, sigtramp); + +return regs->pc == (sigtramp +8 );Instead of hardcoding 'sigtramp + 8' you could add a new label to the 'svc #0' instruction and use that with
VDSO_SYMBOL().Quoted 1 line
It seems that the modification of
__kernel_rt_sigreturn()is not recommendedFor the changes to the object code of the function this is obvious and well explained in the comments.
Quoted 8 lines
Quoted 3 lines
Such a label however would not change the object code of the function. In fact it would not change any bit whatsoever in the final vDSO, save for a new build ID.
Yes, and using labels is easier to maintain than hardcoding offsets directly.
Similar to the code below?
Exactly.
(...)
arch/arm64/kernel/vdso.c int arch_setup_additional_pages(struct linux_binprm
Quoted 13 lines
arch/arm64/kernel/vdso.c +4
-0@@ -343,3 +343,19 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)return ret; } + +bool arch_syscall_is_vdso_sigreturn (struct pt_regs *regs) +{ +unsigned long sigtramp;
Could be named better now.
Quoted 33 lines
arch/arm64/kernel/vdso.c +3
-0+#ifdef CONFIG_COMPAT +if (is_compat_task ()) { + unsigned long sigpage = (unsignedlong)current->mm->context.sigpage;
arch/arm64/kernel/vdso.c +2
-0+ + return regs->pc >= sigpage && regs->pc < (sigpage +
PAGE_SIZE);arch/arm64/kernel/vdso.c +3
-0+ } +#endif + sigtramp = (unsigned long)VDSO_SYMBOL(current->mm->context.vdso,
sigreturn_landing_pad);arch/arm64/kernel/vdso.c +3
-0+ +return regs->pc == sigtramp; +}arch/arm64/kernel/vdso/sigreturn.S +1
-0@@ -73,6 +73,7 @@ SYM_CODE_START(__kernel_rt_sigreturn) mov x8, #__NR_rt_sigreturn // PLEASE DO NOT MODIFY svc #0 + SYM_INNER_LABEL(__sigreturn_landing_pad, SYM_L_GLOBAL) // PLEASE DO NOT MODIFY // .cfi_endproc SYM_CODE_END(__kernel_rt_sigreturn)arch/arm64/kernel/vdso/vdso.lds.S +0
-0
arch/arm64/kernel/vdso/vdso.lds.S VERSION · line 107
Quoted 4 lines
arch/arm64/kernel/vdso/vdso.lds.S +1
-0@@ -104,6 +104,7 @@ VERSION __kernel_clock_gettime; __kernel_clock_getres; __kernel_getrandom; + __sigreturn_landing_pad;
This should not be done. The symbol is not intended to be used by userspace.
Quoted 8 lines
arch/arm64/kernel/vdso/vdso.lds.S +1
-0local: *; }; }@@ -112,3 +113,4 @@ VERSION * Make the sigreturn code visible to the kernel. */ VDSO_sigtramp = __kernel_rt_sigreturn; +VDSO_sigreturn_landing_pad = __sigreturn_landing_pad;