Skip to contentSkip to conversation

seccomp: add bitmap cache support on remaining arches and report cache in procfs

PATCH Superseded YiFei Zhu 5 participants 15 messages Nov 3, 2020 – Nov 9, 2020

Subsystems (9)
PowerPC RISC-V s390 SuperH +5 more subsystems

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

YiFei Zhu

author
#0 lore raw

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 would be appreciated. The series applies on top of Kees's for-next/seccomp branch.

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 | 21 +++++++++++
 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, 181 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

author
#1 lore raw

PATCH 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
index 64876e59e2ef..93372255984d 100644
@@ -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
new file mode 100644
index 000000000000..d33e758126fb
@@ -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
author
#2 lore raw

PATCH 2/8 parisc: Enable seccomp architecture tracking

In reply to YiFei Zhu

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 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
index e3ee5c0bfe80..f16c4db80116 100644
@@ -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
new file mode 100644
index 000000000000..b058b2220322
@@ -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
author
#4 lore raw

PATCH 3/8 powerpc: Enable seccomp architecture tracking

In reply to YiFei Zhu

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 powerpc.

---
 arch/powerpc/include/asm/seccomp.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
arch/powerpc/include/asm/seccomp.h +21 -0
index 51209f6071c5..3efcc83e9cc6 100644
@@ -8,4 +8,25 @@
 
 #include <asm-generic/seccomp.h>
 
+#ifdef __LITTLE_ENDIAN__
+#define __SECCOMP_ARCH_LE_BIT		__AUDIT_ARCH_LE
+#else
+#define __SECCOMP_ARCH_LE_BIT		0
+#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"
+# 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	"powerpc"
+# 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	"powerpc"
+#endif
+
 #endif	/* _ASM_POWERPC_SECCOMP_H */
Signature · 1 line
2.29.2
author
#8 lore raw

PATCH 4/8 riscv: Enable seccomp architecture tracking

In reply to YiFei Zhu

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 riscv.

---
 arch/riscv/include/asm/seccomp.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
arch/riscv/include/asm/seccomp.h +10 -0
index bf7744ee3b3d..c7ee6a3507be 100644
@@ -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
author
#9 lore raw

PATCH 5/8 s390: Enable seccomp architecture tracking

In reply to YiFei Zhu

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 s390.

---
 arch/s390/include/asm/seccomp.h | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/s390/include/asm/seccomp.h +9 -0
index 795bbe0d7ca6..71d46f0ba97b 100644
@@ -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
author
#11 lore raw

PATCH 6/8 sh: Enable seccomp architecture tracking

In reply to YiFei Zhu

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 sh.

---
 arch/sh/include/asm/seccomp.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
arch/sh/include/asm/seccomp.h +10 -0
index 54111e4d32b8..b8d169292a34 100644
@@ -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_BIT		__AUDIT_ARCH_LE
+#else
+#define __SECCOMP_ARCH_LE_BIT		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
author
#12 lore raw

PATCH 7/8 xtensa: Enable seccomp architecture tracking

In reply to YiFei Zhu

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 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
index c59c42a1221a..9718e9593564 100644
@@ -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
new file mode 100644
index 000000000000..f1cb6b0a9e1f
@@ -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
author
#13 lore raw

PATCH 8/8 seccomp/cache: Report cache data through /proc/pid/seccomp_cache

In reply to YiFei Zhu

From: 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 ALLOW
x86_64 1 ALLOW
x86_64 2 ALLOW
x86_64 3 ALLOW
[...]
x86_64 132 ALLOW
x86_64 133 ALLOW
x86_64 134 FILTER
x86_64 135 FILTER
x86_64 136 FILTER
x86_64 137 ALLOW
x86_64 138 ALLOW
x86_64 139 FILTER
x86_64 140 ALLOW
x86_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
index 56b6ccc0e32d..6e2eb7171da0 100644
@@ -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
index 0f707003dda5..d652f9dbaecc 100644
@@ -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
index 02aef2844c38..76963ec4641a 100644
@@ -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
#14 lore raw
In reply to YiFei Zhu
Quoted 10 lines · YiFei Zhu

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.

Quoted 5 lines

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 would be appreciated. The series applies on top of Kees's for-next/seccomp branch.

Thank you! This looks good. I wonder if the different handling of little endian is worth solving -- I'm suspicious about powerpc's use of __LITTLE_ENDIAN__ vs a CONFIG, but I guess the compiler would match the target endian-ness. Regardless, it captures what the architectures are doing, and gets things standardized.

