commit 59b0373338b3be33e9d219bbe85eed4a14464671
parent b063095ca31191935a4bb9a61d60c0bd100a5e47
Author: Frederic Cambus <fred@statdns.com>
Date: Tue, 23 Jun 2020 21:55:58 +0200
Validate architectures for seccomp.
Seccomp support has only been tested on amd64 and aarch64 architectures.
Diffstat:
1 file changed, 14 insertions(+), 0 deletions(-)
diff --git a/src/seccomp.h b/src/seccomp.h
@@ -21,11 +21,25 @@
#include <linux/filter.h>
#include <linux/seccomp.h>
+#if defined(__x86_64__)
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_X86_64
+#elif defined(__aarch64__)
+#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_AARCH64
+#else
+#error "Seccomp is only supported on amd64 and aarch64 architectures."
+#endif
+
#define ANSILOVE_SYSCALL_ALLOW(syscall) \
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, __NR_##syscall, 0, 1), \
BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_ALLOW)
static struct sock_filter filter[] = {
+ /* Validate architecture */
+ BPF_STMT(BPF_LD+BPF_W+BPF_ABS, offsetof(struct seccomp_data, arch)),
+ BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, SECCOMP_AUDIT_ARCH, 1, 0),
+ BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_KILL),
+
+ /* Load syscall */
BPF_STMT(BPF_LD+BPF_W+BPF_ABS, offsetof(struct seccomp_data, nr)),
ANSILOVE_SYSCALL_ALLOW(brk),