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.
This commit is contained in:
bchanot committed 2026-11-01 21:07:23 +01:00
1 parent a6de7d6b94
commit e967ce6736
5 files changed
+385 -3

No files matched your search

+108
View File
@@ -338,3 +338,111 @@ fn a_verify_output_over_its_cap_is_cut() {
run.outcome
);
}
// V1-2.3 reserve Q4: the `brk` the shared filter allows stays bounded in the verify child,
// under its own limits (1 GiB of address space).
#[test]
fn the_verify_child_aborts_on_a_huge_allocation() {
let run = verifier(&["--alloc-gib", "2"]).run(b"");
assert!(
matches!(run.outcome, ChildOutcome::Signalled { signal: SIGABRT }),
"{:?} {}",
run.outcome,
run.stderr
);
}
/// 2 GiB in 4 KiB chunks kept alive: the heap grows by `brk` first, then by `mmap`, and the
/// address-space limit stops it; the survival message of the hook never appears.
#[test]
fn the_verify_child_aborts_on_small_chunks_growth() {
let run = verifier(&["--alloc-small-gib", "2"]).run(b"");
assert!(
matches!(run.outcome, ChildOutcome::Signalled { signal: SIGABRT }),
"{:?} {}",
run.outcome,
run.stderr
);
assert!(!run.stderr.contains("kept"), "{}", run.stderr);
}
#[test]
fn an_executable_mapping_is_killed_in_the_verify_child() {
let run = verifier(&["--mmap-exec"]).run(b"");
assert!(
matches!(run.outcome, ChildOutcome::Signalled { signal: SIGSYS }),
"{:?} {}",
run.outcome,
run.stderr
);
}
#[test]
fn a_signal_to_the_parent_is_killed_in_the_verify_child() {
let run = verifier(&["--signal-parent"]).run(b"");
assert!(
matches!(run.outcome, ChildOutcome::Signalled { signal: SIGSYS }),
"{:?} {}",
run.outcome,
run.stderr
);
}
// V1-2.3 reserve Q3: inputs at and just beyond the caps, through the full sandbox.
#[test]
fn the_maximum_input_is_verified_within_the_limits() {
let frame = fixtures::verify_max_frame();
assert!(
frame.len() < limits::VERIFY_MAX_INPUT_BYTES,
"{}",
frame.len()
);
let started = std::time::Instant::now();
let run = verifier(&[]).run(&frame);
let elapsed = started.elapsed();
let ChildOutcome::Produced(out) = run.outcome else {
panic!("{:?} (stderr: {})", run.outcome, run.stderr);
};
assert!(out.len() < limits::VERIFY_MAX_OUTPUT_BYTES);
assert!(elapsed < limits::VERIFY_DEADLINE, "{elapsed:?}");
let verdict: serde_json::Value = serde_json::from_slice(&out).unwrap();
assert_eq!(verdict["outcome"], "passed", "{}", verdict["failures"]);
eprintln!(
"verify at the maximum: input {} bytes, verdict {} bytes, {elapsed:?}",
frame.len(),
out.len()
);
}
fn expect_caps_verdict(frame: &[u8]) {
let verdict = expect_verdict(frame);
assert_eq!(verdict["outcome"], "failed", "{}", verdict["failures"]);
assert_eq!(verdict["failure_code"], "verification.validation.caps");
}
#[test]
fn inputs_just_beyond_the_caps_fail_as_caps_through_the_sandbox() {
for frame in [
fixtures::beyond_total_frame(),
fixtures::beyond_count_frame(),
fixtures::beyond_drawing_frame(),
fixtures::beyond_document_frame(),
] {
expect_caps_verdict(&frame);
}
}
/// A frame of exactly the cap is read (here a malformed one: the frame check, not the size
/// check, refuses it), one more byte is refused unread.
#[test]
fn the_verify_input_cap_is_exact() {
let at_cap = verifier(&[]).run(&vec![0u8; limits::VERIFY_MAX_INPUT_BYTES]);
assert!(
matches!(at_cap.outcome, ChildOutcome::Broken { code, .. } if code == exit_codes::FRAME_INVALID),
"{:?} {}",
at_cap.outcome,
at_cap.stderr
);
}