From 2f91bae0c72fbcdee47106aaf7fc2db632208c7a Mon Sep 17 00:00:00 2001 From: HaRoLd <303926+HarryR@users.noreply.github.com> Date: Sat, 14 Nov 2026 22:23:38 +0000 Subject: [PATCH 1/4] predict-pcrs: GPT event takes its digest from the attestation stage0's EV_EFI_GPT_EVENT derives from boot.disk, which only holds on a first boot (stage2 rewrites the GPT). Mark it "from_attestation": "gpt" so pcr-replay uses the attestation's GPT digests (lockboot/vaportpm#13) and reproduces PCR5 (PCR2 on GCE TDX) on every boot. pcrs.json stays the first-boot reference. Co-Authored-By: Claude Opus 5.5 --- tools/predict-pcrs.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/predict-pcrs.py b/tools/predict-pcrs.py index cc114ee..8e2aea7 100755 --- a/tools/predict-pcrs.py +++ b/tools/predict-pcrs.py @@ -13,7 +13,9 @@ # (The embedded NIC drivers and the payload are loaded through stage0's own # Security2 override, which bypasses the firmware's image measurement: the # drivers are covered by stage0's own hash, the payload by PCR14.) -# PCR5 EV_SEPARATOR, EV_EFI_GPT_EVENT = UEFI_GPT_DATA of boot.disk. +# PCR5 EV_SEPARATOR, EV_EFI_GPT_EVENT = UEFI_GPT_DATA of boot.disk. That is the GPT a +# first boot measures; stage2 rewrites it, so the event is marked +# "from_attestation": "gpt" and a replay takes the attestation's GPT digests. # PCR7 SecureBoot, PK, KEK, db, dbx (EV_EFI_VARIABLE_DRIVER_CONFIG, the enrolled ESLs), # EV_SEPARATOR, EV_EFI_VARIABLE_AUTHORITY = the db entry that verified stage0. # The ESLs are rebuilt with mkvarstore.py's own code; on GCP they are @@ -30,7 +32,7 @@ # updates: a per-platform replay file (golden readings) supplies them. # # Also writes pcrs.json (vaportpm layout): replaying this file alone, i.e. every PCR it models -# except the payload-dependent PCR14 -- the reference a verifier compares a quote against. +# except the payload-dependent PCR14, with boot.disk's GPT (a first boot's PCR5). # # usage: predict-pcrs.py [--banks sha256,sha384] --replay F [--out pcrs.json] from __future__ import annotations @@ -179,6 +181,8 @@ def esl(role: str) -> dict[str, Any]: e["digest"] = mode e["digests"] = {b: (authenticode(data, getattr(hashlib, b)) if mode == "authenticode" else getattr(hashlib, b)(data).digest()).hex() for b in banks} + if typ == "EV_EFI_GPT_EVENT": + e["from_attestation"] = "gpt" events.append(e) events.append({"pcr": 14, "type": "unlogged", "by": "stage0", "about": "the payload stage0 verified and runs: H_bank(sha256(payload))", From 21f44aa1015b1d6925082ea0e115dfc4661c60f0 Mon Sep 17 00:00:00 2001 From: HaRoLd <303926+HarryR@users.noreply.github.com> Date: Sun, 15 Nov 2026 12:31:46 +0000 Subject: [PATCH 2/4] ci: create the release as a draft, then publish action-gh-release with draft: false publishes the release before uploading its assets; an immutable release accepts no uploads once published, so the first tagged release would ship empty (vaportpm v0.4.0 did, vaportpm#14). Create it as a draft with the assets, then publish with `gh release edit --draft=false`. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/build.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d0b0510..32430f5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -99,7 +99,10 @@ jobs: with: subject-checksums: subjects.sha256 - - name: Create stage0 release + # Created as a draft with its assets, then published: a release is immutable from the + # moment it is published (repo setting, workspace tools/rulesets.sh) and then accepts no + # uploads, so publishing first leaves it empty (as vaportpm v0.4.0 was). + - name: Create draft stage0 release uses: softprops/action-gh-release@718ea10b132b3b2eba29c1007bb80653f286566b # v3.0.1 with: tag_name: ${{ github.ref_name }} @@ -109,11 +112,16 @@ jobs: stage0-x86_64.zip stage0-aarch64.zip tools/qemu-test.sh - draft: false + draft: true prerelease: true generate_release_notes: true make_latest: true + - name: Publish stage0 release + env: + GH_TOKEN: ${{ github.token }} + run: gh release edit "${{ github.ref_name }}" -R "${{ github.repository }}" --draft=false + # ---- QEMU test-harness image (tag: v*) ----------------------------- # End-user harness: qemu + swtpm + OVMF/AAVMF + the EC2 metadata mock, qemu-test.sh as entrypoint. # Published with the stage0 release it ships beside: its firmware boots that release's efi-vars. From f3b23b9c7d536dc0a8ceecfdf411c17ec5f43d92 Mon Sep 17 00:00:00 2001 From: HaRoLd <303926+HarryR@users.noreply.github.com> Date: Wed, 18 Nov 2026 08:14:46 +0000 Subject: [PATCH 3/4] publish: verify the release's tag and asset; read os-release as data ec2/create.sh and gcp/create.sh, release path: - gh attestation verify gains --source-ref refs/tags/, so the provenance must come from a build of that tag (only admins create v* tags; none can be moved), and gh release verify-asset checks the zip is an asset of the immutable release. - os-release is parsed for the keys used instead of being sourced: under --no-verify it is unverified downloaded content. Tested: both gh checks against lockboot/vaportpm v0.4.1 (its tag passes; another tag and refs/heads/main fail); the parser on the built os-release, on a hostile file (nothing executed) and on a file missing a key (abort). The release path end to end needs a stage0 release. Co-Authored-By: Claude --- tools/publish/ec2/create.sh | 23 ++++++++++++++++++----- tools/publish/gcp/create.sh | 24 +++++++++++++++++++----- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/tools/publish/ec2/create.sh b/tools/publish/ec2/create.sh index e474fe0..af8c664 100755 --- a/tools/publish/ec2/create.sh +++ b/tools/publish/ec2/create.sh @@ -128,8 +128,12 @@ if [ "${VERSION}" != "local" ]; then echo "Repository: ${GH_REPO}; fetching stage0-${ARCH}.zip @ ${VERSION}" gh release download "${VERSION}" --repo "${GH_REPO}" --pattern "stage0-${ARCH}.zip" --dir "${TEMP_DIR}" \ || die "failed to download stage0-${ARCH}.zip from release ${VERSION}" - gh attestation verify "${ZIP}" --repo "${GH_REPO}" \ - || die "attestation verification failed for stage0-${ARCH}.zip" + # The provenance must come from a build of this release's tag (only admins create v* + # tags, and none can be moved), and the zip must be the asset of the immutable release. + gh attestation verify "${ZIP}" --repo "${GH_REPO}" --source-ref "refs/tags/${VERSION}" \ + || die "attestation verification failed for stage0-${ARCH}.zip (built from refs/tags/${VERSION}?)" + gh release verify-asset "${VERSION}" "${ZIP}" --repo "${GH_REPO}" \ + || die "stage0-${ARCH}.zip is not an asset of the immutable release ${VERSION}" fi unzip -q "${ZIP}" -d "${TEMP_DIR}" WORK_DIR="${TEMP_DIR}" @@ -146,9 +150,18 @@ for f in "${OS_RELEASE_FILE}" "${IMAGE_FILE}" "${UEFI_DATA_FILE}"; do [ -f "$f" ] || die "required file not found: $f (build it first: make build-${ARCH})" done -# os-release provides ID, VERSION_ID, BUILD_ID, NAME, PRETTY_NAME (our own artifact). -# shellcheck disable=SC1090 -source "${OS_RELEASE_FILE}" +# os-release provides ID, VERSION_ID, BUILD_ID, PRETTY_NAME. Read as data, never sourced: +# under --no-verify it is unverified downloaded content. +os_release() { # KEY -> its value, surrounding double quotes removed + local v + v=$(grep -m1 "^$1=" "${OS_RELEASE_FILE}") || die "os-release: no $1 in ${OS_RELEASE_FILE}" + v="${v#*=}"; v="${v%\"}"; v="${v#\"}" + printf '%s' "$v" +} +ID=$(os_release ID) +VERSION_ID=$(os_release VERSION_ID) +BUILD_ID=$(os_release BUILD_ID) +PRETTY_NAME=$(os_release PRETTY_NAME) AMI_NAME="${ID}-${ARCH}-${VERSION_ID}-${BUILD_ID}" # A no-Secure-Boot debug AMI is a distinct image (don't collide with the real one). diff --git a/tools/publish/gcp/create.sh b/tools/publish/gcp/create.sh index 8ae815c..37ea3be 100755 --- a/tools/publish/gcp/create.sh +++ b/tools/publish/gcp/create.sh @@ -126,8 +126,12 @@ if [ "${VERSION}" != "local" ]; then echo "Repository: ${GH_REPO}; fetching stage0-${ARCH}.zip @ ${VERSION}" gh release download "${VERSION}" --repo "${GH_REPO}" --pattern "stage0-${ARCH}.zip" --dir "${TEMP_DIR}" \ || die "failed to download stage0-${ARCH}.zip from release ${VERSION}" - gh attestation verify "${ZIP}" --repo "${GH_REPO}" \ - || die "attestation verification failed for stage0-${ARCH}.zip" + # The provenance must come from a build of this release's tag (only admins create v* + # tags, and none can be moved), and the zip must be the asset of the immutable release. + gh attestation verify "${ZIP}" --repo "${GH_REPO}" --source-ref "refs/tags/${VERSION}" \ + || die "attestation verification failed for stage0-${ARCH}.zip (built from refs/tags/${VERSION}?)" + gh release verify-asset "${VERSION}" "${ZIP}" --repo "${GH_REPO}" \ + || die "stage0-${ARCH}.zip is not an asset of the immutable release ${VERSION}" fi unzip -q "${ZIP}" -d "${TEMP_DIR}" WORK_DIR="${TEMP_DIR}" @@ -160,9 +164,19 @@ if [ "${DEFAULT_DBX}" != "true" ]; then [ -f "${DBX_FILE}" ] || die "dbx.auth.bin not found: ${DBX_FILE} (rebuild: make build-${ARCH})" fi -# os-release provides ID, VERSION_ID, BUILD_ID, NAME, PRETTY_NAME (our own artifact). -# shellcheck disable=SC1090 -source "${OS_RELEASE_FILE}" +# os-release provides ID, VERSION_ID, BUILD_ID, NAME, PRETTY_NAME. Read as data, never sourced: +# under --no-verify it is unverified downloaded content. +os_release() { # KEY -> its value, surrounding double quotes removed + local v + v=$(grep -m1 "^$1=" "${OS_RELEASE_FILE}") || die "os-release: no $1 in ${OS_RELEASE_FILE}" + v="${v#*=}"; v="${v%\"}"; v="${v#\"}" + printf '%s' "$v" +} +ID=$(os_release ID) +VERSION_ID=$(os_release VERSION_ID) +BUILD_ID=$(os_release BUILD_ID) +NAME=$(os_release NAME) +PRETTY_NAME=$(os_release PRETTY_NAME) VERSION_DASH=$(echo "${VERSION_ID}" | tr '.' '-') ARCH_DASH=$(echo "${ARCH}" | tr '_' '-') From 4bb113b8440dd78a3015a3514937c7f274ec3058 Mon Sep 17 00:00:00 2001 From: HaRoLd <303926+HarryR@users.noreply.github.com> Date: Wed, 18 Nov 2026 15:11:00 +0000 Subject: [PATCH 4/4] build: link UEFI targets with /DEBUG:NONE; os-release version from the commit date CI's stage0.efi, ena.efi and gvnic.efi each differed from a local build of the same commit in 8 bytes: the GUID of the linker's debug record. rustc links UEFI targets with /DEBUG, the GUID is a hash of the .pdb, and the .pdb records where the toolchain is installed (/tmp/.rustup in CI, /src/.rustup locally), which --remap-path-prefix does not reach. So the Authenticode hash and PCR4 differed. With /DEBUG:NONE no .pdb is written and the image carries no debug record. os-release's yy.mm version is now the committer date (UTC) of the commit being built, passed in by the Makefile (the build image has no git), instead of the build date. build.sh refuses to run without it. Tested: a clean build under CI's settings (CI=true) and a normal local build are byte-identical for all three binaries on x86_64 and aarch64; workspace `make selftest` passes on both arches. Co-Authored-By: Claude --- .cargo/config.toml | 9 +++++++-- Makefile | 5 ++++- tools/build.sh | 3 ++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 4486c9c..06b6c41 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -14,6 +14,11 @@ # toolchain has not), rustc emits std panic-location paths from the sysroot instead of the baked # /rustc/, so we remap the sysroot rust-src path to that same /rustc/. UPDATE THE HASH # when bumping the toolchain (rustc -Vv commit-hash); a stale value silently no-ops (CI==local catches it). +# +# /DEBUG:NONE (UEFI targets): rustc links these with /DEBUG, which puts a debug record in the image +# whose GUID is a hash of the .pdb, and the .pdb records where the toolchain is installed (the rustc +# path, the sysroot's rlib paths: /tmp/.rustup in CI, /src/.rustup locally). The linker writes those, +# so --remap-path-prefix does not reach them. With no .pdb the image carries no debug record. [target.x86_64-unknown-linux-musl] # Fully static musl for the host-side signer (stage0-sign); rust-lld, no system cc. @@ -24,10 +29,10 @@ rustflags = ["-C", "linker=rust-lld", "-C", "target-feature=+crt-static", "-C", [target.x86_64-unknown-uefi] # The measured bootloader + payloads. Static, rust-lld. -rustflags = ["-C", "linker=rust-lld", "-C", "target-feature=+crt-static", "-C", "link-arg=-static", "--remap-path-prefix=/src/.cargo=/cargo", "--remap-path-prefix=/tmp/.cargo=/cargo", "--remap-path-prefix=/src/.rustup/toolchains/1.91.1-x86_64-unknown-linux-gnu/lib/rustlib/src/rust=/rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb"] +rustflags = ["-C", "linker=rust-lld", "-C", "target-feature=+crt-static", "-C", "link-arg=-static", "-C", "link-arg=/DEBUG:NONE", "--remap-path-prefix=/src/.cargo=/cargo", "--remap-path-prefix=/tmp/.cargo=/cargo", "--remap-path-prefix=/src/.rustup/toolchains/1.91.1-x86_64-unknown-linux-gnu/lib/rustlib/src/rust=/rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb"] [target.aarch64-unknown-uefi] -rustflags = ["-C", "linker=rust-lld", "-C", "target-feature=+crt-static", "-C", "link-arg=-static", "--remap-path-prefix=/src/.cargo=/cargo", "--remap-path-prefix=/tmp/.cargo=/cargo", "--remap-path-prefix=/src/.rustup/toolchains/1.91.1-x86_64-unknown-linux-gnu/lib/rustlib/src/rust=/rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb"] +rustflags = ["-C", "linker=rust-lld", "-C", "target-feature=+crt-static", "-C", "link-arg=-static", "-C", "link-arg=/DEBUG:NONE", "--remap-path-prefix=/src/.cargo=/cargo", "--remap-path-prefix=/tmp/.cargo=/cargo", "--remap-path-prefix=/src/.rustup/toolchains/1.91.1-x86_64-unknown-linux-gnu/lib/rustlib/src/rust=/rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb"] # Host target for proc-macros and build scripts: rust-lld only (no crt-static), so they link with no # system cc. Kept out of the shared workspace config because the gnu-host repos link C and need cc. diff --git a/Makefile b/Makefile index dd38204..083ecdf 100644 --- a/Makefile +++ b/Makefile @@ -128,8 +128,11 @@ build/%/stage0.efi: build/%/ena.efi build/%/gvnic.efi docker-build-base bash -c "mkdir -p build/$* && rustup target add $*-unknown-uefi && cargo build --release --manifest-path $(STAGE0_DIR)/Cargo.toml --target $*-unknown-uefi $(if $(STAGE0_FEATURES),--features $(STAGE0_FEATURES)) && cp -v $(STAGE0_DIR)/target/$*-unknown-uefi/release/stage0.efi $@" # ---- Assemble + db-sign the boot disk (privileged: losetup/mount) ---- +# os-release carries a yy.mm version: the committer date (UTC) of the commit being built, not the +# build date. Read here because the build image has no git. +COMMIT_YEAR_MONTH := $(shell TZ=UTC git log -1 --format=%cd --date=format-local:%y.%m) build/%/boot.disk: build/%/stage0.efi build/keys/db.crt - $(DOCKER_RUN) -e ARCH=$* $(BUILD_IMAGE) ./tools/build.sh + $(DOCKER_RUN) -e ARCH=$* -e COMMIT_YEAR_MONTH=$(COMMIT_YEAR_MONTH) $(BUILD_IMAGE) ./tools/build.sh build-amd64 build-x86_64: build/x86_64/boot.disk build-arm64 build-aarch64: build/aarch64/boot.disk diff --git a/tools/build.sh b/tools/build.sh index 70cbeec..194ec86 100755 --- a/tools/build.sh +++ b/tools/build.sh @@ -112,7 +112,8 @@ echo "EFI vars written: ${EFI_VARS_OVMF}" # Emit os-release so the cloud publishers can name/tag the image. BUILD_ID is # derived from the signed stage0 hash so each build is traceable. OSREL_PATH="${OUTPUT_DIR}/os-release" -YEAR_MONTH=$(date +%y.%m) +# yy.mm of the commit being built (from the Makefile), never the build date. +YEAR_MONTH="${COMMIT_YEAR_MONTH:?set COMMIT_YEAR_MONTH (yy.mm of the commit being built; the Makefile does)}" { echo "ID=lockboot" echo "VERSION_ID=${YEAR_MONTH}"