Quoted 4 lines

YiFei Zhu (8):
csky: Enable seccomp architecture tracking
parisc: Enable seccomp architecture tracking

I don't have compilers for these.

Quoted 3 lines

powerpc: Enable seccomp architecture tracking
riscv: Enable seccomp architecture tracking
s390: Enable seccomp architecture tracking

These I can build-test immediately.

Quoted 2 lines

sh: Enable seccomp architecture tracking
xtensa: Enable seccomp architecture tracking

These two are available in Ubuntu's cross compiler set, so I'll get them added to my cross-builders.

Quoted 1 line

seccomp/cache: Report cache data through /proc/pid/seccomp_cache

In the meantime, I'll wait a bit to see if we can get some Acks/Reviews from arch maintainers. :)

-Kees

Quoted 24 lines
 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 | 21 +++++++++++
 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, 181 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

Signature · 1 line
Kees Cook
#5 lore raw

Re: [PATCH seccomp 3/8] powerpc: Enable seccomp architecture tracking

In reply to YiFei Zhu
Quoted 16 lines · YiFei Zhu

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 powerpc.

---
 arch/powerpc/include/asm/seccomp.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
arch/powerpc/include/asm/seccomp.h +0 -0
index 51209f6071c5..3efcc83e9cc6 100644

arch/powerpc/include/asm/seccomp.h line 11

Quoted 4 lines
arch/powerpc/include/asm/seccomp.h +1 -0
@@ -8,4 +8,25 @@
 
 #include <asm-generic/seccomp.h>
 
+#ifdef __LITTLE_ENDIAN__

As Kees mentioned this should (must?!) match the configured endian.

But I think it would still be better to use the CONFIG symbol, which is CONFIG_CPU_LITTLE_ENDIAN.

arch/powerpc/include/asm/seccomp.h line 18

Quoted 7 lines
arch/powerpc/include/asm/seccomp.h +7 -0
+#define __SECCOMP_ARCH_LE_BIT		__AUDIT_ARCH_LE
+#else
+#define __SECCOMP_ARCH_LE_BIT		0
+#endif
+
+#ifdef CONFIG_PPC64
+# define SECCOMP_ARCH_NATIVE		(AUDIT_ARCH_PPC64 | __SECCOMP_ARCH_LE)

You use __SECCOMP_ARCH_LE there, but previously you only defined __SECCOMP_ARCH_LE_BIT.

Is there some magic somewhere that defines __SECCOMP_ARCH_LE based on __SECCOMP_ARCH_LE_BIT ?

arch/powerpc/include/asm/seccomp.h line 20

Quoted 2 lines
arch/powerpc/include/asm/seccomp.h +2 -0
+# define SECCOMP_ARCH_NATIVE_NR		NR_syscalls
+# define SECCOMP_ARCH_NATIVE_NAME	"ppc64"

What's the name used for?

Usually we use "ppc64" for 64-bit big endian and "ppc64le" for 64-bit little endian.

arch/powerpc/include/asm/seccomp.h line 24

Quoted 4 lines
arch/powerpc/include/asm/seccomp.h +4 -0
+# 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	"powerpc"

And usually we use "ppc" for 32-bit.

Quoted 10 lines
arch/powerpc/include/asm/seccomp.h +7 -0
+# 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	"powerpc"
+#endif
+
 #endif	/* _ASM_POWERPC_SECCOMP_H */
Signature · 1 line
2.29.2

cheers

author
#6 lore raw

Re: [PATCH seccomp 3/8] powerpc: Enable seccomp architecture tracking

Quoted 6 lines · Michael Ellerman
Quoted 1 line

+#ifdef __LITTLE_ENDIAN__

As Kees mentioned this should (must?!) match the configured endian.

But I think it would still be better to use the CONFIG symbol, which is CONFIG_CPU_LITTLE_ENDIAN.

My attempt here is to be consistent with asm/syscall.h syscall_get_arch [1]. Would it make sense to change that to CONFIG_CPU_LITTLE_ENDIAN then?

[1] https://elixir.bootlin.com/linux/latest/source/arch/powerpc/include/asm/syscall.h#L116

Quoted 7 lines
Quoted 1 line

+# define SECCOMP_ARCH_NATIVE (AUDIT_ARCH_PPC64 | __SECCOMP_ARCH_LE)

