Skip to content

stage0: reproducible SB varstores, GCP support (gVNIC, dbx, TDX), PCR replay file, pinned harness - #12

Merged
HarryR merged 21 commits into
mainfrom
mkvarstore-port-forward
Nov 14, 2026
Merged

HarryR merged 21 commits into
mainfrom
mkvarstore-port-forward

Conversation

@HarryR

@HarryR HarryR commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

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

  • 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.
  • 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
  • Removed virt-firmware and python3-pip from Dockerfile.build, synced to stage1 #21, stage2 Signed-mode admission is malleable: rollback + mix-and-match of independently-signed artifacts #2 and vaportpm ci: fmt/clippy/test gate + tree cleanup #11. The workspace sync now covers stage2 (workspace stage0: admit _stage1 via a signed manifest (fix mix-and-match, #2) #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

  • bash -n tools/qemu-test.sh
  • make docker-build-harness: the pinned base builds; the amd64 mock is baked in and sha256-checked; the OVMF/AAVMF CODE images are present
  • Workflow YAML parses; the job chain is ci -> build -> release-stage0 -> release-harness

Not yet tested

  • 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 (Attestation: carry the GPT event digest as auxiliary data (pin PCR2/PCR5 on TDX and non-TDX) 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

HarryR and others added 2 commits November 4, 2026 08:27
Replace virt-fw-vars + the distro OVMF/AAVMF VARS templates with
tools/mkvarstore.py: pure-stdlib Python that builds the enrolled edk2
pflash varstore and the AWS AMZNUEFI v0 blob from stage0's PK/KEK/db.
The authenticated-variable timestamp is fixed from SOURCE_DATE_EPOCH, so
the output is byte-reproducible (virt-fw-vars stamps wall-clock time).
Per-arch flash geometry and the FTW tail are captured from the reference
varstores; the AMZNUEFI zlib preset dictionary is vendored under
tools/firmware/.

qemu-test.sh: add repeatable --forward <port> (host TCP -> guest DNAT).
To make the target deterministic, DHCP now hands out exactly one lease,
10.0.2.10; gateway/guest IP are named variables.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
stage0 now builds its Secure Boot varstores with tools/mkvarstore.py
(stdlib only), so nothing runs virt-fw-vars, and pip was installed only
for it. Canonical copy; synced to stage1, stage2 and vaportpm with
`make sync-harness` in the workspace.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ease

The QEMU harness is an end-user artifact, and its OVMF/AAVMF CODE
images boot the varstores mkvarstore.py lays out for bookworm's pflash
geometry, so it must not drift from the stage0 release it ships with.

- Pin debian:bookworm-slim by index digest.
- EC2 metadata mock per arch: the image selects it by TARGETARCH,
  qemu-test.sh by host `uname -m` (arm64 sha256 from the upstream
  v1.13.0 asset; amd64 unchanged).
- qemu-test.sh: KVM when host arch == guest arch (aarch64 guest on an
  arm64 host: -cpu host, gic-version=host), TCG otherwise. x86_64 hosts
  behave exactly as before.
- release-harness job on stage0-v* (after release-stage0): multi-arch
  (amd64 + arm64) push to ghcr with provenance + SBOM + attestation, and
  the digest appended to that release's notes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@HarryR HarryR changed the title build: in-tree reproducible SB varstores (mkvarstore.py); harness --forward stage0: in-tree reproducible SB varstores, harness --forward, pinned + published harness Nov 4, 2026
HarryR and others added 13 commits November 4, 2026 15:34
tpm2-tools 5.4 (bookworm) tpm2_nvreadpublic SEGFAULTs on an undefined
NV index (exit 139). The provisioning probe treated that as "not yet
provisioned" and carried on, so tests passed, but every fresh-TPM boot
dumped a root-owned 0600 `core` into the caller's cwd (the repo; the
host core_pattern is a bare `core`). List the NV handles with
tpm2_getcap handles-nv-index instead.

Verified: a fresh-TPM boot provisions, reaches `payload: done`, and
leaves no core file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- qemu-test.sh --timeout <s>: bound an unattended boot (timeout(1)
  around QEMU); a guest that never powers off exits 124 instead of
  blocking. Opt-in; default unchanged.
