blob: 6512c2d4f0858c6879b817a6d42728ddb9f0bd63 [file] [view]
<!-- Copyright 2026 The Fuchsia Authors
Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
<LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
This file may not be copied, modified, or distributed except according to
those terms. -->
# Two-Phase Soundness Bug Management
When differential testing, fuzzing, red-teaming, or correspondence audits
uncover a soundness defect in Anneal's capture, MIR semantics, or TCB
auditing, landing a permanent root-cause fix (`Trusted.MirSemantics`,
correspondence proofs, and `check_guard_mutation.py` refutations) can take days.
Leaving the soundness hole open on `main` in the meantime risks admitting
unsound code.
Anneal separates emergency containment from permanent fixes using a
**Phase 0 -> Phase 1** workflow:
1. **Phase 0 (Fail-Closed Containment Tripwire):** Narrow capture, execution,
or admission strictly monotonically so affected inputs fail closed (for
example `status: "unsupported"` emitting `[PHASE0_TRIPWIRE:<bug_id>]` in
capture, or `.fault .unsupported` at runtime) without altering semantics on
surviving inputs.
2. **Phase 1 (Root-Cause Fix, Cleanup & Test Flip):** Land the permanent fix,
correspondence updates, and guard-mutation coverage, completely delete the
Phase-0 tripwire (zero commented or disabled stubs), and flip the bound
regression test to positive verification or `FaultUb` parity.
## Canonical bug ID namespaces
This document and [`tripwires.rs`][tripwires-rs] standardize five canonical
tripwire prefixes matching
`^(?:ITREE|DIFF|RT|LMIRI|MINIRUST)-[A-Z][A-Z0-9_]*-[0-9a-f]{12}$`:
- `ITREE-<CATEGORY>-<12hex>` — issues uncovered in the multi-step
observable-trace differential test suite (under `tests/itree_diff/`).
- `DIFF-<CATEGORY>-<12hex>` — standalone differential harness bugs outside
`itree_diff`.
- `LMIRI-<CATEGORY>-<12hex>` — Lean-Miri correspondence or TCB gaps
(context: [`MirCorrespondenceProof`][lmiri-proof]).
- `MINIRUST-<CATEGORY>-<12hex>` — MiniRust operational/spec correspondence gaps
(context: [`MiniRustProof`][minirust-proof]).
- `RT-<KIND>-<12hex>` — red-team containment, preflight, and proof-hack vectors.
## Authoritative issue tracking & private disclosure
Every public `PHASE0_TRIPWIRE!` entry must track a public GitHub issue in
`google/zerocopy` titled `[anneal][<subsystem>] <BUG_ID>: <concise summary>`
with label `anneal` and a reference to its owning `[anneal][*]` subsystem
umbrella (`[anneal][mir]`, `[anneal][capture]`, `[anneal][audit]`,
`[anneal][theory]`, `[anneal][ffi-isa]`, `[anneal][specs]`, or `[anneal][ux]`):
- **Embargoed / Unvetted Defects Stay Outside `PHASE0_TRIPWIRE!`:** Per
[AGENTS.md][agents-md] and [rustc workarounds][rustc-wa], an unvetted upstream
compiler soundness or security defect—and any embargoed security
report—must stay under private disclosure until a public issue exists in
`google/zerocopy` or `rust-lang/rust`. Do **not** register embargoed defects
in `PHASE0_TRIPWIRE!`, assign public soundness bug IDs, emit
`[PHASE0_TRIPWIRE:<bug_id>]`, add `RUSTC-WORKAROUND` anchors, or reference a
private report in code or tests. Instead, place any needed fail-closed
capture guard directly in `rustc-capture` naming **only** its neutral
fail-closed invariant (confirming necessity privately at Gate 5), and convert
or anchor it only once responsible disclosure opens `#<N>`.
- **Pre-Triage Human Confirmation (`needs_human_review` for non-oracle `RT-*`
reports):** Red-team reports lacking executable-oracle (`rustc`/Miri)
confirmation—either a candidate `Trusted.MirSemantics` fix with a
machine-checked incorrectness + canary-preservation proof, or a structured
prose incorrectness claim—enter `needs_human_review` before triage. Humans
confirm incorrectness first; validated candidate semantics patches seed Phase
1 directly.
- **Opening & Deduplication (`open` -> `triaged`):** Once public disclosure
applies, file the issue on `google/zerocopy` before merging Phase 0
containment, capturing a minimal reproducible witness and collapsing
syntactic variants onto the same root-cause issue. If a public Phase-0
tripwire guards an evaluated upstream compiler or toolchain limitation, also
anchor it with `RUSTC-WORKAROUND(#NNNN)` per [rustc workarounds][rustc-wa]
and link the owning `[anneal][*]` umbrella.
- **Phase 0 PR (`mitigated_phase0`, issue stays OPEN):** Link Phase-0 PRs using
**`Mitigates #<N>`** (never `Fixes #<N>`), and record the exact public issue
URL `https://github.com/google/zerocopy/issues/<N>` in the tripwire's
`issue:` field alongside a live Cargo negative regression test executed by CI
asserting `[PHASE0_TRIPWIRE:<bug_id>]` refusal.
- **Phase 1 PR (`fixed`, closes `#<N>`):** Only after deleting the tripwire,
flipping the regression test off `[PHASE0_TRIPWIRE:<bug_id>]`, and replaying
all retained duplicate witnesses cleanly on the un-tripwired Phase-1 tree,
close `#<N>` with **`Fixes #<N>`**. Any surviving witness that still fails
Phase-1 verification opens a distinct `[anneal][...]` issue instead of closing
`#<N>`.
## Setup & teardown runbooks
### Runbook A: Static `rustc-capture` tripwire (`tripwires.rs`)
Default Phase-0 mechanism. Hooks `check_crate` and `check_mir_body` in
[`capture.rs`][capture-rs] inspect crate-level flags/features (including
`--stdlib-crate` captures without leaking taint into normal manifest fields) and
raw `&mir::Body<'_>` across callable local bodies, `--instantiate` targets,
transitive local callees, and whole-crate `Const`/`AssocConst`/`AnonConst` CTFE
MIR prior to extraction. `check_crate` executes in `after_analysis` before
capture-side item enumeration, `mir_for_ctfe`, `const_eval_poly`, and MIR
extraction, short-circuiting immediately via `Failure::unsupported` (it does not
prevent compiler-internal ICEs earlier during `rustc` analysis). Leaving
`ACTIVE_PHASE0_TRIPWIRES` empty incurs zero production change;
`SYNTHETIC_DEMO_TRIPWIRE` (`ITREE-DEMO-000000000001`) and
`SYNTHETIC_DEMO_CRATE_TRIPWIRE` (`ITREE-DEMO_CRATE-000000000001`, optional
`ANNEAL_PHASE0_TRIPWIRE_SELFTEST_FEATURE` filter) activate only on explicit
`--env ANNEAL_PHASE0_TRIPWIRE_SELFTEST=...` in [selftest tests][phase0-tests].
**Phase 0 Setup checklist:**
1. Open public issue `#<N>` in `google/zerocopy` (`[anneal][<subsys>] <BUG_ID>`)
and allocate `<BUG_ID>` (for embargoed upstream defects without a public
issue, use a neutral invariant guard outside `PHASE0_TRIPWIRE!` per
[rustc workarounds][rustc-wa]).
2. Edit only between `// === PHASE 0 MUTABLE REGISTRY START ===` and `END` in
[`tripwires.rs`][tripwires-rs] to add a `PHASE0_TRIPWIRE!` entry with
`issue: "https://github.com/google/zerocopy/issues/<N>"` and
`activation: TripwireActivation::Always`. Keep the macro definition,
synthetic selftest hooks, `check_crate`, `check_mir_body`, and `#[cfg(test)]`
unit tests unchanged.
3. Add a dedicated negative Cargo integration test under
`anneal/tests/{rustc-capture,itree_diff}/tests/*.rs` matching `*phase0*` or
`*tripwire*` (`#[test]`, never `#[ignore]`) asserting both
`[PHASE0_TRIPWIRE:<BUG_ID>]` and refusal (`unsupported` / error exit).
4. Verify targeted `anneal-rustc-capture` tests pass locally, then open a PR
with `Mitigates #<N>`.
**Phase 1 Teardown checklist:**
1. Land the permanent root-cause fix (`rustc-capture` / `Trusted.MirSemantics`).
2. Delete the `PHASE0_TRIPWIRE!` rule and any helper predicates completely from
[`tripwires.rs`][tripwires-rs] (zero commented-out or disabled stubs).
3. Keep the regression test function at the exact `regression_test` path::fn,
flipping it from `[PHASE0_TRIPWIRE:<BUG_ID>]` refusal to positive
verification or `FaultUb` parity, and replay all retained duplicate
witnesses cleanly.
4. Confirm zero residual `<BUG_ID>` references remain under `anneal/trusted/`,
then merge with `Fixes #<N>`.
### Runbook B: Dynamic `Trusted.MirSemantics` fallback (`.fault .unsupported`)
Fallback mechanism used **only** when a static MIR-shape predicate in
`tripwires.rs` would reject unrelated valid proof crates too broadly.
**Phase 0 Setup checklist:**
1. Document why `tripwires.rs` is over-broad in `#<N>` (`Mitigates #<N>`).
2. Add the narrow runtime check returning `StepResult.fault .unsupported` in
[`Trusted/MirSemantics/`][mir-semantics] (`Boundary.lean`'s
`WellFormed[V2]` quantifies universally over all `FaultKind` values, so
converting an unsound step to `.fault .unsupported` remains sound on
surviving runs). Annotate immediately above with `-- PHASE0_TRIPWIRE(...)`.
3. Add a dedicated negative regression test asserting `.fault .unsupported`
refusal (`FaultKind.unsupported`, which carries no runtime string payload)
and tagging `<BUG_ID>` in the assertion failure context.
4. Check downstream TCB impacts (`trusted/root-manifest.sha256`,
[`check_guard_mutation.py`][guard-mut], `correspondence/`,
`cargo test -p anneal-audit-tests`), and complete full Pass 2 semantic review
before merge.
**Phase 1 Teardown checklist:**
1. Replace the `.fault .unsupported` guard with the real operational rule and
delete the `-- PHASE0_TRIPWIRE(...)` comment and any bug-ID mentions across
all of `anneal/trusted/`.
2. Update [`MirCorrespondenceProof`][lmiri-proof] and
[`MiniRustProof`][minirust-proof] proofs, add a negative refutation theorem
and guard entry to [`check_guard_mutation.py`][guard-mut], and refresh
`trusted/root-manifest.sha256` if tracked manifests change.
3. Flip the bound regression test to positive / `FaultUb` parity, replay
retained witnesses, and land with `Fixes #<N>`.
## CI enforcement & local Git-history tools
[`check_phase0_tripwires.py`][tripwire-ci] (backed by modular helpers under
`anneal/ci/tripwire_checker/` and
[`test_check_phase0_tripwires.py`][tripwire-ci-tests]) provides three
structural hygiene modes (`--repo-root`, `--head`, `--json` apply across modes):
- **`--mode tree` (runs automatically in CI):** Wired into `anneal-ci-tests`
via [`run_anneal_check.sh`][run-check]. Validates `PHASE0_TRIPWIRE!` rules in
[`tripwires.rs`][tripwires-rs] and trusted comment markers across
`anneal/trusted/**/*.{rs,lean}`, canonical IDs, public `google/zerocopy`
`issue` URLs, valid dates, CI-wired Rust/Python regression tests
(`anneal/Cargo.toml`, crate `Cargo.toml`, and
`ci/checks.toml`/`run_anneal_check.sh` when present) citing `<bug_id>` refusal
without skips or disabling `#[cfg(...)]`, and zero raw struct literals, type
aliases, disabled stubs, or unreferenced top-level helpers in
[`tripwires.rs`][tripwires-rs]. Supports `--known-bugs` and
`--strict-mitigated-link`.
- **`--mode phase0-diff` (local Git-history check):** Compares `--base` against
`--head` (or working tree, with optional `--diff-files` check) to confirm
regular-file containment edits stay inside `tripwires.rs`'s mutable registry
plus bound `*phase0*`/`*tripwire*` Rust test files (preserving existing
active entries and adding new tripwires) unless
`--allow-runtime-semantics-fallback` is requested with a new
`-- PHASE0_TRIPWIRE(...)` annotation in each edited `MirSemantics` file.
- **`--mode phase1-cleanup` (local Git-history check):** Compares against
`--base`, `--resolved-bug`, `--test-ref`, and/or `--known-bugs` to confirm
resolved bug IDs leave zero residual `PHASE0_TRIPWIRE` or `<bug_id>`
references in `anneal/trusted/**/*.{rs,lean}` while retaining flipped active
tests (allowing permanent CLI exit-code assertions for `trusted_comment`
entries).
Static capture containment and structural CI hygiene linting catch common
accidental omissions and syntactic stubs, and never substitute for Gate 1,
Gate 2, or Gate 5 code review or `AGENTS.md` Pass 1 / Pass 2 semantic gates.
[rustc-wa]: rustc-workarounds.md
[agents-md]: ../AGENTS.md
[lmiri-proof]: ../correspondence/Anneal/MirCorrespondenceProof.lean
[minirust-proof]: ../correspondence/Anneal/MiniRustProof.lean
[tripwires-rs]: ../trusted/rustc-capture/src/tripwires.rs
[capture-rs]: ../trusted/rustc-capture/src/capture.rs
[phase0-tests]: ../tests/rustc-capture/tests/phase0_tripwires.rs
[mir-semantics]: ../trusted/lean/Trusted/MirSemantics/Boundary.lean
[guard-mut]: ../ci/check_guard_mutation.py
[tripwire-ci]: ../ci/check_phase0_tripwires.py
[tripwire-ci-tests]: ../ci/test_check_phase0_tripwires.py
[run-check]: ../ci/run_anneal_check.sh