Repository navigation
ci: fmt/clippy/test gate + tree cleanup - #11
Merged
Merged
Conversation
Add `ci` + `fmt-fix` Makefile targets (fmt-check + clippy -D warnings + unit tests -- per crate, for stage0's non-workspace UEFI+host mix) and a `ci` job to the workflow, with `build` renamed to the clean contexts build-x86_64 / build-aarch64 (needs: ci). This is the uniform CI gate the workspace branch ruleset requires. The tree had never been fmt/clippy-checked in CI; bring it clean, no #[allow]: - rustfmt across all crates - is_multiple_of (clippy --fix) - drop 2 redundant core::mem::forget in the ENA driver (the Dma buffers have no Drop, so they already leak for the device lifetime -- behavior identical) - de-prefix the PciMapOp (BusMaster*) and Domain (Stage1*) enum variants - extract the repeated admission tuple to a `type Admitted` alias make ci green (fmt + clippy + stage0-sign golden test). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
7 of 11 tasks
HarryR
added a commit
that referenced
this pull request
Nov 14, 2026
… replay file, pinned harness (#12) ## 1. In-tree reproducible Secure Boot varstores + harness --forward ### `tools/mkvarstore.py` replaces `virt-fw-vars` - Pure-stdlib Python builds both the enrolled edk2 pflash varstore (`efi-vars.ovmf`) and the AWS AMZNUEFI v0 blob (`efi-vars.aws`) from stage0's PK/KEK/db. No distro firmware template is used as input. - **Reproducibility:** the PK/KEK/db authenticated-variable timestamp is taken from `SOURCE_DATE_EPOCH`. `virt-fw-vars` stamped wall-clock time, so its output differed on every build. - Variable set and order follow `virt-fw-vars`: CustomMode, DeployedMode=1, KEK, PK, SecureBootEnable, db, plus the placeholder `dbx` (sha256 of empty input). - **Signature owner GUID** for PK/KEK/db is GCP's fixed `d281fad2-8d88-47a4-9792-5baa47bb1b89` (`gen-keys.sh`, previously a random `uuidgen` per key). GCP stamps that GUID on every certificate it wraps, so our ESLs are now byte-identical to what GCP enrolls and PCR7 is one value on QEMU, EC2 and GCP (see section 4). - Per-arch flash geometry (FV header, block map, attributes) and the FTW working-block tail are hardcoded, captured from `OVMF_VARS_4M.fd` / `AAVMF_VARS`. - The AMZNUEFI zlib preset dictionary is vendored at `tools/firmware/amznuefi-v0.dict`. - **Security fix (aarch64):** the old path started from `AAVMF_VARS.snakeoil.fd`. That template comes pre-enrolled with Debian's SnakeOil KEK and db certificates, and `--add-kek`/`--add-db` *appended* ours alongside them. Every aarch64 varstore built that way therefore also trusted SnakeOil (`C=US, ST=Colorado, L=Fort Collins, O=SnakeOil`). Its private key is public: it ships in the same image as `/usr/share/ovmf/PkKek-1-snakeoil.key`. Anyone could sign a binary that firmware would accept. That covers both the edk2 varstore and the AWS `--uefi-data` blob, so **any Graviton AMI published from a pre-mkvarstore build should be treated as Secure Boot-bypassable**. `mkvarstore.py` enrolls only the Lock.Boot PK/KEK/db. The old template also brought boot entries, ConIn/ConOut and similar variables, which are now gone (firmware recreates them). - **Trust:** this moves varstore construction (and therefore which keys are enrolled) into code we own and review, instead of a pip package plus a distro template. ### `qemu-test.sh --forward <port>` - Repeatable option: host TCP port -> guest `10.0.2.10`, via iptables DNAT and FORWARD. - DHCP now hands out exactly one lease (`10.0.2.10`) instead of `.10-.20`, so the forward target is deterministic. Only one guest per harness. ### Before marking ready - [x] Compared against `virt-fw-vars` 26.6 in `lockboot:build`, using the same keys and timestamp fields zeroed: - **x86_64:** edk2 and AWS outputs are identical. - **aarch64:** FV header, variable-store header and FTW tail (`0x40000..end`) are identical. Our PK/KEK/db ESLs are byte-identical to the Lock.Boot entries `virt-fw-vars` produced. The remaining difference is the SnakeOil entries and the template's other variables, as described above. - `mkvarstore.py` is byte-reproducible run-to-run on both archs. - [x] Secure Boot smoke boot, x86_64 + aarch64 (smoke-boot matrix + selftest) - [ ] EC2 launch with the AWS blob -- **blocked**: the AWS account is restricted (support case open); the AMI uploads and registers, launches are refused at the account level - [x] Removed `virt-firmware` and `python3-pip` from `Dockerfile.build`, synced to stage1 #21, stage2 #2 and vaportpm #11. The workspace sync now covers stage2 (workspace #5). - [ ] Add the varstore/FTW notes to `REPRODUCIBLE-BUILDS.md` (referenced by the script, not yet written) Note: `ovmf` and `qemu-efi-aarch64` stay in the build image. The build no longer reads their VARS templates, but I have not audited whether anything run in `lockboot:build` still needs the CODE images. ## 2. Harness: pinned, multi-arch, published per release The QEMU test harness (`lockboot:harness`, with `qemu-test.sh` as entrypoint) is an end-user artifact. Its OVMF/AAVMF CODE images boot the varstores that `tools/mkvarstore.py` lays out for bookworm's pflash geometry, so each harness is published with the stage0 release whose efi-vars it boots. - **Pin:** `debian:bookworm-slim@sha256:99c0b25c...` (multi-arch index digest). - **The EC2 metadata mock is now per architecture:** - The image picks it via `TARGETARCH`; `qemu-test.sh` (also shipped standalone) via host `uname -m`. - The arm64 sha256 `9dae5b58...` comes from downloading the upstream v1.13.0 asset. The amd64 pin is unchanged. - **Host-aware acceleration in `qemu-test.sh`:** - KVM when host arch == guest arch. For an aarch64 guest on an arm64 host that means `-cpu host` and `-machine virt,gic-version=host`. - TCG otherwise. - **x86_64 hosts behave exactly as before:** x86_64 guest under KVM (still fails loudly without `/dev/kvm`), aarch64 guest under TCG `cortex-a72`. - **`release-harness` job (`v*`, after `release-stage0`):** - multi-arch (amd64 + arm64, via `setup-qemu-action`) push to `ghcr.io/lockboot/stage0-harness`, with provenance, SBOM and a registry attestation - the digest is appended to that stage0 release's notes ### Tested locally - [x] `bash -n tools/qemu-test.sh` - [x] `make docker-build-harness`: the pinned base builds; the amd64 mock is baked in and sha256-checked; the OVMF/AAVMF CODE images are present - [x] Workflow YAML parses; the job chain is `ci -> build -> release-stage0 -> release-harness` ### Not yet tested - [x] A boot on an x86_64 host (`make boot-x86_64` / `boot-aarch64`), to confirm no regression - [ ] **Running on an arm64 host** (no arm64 host was available): aarch64 KVM (`-cpu host`, `gic-version=host`) and x86_64 under TCG with `q35,smm=on` - [ ] The release job only runs on `v*`, and the first push of a **new** ghcr package from `GITHUB_TOKEN` depends on the org's package-creation policy ## 3. GCP support GCP's UEFI firmware ships no gVNIC driver (and, on x86, no virtio-net either), and GCP requires gVNIC for Confidential VMs and Arm, so stage0 had no network on any current GCP configuration. - **`crates/gvnic`** (34bd6fa): an embedded, measured Driver-Model SNP driver, like `ena.efi`. GQI_QPL queue format, one TX + one RX queue, polled. Protocol derived from the Linux gve driver (GPL-2.0 OR MIT, used under MIT; reference torvalds/linux 45e0a63f9c86). All DMA through PciIo `Map(CommonBuffer)`. stage0 loads ena and gvnic in one loop and logs a network inventory if no IPv4 stack appears. - **Doorbells** (615b810): BAR2 (queue doorbells) is written with direct big-endian stores to the BAR's host address (`PciIo.GetBarAttributes`), as every reference driver does (Linux, FreeBSD, DPDK, iPXE's EFI build); BAR0 stays on `PciIo.Mem`. GCE backs the doorbell BAR as memory, not trapping MMIO: under TDX the firmware's `PciIo.Mem` is a TDVMCALL MMIO hypercall that never reaches it (doorbells read back 0, no TX/RX). Device-supplied doorbell indices are bounds-checked against the BAR. - **Teardown at ExitBootServices** (615b810): what Linux does on close + remove -- destroy TX/RX queues, unregister both page lists, deconfigure device resources, then reset (previously only a reset). - **Logging** (bd5f47c): one summary line per probe by default, on stage0's `[ S.mmm]` timeline (stage0 passes its timestamp epoch in the driver's LoadOptions); step-by-step detail behind a `verbose` feature; every error path still logs. - **LAPIC tick** (34dbc69): GCE's firmware ticks from the 8254 PIT via the 8259. A TDX guest only receives interrupts through its virtual x2APIC, so no UEFI timer event ever fires there and EDK2's network stack never runs (0 ticks in 300 ms under TDX, 30 on Shielded). `lapic_tick::ensure()` probes the firmware tick for 50 ms and only if it is dead does what OVMF's `LocalApicTimerDxe` would: LAPIC timer periodic at the firmware timer's period, ISR calling the timer driver's `GenerateSoftInterrupt()`, structured like `LocalApicTimerDxe` including a port of `NestedInterruptTplLib`; LAPIC registers restored at ExitBootServices. Elsewhere only the 50 ms probe changes. - **Secure Boot gate** (be996b4): GCP can only provision PK/KEK/db/dbx, so its firmware boots in User Mode and the old `DeployedMode==1` gate refused every GCP boot. The gate is now SecureBoot==1, SetupMode==0, AuditMode 0 or absent; User and Deployed Mode are both accepted. stage0 never writes DeployedMode (on GCP a write is volatile only; PCR7 did not move across reboots). - **UDP4 RecycleSignal** (db8caab): `udp_recv()` never signalled it. EDK2's `Udp4Configure(NULL)` ASSERTs the delivered queue is empty; GCP's firmware has ASSERTs enabled, so it reset the VM after every DNS answer. - **Our own dbx on GCP** (b3df2b0): left unset, GCP substitutes Microsoft's. `mkvarstore.py` now also emits `dbx.esl` and `dbx.auth.bin`, the same ESL as a KEK-signed `EFI_VARIABLE_AUTHENTICATION_2` update (the only form GCP's BIN dbx accepts at VM start); `gcp/create.sh` passes it. Verified on GCP (spot, asia-southeast1-b), x86_64: Shielded n2d, SEV, SEV-SNP (Milan), Shielded c3, **TDX (c3)** -- DHCP, DNS, HTTP, pin verify, payload. Full chain (stage0 -> UKI -> stage1 -> stage2) on SEV, SEV-SNP and TDX; a full chain needs a Confidential VM (GCE provisions AK certificates only there). TDX also needed stage1's kernel cmdline to drop `init_on_free=1` (stage1 #21). It measures differently: stage0's Authenticode measurement and the GPT land in PCR2 instead of PCR4/PCR5. The TDX platform file expresses this as `route` rules (workspace #5); stage0's replay file is unchanged apart from its event order (section 4). Not yet working: - **Arm (t2a)**: GCP's AAVMF ships no network stack at all; needs one before gvnic can help. ## 4. PCR replay file `tools/predict-pcrs.py` (315e8de, af0957c) writes `stage0.replay.json`, a `pcr-replay/v1` file (format and verifier: workspace `tools/pcr-replay`): every event the firmware and stage0 add from reset to the payload handoff, each with its derivation from the release artifacts (`BOOT*.EFI`, `boot.disk`, `*.cer`, `*.guid`, `dbx.esl`) and the digests computed here, plus the reference `pcrs.json` (vaportpm layout) replayed from them. Grouped by PCR here: | PCR | Events | |---|---| | 3, 6 | separator | | 4 | "Calling EFI Application from Boot Option", separator, Authenticode hash of `BOOT*.EFI` | | 5 | separator, `UEFI_GPT_DATA` of `boot.disk` | | 7 | SecureBoot, PK, KEK, db, dbx, separator, the db authority that verified stage0 | | 14 | input `payload`: stage0's `H_bank(sha256(payload))` (bound to the next stage's entry) | PCR0-2 (provider firmware, boot entries, option ROMs) come from per-platform files (workspace `tools/pcr-replay/platforms/`). The embedded NIC drivers and the payload load through stage0's Security2 override, which bypasses firmware image measurement: the drivers are inside stage0's own hash, the payload is in PCR14. - **Log order** (8322629): the file lists events in the order the firmware logs them (OVMF and GCE alike), not grouped by PCR, so a platform that routes some into another PCR (GCE TDX: GPT, then `BOOT*.EFI`, into PCR2) gets them in the right order there. Same event set; `pcrs.json` byte-identical. - **GPT, first boot only:** the GPT event derives from `boot.disk`, but stage2 rewrites the GPT on first boot, so later boots measure a GPT no artifact describes (PCR5; PCR2 on TDX). Planned: the attestation carries the GPT event digest (lockboot/vaportpm#12). - `build.sh` writes `build/<arch>/stage0.replay.json` and `pcrs.json`; CI uploads both, so they ship in the attested release zips. - The test payload dumps every PCR and the TCG2 event log (best effort; EC2 provides none), the input for platform captures and for `pcr-replay --check`. - The PCR7 difference between GCP and QEMU was the owner GUID (section 1): the offline replay reproduced both the old QEMU and the GCP value exactly. Verified with `pcr-replay`: QEMU x86_64 and aarch64 full chains (30 events re-derived and verified); GCP n2d SEV, SEV-SNP and c3 TDX full chains with the golden GCP platform files (only the 3 ACPI events per platform taken on trust); GCP Shielded n2d and c3 stage0 probes. ## 5. Publish tooling - **faa8604:** GCP image names include `BUILD_ID`; `--manifest` records only what this run created; `launch-instance.sh` maps n2d -> SEV-SNP (Milan), c2d -> SEV, c3 -> TDX, t2a -> Shielded, and runs with `--no-service-account --no-scopes`; `cleanup.sh` handles instances; console follow resumes from GCP's byte offset. - **aeecd8d:** `HAZMAT_WARNING_NO_REGEN_KEYS_DEV_ONLY=1` reuses `build/keys` for dev iteration (refused under CI); `STAGE0_FEATURES=verbose`; `get-console.sh --follow` exits when the instance stops. - **5feb45f:** both `create.sh` exited 1 after a successful local-build run (EXIT-trap status); EC2 instances are tagged `Project=lockboot` (the workspace deploy role only starts/stops/reboots tagged instances). ## Self-test - `qemu-test.sh --timeout <s>`: a hung boot exits 124 instead of blocking (opt-in). - aarch64: PL011 (AAVMF UEFI ConOut) is attached to the captured stdio mux, so stage0 output is visible as on x86. Before this, `smoke-boot-aarch64` could never PASS. - Provisioning probe uses `tpm2_getcap handles-nv-index`. tpm2-tools 5.4 `tpm2_nvreadpublic` segfaults on an undefined index, which dumped a root-owned `core` into the repo on every fresh-TPM boot. Verified: a fresh boot provisions, passes, and leaves no core. - `selftest-<arch>` = the smoke-boot matrix with a 300 s per-boot bound. Part of workspace `make selftest`, which passed on x86_64 and aarch64 with all consolidated branches together. ## Release attestation covers the zip contents The release job unzips both arches and attests, in the same single step, the 2 zips, tools/qemu-test.sh (released but previously unattested), and the 11 files inside each zip (25 subjects). Subjects come from a `subject-checksums` file named `<arch>/<path-in-zip>`, so same-named per-arch files stay distinguishable. A consumer can verify the zip and extract from it as before, or verify any extracted file on its own (`gh attestation verify <file> --repo lockboot/<repo> --signer-workflow ...`). The listing step was tested on real build outputs: each extracted file's digest matches the built file. ## Merge gate This is the whole stage0 changeset for the release. It merges only after the cross-repo self-test suite passes on **both** x86_64 and aarch64, run against this branch together with the matching branches in the other repos, followed by GCP + EC2 testing (EC2 is blocked on the AWS account). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds the uniform CI gate (fmt + clippy + unit tests) that the workspace branch ruleset requires, and cleans the tree so it passes.
ci+fmt-fixMakefile targets — fmt-check +clippy -D warnings+ unit tests. stage0 isn't a cargo workspace (4 independent crates, UEFI + host), so it lints the UEFI crates on the uefi target and runsstage0-sign's tests on host.cijob;buildnowneeds: ciand renamed to the clean contextsbuild-x86_64/build-aarch64.#[allow]) — never fmt/clippy-checked in CI before: rustfmt all crates;is_multiple_of; dropped 2 redundantcore::mem::forgetin the ENA driver (theDmabuffers have noDrop, so they already leak for the device lifetime — identical behavior); de-prefixed thePciMapOp(BusMaster*) andDomain(Stage1*) enum variants; extracted the repeated admission tuple to atype Admitted.make cigreen locally (fmt + clippy +stage0-signgolden test).🤖 Generated with Claude Code