- qemu-test.sh aarch64: attach the virt board's PL011 (AAVMF UEFI
  ConOut, i.e. stage0's output) to the same muxed stdio as pci-serial,
  so the whole chain is captured as on x86. Kernel printk now appears
  twice (console=ttyAMA0 console=ttyS0); /dev/console is still ttyS0.
  Without this, stage0's aarch64 boot matrix could never PASS.
- Makefile: HARNESS_TIMEOUT passes --timeout through; selftest-<arch>
  runs the smoke-boot matrix with a 300 s bound (~3x the slowest boot
  measured on either arch). Part of the workspace `make selftest`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The stage0-v* prefix dates from the pre-split lockboot/lockboot repo, where
one workflow carried two release tracks (stage0-v* and uki-v*) and the
prefix told them apart. Each repo now releases one product, so every
release repo uses plain v* (as vaportpm already does). Workflow
trigger, release-job ref checks, and docs updated; release asset names
are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The release attestation covered only the GitHub artifact zips. A
consumer can verify a zip and extract from it, but could not verify an
extracted file on its own. The release job now unzips both arches and
attests, in the same single attestation step, the zips plus every file
inside them, and tools/qemu-test.sh, which was released but not attested. Subjects come from a sha256sum-format checksums file
(subject-checksums), named <arch>/<path-in-zip>, so the per-arch copies of
same-named files stay distinguishable; verification matches by digest.
xargs -r keeps an empty listing from hashing stdin.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e follow

- gcp/create.sh: image name includes BUILD_ID (as the EC2 AMI name does), so
  a rebuild with the same VERSION_ID (new keys/binary) makes a new image
  instead of silently reusing a stale one.
- ec2/create.sh, gcp/create.sh: record a resource in --manifest only when
  this run created it; reused snapshots/AMIs/GCS objects/images may belong to
  an earlier session and must not be swept by this run's teardown.
- gcp/launch-instance.sh: n2d -> SEV_SNP + --min-cpu-platform="AMD Milan"
  (was SEV); c2d -> SEV; c3 -> TDX; t2a -> Shielded VM only (was the
  deprecated --confidential-compute = SEV; GCP documents no Arm CVM series),
  a confidential type can be passed as a trailing option for experiments.
  --no-service-account --no-scopes (the guest never calls GCP APIs). Unknown
  machine families are refused instead of an interactive prompt. Optional
  leading --manifest records the instance.
- ec2/launch.sh: --manifest records the instance; --tail-timeout bounds
  --tail (pivot-init keeps the instance running, so it never powers off).
- cleanup.sh: aws/gcp instance kinds (terminate / delete), processed first
  since they are recorded last.
- gcp/get-console.sh --follow: --start is a byte index; resume from the
  response's `next` offset instead of a running line count.
- README: launch flags and machine-type table updated to match.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
GCP can only provision PK/KEK/db/dbx (no varstore), so its firmware boots in
UEFI User Mode and the DeployedMode==1 gate (11da7ab) refused every GCP boot
with SECURITY_VIOLATION. QEMU and EC2 only passed because our own varstore
presets DeployedMode=1.

- Gate (require_secure_boot_enforcing): SecureBoot==1, SetupMode==0 (absent
  -> refuse), AuditMode 0 or absent (pre-UEFI-2.5 firmware has no Audit
  Mode). Admits User and Deployed Mode -- both enforce signatures and only
  accept PK/KEK-signed key updates; refuses Setup and Audit Mode. Logs the
  mode. stage0 itself never writes DeployedMode.
- stage0-test-payload: prints SecureBoot/SetupMode/AuditMode/DeployedMode
  (value + attributes, or absent) every boot; --set-deployed tries
  SetVariable(DeployedMode=1) after the PCR dump (BS|RT, then NV|BS|RT) and
  reports; --reboot cold-resets instead of powering off, for one PCR dump per
  boot on one instance. Used to measure whether a User->Deployed transition
  persists and moves PCR 7 before stage0 ever does it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
GCP's UEFI firmware ships no gVNIC driver -- and no longer a virtio-net one
either (its x86 OVMF has the full NetworkPkg stack but no NIC driver), while
GCP requires gVNIC for Confidential VMs and Arm. stage0 therefore had no
network on any current GCP configuration (`no EFI_IP4_CONFIG2 ... NOT_FOUND`).

crates/gvnic is an embedded, measured Driver-Model driver like ena.efi:
- GQI_QPL queue format, one TX + one RX queue, polled, no offloads. Protocol
  derived from the Linux gve driver ((GPL-2.0 OR MIT), used under MIT;
  reference torvalds/linux 45e0a63f9c86).
