Files
faunosteo/crates/worker/scripts/derive-seccomp.sh
T
bchanot e967ce6736 test(worker): verify child at the input caps, brk bounded by the limits
Max frame (document and base 2 MiB, drawings 6 MiB) passes through the full
sandbox; refusals just beyond give caps verdicts; RLIMIT_AS and the argument
filters still stop the verify child; seccomp traced on the max input; the two
tracked misclassifications asserted as current behaviour.
2026-11-01 21:07:23 +01:00

58 lines
2.6 KiB
Bash
Executable File

#!/bin/sh
# Derives the seccomp allowlist of the decode and verify children from a real trace and
# checks it against `sandbox::ALLOWED_SYSCALLS` (review Part IV.1: "derived by strace over
# the fixture corpus at the caps on the production image, not hand-written"). Runs in the
# Alpine `test` stage of crates/worker/Dockerfile, where the musl binary that ships is built.
# The verify child (V1-2.3) shares the filter: its framed fixtures (a small sheet, the
# sheet at every cap and the input at the maximum: 2 MiB document and base, four drawings)
# are traced the same way.
#
# Exit 1 when a traced syscall is missing from the allowlist (the sandbox would kill a
# legitimate decode or verification). Syscalls the list allows but the trace never shows are
# printed for review (the abort path is expected there).
set -eu
bin=target/release/faunosteo-worker
cargo build -p faunosteo-worker --release --features test-hooks --locked
work=$(mktemp -d)
: > "$work/traced.raw"
# trace <command> <fixture>: one child run, the syscalls after the marker appended.
trace() {
"$bin" fixture "$2" > "$work/$2.bin"
# `env -i`: the child refuses a non-empty environment; `--no-seccomp` keeps the rlimits
# and makes one sched_yield where the filter would be installed (strace cannot read the
# child's memory once PR_SET_DUMPABLE is 0, so the marker is a syscall, not a string).
env -i strace -f -qq -o "$work/trace.$2" "$bin" "$1" --no-seccomp \
< "$work/$2.bin" > "$work/$2.out"
awk 'found { print } /sched_yield\(/ { found = 1 }' "$work/trace.$2" \
| sed -E 's/^[0-9]+ +//; /^(\+\+\+|---)/d; s/^<\.\.\. ([a-z0-9_]+) resumed>.*/\1/; s/\(.*//' \
| grep -E '^[a-z0-9_]+$' >> "$work/traced.raw" || true
}
for kind in png jpeg webp big-jpeg big-png; do
trace decode "$kind"
done
for kind in verify-clean verify-caps verify-max; do
trace verify "$kind"
done
sort -u "$work/traced.raw" > "$work/traced.txt"
"$bin" print-allowlist | sort -u > "$work/allowed.txt"
if [ ! -s "$work/traced.txt" ]; then
echo "== NO SYSCALL TRACED AFTER THE MARKER: the derivation is broken, not the allowlist" >&2
echo "== tail of the png trace:" >&2
tail -n 40 "$work/trace.png" >&2
exit 1
fi
echo "== syscalls traced after the sandbox marker"
cat "$work/traced.txt"
missing=$(comm -23 "$work/traced.txt" "$work/allowed.txt")
extra=$(comm -13 "$work/traced.txt" "$work/allowed.txt")
echo "== allowed but not traced (abort path expected): $(echo "$extra" | tr '\n' ' ')"
if [ -n "$missing" ]; then
echo "== TRACED BUT NOT ALLOWED (the filter would kill a legitimate decode or verification):"
echo "$missing"
exit 1
fi
echo "== allowlist covers the trace"