Skip to contentSkip to conversation

alpha: add support for SECCOMP and SECCOMP_FILTER

PATCH Superseded Magnus Lindholm 3 participants 6 messages Feb 5 – Feb 19

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Magnus Lindholm

author maintainer
#0 lore raw

cover alpha: add support for SECCOMP and SECCOMP_FILTER

This patch adds SECCOMP and SECCOMP_FILTER support to the Alpha architecture.

The seccomp-bpf selftests exercise syscall tracing, restart, and signal interaction paths that were previously untested on Alpha. To support these, the ptrace/strace syscall path is updated to reliably distinguish internal skip-dispatch from userspace invalid syscall numbers, ensuring that syscall(-1) continues to return -ENOSYS with correct r0/a3 semantics.

Supporting seccomp also requires correct syscall restart handling when ptrace and signal delivery are involved. The traced syscall entry path now consistently tracks syscall state using r0, r1, and r2 while preserving Alpha's a3-based error reporting ABI:

- r1 holds the mutable "current" syscall number
- r2 preserves the original syscall number for restart
- r0 and r19 (a3) retain their traditional roles as return value and error indicator

This separation allows syscall restarts to be gated strictly on valid ERESTART* return codes in the ptrace/strace paths and prevents kernel-internal restart values from leaking into userspace.

Alpha also lacked support for PTRACE_GETREGSET(NT_PRSTATUS), causing ptrace-based seccomp tests to fail with -EIO. Minimal GETREGSET and SETREGSET support is added to export struct pt_regs directly.

With these changes applied, the seccomp-bpf and ptrace syscall selftests (seccomp_bpf, extended for Alpha) pass reliably on Alpha systems.

Magnus Lindholm (1):
alpha: add support for SECCOMP and SECCOMP_FILTER

 arch/alpha/Kconfig                   |   2 +
 arch/alpha/include/asm/seccomp.h     |  13 +++
 arch/alpha/include/asm/syscall.h     |  90 +++++++++++++++++++-
 arch/alpha/include/asm/thread_info.h |  16 +++-
 arch/alpha/kernel/entry.S            | 123 +++++++++++++++++++++++----
 arch/alpha/kernel/ptrace.c           |  83 ++++++++++++++++--
 6 files changed, 304 insertions(+), 23 deletions(-)
 create mode 100644 arch/alpha/include/asm/seccomp.h
Signature · 1 line
2.52.0
author maintainer
#1 lore raw

PATCH 1/1 alpha: add support for SECCOMP and SECCOMP_FILTER

Add SECCOMP and SECCOMP_FILTER support to the Alpha architecture and fix syscall entry and ptrace issues uncovered by the seccomp-bpf selftests.

The syscall entry path is reworked to consistently track syscall state using r0, r1 and r2:
- r1 holds the active syscall number
- r2 preserves the original syscall number for restart
- r0 carries the return value, with r19 (a3) indicating success/error

This allows syscall restarts to be permitted only for valid ERESTART* return codes and prevents kernel-internal restart values from leaking to userspace. The syscall tracing error marker is corrected to use the saved syscall number slot, matching the Alpha ABI.

Additionally, implement minimal PTRACE_GETREGSET and PTRACE_SETREGSET support for NT_PRSTATUS, exporting struct pt_regs directly. This fixes ptrace-based seccomp tests that previously failed with -EIO.

With these changes, seccomp-bpf and ptrace syscall tests pass reliably on Alpha.

---
 arch/alpha/Kconfig                   |   2 +
 arch/alpha/include/asm/seccomp.h     |  13 +++
 arch/alpha/include/asm/syscall.h     |  90 +++++++++++++++++++-
 arch/alpha/include/asm/thread_info.h |  16 +++-
 arch/alpha/kernel/entry.S            | 123 +++++++++++++++++++++++----
 arch/alpha/kernel/ptrace.c           |  83 ++++++++++++++++--
 6 files changed, 304 insertions(+), 23 deletions(-)
 create mode 100644 arch/alpha/include/asm/seccomp.h
arch/alpha/Kconfig +2 -0
index 80367f2cf821..7f2d4e794d21 100644
@@ -31,6 +31,8 @@ config ALPHA
 	select GENERIC_SMP_IDLE_THREAD
 	select HAS_IOPORT
 	select HAVE_ARCH_AUDITSYSCALL