You use __SECCOMP_ARCH_LE there, but previously you only defined __SECCOMP_ARCH_LE_BIT.

Is there some magic somewhere that defines __SECCOMP_ARCH_LE based on __SECCOMP_ARCH_LE_BIT ?

Oops, my bad here.

Quoted 4 lines

arch/powerpc/include/asm/seccomp.h line 20

Quoted 2 lines
arch/powerpc/include/asm/seccomp.h +2 -0
+# define SECCOMP_ARCH_NATIVE_NR              NR_syscalls
+# define SECCOMP_ARCH_NATIVE_NAME    "ppc64"

What's the name used for?

This is used in the last patch in this series to report in procfs the name of each architecture tracked by the bitmap cache.

Quoted 4 lines

Usually we use "ppc64" for 64-bit big endian and "ppc64le" for 64-bit little endian.

And usually we use "ppc" for 32-bit.

Ok.

YiFei Zhu

#7 lore raw

Re: [PATCH seccomp 3/8] powerpc: Enable seccomp architecture tracking

Quoted 5 lines · YiFei Zhu
Quoted 4 lines · Michael Ellerman
Quoted 1 line

+#ifdef __LITTLE_ENDIAN__

As Kees mentioned this should (must?!) match the configured endian.

Quoted 8 lines
Quoted 2 lines

But I think it would still be better to use the CONFIG symbol, which is CONFIG_CPU_LITTLE_ENDIAN.

My attempt here is to be consistent with asm/syscall.h syscall_get_arch [1]. Would it make sense to change that to CONFIG_CPU_LITTLE_ENDIAN then?

[1] https://elixir.bootlin.com/linux/latest/source/arch/powerpc/include/asm/syscall.h#L116

Looking across the tree with have thousands of usages of __LITTLE_ENDIAN__, so it's probably not worth converting to CONFIG_CPU_LITTLE_ENDIAN.

Quoted 9 lines
Quoted 7 lines
Quoted 1 line

+# define SECCOMP_ARCH_NATIVE (AUDIT_ARCH_PPC64 | __SECCOMP_ARCH_LE)

You use __SECCOMP_ARCH_LE there, but previously you only defined __SECCOMP_ARCH_LE_BIT.

Is there some magic somewhere that defines __SECCOMP_ARCH_LE based on __SECCOMP_ARCH_LE_BIT ?

Oops, my bad here.

OK :)

Quoted 7 lines
Quoted 4 lines

arch/powerpc/include/asm/seccomp.h line 20

Quoted 2 lines
arch/powerpc/include/asm/seccomp.h +2 -0
+# define SECCOMP_ARCH_NATIVE_NR              NR_syscalls
+# define SECCOMP_ARCH_NATIVE_NAME    "ppc64"

What's the name used for?

This is used in the last patch in this series to report in procfs the name of each architecture tracked by the bitmap cache.

OK, yeah I think it would be better if the matched the uname -m values.

Quoted 6 lines
Quoted 4 lines

Usually we use "ppc64" for 64-bit big endian and "ppc64le" for 64-bit little endian.

And usually we use "ppc" for 32-bit.

Ok.

cheers

maintainer Acked-by on v1 2/8
#3 lore raw

Re: [PATCH seccomp 2/8] parisc: Enable seccomp architecture tracking

In reply to YiFei Zhu
Quoted 6 lines · YiFei Zhu

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 parisc.

Quoted 1 line

I did compile- and boot-tested it, works on 32- and 64-bit parisc kernel. I don't know how to test it actually, but anyway:

Thanks!
Helge

Quoted 45 lines
---
 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
index e3ee5c0bfe80..f16c4db80116 100644
@@ -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
new file mode 100644
index 000000000000..b058b2220322
@@ -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 */
maintainer Acked-by on v1 5/8
#10 lore raw

Re: [PATCH seccomp 5/8] s390: Enable seccomp architecture tracking

In reply to YiFei Zhu
Quoted 18 lines · YiFei Zhu

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 s390.

---
 arch/s390/include/asm/seccomp.h | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/s390/include/asm/seccomp.h +0 -0
index 795bbe0d7ca6..71d46f0ba97b 100644
@@ -16,4 +16,13 @@
 
 #include <asm-generic/seccomp.h>

arch/s390/include/asm/seccomp.h line 27

Quoted 10 lines
arch/s390/include/asm/seccomp.h +9 -0
 
+#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
+