feat(runner): add the own code runner contract, client and nsjail service
This commit is contained in:
1 parent
5e1db37746
commit
cdf6bcbb91
109 files changed
+24084
-28
No files matched your search
+91
@@ -0,0 +1,91 @@
|
||||
{
|
||||
"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.",
|
||||
"default_limits": {
|
||||
"time_limit_ms": 1000,
|
||||
"memory_limit_mb": 64,
|
||||
"output_limit_kb": 64
|
||||
},
|
||||
"cases": [
|
||||
{
|
||||
"name": "correct_sum",
|
||||
"language": "python3",
|
||||
"source": "python/sum_correct.py",
|
||||
"input": "1 2 3\n",
|
||||
"expected_output": "6\n",
|
||||
"expect": {"outcome": "accepted", "limit": ""}
|
||||
},
|
||||
{
|
||||
"name": "syntax_error",
|
||||
"language": "python3",
|
||||
"source": "python/syntax_error.py",
|
||||
"input": "",
|
||||
"expected_output": "",
|
||||
"expect": {"outcome": "compile_error", "limit": ""}
|
||||
},
|
||||
{
|
||||
"name": "infinite_loop",
|
||||
"language": "python3",
|
||||
"source": "python/infinite_loop.py",
|
||||
"input": "",
|
||||
"expected_output": "",
|
||||
"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",
|
||||
"language": "python3",
|
||||
"source": "python/network_probe.py",
|
||||
"input": "",
|
||||
"expected_output": "blocked\n",
|
||||
"expect": {"outcome": "accepted", "limit": ""}
|
||||
},
|
||||
{
|
||||
"name": "filesystem_probe",
|
||||
"language": "python3",
|
||||
"source": "python/filesystem_probe.py",
|
||||
"input": "",
|
||||
"expected_output": "isolated\n",
|
||||
"expect": {"outcome": "accepted", "limit": ""}
|
||||
},
|
||||
{
|
||||
"name": "privilege_probe",
|
||||
"language": "python3",
|
||||
"source": "python/privilege_probe.py",
|
||||
"input": "",
|
||||
"expected_output": "unprivileged\n",
|
||||
"expect": {"outcome": "accepted", "limit": ""}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
# Isolation probe: the root file system and the source are read-only, the
|
||||
# scratch directory is writable, and runner files are not visible.
|
||||
import os
|
||||
|
||||
writable = []
|
||||
for path in ("/box/injected", "/usr/injected", "/injected", "/lib/injected"):
|
||||
try:
|
||||
with open(path, "w") as stream:
|
||||
stream.write("x")
|
||||
writable.append(path)
|
||||
except OSError:
|
||||
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))
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
# Fork bomb that ignores refused forks: the cgroup process limit must stop it.
|
||||
import os
|
||||
|
||||
while True:
|
||||
try:
|
||||
os.fork()
|
||||
except OSError:
|
||||
pass
|
||||
@@ -0,0 +1,6 @@
|
||||
# Endless standard output: the output limit must stop it.
|
||||
import sys
|
||||
|
||||
block = "x" * 65536
|
||||
while True:
|
||||
sys.stdout.write(block)
|
||||
@@ -0,0 +1,3 @@
|
||||
# Busy loop: the CPU time limit must stop it.
|
||||
while True:
|
||||
pass
|
||||
@@ -0,0 +1,4 @@
|
||||
# Unbounded allocation of touched memory: the cgroup memory limit must stop it.
|
||||
chunks = []
|
||||
while True:
|
||||
chunks.append(b"x" * (1 << 20))
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
# Isolation probe: every attempt to reach a network must fail.
|
||||
import socket
|
||||
|
||||
attempts = [
|
||||
(socket.AF_INET, ("1.1.1.1", 53)),
|
||||
(socket.AF_INET, ("127.0.0.1", 8080)),
|
||||
(socket.AF_INET6, ("::1", 8080)),
|
||||
]
|
||||
reached = []
|
||||
for family, address in attempts:
|
||||
try:
|
||||
with socket.socket(family, socket.SOCK_STREAM) as connection:
|
||||
connection.settimeout(1)
|
||||
connection.connect(address)
|
||||
reached.append(address[0])
|
||||
except OSError:
|
||||
pass
|
||||
print("blocked" if not reached else "reached " + " ".join(reached))
|
||||
@@ -0,0 +1,19 @@
|
||||
# Isolation probe: the program is an unprivileged user that cannot become
|
||||
# root or take ownership for root.
|
||||
import os
|
||||
|
||||
checks = [os.getuid() != 0, os.geteuid() != 0, os.getgid() != 0, os.getegid() != 0]
|
||||
for attempt in (lambda: os.setuid(0), lambda: os.setgid(0)):
|
||||
try:
|
||||
attempt()
|
||||
checks.append(False)
|
||||
except OSError:
|
||||
checks.append(True)
|
||||
with open("/tmp/owned", "w"):
|
||||
pass
|
||||
try:
|
||||
os.chown("/tmp/owned", 0, 0)
|
||||
checks.append(False)
|
||||
except OSError:
|
||||
checks.append(True)
|
||||
print("unprivileged" if all(checks) else "privileged")
|
||||
@@ -0,0 +1,4 @@
|
||||
# Idle wait: it uses no CPU, so only the wall-clock limit can stop it.
|
||||
import time
|
||||
|
||||
time.sleep(3600)
|
||||
@@ -0,0 +1,4 @@
|
||||
# Correct solution: prints the sum of the integers on standard input.
|
||||
import sys
|
||||
|
||||
print(sum(int(token) for token in sys.stdin.read().split()))
|
||||
@@ -0,0 +1,3 @@
|
||||
# Syntax error: the syntax check must reject it before any test runs.
|
||||
def broken(:
|
||||
return 1
|
||||
Reference in new issue
Block a user