fix(runner): load the seccomp policy on amd64 and make the A16 bombs deterministic

This commit is contained in:
shira committed 2026-10-11 09:44:45 +03:00
1 parent e858280d91
commit 1ebd23693e
8 files changed
+68 -24

No files matched your search

+7 -14
View File
@@ -1,7 +1,6 @@
package sandbox
import (
"runtime"
"strconv"
"strings"
)
@@ -20,7 +19,9 @@ const (
// never needs them; they open kernel attack surface or would let the program
// observe or change the jail: debugging other processes, mounts and
// namespaces, keyrings, eBPF, perf, userfaultfd, io_uring, kernel modules,
// and host clock, name, and swap administration.
// and host clock, name, and swap administration. Kafel names umount2 (166 on
// amd64, 39 on arm64) "umount" on both architectures and rejects the name
// umount2, so "umount" kills the only unmount syscall these kernels have.
var killedSyscalls = []string{
"acct", "add_key", "adjtimex", "bpf", "chroot", "clock_settime",
"delete_module", "finit_module", "fsconfig", "fsmount", "fsopen", "fspick",
@@ -30,10 +31,11 @@ var killedSyscalls = []string{
"perf_event_open", "pivot_root", "process_vm_readv", "process_vm_writev",
"ptrace", "quotactl", "reboot", "request_key", "sethostname",
"setdomainname", "setns", "settimeofday", "swapoff", "swapon", "syslog",
"unshare", "userfaultfd",
"umount", "unshare", "userfaultfd",
}
// seccompPolicy returns the kafel policy for the build architecture.
// seccompPolicy returns the kafel policy; nsjail compiles it for the
// architecture it runs on.
//
// It is a deny list on top of the namespaces, the dropped capabilities, and
// no_new_privs: the program keeps the syscalls an interpreter or a compiled
@@ -41,22 +43,13 @@ var killedSyscalls = []string{
// reported as missing so that libc falls back to the filtered clone, and
// sockets other than AF_UNIX fail with EAFNOSUPPORT.
func seccompPolicy() string {
killed := append([]string{umountSyscall()}, killedSyscalls...)
var policy strings.Builder
policy.WriteString("POLICY runner {\n")
policy.WriteString(" KILL_PROCESS {\n ")
policy.WriteString(strings.Join(killed, ",\n "))
policy.WriteString(strings.Join(killedSyscalls, ",\n "))
policy.WriteString(",\n clone(flags) { (flags & " + cloneNamespaceFlags + ") != 0 }\n },\n")
policy.WriteString(" ERRNO(" + errnoENOSYS + ") { clone3 },\n")
policy.WriteString(" ERRNO(" + errnoEAFNOSUPPORT + ") { socket(domain) { domain != " + strconv.Itoa(afUnix) + " } }\n")
policy.WriteString("}\nUSE runner DEFAULT ALLOW\n")
return policy.String()
}
// umountSyscall returns the kafel name of umount2 for the architecture.
func umountSyscall() string {
if runtime.GOARCH == "arm64" {
return "umount"
}
return "umount2"
}