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
);
}
+36
View File
@@ -344,6 +344,42 @@ fn rows_outside_the_policy_are_never_fetched() {
}
}
// Tracked misclassification (owner brief 2026-11-01), not fixed: an object larger than the
// policy is passed without bytes, so the core judges it missing (`drawing_missing`, listed
// after `caps`: the row's declared size already exceeds the cap) where `size_mismatch` would
// name it.
#[test]
fn tracked_an_object_over_the_policy_is_reported_drawing_missing() {
let mut too_big = row();
too_big.byte_size = VERIFY_MAX_DRAWING_BYTES as u64 + 1;
let fake = Fake::with_input(input(document().to_string(), vec![too_big]));
assert_eq!(process(&fake, &InProcess), VerifyEnd::Failed);
assert_eq!(fake.names(), ["input", "complete"]);
let verdict = fake.verdict();
assert_eq!(
verdict["failures"],
json!([verdict_codes::CAPS, verdict_codes::DRAWING_MISSING])
);
assert_eq!(verdict["drawings"][0]["result"], "missing");
}
// Tracked misclassification (owner brief 2026-11-01), not fixed: a document naming enough
// drawings that the frame header passes 64 KiB is refused by the parent's own framing and
// reported `resource_limit` (a worker failure, retried) where `caps` would name it.
#[test]
fn tracked_a_header_over_64_kib_is_reported_resource_limit() {
let rows = vec![row(); 600];
let fake = Fake::with_input(input(document().to_string(), rows));
assert_eq!(
process(&fake, &Fixed::never()),
VerifyEnd::Reported(codes::RESOURCE_LIMIT)
);
assert_eq!(
fake.calls().last().unwrap(),
&fail_call(codes::RESOURCE_LIMIT)
);
}
#[test]
fn downloads_stop_at_the_drawing_count() {
let rows = vec![row(); 6];