seccomp: add bitmap cache support on remaining arches and report cache in procfs
v2 cover seccomp: add bitmap cache support on remaining arches and report cache in procfs
From: YiFei Zhu <[email protected]>
This patch series enables bitmap cache for the remaining arches with SECCOMP_FILTER, other than MIPS.
I was unable to find any of the arches having subarch-specific NR_syscalls macros, so generic NR_syscalls is used. SH's syscall_get_arch seems to only have the 32-bit subarch implementation. I'm not sure if this is expected.
This series has not been tested; I have not built all the cross compilers necessary to build test, let alone run the kernel or benchmark the performance, so help on making sure the bitmap cache works as expected (selftests/seccomp/{seccomp_benchmark,seccomp_bpf}) would be appreciated. The series applies on top of Kees's for-next/seccomp branch.
v1 -> v2:
* ppc, sh: s/__SECCOMP_ARCH_LE_BIT/__SECCOMP_ARCH_LE/
* ppc: add "le" suffix to arch name when the arch is little endian.
* ppc: add explanation of why __LITTLE_ENDIAN__ is used to commit message.
YiFei Zhu (8):
csky: Enable seccomp architecture tracking
parisc: Enable seccomp architecture tracking
powerpc: Enable seccomp architecture tracking
riscv: Enable seccomp architecture tracking
s390: Enable seccomp architecture tracking
sh: Enable seccomp architecture tracking
xtensa: Enable seccomp architecture tracking seccomp/cache: Report cache data through /proc/pid/seccomp_cache
arch/Kconfig | 15 ++++++++ arch/csky/include/asm/Kbuild | 1 - arch/csky/include/asm/seccomp.h | 11 ++++++ arch/parisc/include/asm/Kbuild | 1 - arch/parisc/include/asm/seccomp.h | 22 +++++++++++ arch/powerpc/include/asm/seccomp.h | 23 ++++++++++++ arch/riscv/include/asm/seccomp.h | 10 +++++ arch/s390/include/asm/seccomp.h | 9 +++++ arch/sh/include/asm/seccomp.h | 10 +++++ arch/xtensa/include/asm/Kbuild | 1 - arch/xtensa/include/asm/seccomp.h | 11 ++++++ fs/proc/base.c | 6 +++ include/linux/seccomp.h | 7 ++++ kernel/seccomp.c | 59 ++++++++++++++++++++++++++++++ 14 files changed, 183 insertions(+), 3 deletions(-) create mode 100644 arch/csky/include/asm/seccomp.h create mode 100644 arch/parisc/include/asm/seccomp.h create mode 100644 arch/xtensa/include/asm/seccomp.h
base-commit: 38c37e8fd3d2590c4234d8cfbc22158362f0eb04 --
2.29.2
PATCH v2 1/8 csky: Enable seccomp architecture tracking
From: YiFei Zhu <[email protected]>
To enable seccomp constant action bitmaps, we need to have a static mapping to the audit architecture and system call table size. Add these for csky.
--- arch/csky/include/asm/Kbuild | 1 - arch/csky/include/asm/seccomp.h | 11 +++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 arch/csky/include/asm/seccomp.h
arch/csky/include/asm/Kbuild +0 -1
@@ -4,6 +4,5 @@ generic-y += gpio.h generic-y += kvm_para.h generic-y += local64.h generic-y += qrwlock.h -generic-y += seccomp.h generic-y += user.h generic-y += vmlinux.lds.h
arch/csky/include/asm/seccomp.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _ASM_SECCOMP_H +#define _ASM_SECCOMP_H + +#include <asm-generic/seccomp.h> + +#define SECCOMP_ARCH_NATIVE AUDIT_ARCH_CSKY +#define SECCOMP_ARCH_NATIVE_NR NR_syscalls +#define SECCOMP_ARCH_NATIVE_NAME "csky" + +#endif /* _ASM_SECCOMP_H */
Signature · 1 line
2.29.2
PATCH v2 2/8 parisc: Enable seccomp architecture tracking
In reply to YiFei ZhuFrom: YiFei Zhu <[email protected]>
To enable seccomp constant action bitmaps, we need to have a static mapping to the audit architecture and system call table size. Add these for parisc.
--- arch/parisc/include/asm/Kbuild | 1 - arch/parisc/include/asm/seccomp.h | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 arch/parisc/include/asm/seccomp.h
arch/parisc/include/asm/Kbuild +0 -1
@@ -5,5 +5,4 @@ generated-y += syscall_table_c32.h generic-y += kvm_para.h generic-y += local64.h generic-y += mcs_spinlock.h -generic-y += seccomp.h generic-y += user.h
arch/parisc/include/asm/seccomp.h new file +22 -0
@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _ASM_SECCOMP_H +#define _ASM_SECCOMP_H + +#include <asm-generic/seccomp.h> + +#ifdef CONFIG_64BIT +# define SECCOMP_ARCH_NATIVE AUDIT_ARCH_PARISC64 +# define SECCOMP_ARCH_NATIVE_NR NR_syscalls +# define SECCOMP_ARCH_NATIVE_NAME "parisc64" +# ifdef CONFIG_COMPAT +# define SECCOMP_ARCH_COMPAT AUDIT_ARCH_PARISC +# define SECCOMP_ARCH_COMPAT_NR NR_syscalls +# define SECCOMP_ARCH_COMPAT_NAME "parisc" +# endif +#else /* !CONFIG_64BIT */ +# define SECCOMP_ARCH_NATIVE AUDIT_ARCH_PARISC +# define SECCOMP_ARCH_NATIVE_NR NR_syscalls +# define SECCOMP_ARCH_NATIVE_NAME "parisc" +#endif + +#endif /* _ASM_SECCOMP_H */
Signature · 1 line
2.29.2
PATCH v2 3/8 powerpc: Enable seccomp architecture tracking
In reply to YiFei ZhuFrom: YiFei Zhu <[email protected]>
To enable seccomp constant action bitmaps, we need to have a static mapping to the audit architecture and system call table size. Add these for powerpc.
__LITTLE_ENDIAN__ is used here instead of CONFIG_CPU_LITTLE_ENDIAN to keep it consistent with asm/syscall.h.
--- arch/powerpc/include/asm/seccomp.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
arch/powerpc/include/asm/seccomp.h +23 -0
@@ -8,4 +8,27 @@#include <asm-generic/seccomp.h> +#ifdef __LITTLE_ENDIAN__ +#define __SECCOMP_ARCH_LE __AUDIT_ARCH_LE +#define __SECCOMP_ARCH_LE_NAME "le" +#else +#define __SECCOMP_ARCH_LE 0 +#define __SECCOMP_ARCH_LE_NAME +#endif + +#ifdef CONFIG_PPC64 +# define SECCOMP_ARCH_NATIVE (AUDIT_ARCH_PPC64 | __SECCOMP_ARCH_LE) +# define SECCOMP_ARCH_NATIVE_NR NR_syscalls +# define SECCOMP_ARCH_NATIVE_NAME "ppc64" __SECCOMP_ARCH_LE_NAME +# ifdef CONFIG_COMPAT +# define SECCOMP_ARCH_COMPAT (AUDIT_ARCH_PPC | __SECCOMP_ARCH_LE) +# define SECCOMP_ARCH_COMPAT_NR NR_syscalls +# define SECCOMP_ARCH_COMPAT_NAME "ppc" __SECCOMP_ARCH_LE_NAME +# endif +#else /* !CONFIG_PPC64 */ +# define SECCOMP_ARCH_NATIVE (AUDIT_ARCH_PPC | __SECCOMP_ARCH_LE) +# define SECCOMP_ARCH_NATIVE_NR NR_syscalls +# define SECCOMP_ARCH_NATIVE_NAME "ppc" __SECCOMP_ARCH_LE_NAME +#endif +#endif /* _ASM_POWERPC_SECCOMP_H */
Signature · 1 line
2.29.2
PATCH v2 4/8 riscv: Enable seccomp architecture tracking
In reply to YiFei ZhuFrom: YiFei Zhu <[email protected]>
To enable seccomp constant action bitmaps, we need to have a static mapping to the audit architecture and system call table size. Add these for riscv.
--- arch/riscv/include/asm/seccomp.h | 10 ++++++++++ 1 file changed, 10 insertions(+)
arch/riscv/include/asm/seccomp.h +10 -0
@@ -7,4 +7,14 @@#include <asm-generic/seccomp.h> +#ifdef CONFIG_64BIT +# define SECCOMP_ARCH_NATIVE AUDIT_ARCH_RISCV64 +# define SECCOMP_ARCH_NATIVE_NR NR_syscalls +# define SECCOMP_ARCH_NATIVE_NAME "riscv64" +#else /* !CONFIG_64BIT */ +# define SECCOMP_ARCH_NATIVE AUDIT_ARCH_RISCV32 +# define SECCOMP_ARCH_NATIVE_NR NR_syscalls +# define SECCOMP_ARCH_NATIVE_NAME "riscv32" +#endif +#endif /* _ASM_SECCOMP_H */
Signature · 1 line
2.29.2
PATCH v2 5/8 s390: Enable seccomp architecture tracking
In reply to YiFei ZhuFrom: YiFei Zhu <[email protected]>
To enable seccomp constant action bitmaps, we need to have a static mapping to the audit architecture and system call table size. Add these for s390.
--- arch/s390/include/asm/seccomp.h | 9 +++++++++ 1 file changed, 9 insertions(+)
arch/s390/include/asm/seccomp.h +9 -0
@@ -16,4 +16,13 @@#include <asm-generic/seccomp.h> +#define SECCOMP_ARCH_NATIVE AUDIT_ARCH_S390X +#define SECCOMP_ARCH_NATIVE_NR NR_syscalls +#define SECCOMP_ARCH_NATIVE_NAME "s390x" +#ifdef CONFIG_COMPAT +# define SECCOMP_ARCH_COMPAT AUDIT_ARCH_S390 +# define SECCOMP_ARCH_COMPAT_NR NR_syscalls +# define SECCOMP_ARCH_COMPAT_NAME "s390" +#endif +#endif /* _ASM_S390_SECCOMP_H */
Signature · 1 line
2.29.2
PATCH v2 6/8 sh: Enable seccomp architecture tracking
In reply to YiFei ZhuFrom: YiFei Zhu <[email protected]>
To enable seccomp constant action bitmaps, we need to have a static mapping to the audit architecture and system call table size. Add these for sh.
--- arch/sh/include/asm/seccomp.h | 10 ++++++++++ 1 file changed, 10 insertions(+)
arch/sh/include/asm/seccomp.h +10 -0
@@ -8,4 +8,14 @@#define __NR_seccomp_exit __NR_exit#define __NR_seccomp_sigreturn __NR_rt_sigreturn +#ifdef CONFIG_CPU_LITTLE_ENDIAN +#define __SECCOMP_ARCH_LE __AUDIT_ARCH_LE +#else +#define __SECCOMP_ARCH_LE 0 +#endif + +#define SECCOMP_ARCH_NATIVE (AUDIT_ARCH_SH | __SECCOMP_ARCH_LE) +#define SECCOMP_ARCH_NATIVE_NR NR_syscalls +#define SECCOMP_ARCH_NATIVE_NAME "sh" +#endif /* __ASM_SECCOMP_H */
Signature · 1 line
2.29.2
PATCH v2 7/8 xtensa: Enable seccomp architecture tracking
In reply to YiFei ZhuFrom: YiFei Zhu <[email protected]>
To enable seccomp constant action bitmaps, we need to have a static mapping to the audit architecture and system call table size. Add these for xtensa.
--- arch/xtensa/include/asm/Kbuild | 1 - arch/xtensa/include/asm/seccomp.h | 11 +++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 arch/xtensa/include/asm/seccomp.h
arch/xtensa/include/asm/Kbuild +0 -1
@@ -7,5 +7,4 @@ generic-y += mcs_spinlock.h generic-y += param.h generic-y += qrwlock.h generic-y += qspinlock.h -generic-y += seccomp.h generic-y += user.h
arch/xtensa/include/asm/seccomp.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _ASM_SECCOMP_H +#define _ASM_SECCOMP_H + +#include <asm-generic/seccomp.h> + +#define SECCOMP_ARCH_NATIVE AUDIT_ARCH_XTENSA +#define SECCOMP_ARCH_NATIVE_NR NR_syscalls +#define SECCOMP_ARCH_NATIVE_NAME "xtensa" + +#endif /* _ASM_SECCOMP_H */
Signature · 1 line
2.29.2
PATCH v2 8/8 seccomp/cache: Report cache data through /proc/pid/seccomp_cache
In reply to YiFei ZhuFrom: YiFei Zhu <[email protected]>
Currently the kernel does not provide an infrastructure to translate architecture numbers to a human-readable name. Translating syscall numbers to syscall names is possible through FTRACE_SYSCALL infrastructure but it does not provide support for compat syscalls.
This will create a file for each PID as /proc/pid/seccomp_cache. The file will be empty when no seccomp filters are loaded, or be in the format of:
<arch name> <decimal syscall number> <ALLOW | FILTER> where ALLOW means the cache is guaranteed to allow the syscall, and filter means the cache will pass the syscall to the BPF filter.
For the docker default profile on x86_64 it looks like:x86_64 0 ALLOWx86_64 1 ALLOWx86_64 2 ALLOWx86_64 3 ALLOW
[...]x86_64 132 ALLOWx86_64 133 ALLOWx86_64 134 FILTERx86_64 135 FILTERx86_64 136 FILTERx86_64 137 ALLOWx86_64 138 ALLOWx86_64 139 FILTERx86_64 140 ALLOWx86_64 141 ALLOW
[...]
This file is guarded by CONFIG_SECCOMP_CACHE_DEBUG with a default of N because I think certain users of seccomp might not want the application to know which syscalls are definitely usable. For the same reason, it is also guarded by CAP_SYS_ADMIN.
--- arch/Kconfig | 15 +++++++++++ fs/proc/base.c | 6 +++++ include/linux/seccomp.h | 7 +++++ kernel/seccomp.c | 59 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+)
arch/Kconfig +15 -0
@@ -514,6 +514,21 @@ config SECCOMP_FILTER See Documentation/userspace-api/seccomp_filter.rst for details. +config SECCOMP_CACHE_DEBUG + bool "Show seccomp filter cache status in /proc/pid/seccomp_cache" + depends on SECCOMP + depends on SECCOMP_FILTER && !HAVE_SPARSE_SYSCALL_NR + depends on PROC_FS + help + This enables the /proc/pid/seccomp_cache interface to monitor + seccomp cache data. The file format is subject to change. Reading + the file requires CAP_SYS_ADMIN. + + This option is for debugging only. Enabling presents the risk that + an adversary may be able to infer the seccomp filter logic. + + If unsure, say N. + config HAVE_ARCH_STACKLEAK bool help
fs/proc/base.c +6 -0
@@ -3261,6 +3261,9 @@ static const struct pid_entry tgid_base_stuff[] = {#ifdef CONFIG_PROC_PID_ARCH_STATUS ONE("arch_status", S_IRUGO, proc_pid_arch_status),#endif +#ifdef CONFIG_SECCOMP_CACHE_DEBUG + ONE("seccomp_cache", S_IRUSR, proc_pid_seccomp_cache), +#endif };static int proc_tgid_base_readdir (struct file *file,struct dir_context *ctx)
@@ -3590,6 +3593,9 @@ static const struct pid_entry tid_base_stuff[] = {#ifdef CONFIG_PROC_PID_ARCH_STATUS ONE("arch_status", S_IRUGO, proc_pid_arch_status),#endif +#ifdef CONFIG_SECCOMP_CACHE_DEBUG + ONE("seccomp_cache", S_IRUSR, proc_pid_seccomp_cache), +#endif };static int proc_tid_base_readdir (struct file *file,struct dir_context *ctx)
include/linux/seccomp.h +7 -0
@@ -121,4 +121,11 @@ static inline long seccomp_get_metadata(struct task_struct *task,return -EINVAL ; }#endif /* CONFIG_SECCOMP_FILTER && CONFIG_CHECKPOINT_RESTORE */ + +#ifdef CONFIG_SECCOMP_CACHE_DEBUG +struct seq_file ; + +int proc_pid_seccomp_cache (struct seq_file *m,struct pid_namespace *ns, +struct pid *pid,struct task_struct *task); +#endif #endif /* _LINUX_SECCOMP_H */
kernel/seccomp.c +59 -0
68 lines not on this page · raw message
Signature · 1 line
2.29.2
Kees Cook
AppliedQuoted 9 lines · YiFei Zhu
This patch series enables bitmap cache for the remaining arches with
SECCOMP_FILTER, other than MIPS.I was unable to find any of the arches having subarch-specific
NR_syscallsmacros, so genericNR_syscallsis used. SH'ssyscall_get_archseems to only have the 32-bit subarch implementation. I'm not sure if this is expected.[...]
Applied to for-next/seccomp, thanks!
I made a small tweak to the last patch to add more details to the per-ARCH help text, and to drop the needless "depends on SECCOMP" (which "depends on SECCOMP_FILTER" was already present).
I successfully build-tested on parisc, powerpc, riscv, s390, and sh. xtensa doesn't build using the existing Debian cross-compiler, and I can't make csky with clang work, but they look correct. *cross fingers*
[1/8] csky: Enable seccomp architecture tracking
https://git.kernel.org/kees/c/ee7ce951028f [2/8] parisc: Enable seccomp architecture tracking https://git.kernel.org/kees/c/7f049cc068a3 [3/8] powerpc: Enable seccomp architecture tracking https://git.kernel.org/kees/c/95f8ae2624a0 [4/8] riscv: Enable seccomp architecture tracking https://git.kernel.org/kees/c/8f9f0f44a37b [5/8] s390: Enable seccomp architecture tracking https://git.kernel.org/kees/c/5897106c6902 [6/8] sh: Enable seccomp architecture tracking https://git.kernel.org/kees/c/75186111c257 [7/8] xtensa: Enable seccomp architecture tracking https://git.kernel.org/kees/c/4f408bc643aa [8/8] seccomp/cache: Report cache data through /proc/pid/seccomp_cache https://git.kernel.org/kees/c/49a6968cc78f
Signature · 1 line
Kees Cook