- Bring-up: version string, admin queue (registered per PCI revision),
  VERIFY_DRIVER_COMPATIBILITY, DESCRIBE_DEVICE (+ option TLVs, logged),
  CONFIGURE_DEVICE_RESOURCES, REGISTER_PAGE_LIST x2, CREATE_TX/RX_QUEUE.
- TX: frame copied into a fixed 2 KiB TX QPL slot, one packet descriptor;
  completions from the event counter. RX: QPL page per slot, 3-bit seqno,
  2-byte pad; buffers handed back only after copy-out.
- MTU from the device (GCP 1460), capped to fit one 2 KiB buffer; SNP
  MaxPacketSize follows it.
- Resets the device at ExitBootServices so RX DMA stops before the OS owns
  the memory. SNP GetStatus(TxBuf=NULL) does not reap TX completions.
- All DMA via PciIo AllocateBuffer + Map(CommonBuffer): correct under SEV.

stage0: both drivers embedded via one macro and loaded in a loop; on a
missing IPv4 stack, net::bringup() now logs a network inventory (handle
counts per layer + every loaded driver's name) before failing closed.

Verified on GCP (spot, asia-southeast1-b): Shielded n2d-standard-2, SEV,
SEV-SNP (Milan), Shielded c3-standard-4 -- DHCP, DNS, HTTP download, pin
verify, payload; PCRs stable across reboots. Idle on local QEMU. TDX
(c3) probes OK but passes no traffic -- tracked separately.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
udp_recv() never signalled the RxData RecycleSignal, relying on child
destruction to reclaim the buffer. That is not what the UEFI spec requires,
and EDK2's Udp4Configure(NULL) ASSERTs the delivered-datagram queue is empty:
on firmware built with ASSERTs enabled (GCP) that reset the machine right
after every DNS answer, silently (ASSERT output goes to the debug port).
Release-built firmware (EC2, local QEMU) compiled the ASSERT away.

Verified: GCP DNS resolution now completes (Configure(NULL) SUCCESS, child
destroyed, name resolved, payload fetched); local QEMU DNS path unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Left unset, GCP substitutes its default (Microsoft) dbx, so PCR 7 on GCP
depended on a list we don't control and that changes over time.

- mkvarstore.py --out-dbx writes the dbx EFI_SIGNATURE_LIST it already enrolls
  in efi-vars.{ovmf,aws}; --out-dbx-auth (+ --kek-key) wraps it as an
  EFI_VARIABLE_AUTHENTICATION_2 update signed by our KEK (openssl cms -noattr,
  fixed timestamp): reproducible for a given key set. build.sh emits
  build/<arch>/dbx.esl + dbx.auth.bin; both ship in the release artifacts.
- gcp/create.sh passes dbx.auth.bin as --forbidden-database-file. GCP's BIN
  dbx is an authenticated update (cf. uefi.org DBXUpdate.bin): a bare ESL is
  accepted at image create but kills every VM at start (hostError). gcloud
  types the file by extension (.bin -> BIN, else must be DER X.509).
  --default-dbx (test only) omits it for A/B runs, as a separate -defdbx image.
- gcp/create.sh: x86 images also get TDX_CAPABLE; the existing-image check is
  an exact `images describe` (`images list --filter=name=X` pattern-matched X
  against X-defdbx and reused the wrong image).

Verified on GCP: built dbx.auth.bin is byte-identical to the experiment image
that booted; image via create.sh boots (Shielded n2d), PCR7 ee5f65dc (vs
c05a3c37 with GCP's default dbx).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…llow

- HAZMAT_WARNING_NO_REGEN_KEYS_DEV_ONLY=1: reuse build/keys instead of
  re-minting them, so a rebuilt boot.disk still matches a cloud image already
  enrolled with those keys (swap the disk, keep the keys). Loud warning at
  parse time, refused under CI, fails if the keys are missing. Never for a
  release.
- STAGE0_FEATURES=verbose: debug build of stage0 (DNS/TCP/HTTP step logging);
  changes the measured binary, debug only.
- gcp/get-console.sh --follow: poll every 10 s (each gcloud call is a ~1 s
  Python start-up) and exit once the instance is no longer RUNNING (one last
  read first), instead of polling a stopped/deleted instance forever.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
GCP wraps the PK/KEK/db certificates we upload into EFI_SIGNATURE_LISTs
with a fixed SignatureOwner, d281fad2-8d88-47a4-9792-5baa47bb1b89
(undocumented; present in the GCE event logs in go-tpm-tools' test data).
gen-keys.sh used a random uuidgen GUID per key, so our efi-vars.* ESLs
differed from GCP's by those 16 bytes and PCR7 differed per provider
(GCP ee5f65dc, QEMU 965cb27a) even with byte-identical dbx.

Write GCP's GUID for all three keys. The ESLs are now byte-identical to
what GCP enrolls, and PCR7 is one value everywhere: QEMU now measures
ee5f65dc, matching GCP, with PCR0-6 and PCR14 unchanged. An offline
replay of SecureBoot, PK, KEK, db, dbx, separator, and the db authority
reproduces both the old and new values exactly. The owner GUID is
metadata only; firmware never uses it for verification.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…boot

create.sh (ec2 + gcp): the EXIT trap's cleanup loop ended on a failing
`[ -n "$p" ] && ...` when there was nothing to clean (local builds), so
the script exited 1 after a successful run. Use `[ -z "$p" ] || ...`.

ec2/launch.sh: tag every instance Project=lockboot. The deploy role
(workspace tools/deploy/aws-iam.sh) only allows Start/Stop/Reboot on
instances carrying that tag, and can only tag instances at launch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tools/predict-pcrs.py computes the PCRs at stage0's payload handoff from
BOOT*.EFI, boot.disk, *.cer, *.guid and dbx.esl alone, by replaying the
event sequence the firmware logs:
- PCR3, PCR6: separator only.
- PCR4: "Calling EFI Application from Boot Option", separator, and the
  Authenticode hash of the signed BOOT*.EFI. The embedded NIC drivers and
  the payload load through stage0's Security2 override, which bypasses
  firmware image measurement (drivers are inside stage0's hash; the
  payload is in PCR14).
- PCR5: separator, UEFI_GPT_DATA of boot.disk.
- PCR7: SecureBoot, PK, KEK, db, dbx, separator, and the db authority
  that verified stage0, with the ESLs rebuilt by mkvarstore.py's code.
- PCR14 (with --payload-sha256): stage0's H_bank(sha256(payload)).
PCR0-2 (provider firmware, boot entries, ROMs) are left to golden
readings. --check compares against a test-payload serial log.

build.sh writes build/<arch>/pcrs.json (sha256 + sha384, vaportpm
layout); CI uploads it, so it ships in the attested release zips.

The test payload also dumps the TCG2 event log (best effort; EC2 does
not provide one), to diagnose a prediction mismatch event by event.

Verified, all predicted PCRs in sha1/sha256/sha384/sha512: QEMU x86_64
and aarch64; GCP final + dbx runs (sha256/sha384, PCR3-7,14); GCP
Shielded n2d, SEV, SEV-SNP, c3 (PCR3-6,14; PCR7 differs only because
those images carried GCP's default dbx).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@HarryR HarryR changed the title stage0: in-tree reproducible SB varstores, harness --forward, pinned + published harness stage0: reproducible SB varstores, GCP support (gVNIC, dbx), PCR reproduction, pinned harness Nov 6, 2026
HarryR and others added 4 commits November 9, 2026 16:43
… pcrs.json

tools/predict-pcrs.py now writes stage0's PCR replay file -- every event stage0 and the
firmware add between reset and the stage1 handoff, each with its derivation from the build
artifacts and the digests computed here -- plus the vaportpm-format pcrs.json reference,
replayed from those digests. Format and verifier: workspace tools/pcr-replay. build.sh
writes both; CI uploads stage0.replay.json with the build.

Verified: make build-x86_64/aarch64 writes both files; on GCP n2d-standard-2 Shielded the
probe's PCRs reproduce with the workspace GCP platform file + this stage0.replay.json (all
non-ACPI events re-derived), and the full stage0 -> UKI -> stage2 chain verifies on GCP SEV
and SEV-SNP.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The driver printed ~25 lines per probe and, as a separate image, had no access to stage0's
[    S.mmm] timestamps. Now:

- stage0 hands each embedded driver its timestamp epoch (counter value at t = 0 + calibrated
  cycles/ms, two LE u64) as the image's LoadOptions before start_image; gvnic's clock.rs
  reads the same free-running counter, so its lines carry stage0's stamp ([    ?.???] if no
  epoch was passed).
- A successful probe prints one line:
    [    0.115] gvnic: 1ae0:0042 rev 0, GQI_QPL, 1 tx/1 rx, mtu 1460, mac ..., link up
  Step-by-step AQ/describe/queue detail moves behind a `verbose` cargo feature (vlog!).
  Every error path still prints at default, with its detail.

Verified on GCP n2d-standard-2 Shielded (gVNIC) and locally on QEMU x86_64.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Doorbells: BAR2 (queue doorbells) is now written with direct big-endian stores to the BAR's host
address (PciIo.GetBarAttributes; host = AddrRangeMin - AddrTranslationOffset), as every reference
driver does (Linux iowrite32be, FreeBSD bus_write_4, DPDK rte_write32, iPXE's EFI build writel).
BAR0 (registers, admin queue) stays on PciIo.Mem. GCE backs the doorbell BAR as memory rather
than trapping MMIO: under Intel TDX the firmware's PciIo.Mem path is a TDVMCALL MMIO hypercall
that never reaches it (doorbells read back 0, the device never sees TX or RX posts), while a
direct store through the firmware's shared MMIO mapping does. Device-supplied doorbell indices are
bounds-checked against the BAR length, since the address is now dereferenced directly.

Teardown: the ExitBootServices hook now does what Linux does on close + remove instead of only a
reset: DESTROY_TX_QUEUE, DESTROY_RX_QUEUE, UNREGISTER_PAGE_LIST (TX, RX),
DECONFIGURE_DEVICE_RESOURCES, then reset (a failed command surrenders to the reset, as gve_close
does). Admin-queue commands use pre-allocated DMA memory and Stall-based polling only, as EBS
requires. The hook is armed once the device has its fixed home in the SNP instance.

Verified: GCP c3 TDX (where gVNIC had no working data path before), c3 Shielded and n2d SEV-SNP;
QEMU x86_64 / aarch64 (no gVNIC there; the driver stays idle).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ves (GCE TDX)

GCE's firmware (ovmf_x64_csm) drives the UEFI tick from the 8254 PIT through the 8259 PIC. An
Intel TDX guest receives interrupts only through its virtual x2APIC, so IRQ0 is never delivered:
the PIT counts but no UEFI timer event ever fires, and EDK2's network stack (MNP receive polling,
DHCP retransmits, TCP timers) never runs. Measured on c3-standard-4: 0 ticks of a 10 ms event in
300 ms under TDX, 30 on Shielded; the firmware's LAPIC timer is masked on both.

lapic_tick::ensure() (x86_64, right after timing::init) probes the firmware tick for 50 ms and,
only if it is dead, does what OVMF's LocalApicTimerDxe would: calibrates the LAPIC timer against
a stall, programs it periodic at the firmware timer's own period on the first free vector, and
from its interrupt calls the firmware timer driver's GenerateSoftInterrupt() (one CoreTimerTick
per period). The ISR follows LocalApicTimerDxe's structure, including a port of OVMF's
NestedInterruptTplLib (BSD-2-Clause-Patent, Fen Systems Ltd.) so a burst of ticks cannot nest
RestoreTPL() frames without bound. The LAPIC timer registers are saved and restored exactly at
ExitBootServices. Where the firmware tick works (QEMU, Shielded, SEV, SEV-SNP) nothing changes
beyond the 50 ms probe.

Verified: GCP c3 TDX full chain (22 MB UKI download under the LAPIC tick, stage1, stage2); c3
Shielded and n2d SEV-SNP (tick alive, workaround off); QEMU x86_64 / aarch64 full chains.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@HarryR HarryR changed the title stage0: reproducible SB varstores, GCP support (gVNIC, dbx), PCR reproduction, pinned harness stage0: reproducible SB varstores, GCP support (gVNIC, dbx, TDX), PCR replay file, pinned harness Nov 10, 2026
Events were grouped by PCR. Only the order within one PCR affects its value, but a platform
that routes events into another PCR (GCE TDX logs the GPT and BOOT*.EFI into PCR2) needs them
in the order they really reach it: GPT, then the application. The order matches OVMF and GCE
event logs. Same event set; pcrs.json byte-identical on x86_64 and aarch64.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@HarryR
HarryR marked this pull request as ready for review November 14, 2026 05:56
@HarryR
HarryR merged commit 32f078c into main Nov 14, 2026
5 checks passed
@HarryR
HarryR deleted the mkvarstore-port-forward branch November 14, 2026 05:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant