Skip to content

Commit 1bac899

Browse files
committed
add conditional directives to the sandbox initializer to improve architecture awareness
1 parent 63e4391 commit 1bac899

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

executor/sandbox_init.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,32 @@ const sandboxInitSource = `#define _GNU_SOURCE
8484
#define AUDIT_ARCH_X86_64 0xC000003E
8585
#endif
8686
87+
#ifndef AUDIT_ARCH_AARCH64
88+
#define AUDIT_ARCH_AARCH64 0xC00000B7
89+
#endif
90+
91+
#ifndef AUDIT_ARCH_ARM
92+
#define AUDIT_ARCH_ARM 0x40000028
93+
#endif
94+
95+
#if defined(__x86_64__)
96+
#define SANDBOX_AUDIT_ARCH AUDIT_ARCH_X86_64
97+
#elif defined(__aarch64__)
98+
#define SANDBOX_AUDIT_ARCH AUDIT_ARCH_AARCH64
99+
#elif defined(__arm__)
100+
#define SANDBOX_AUDIT_ARCH AUDIT_ARCH_ARM
101+
#else
102+
#error "unsupported architecture for seccomp filter"
103+
#endif
104+
87105
#define DENY_SYSCALL(syscall_nr) \
88106
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, syscall_nr, 0, 1), \
89107
BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ERRNO | (EPERM & SECCOMP_RET_DATA))
90108
91109
static int install_seccomp_filter(void) {
92110
struct sock_filter filter[] = {
93111
BPF_STMT(BPF_LD | BPF_W | BPF_ABS, (unsigned int)offsetof(struct seccomp_data, arch)),
94-
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, AUDIT_ARCH_X86_64, 1, 0),
112+
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SANDBOX_AUDIT_ARCH, 1, 0),
95113
BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS),
96114
BPF_STMT(BPF_LD | BPF_W | BPF_ABS, (unsigned int)offsetof(struct seccomp_data, nr)),
97115
#ifdef __NR_mount

0 commit comments

Comments
 (0)