+	select HAVE_ARCH_SECCOMP
+	select HAVE_ARCH_SECCOMP_FILTER
 	select HAVE_MOD_ARCH_SPECIFIC
 	select LOCK_MM_AND_FIND_VMA
 	select MODULES_USE_ELF_RELA
arch/alpha/include/asm/seccomp.h new file +13 -0
new file mode 100644
index 000000000000..311934d20340
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_ALPHA_SECCOMP_H
+#define _ASM_ALPHA_SECCOMP_H
+
+#include <asm/unistd.h>
+#include <asm-generic/seccomp.h>
+#include <uapi/linux/audit.h>
+
+#define SECCOMP_ARCH_NATIVE            AUDIT_ARCH_ALPHA
+#define SECCOMP_ARCH_NATIVE_NR         NR_syscalls
+#define SECCOMP_ARCH_NATIVE_NAME       "alpha"
+
+#endif /* _ASM_ALPHA_SECCOMP_H */
arch/alpha/include/asm/syscall.h +89 -1

102 lines not on this page · raw message

arch/alpha/include/asm/thread_info.h +15 -1
index 98ccbca64984..94ef9cfa30f5 100644
@@ -56,7 +56,8 @@ register unsigned long *current_stack_pointer __asm__ ("$30");
  * - pending work-to-be-done flags come first and must be assigned to be
  *   within bits 0 to 7 to fit in and immediate operand.
  *
- * TIF_SYSCALL_TRACE is known to be 0 via blbs.
+ * (Historically TIF_SYSCALL_TRACE was known to be 0 via blbs, but we may
+ *  also test multiple bits via masks now.)
  */
 #define TIF_SYSCALL_TRACE	0	/* syscall trace active */
 #define TIF_NOTIFY_RESUME	1	/* callback before returning to user */
@@ -64,6 +65,7 @@ register unsigned long *current_stack_pointer __asm__ ("$30");
 #define TIF_NEED_RESCHED	3	/* rescheduling necessary */
 #define TIF_SYSCALL_AUDIT	4	/* syscall audit active */
 #define TIF_NOTIFY_SIGNAL	5	/* signal notifications exist */
+#define TIF_SECCOMP		6	/* seccomp syscall filtering active */
 #define TIF_DIE_IF_KERNEL	9	/* dik recursion lock */
 #define TIF_MEMDIE		13	/* is terminating due to OOM killer */
 #define TIF_POLLING_NRFLAG	14	/* idle is polling for TIF_NEED_RESCHED */
@@ -74,8 +76,20 @@ register unsigned long *current_stack_pointer __asm__ ("$30");
 #define _TIF_NOTIFY_RESUME	(1<<TIF_NOTIFY_RESUME)
 #define _TIF_SYSCALL_AUDIT	(1<<TIF_SYSCALL_AUDIT)
 #define _TIF_NOTIFY_SIGNAL	(1<<TIF_NOTIFY_SIGNAL)
+#define _TIF_SECCOMP		(1<<TIF_SECCOMP)
 #define _TIF_POLLING_NRFLAG	(1<<TIF_POLLING_NRFLAG)
 
+/*
+ * Work to do on syscall entry (in entry.S).
+ * If you want this to exactly mirror what entry.S checks, keep it aligned
+ * with the mask used before branching to syscall_trace_enter().
+ */
+#ifdef CONFIG_AUDITSYSCALL
+# define _TIF_SYSCALL_WORK	(_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SECCOMP)
+#else
+# define _TIF_SYSCALL_WORK	(_TIF_SYSCALL_TRACE | _TIF_SECCOMP)
+#endif
+
 /* Work to do on interrupt/exception return.  */
 #define _TIF_WORK_MASK		(_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
 				 _TIF_NOTIFY_RESUME | _TIF_NOTIFY_SIGNAL)
arch/alpha/kernel/entry.S +107 -16

201 lines not on this page · raw message

arch/alpha/kernel/ptrace.c +78 -5

110 lines not on this page · raw message

Signature · 1 line
2.52.0
#2 lore raw

Hi Magnus,

Quoted 22 lines · Magnus Lindholm

