test(runner): verify sandbox isolation with a hostile program suite
This commit is contained in:
1 parent
afee564bf4
commit
e858280d91
38 files changed
+1359
-168
No files matched your search
+46
@@ -0,0 +1,46 @@
|
||||
// Disk exhaustion: the file size limit and the scratch tmpfs refuse writes.
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
block := make([]byte, 1<<20)
|
||||
refused := 0
|
||||
if file, err := os.Create("/tmp/one-big-file"); err == nil {
|
||||
for range 64 {
|
||||
if _, err := file.Write(block); err != nil {
|
||||
refused++
|
||||
break
|
||||
}
|
||||
}
|
||||
_ = file.Close()
|
||||
_ = os.Remove("/tmp/one-big-file")
|
||||
}
|
||||
for index := range 64 {
|
||||
file, err := os.Create(fmt.Sprintf("/tmp/part-%d", index))
|
||||
if err != nil {
|
||||
refused++
|
||||
break
|
||||
}
|
||||
failed := false
|
||||
for range 4 {
|
||||
if _, err := file.Write(block); err != nil {
|
||||
failed = true
|
||||
break
|
||||
}
|
||||
}
|
||||
_ = file.Close()
|
||||
if failed {
|
||||
refused++
|
||||
break
|
||||
}
|
||||
}
|
||||
if refused == 2 {
|
||||
fmt.Println("refused")
|
||||
return
|
||||
}
|
||||
fmt.Println("wrote everything")
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
// Isolation probe: read-only root, source, and build output; a writable
|
||||
// scratch directory only; no host, runner, secret, or process files; no
|
||||
// secret in the environment.
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var writable, visible, leaked []string
|
||||
for _, path := range []string{"/box/injected", "/out/injected", "/usr/injected", "/injected", "/lib/injected"} {
|
||||
if err := os.WriteFile(path, []byte("x"), 0o600); err == nil {
|
||||
writable = append(writable, path)
|
||||
}
|
||||
}
|
||||
if err := os.WriteFile("/tmp/scratch", []byte("ok"), 0o600); err != nil {
|
||||
fmt.Println("scratch not writable:", err)
|
||||
return
|
||||
}
|
||||
for _, path := range []string{
|
||||
"/etc/passwd", "/etc/shadow", "/run/secrets", "/run/secrets/runner_api_token", "/opt/lincodex-runner",
|
||||
"/var/lib/lincodex-runner", "/proc/1", "/proc/self/environ", "/proc/self/mounts", "/sys/fs/cgroup",
|
||||
"/dev/mem", "/dev/kmsg", "/root", "/home",
|
||||
} {
|
||||
if _, err := os.Lstat(path); err == nil {
|
||||
visible = append(visible, path)
|
||||
}
|
||||
}
|
||||
for _, variable := range os.Environ() {
|
||||
name, _, _ := strings.Cut(variable, "=")
|
||||
if strings.Contains(name, "RUNNER") || strings.Contains(name, "TOKEN") || strings.Contains(name, "SECRET") {
|
||||
leaked = append(leaked, name)
|
||||
}
|
||||
}
|
||||
if len(writable)+len(visible)+len(leaked) == 0 {
|
||||
fmt.Println("isolated")
|
||||
return
|
||||
}
|
||||
fmt.Println("writable", writable, "visible", visible, "env", leaked)
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// Process bomb: every copy starts more copies and ignores failures; the
|
||||
// cgroup process limit must stop it.
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
func main() {
|
||||
for {
|
||||
_ = exec.Command(os.Args[0]).Start()
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// Endless standard output: the output limit must stop it.
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
block := bytes.Repeat([]byte("x"), 65536)
|
||||
for {
|
||||
_, _ = os.Stdout.Write(block)
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// Timeout survival: ignores every catchable signal and spins; only SIGKILL
|
||||
// from the supervisor stops it.
|
||||
package main
|
||||
|
||||
import (
|
||||
"os/signal"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func main() {
|
||||
signal.Ignore(syscall.SIGTERM, syscall.SIGINT, syscall.SIGHUP, syscall.SIGXCPU, syscall.SIGALRM, syscall.SIGUSR1)
|
||||
for {
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// Unbounded allocation of touched memory: the cgroup memory limit must stop it.
|
||||
package main
|
||||
|
||||
func main() {
|
||||
var chunks [][]byte
|
||||
for {
|
||||
chunk := make([]byte, 1<<20)
|
||||
for index := range chunk {
|
||||
chunk[index] = 1
|
||||
}
|
||||
chunks = append(chunks, chunk)
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// Escape attempt: mounting a fresh procfs is killed by the seccomp policy.
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func main() {
|
||||
_ = os.MkdirAll("/tmp/proc", 0o700)
|
||||
err := syscall.Mount("proc", "/tmp/proc", "proc", 0, "")
|
||||
fmt.Println("mount returned", err)
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
// Isolation probe: TCP, UDP, listening, name resolution, and raw, packet,
|
||||
// and netlink sockets must all fail.
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var reached []string
|
||||
for _, target := range []struct{ network, address string }{
|
||||
{"tcp", "1.1.1.1:53"}, {"tcp", "127.0.0.1:8443"}, {"tcp6", "[::1]:8443"}, {"udp", "8.8.8.8:53"},
|
||||
} {
|
||||
connection, err := net.DialTimeout(target.network, target.address, time.Second)
|
||||
if err == nil {
|
||||
// UDP "connects" without traffic; a write proves the route.
|
||||
if _, writeErr := connection.Write([]byte("x")); writeErr == nil {
|
||||
reached = append(reached, target.address)
|
||||
}
|
||||
_ = connection.Close()
|
||||
}
|
||||
}
|
||||
if listener, err := net.Listen("tcp", "127.0.0.1:0"); err == nil {
|
||||
reached = append(reached, "listen")
|
||||
_ = listener.Close()
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
defer cancel()
|
||||
if _, err := net.DefaultResolver.LookupHost(ctx, "example.com"); err == nil {
|
||||
reached = append(reached, "dns")
|
||||
}
|
||||
for _, socket := range []struct{ domain, kind, protocol int }{
|
||||
{syscall.AF_INET, syscall.SOCK_RAW, syscall.IPPROTO_ICMP},
|
||||
{syscall.AF_PACKET, syscall.SOCK_RAW, 0},
|
||||
{syscall.AF_NETLINK, syscall.SOCK_RAW, 0},
|
||||
} {
|
||||
if fd, err := syscall.Socket(socket.domain, socket.kind, socket.protocol); err == nil {
|
||||
reached = append(reached, fmt.Sprintf("socket %d", socket.domain))
|
||||
_ = syscall.Close(fd)
|
||||
}
|
||||
}
|
||||
if len(reached) == 0 {
|
||||
fmt.Println("blocked")
|
||||
return
|
||||
}
|
||||
fmt.Println("reached " + strings.Join(reached, ", "))
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// Timeout survival: a child in its own session outlives the parent; the PID
|
||||
// namespace must take it down with the run.
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) > 1 {
|
||||
time.Sleep(time.Hour)
|
||||
return
|
||||
}
|
||||
child := exec.Command(os.Args[0], "daemon")
|
||||
child.SysProcAttr = &syscall.SysProcAttr{Setsid: true}
|
||||
if err := child.Start(); err != nil {
|
||||
fmt.Println("start failed:", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("parent done")
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// Isolation probe: the program is not root and cannot become root, change
|
||||
// ownership to root, or raise its limits.
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ok := os.Getuid() != 0 && os.Geteuid() != 0 && os.Getgid() != 0 && os.Getegid() != 0
|
||||
ok = ok && syscall.Setuid(0) != nil && syscall.Setgid(0) != nil
|
||||
if err := os.WriteFile("/tmp/owned", nil, 0o600); err == nil {
|
||||
ok = ok && os.Chown("/tmp/owned", 0, 0) != nil
|
||||
}
|
||||
limit := syscall.Rlimit{Cur: 1 << 40, Max: 1 << 40}
|
||||
ok = ok && syscall.Setrlimit(syscall.RLIMIT_NOFILE, &limit) != nil
|
||||
if ok {
|
||||
fmt.Println("unprivileged")
|
||||
return
|
||||
}
|
||||
fmt.Println("privileged")
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// Escape attempt: ptrace is killed by the seccomp policy (SIGSYS).
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func main() {
|
||||
err := syscall.PtraceAttach(1)
|
||||
fmt.Println("ptrace returned", err)
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// Idle wait: it uses no CPU, so only the wall-clock limit can stop it.
|
||||
package main
|
||||
|
||||
import "time"
|
||||
|
||||
func main() {
|
||||
time.Sleep(time.Hour)
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// Correct solution: prints the sum of the integers on standard input.
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
scanner := bufio.NewScanner(os.Stdin)
|
||||
scanner.Split(bufio.ScanWords)
|
||||
total := 0
|
||||
for scanner.Scan() {
|
||||
value, err := strconv.Atoi(scanner.Text())
|
||||
if err != nil {
|
||||
os.Exit(2)
|
||||
}
|
||||
total += value
|
||||
}
|
||||
fmt.Println(total)
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// Thread bomb: goroutines blocked in system calls force the runtime to
|
||||
// create threads; the cgroup process limit must stop it.
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var fds [2]int
|
||||
if err := syscall.Pipe(fds[:]); err != nil {
|
||||
os.Exit(2)
|
||||
}
|
||||
for {
|
||||
go func() {
|
||||
buffer := make([]byte, 1)
|
||||
_, _ = syscall.Read(fds[0], buffer)
|
||||
}()
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// Escape attempt: unshare into a new user namespace is killed by the
|
||||
// seccomp policy.
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func main() {
|
||||
err := syscall.Unshare(syscall.CLONE_NEWUSER)
|
||||
fmt.Println("unshare returned", err)
|
||||
}
|
||||
+356
-46
@@ -1,91 +1,401 @@
|
||||
{
|
||||
"schema": "lincodex.runner-hostile-fixtures/v1",
|
||||
"description": "Programs that a sandbox run must stop or contain. Each case runs as one public group with one test; expect.limit is the termination limit, or empty when the program ends by itself.",
|
||||
"schema": "lincodex.runner-hostile-fixtures/v2",
|
||||
"description": "A16 hostile-program suite. Every case runs as one public group with one test under default_limits. expect.limit is the termination limit or empty when the program ends by itself; expect.signal, when present, is the signal that must stop it (31 is SIGSYS from the seccomp policy). Probe programs print one word when every attempt was refused.",
|
||||
"default_limits": {
|
||||
"time_limit_ms": 1000,
|
||||
"memory_limit_mb": 64,
|
||||
"output_limit_kb": 64
|
||||
},
|
||||
"categories": {
|
||||
"baseline": "A correct program still works, and a syntax error stops before any test.",
|
||||
"network": "TCP, UDP, listening, DNS, raw, packet, and netlink sockets are refused.",
|
||||
"files_and_secrets": "Host files, runner files, the API token, procfs, sysfs, and secret environment variables are invisible; root, source, and build output are read-only.",
|
||||
"privileges": "The program is not root and cannot setuid, setgid, chown to root, or raise rlimits.",
|
||||
"escape": "ptrace, mount (including a fresh procfs), and unshare are killed by seccomp.",
|
||||
"processes": "Fork and thread bombs are stopped by the cgroup process limit.",
|
||||
"memory": "Memory exhaustion is stopped by the cgroup memory limit.",
|
||||
"disk": "Disk exhaustion is refused by the file size limit and the scratch tmpfs size.",
|
||||
"output": "Endless output is stopped by the output limit.",
|
||||
"timeout": "Busy loops, ignored signals, idle waits, and detached daemons do not outlive the time limits or the run."
|
||||
},
|
||||
"cases": [
|
||||
{
|
||||
"name": "correct_sum",
|
||||
"name": "py_correct_sum",
|
||||
"category": "baseline",
|
||||
"language": "python3",
|
||||
"source": "python/sum_correct.py",
|
||||
"input": "1 2 3\n",
|
||||
"expected_output": "6\n",
|
||||
"expect": {"outcome": "accepted", "limit": ""}
|
||||
"expect": {
|
||||
"outcome": "accepted",
|
||||
"limit": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "syntax_error",
|
||||
"name": "py_syntax_error",
|
||||
"category": "baseline",
|
||||
"language": "python3",
|
||||
"source": "python/syntax_error.py",
|
||||
"input": "",
|
||||
"expected_output": "",
|
||||
"expect": {"outcome": "compile_error", "limit": ""}
|
||||
"expect": {
|
||||
"outcome": "compile_error",
|
||||
"limit": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "infinite_loop",
|
||||
"name": "py_infinite_loop",
|
||||
"category": "timeout",
|
||||
"language": "python3",
|
||||
"source": "python/infinite_loop.py",
|
||||
"input": "",
|
||||
"expected_output": "",
|
||||
"expect": {"outcome": "time_limit_exceeded", "limit": "cpu_time"}
|
||||
"expect": {
|
||||
"outcome": "time_limit_exceeded",
|
||||
"limit": "cpu_time"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "sleep_forever",
|
||||
"language": "python3",
|
||||
"source": "python/sleep_forever.py",
|
||||
"input": "",
|
||||
"expected_output": "",
|
||||
"expect": {"outcome": "time_limit_exceeded", "limit": "wall_time"}
|
||||
},
|
||||
{
|
||||
"name": "memory_leak",
|
||||
"language": "python3",
|
||||
"source": "python/memory_leak.py",
|
||||
"input": "",
|
||||
"expected_output": "",
|
||||
"expect": {"outcome": "memory_limit_exceeded", "limit": "memory"}
|
||||
},
|
||||
{
|
||||
"name": "huge_output",
|
||||
"language": "python3",
|
||||
"source": "python/huge_output.py",
|
||||
"input": "",
|
||||
"expected_output": "",
|
||||
"expect": {"outcome": "output_limit_exceeded", "limit": "output"}
|
||||
},
|
||||
{
|
||||
"name": "fork_bomb",
|
||||
"language": "python3",
|
||||
"source": "python/fork_bomb.py",
|
||||
"input": "",
|
||||
"expected_output": "",
|
||||
"expect": {"outcome": "runtime_error", "limit": "processes"}
|
||||
},
|
||||
{
|
||||
"name": "network_probe",
|
||||
"name": "py_network",
|
||||
"category": "network",
|
||||
"language": "python3",
|
||||
"source": "python/network_probe.py",
|
||||
"input": "",
|
||||
"expected_output": "blocked\n",
|
||||
"expect": {"outcome": "accepted", "limit": ""}
|
||||
"expect": {
|
||||
"outcome": "accepted",
|
||||
"limit": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "filesystem_probe",
|
||||
"name": "py_files_and_secrets",
|
||||
"category": "files_and_secrets",
|
||||
"language": "python3",
|
||||
"source": "python/filesystem_probe.py",
|
||||
"input": "",
|
||||
"expected_output": "isolated\n",
|
||||
"expect": {"outcome": "accepted", "limit": ""}
|
||||
"expect": {
|
||||
"outcome": "accepted",
|
||||
"limit": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "privilege_probe",
|
||||
"name": "py_privileges",
|
||||
"category": "privileges",
|
||||
"language": "python3",
|
||||
"source": "python/privilege_probe.py",
|
||||
"input": "",
|
||||
"expected_output": "unprivileged\n",
|
||||
"expect": {"outcome": "accepted", "limit": ""}
|
||||
"expect": {
|
||||
"outcome": "accepted",
|
||||
"limit": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "py_ptrace",
|
||||
"category": "escape",
|
||||
"language": "python3",
|
||||
"source": "python/ptrace_attach.py",
|
||||
"input": "",
|
||||
"expected_output": "",
|
||||
"expect": {
|
||||
"outcome": "runtime_error",
|
||||
"limit": "",
|
||||
"signal": 31
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "py_mount_proc",
|
||||
"category": "escape",
|
||||
"language": "python3",
|
||||
"source": "python/mount_proc.py",
|
||||
"input": "",
|
||||
"expected_output": "",
|
||||
"expect": {
|
||||
"outcome": "runtime_error",
|
||||
"limit": "",
|
||||
"signal": 31
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "py_unshare_user",
|
||||
"category": "escape",
|
||||
"language": "python3",
|
||||
"source": "python/unshare_user.py",
|
||||
"input": "",
|
||||
"expected_output": "",
|
||||
"expect": {
|
||||
"outcome": "runtime_error",
|
||||
"limit": "",
|
||||
"signal": 31
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "py_fork_bomb",
|
||||
"category": "processes",
|
||||
"language": "python3",
|
||||
"source": "python/fork_bomb.py",
|
||||
"input": "",
|
||||
"expected_output": "",
|
||||
"expect": {
|
||||
"outcome": "runtime_error",
|
||||
"limit": "processes"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "py_memory_leak",
|
||||
"category": "memory",
|
||||
"language": "python3",
|
||||
"source": "python/memory_leak.py",
|
||||
"input": "",
|
||||
"expected_output": "",
|
||||
"expect": {
|
||||
"outcome": "memory_limit_exceeded",
|
||||
"limit": "memory"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "py_disk_fill",
|
||||
"category": "disk",
|
||||
"language": "python3",
|
||||
"source": "python/disk_fill.py",
|
||||
"input": "",
|
||||
"expected_output": "refused\n",
|
||||
"expect": {
|
||||
"outcome": "accepted",
|
||||
"limit": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "py_huge_output",
|
||||
"category": "output",
|
||||
"language": "python3",
|
||||
"source": "python/huge_output.py",
|
||||
"input": "",
|
||||
"expected_output": "",
|
||||
"expect": {
|
||||
"outcome": "output_limit_exceeded",
|
||||
"limit": "output"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "py_ignore_signals",
|
||||
"category": "timeout",
|
||||
"language": "python3",
|
||||
"source": "python/ignore_signals.py",
|
||||
"input": "",
|
||||
"expected_output": "",
|
||||
"expect": {
|
||||
"outcome": "time_limit_exceeded",
|
||||
"limit": "cpu_time"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "py_sleep_forever",
|
||||
"category": "timeout",
|
||||
"language": "python3",
|
||||
"source": "python/sleep_forever.py",
|
||||
"input": "",
|
||||
"expected_output": "",
|
||||
"expect": {
|
||||
"outcome": "time_limit_exceeded",
|
||||
"limit": "wall_time"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "py_orphan_daemon",
|
||||
"category": "timeout",
|
||||
"language": "python3",
|
||||
"source": "python/orphan_daemon.py",
|
||||
"input": "",
|
||||
"expected_output": "parent done\n",
|
||||
"expect": {
|
||||
"outcome": "accepted",
|
||||
"limit": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "go_correct_sum",
|
||||
"category": "baseline",
|
||||
"language": "go",
|
||||
"source": "go/sum_correct.go",
|
||||
"input": "1 2 3\n",
|
||||
"expected_output": "6\n",
|
||||
"expect": {
|
||||
"outcome": "accepted",
|
||||
"limit": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "go_network",
|
||||
"category": "network",
|
||||
"language": "go",
|
||||
"source": "go/network_probe.go",
|
||||
"input": "",
|
||||
"expected_output": "blocked\n",
|
||||
"expect": {
|
||||
"outcome": "accepted",
|
||||
"limit": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "go_files_and_secrets",
|
||||
"category": "files_and_secrets",
|
||||
"language": "go",
|
||||
"source": "go/filesystem_probe.go",
|
||||
"input": "",
|
||||
"expected_output": "isolated\n",
|
||||
"expect": {
|
||||
"outcome": "accepted",
|
||||
"limit": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "go_privileges",
|
||||
"category": "privileges",
|
||||
"language": "go",
|
||||
"source": "go/privilege_probe.go",
|
||||
"input": "",
|
||||
"expected_output": "unprivileged\n",
|
||||
"expect": {
|
||||
"outcome": "accepted",
|
||||
"limit": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "go_ptrace",
|
||||
"category": "escape",
|
||||
"language": "go",
|
||||
"source": "go/ptrace_attach.go",
|
||||
"input": "",
|
||||
"expected_output": "",
|
||||
"expect": {
|
||||
"outcome": "runtime_error",
|
||||
"limit": "",
|
||||
"signal": 31
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "go_mount_proc",
|
||||
"category": "escape",
|
||||
"language": "go",
|
||||
"source": "go/mount_proc.go",
|
||||
"input": "",
|
||||
"expected_output": "",
|
||||
"expect": {
|
||||
"outcome": "runtime_error",
|
||||
"limit": "",
|
||||
"signal": 31
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "go_unshare_user",
|
||||
"category": "escape",
|
||||
"language": "go",
|
||||
"source": "go/unshare_user.go",
|
||||
"input": "",
|
||||
"expected_output": "",
|
||||
"expect": {
|
||||
"outcome": "runtime_error",
|
||||
"limit": "",
|
||||
"signal": 31
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "go_fork_bomb",
|
||||
"category": "processes",
|
||||
"language": "go",
|
||||
"source": "go/fork_bomb.go",
|
||||
"input": "",
|
||||
"expected_output": "",
|
||||
"expect": {
|
||||
"outcome": "runtime_error",
|
||||
"limit": "processes"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "go_memory_leak",
|
||||
"category": "memory",
|
||||
"language": "go",
|
||||
"source": "go/memory_leak.go",
|
||||
"input": "",
|
||||
"expected_output": "",
|
||||
"expect": {
|
||||
"outcome": "memory_limit_exceeded",
|
||||
"limit": "memory"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "go_disk_fill",
|
||||
"category": "disk",
|
||||
"language": "go",
|
||||
"source": "go/disk_fill.go",
|
||||
"input": "",
|
||||
"expected_output": "refused\n",
|
||||
"expect": {
|
||||
"outcome": "accepted",
|
||||
"limit": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "go_huge_output",
|
||||
"category": "output",
|
||||
"language": "go",
|
||||
"source": "go/huge_output.go",
|
||||
"input": "",
|
||||
"expected_output": "",
|
||||
"expect": {
|
||||
"outcome": "output_limit_exceeded",
|
||||
"limit": "output"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "go_ignore_signals",
|
||||
"category": "timeout",
|
||||
"language": "go",
|
||||
"source": "go/ignore_signals.go",
|
||||
"input": "",
|
||||
"expected_output": "",
|
||||
"expect": {
|
||||
"outcome": "time_limit_exceeded",
|
||||
"limit": "cpu_time"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "go_sleep_forever",
|
||||
"category": "timeout",
|
||||
"language": "go",
|
||||
"source": "go/sleep_forever.go",
|
||||
"input": "",
|
||||
"expected_output": "",
|
||||
"expect": {
|
||||
"outcome": "time_limit_exceeded",
|
||||
"limit": "wall_time"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "go_orphan_daemon",
|
||||
"category": "timeout",
|
||||
"language": "go",
|
||||
"source": "go/orphan_daemon.go",
|
||||
"input": "",
|
||||
"expected_output": "parent done\n",
|
||||
"expect": {
|
||||
"outcome": "accepted",
|
||||
"limit": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "go_thread_bomb",
|
||||
"category": "processes",
|
||||
"language": "go",
|
||||
"source": "go/thread_bomb.go",
|
||||
"input": "",
|
||||
"expected_output": "",
|
||||
"expect": {
|
||||
"outcome": "runtime_error",
|
||||
"limit": "processes"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
# Disk exhaustion: the scratch tmpfs and the file size limit refuse writes
|
||||
# long before the host is affected.
|
||||
import os
|
||||
|
||||
block = b"x" * (1 << 20)
|
||||
refused = []
|
||||
try:
|
||||
with open("/tmp/one-big-file", "wb") as stream:
|
||||
for _ in range(64):
|
||||
stream.write(block)
|
||||
stream.flush()
|
||||
except OSError as error:
|
||||
refused.append("file:" + os.strerror(error.errno))
|
||||
os.remove("/tmp/one-big-file")
|
||||
try:
|
||||
for index in range(64):
|
||||
with open(f"/tmp/part-{index}", "wb") as stream:
|
||||
for _ in range(4):
|
||||
stream.write(block)
|
||||
except OSError as error:
|
||||
refused.append("tmpfs:" + os.strerror(error.errno))
|
||||
print("refused" if len(refused) == 2 else f"wrote everything {refused}")
|
||||
+13
-5
@@ -1,9 +1,11 @@
|
||||
# Isolation probe: the root file system and the source are read-only, the
|
||||
# scratch directory is writable, and runner files are not visible.
|
||||
# Isolation probe: the root, the source, and the build output are read-only,
|
||||
# only the scratch directory is writable, and no host file, runner file,
|
||||
# secret, or process information is visible, neither on disk nor in the
|
||||
# environment.
|
||||
import os
|
||||
|
||||
writable = []
|
||||
for path in ("/box/injected", "/usr/injected", "/injected", "/lib/injected"):
|
||||
for path in ("/box/injected", "/out/injected", "/usr/injected", "/injected", "/lib/injected"):
|
||||
try:
|
||||
with open(path, "w") as stream:
|
||||
stream.write("x")
|
||||
@@ -12,5 +14,11 @@ for path in ("/box/injected", "/usr/injected", "/injected", "/lib/injected"):
|
||||
pass
|
||||
with open("/tmp/scratch", "w") as stream:
|
||||
stream.write("ok")
|
||||
visible = [path for path in ("/etc/passwd", "/run/secrets", "/opt/lincodex-runner", "/proc/1") if os.path.exists(path)]
|
||||
print("isolated" if not writable and not visible else "writable=" + ",".join(writable) + " visible=" + ",".join(visible))
|
||||
hidden = (
|
||||
"/etc/passwd", "/etc/shadow", "/etc/hosts", "/run/secrets", "/run/secrets/runner_api_token",
|
||||
"/opt/lincodex-runner", "/var/lib/lincodex-runner", "/proc/1", "/proc/self/environ",
|
||||
"/proc/self/mounts", "/sys/fs/cgroup", "/dev/mem", "/dev/kmsg", "/root", "/home",
|
||||
)
|
||||
visible = [path for path in hidden if os.path.lexists(path)]
|
||||
leaked = [name for name in os.environ if "RUNNER" in name or "TOKEN" in name or "SECRET" in name]
|
||||
print("isolated" if not writable and not visible and not leaked else f"writable={writable} visible={visible} env={leaked}")
|
||||
@@ -0,0 +1,8 @@
|
||||
# Timeout survival: ignores every catchable signal and spins; only SIGKILL
|
||||
# from the supervisor stops it.
|
||||
import signal
|
||||
|
||||
for number in (signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGXCPU, signal.SIGALRM, signal.SIGUSR1):
|
||||
signal.signal(number, signal.SIG_IGN)
|
||||
while True:
|
||||
pass
|
||||
@@ -0,0 +1,8 @@
|
||||
# Escape attempt: mounting a fresh procfs is killed by the seccomp policy.
|
||||
import ctypes
|
||||
import os
|
||||
|
||||
os.makedirs("/tmp/proc", exist_ok=True)
|
||||
libc = ctypes.CDLL(None, use_errno=True)
|
||||
libc.mount(b"proc", b"/tmp/proc", b"proc", 0, None)
|
||||
print("mount returned")
|
||||
+18
-8
@@ -1,13 +1,11 @@
|
||||
# Isolation probe: every attempt to reach a network must fail.
|
||||
# Isolation probe: every attempt to reach or sniff a network must fail,
|
||||
# including raw, packet, and netlink sockets and name resolution.
|
||||
import socket
|
||||
|
||||
attempts = [
|
||||
(socket.AF_INET, ("1.1.1.1", 53)),
|
||||
(socket.AF_INET, ("127.0.0.1", 8080)),
|
||||
(socket.AF_INET6, ("::1", 8080)),
|
||||
]
|
||||
attempts = 0
|
||||
reached = []
|
||||
for family, address in attempts:
|
||||
for family, address in ((socket.AF_INET, ("1.1.1.1", 53)), (socket.AF_INET, ("127.0.0.1", 8443)), (socket.AF_INET6, ("::1", 8443))):
|
||||
attempts += 1
|
||||
try:
|
||||
with socket.socket(family, socket.SOCK_STREAM) as connection:
|
||||
connection.settimeout(1)
|
||||
@@ -15,4 +13,16 @@ for family, address in attempts:
|
||||
reached.append(address[0])
|
||||
except OSError:
|
||||
pass
|
||||
print("blocked" if not reached else "reached " + " ".join(reached))
|
||||
for family, kind, protocol in ((socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_ICMP), (getattr(socket, "AF_PACKET", 17), socket.SOCK_RAW, 0), (getattr(socket, "AF_NETLINK", 16), socket.SOCK_RAW, 0)):
|
||||
attempts += 1
|
||||
try:
|
||||
socket.socket(family, kind, protocol).close()
|
||||
reached.append(f"socket {family}/{kind}")
|
||||
except OSError:
|
||||
pass
|
||||
try:
|
||||
socket.getaddrinfo("example.com", 443)
|
||||
reached.append("dns")
|
||||
except OSError:
|
||||
pass
|
||||
print("blocked" if not reached else "reached " + ", ".join(reached))
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
# Timeout survival: a detached child in its own session outlives the
|
||||
# parent; the PID namespace must take it down with the run.
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
|
||||
if os.fork() == 0:
|
||||
os.setsid()
|
||||
if os.fork() == 0:
|
||||
time.sleep(3600)
|
||||
os._exit(0)
|
||||
print("parent done")
|
||||
sys.stdout.flush()
|
||||
@@ -0,0 +1,6 @@
|
||||
# Escape attempt: ptrace is killed by the seccomp policy (SIGSYS).
|
||||
import ctypes
|
||||
|
||||
libc = ctypes.CDLL(None, use_errno=True)
|
||||
libc.ptrace(0, 0, None, None)
|
||||
print("ptrace returned")
|
||||
@@ -0,0 +1,8 @@
|
||||
# Escape attempt: a new user namespace would give capabilities inside it;
|
||||
# unshare is killed by the seccomp policy.
|
||||
import ctypes
|
||||
|
||||
CLONE_NEWUSER = 0x10000000
|
||||
libc = ctypes.CDLL(None, use_errno=True)
|
||||
libc.unshare(CLONE_NEWUSER)
|
||||
print("unshare returned")
|
||||
Reference in new issue
Block a user