Add SECCOMP and SECCOMP_FILTER support to the Alpha architecture and fix syscall entry and ptrace issues uncovered by the seccomp-bpf selftests.

The syscall entry path is reworked to consistently track syscall state using r0, r1 and r2:
- r1 holds the active syscall number
- r2 preserves the original syscall number for restart
- r0 carries the return value, with r19 (a3) indicating success/error

This allows syscall restarts to be permitted only for valid ERESTART* return codes and prevents kernel-internal restart values from leaking to userspace. The syscall tracing error marker is corrected to use the saved syscall number slot, matching the Alpha ABI.

Additionally, implement minimal PTRACE_GETREGSET and PTRACE_SETREGSET support for NT_PRSTATUS, exporting struct pt_regs directly. This fixes ptrace-based seccomp tests that previously failed with -EIO.

With these changes, seccomp-bpf and ptrace syscall tests pass reliably on Alpha.

Quoted 9 lines
---
 arch/alpha/Kconfig                   |   2 +
 arch/alpha/include/asm/seccomp.h     |  13 +++
 arch/alpha/include/asm/syscall.h     |  90 +++++++++++++++++++-
 arch/alpha/include/asm/thread_info.h |  16 +++-
 arch/alpha/kernel/entry.S            | 123 +++++++++++++++++++++++----
 arch/alpha/kernel/ptrace.c           |  83 ++++++++++++++++--
 6 files changed, 304 insertions(+), 23 deletions(-)
 create mode 100644 arch/alpha/include/asm/seccomp.h

Thanks so much for working on this! Alpha and SPARC are the last two architectures in Debian that are missing full support for SECCOMP filter. Great to see that Alpha is now being worked on.

FWIW, I haven't tested your patches yet, but I think you should also update the documentation in Documentation/features/seccomp/seccomp-filter/arch-support.txt.

I will try to add support for Alpha in libseccomp over the weekend to test your patch.

Adrian

Signature · 4 lines
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913
author maintainer
#3 lore raw
Quoted 8 lines

Thanks so much for working on this! Alpha and SPARC are the last two architectures in Debian that are missing full support for SECCOMP filter. Great to see that Alpha is now being worked on.

FWIW, I haven't tested your patches yet, but I think you should also update the documentation in Documentation/features/seccomp/seccomp-filter/arch-support.txt.

Thanks for taking a look! I'll put out a v2 of this patch, including an update to the
documentation.

Quoted 2 lines

I will try to add support for Alpha in libseccomp over the weekend to test your patch.

Btw. I've tested your libseccomp with updated alpha support, real nice progress

Magnus

#4 lore raw
Quoted 9 lines · Magnus Lindholm
Quoted 8 lines

Thanks so much for working on this! Alpha and SPARC are the last two architectures in Debian that are missing full support for SECCOMP filter. Great to see that Alpha is now being worked on.

FWIW, I haven't tested your patches yet, but I think you should also update the documentation in Documentation/features/seccomp/seccomp-filter/arch-support.txt.

Quoted 8 lines

Thanks for taking a look! I'll put out a v2 of this patch, including an update to the
documentation.

Quoted 2 lines

I will try to add support for Alpha in libseccomp over the weekend to test your patch.

Btw. I've tested your libseccomp with updated alpha support, real nice progress

Where is this updated libseccomp? I would like to test it too.

Cheers
Michael.

#5 lore raw

Hi Michael,

Quoted 14 lines · Michael Cree
Quoted 13 lines · Magnus Lindholm
Quoted 8 lines

Thanks so much for working on this! Alpha and SPARC are the last two architectures in Debian that are missing full support for SECCOMP filter. Great to see that Alpha is now being worked on.

FWIW, I haven't tested your patches yet, but I think you should also update the documentation in Documentation/features/seccomp/seccomp-filter/arch-support.txt.

Thanks for taking a look! I'll put out a v2 of this patch, including an update to the
documentation.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

I will try to add support for Alpha in libseccomp over the weekend to test your patch.

Btw. I've tested your libseccomp with updated alpha support, real nice progress

Where is this updated libseccomp? I would like to test it too.

See: https://github.com/glaubitz/libseccomp/tree/alpha-support

Had some issues with updating syscalls.csv though, see: https://github.com/seccomp/libseccomp/issues/480

Adrian

Signature · 4 lines
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913