From 7a4acb6d0fba509834d8f7f0eebd8f99d089a6db Mon Sep 17 00:00:00 2001 From: Thierry Laurion Date: Thu, 17 Sep 2026 11:25:22 -0400 Subject: [PATCH 1/4] tpm: align documentation with sealing and attestation code Correct the PCR map, sealing policies, rollback counter, integrity gate and PCR 16 history against the sealing and attestation code. Describe the TOTP/HOTP and LUKS DUK seal policies as they are actually applied, and stop conflating a missing rollback record with a mismatched one (#2068). Drop the unused owner-passphrase argument from seal-totp.sh. tpmr.sh prompts for and caches the passphrase itself, so the call site changes nothing at runtime. State the real 8-character Owner Passphrase minimum. Signed-off-by: Thierry Laurion --- doc/architecture.md | 6 +-- doc/boot-process.md | 5 ++- doc/keys.md | 21 ++++----- doc/logging.md | 4 +- doc/prerequisites.md | 5 ++- doc/recovery-shell.md | 7 +-- doc/security-model.md | 83 +++++++++++++++++++--------------- doc/tpm.md | 99 +++++++++++++++++++++++++++-------------- doc/ux-patterns.md | 11 ++--- initrd/bin/seal-totp.sh | 3 +- 10 files changed, 149 insertions(+), 95 deletions(-) diff --git a/doc/architecture.md b/doc/architecture.md index 98d871917c..2d1e8d96c5 100644 --- a/doc/architecture.md +++ b/doc/architecture.md @@ -37,7 +37,7 @@ without a second-stage bootloader. Measured boot is transitive: each stage meas next before executing it. The CRTM (running in bootblock) measures FMAP and the bootblock image into the preram log. Measurements taken before the TPM hardware is initialized are cached in the preram log and flushed to PCR 2 once TPM setup is complete. See -[tpm.md](tpm.md#srtm-in-coreboot) for per-board TPM init timing. +[tpm.md](tpm.md#root-of-trust-and-srtm-chain) for TPM init timing for each board. The framebuffer initialized by coreboot (libgfxinit on pre-Alder Lake, FSP GOP on Alder Lake and newer) must survive across kexec for display @@ -74,7 +74,7 @@ execution. Source lives in `initrd/`. | Boot signing | `initrd/bin/kexec-sign-config.sh` | GPG-sign /boot files, create checksums | | Boot verification | `initrd/bin/kexec-select-boot.sh` | Verify checksums, select and kexec the OS | | LUKS key sealing | `initrd/bin/kexec-seal-key.sh` | Seal disk encryption key to TPM | -| TOTP/HOTP | `initrd/bin/seal-totp.sh`, `initrd/bin/seal-hotpkey.sh` | Seal attestation secrets to TPM | +| TOTP/HOTP | `initrd/bin/seal-totp.sh` (seal), `initrd/bin/seal-hotpkey.sh` (reuse) | TOTP secret sealed to TPM; the same secret programs the HOTP dongle | | OEM reset | `initrd/bin/oem-factory-reset.sh` | Full re-ownership: GPG, TPM, TOTP, checksums | | Config GUI | `initrd/bin/config-gui.sh` | Runtime configuration menus | | Functions lib | `initrd/etc/functions.sh` | Shared utilities: logging, INPUT, TPM helpers | @@ -132,7 +132,7 @@ The CI pipeline's workspace and cache behavior is documented in ## Key design principles - **No network at boot** — all verification is local; no certificate authorities -- **Hardware root of trust** — the coreboot bootblock (IBB) is the Static Core Root of Trust for Measurement (S-CRTM): the first code executed by the CPU, directly from SPI flash. Coreboot implements a transitive measurement chain: the CRTM measures FMAP and the bootblock image into the preram log, then each subsequent stage measures the next before executing it — bootblock measures romstage, romstage measures ramstage, ramstage measures the Heads payload. Measurements are taken during CBFS file loading, before decompression, and are recorded in TPM PCR 2 (SRTM) once the TPM hardware is initialized (`tpm_setup()`). Measurements taken before TPM init are cached in the preram log and flushed to PCR 2 by `tspi_measure_cache_to_pcr()` during `tpm_setup()`. The full chain — bootblock → romstage → ramstage → Heads Linux kernel + initrd — is recorded into PCR 2. PCRs 0, 1, and 3 remain zero as policy anchors. See [tpm.md](tpm.md#srtm-in-coreboot) for TPM init timing per board. See [wp-notes.md](wp-notes.md#pr0-chipset-locking) for SPI write-protection and PR0 chipset locking details. +- **Hardware root of trust** — the coreboot bootblock (IBB) is the Static Core Root of Trust for Measurement (S-CRTM): the first code executed by the CPU, directly from SPI flash. Coreboot implements a transitive measurement chain: the CRTM measures FMAP and the bootblock image into the preram log, then each subsequent stage measures the next before executing it — bootblock measures romstage, romstage measures ramstage, ramstage measures the Heads payload. Measurements are taken during CBFS file loading, before decompression, and are recorded in TPM PCR 2 (SRTM) once the TPM hardware is initialized (`tpm_setup()`). Measurements taken before TPM init are cached in the preram log and flushed to PCR 2 by `tspi_measure_cache_to_pcr()` during `tpm_setup()`. The full chain — bootblock → romstage → ramstage → Heads Linux kernel + initrd — is recorded into PCR 2. PCRs 1 and 3 are read live at seal time and are zero while their coreboot features stay disabled; PCR 0 is normally zero but may be populated by BootGuard Measured Boot. See [tpm.md](tpm.md#root-of-trust-and-srtm-chain) for TPM init timing per board. See [wp-notes.md](wp-notes.md#pr0-chipset-locking) for SPI write protection and PR0 chipset locking details. - **Fail-closed** — failed integrity verification drops to a recovery shell. Recovery shell authentication via GPG smartcard is enforced when GPG key backup has been configured (`CONFIG_HAVE_GPG_KEY_BACKUP=y`), which is set by answering "y" to `"Would you like to format an encrypted USB Thumb drive to store GPG key material? (Required to enable GPG authentication)"` during OEM Factory Reset / Re-Ownership. Otherwise the recovery shell is unauthenticated. An "Ignore tampering and force a boot (Unsafe!)" option is available to override this. - **Separation of duties** — the public key that verifies `/boot` signatures is stored in CBFS (ROM). The private key that signs `/boot` stays on a USB security dongle and never leaves it. - **Auditability** — all source is open, builds are reproducible, ROM images are verifiable diff --git a/doc/boot-process.md b/doc/boot-process.md index 99abd04bc4..089b759a51 100644 --- a/doc/boot-process.md +++ b/doc/boot-process.md @@ -309,7 +309,10 @@ Optionally, root partition hashes are also checked if `CONFIG_ROOT_CHECK_AT_BOOT The TPM monotonic counter index is read from `/boot/kexec_rollback.txt` and the counter is read from the TPM. The SHA-256 of the counter file is then checked -against the hash stored in `kexec_rollback.txt`. Any discrepancy aborts the boot. +against the hash stored in `kexec_rollback.txt`. A missing rollback record +blocks boot only when `CONFIG_BOOT_REQ_ROLLBACK=y`; an existing record mismatch +aborts boot unless `CONFIG_IGNORE_ROLLBACK=y`. No board config enables the +missing record check. ### OS boot execution (`do_boot`) diff --git a/doc/keys.md b/doc/keys.md index 1f7de8c6f9..ec64d0b423 100644 --- a/doc/keys.md +++ b/doc/keys.md @@ -17,7 +17,8 @@ Key passphrase. ## TPMTOTP / HOTP Shared Secret -A random 20-byte value generated during OEM Factory Reset / Re-Ownership. +A random 20-byte value generated when a new TOTP/HOTP secret is created, +normally on the first boot after OEM Factory Reset / Re-Ownership. - **TOTP (smartphone):** sealed into TPM NVRAM against PCR values; on each boot Heads unseals it if PCRs match and displays the current TOTP code for @@ -67,7 +68,7 @@ from the expected firmware. - Ties the disk to one machine. - In recovery mode PCRs will not match; use the Disk Recovery Key instead. -- After 3 failed unlock attempts Heads falls back to the Disk Recovery Key. +- After 3 failed unlock attempts Heads offers to boot using the Disk Recovery Key. - **Recommended length:** 3 Diceware words. ## Owner's GPG Key @@ -80,27 +81,27 @@ firmware image and used to verify `/boot` signatures on every boot. | PCR | Content | |-----|---------| -| 0 | (reserved; populated by binary blobs where applicable for SRTM) | +| 0 | (unused by Heads; zero unless BootGuard's Measured Boot policy populates it before coreboot) | | 1 | (reserved) | | 2 | coreboot bootblock, ROM stage, RAM stage, Heads Linux kernel + initrd | | 3 | (reserved) | -| 4 | Boot mode (0 during `/init`, then `recovery` or `normal-boot`) | +| 4 | Boot path (`"usb"` = USB boot, `"generic"` = normal boot, `"recovery"` = recovery shell; precomputed at seal time from the firmware event log) | | 5 | Heads Linux kernel modules | | 6 | Drive LUKS headers | | 7 | Heads user-specific CBFS files (config.user, GPG keyring, etc.) | -| 16 | Used for TPM future-calc of LUKS header during DUK setup | -Secrets sealed against PCRs 2, 4, 5, 6, 7. If any of these change -(firmware update, kernel module change, LUKS header change, config change) -unseal operations fail until secrets are re-sealed. +TOTP/HOTP is sealed against PCRs 0,1,2,3,4,7; the LUKS DUK against PCRs +0,1,2,3,4,5,6,7. A firmware, kernel module, LUKS header, or CBFS config change +breaks the relevant unseal until secrets are sealed again. ## TPM Unseal Errors `Error Authentication failed (Incorrect Password) from TPM_Unseal` — PCRs match but the passphrase is wrong (expected; just re-enter it). -Any other TPM_Unseal error means the PCR measurements differ from when -secrets were sealed — potential tampering or an unsigned firmware update. +A different TPM_Unseal error can have several causes, including a decryption +failure or TPM dictionary attack lockout. Check the event log (`cbmem -L`) and +the TPM state before assuming tampering. Review the PCR2 TCPA event log from Recovery Shell: diff --git a/doc/logging.md b/doc/logging.md index bb8f0935cb..0e2e474c35 100644 --- a/doc/logging.md +++ b/doc/logging.md @@ -124,9 +124,9 @@ For example: * `INFO "TPM: Extending PCR[4] with string 'text' (hash: abc123...)"` — string extend * `INFO "TPM: Extending PCR[4] with content of /path/file (hash: abc123...)"` — file content extend -* `INFO "Measuring /boot/vmlinuz into TPM PCR[4]"` — integrity measurement start +* `INFO "TPM: Extending PCR[4] with content of string 'generic' to prevent secret unsealing"` — boot path string extend on the normal boot path * `INFO "TPM: PCR[4] after extend: 0x..."` — PCR state after extend -* `STATUS "Measuring TPM Disk Unlock Key (DUK) into PCR[6]"` — action announcement (PCR[6] for LUKS sealing) +* `STATUS "Measuring TPM Disk Unlock Key (DUK) for sealing policy (PCR[6])"` — action announcement (PCR[6] for LUKS sealing) Do NOT use INFO for: diff --git a/doc/prerequisites.md b/doc/prerequisites.md index d37cf7f62a..4dd4cb6732 100644 --- a/doc/prerequisites.md +++ b/doc/prerequisites.md @@ -35,7 +35,10 @@ Source of truth for IDs is `initrd/etc/dongle-versions`. **HOTP (recommended when available):** - Heads generates HOTP codes and the dongle verifies them automatically. -- Pass = green LED, fail = red LED and boot halt. +- Pass = green LED; fail = red LED and an error screen whose options depend + on the failure: an invalid code offers generating a new secret, ignoring + the error, or exiting to the recovery shell; a dongle communication error + offers retrying or ignoring it. - Does not require accurate time. **TPMTOTP (smartphone fallback):** diff --git a/doc/recovery-shell.md b/doc/recovery-shell.md index cab3d690bb..5df5a08ce6 100644 --- a/doc/recovery-shell.md +++ b/doc/recovery-shell.md @@ -13,11 +13,12 @@ gives direct access to block devices, GPG, TPM tools, and flash utilities. ## Limitations -The Recovery Shell boots with PCR 4 set to `recovery` instead of -`normal-boot`. This means: +Entering the Recovery Shell extends PCR 4 with `recovery` instead of the +normal `generic` value (or the unextended state). This means: - **TPM-sealed secrets will not unseal** — PCRs no longer match. -- TOTP/HOTP sealing and TPM Disk Unlock Key creation/unsealing do not work. +- TOTP/HOTP and TPM Disk Unlock Key unsealing fail; the GUI flows that + create or reseal secrets are not available in the recovery shell. - To perform seal/unseal operations return to the normal GUI boot. ## Common Operations diff --git a/doc/security-model.md b/doc/security-model.md index 5979db53c2..eb08a962d4 100644 --- a/doc/security-model.md +++ b/doc/security-model.md @@ -147,19 +147,24 @@ hardware. See [tpm.md](tpm.md) for the full breakdown. PCRs 0, 1, and 3 are unused — the `CONFIG_PCR_*` entries for those registers are slot assignments for optional coreboot features that are not enabled. They -remain at zero and are anchored as zero in sealing policies. +are read live at seal time and are normally zero (BootGuard Measured Boot, if +enabled, populates PCR 0 before coreboot). On boards with coreboot measured +boot, PCR 2 is not zero: it carries the SRTM chain. Heads extends additional PCRs during userspace boot: -- **PCR 4** — boot mode tracking; see below +- **PCR 4** — boot path tracking; see below - **PCR 5** — each kernel module loaded via the `insmod` wrapper (binary + parameters) - **PCR 6** — LUKS header dump (by `qubes-measure-luks`) before disk unlock - **PCR 7** — each CBFS/UEFI file extracted from ROM (by `cbfs-init`/`uefi-init`) Heads extends PCR 4 further depending on execution path: +- **USB boot**: PCR 4 is extended with `"usb"`, locking out unsealing on the USB + boot path. - **Normal boot**: `calcfuturepcr 4` pre-computes the expected value and secrets - are sealed against it. + are sealed against it; the running path then extends `"generic"` to lock out + further unsealing. - **Recovery shell**: PCR 4 is extended with `"recovery"`, invalidating normal-boot unsealing for the rest of the session. @@ -178,8 +183,9 @@ which the user observes as a TOTP/HOTP mismatch. ### TOTP -A 20-byte random secret is generated at OEM Factory Reset and sealed to -TPM NVRAM. At each boot, `unseal-totp` retrieves it and generates the current +A 20-byte random secret is generated when a new TOTP/HOTP secret is created, +normally on the first boot after OEM Factory Reset / Re-Ownership, and sealed +to TPM NVRAM. At each boot, `unseal-totp` retrieves it and generates the current 30-second code. The user compares this against their authenticator app. ### HOTP (Reverse HOTP) @@ -206,10 +212,10 @@ in TPM NVRAM). On boards where `CONFIG_NO_TPM=y` (currently the Librem Mini, Librem Mini v2, and Librem 11), there is no TPM to seal secrets against PCR values. Heads falls back to a different HOTP secret derivation implemented in `secret_from_rom_hash` -in `initrd/etc/functions`: +in `initrd/etc/functions.sh`: 1. At seal time, `flash.sh` reads the full SPI ROM via flashrom/flashprog. -2. The SHA-256 of the ROM image is used directly as the HOTP secret. +2. The first 20 bytes of the SHA-256 of the ROM image are used as the HOTP secret. 3. The secret is programmed onto the USB security dongle. 4. At each boot, the ROM is read again, SHA-256 recomputed, and the HOTP code sent to the dongle for comparison. A changed ROM produces a different hash, @@ -241,8 +247,10 @@ does not provide the same tamper-evident guarantees as TPM PCR sealing. ### Attestation failure handling -If TOTP or HOTP unseal fails, `INTEGRITY_GATE_REQUIRED` is set and all TPM -secret sealing operations are blocked until the integrity gate passes. +If a TOTP unseal fails, `INTEGRITY_GATE_REQUIRED` is set and sealing new TPM +secrets is blocked until the integrity gate passes. A failed HOTP unseal or +missing token only shows a warning and returns to the menu; a failed HOTP code +check sets the gate. See [ux-patterns.md](ux-patterns.md#gate-before-sealing). --- @@ -259,8 +267,9 @@ When the user installs or updates the OS, `kexec-sign-config`: 1. Hashes all non-`kexec*` files in `/boot` into `kexec_hashes.txt` and generates a directory tree listing in `kexec_tree.txt`. 2. Signs the hash manifest with a GPG key, producing `kexec.sig`. -3. Increments the TPM rollback counter and stores the new counter hash in - `kexec_rollback.txt`. +3. When signing runs with the rollback counter enabled (`-r` on TPM boards + without `CONFIG_IGNORE_ROLLBACK`), increments the TPM rollback counter and + stores the new counter hash in `kexec_rollback.txt`. The signing key lives on a hardware security dongle (OpenPGP smartcard), never in the ROM. Signing requires physical possession of the card and @@ -338,11 +347,15 @@ and the /boot disk, preventing swap attacks. ### How the binding works -1. **TPM stores counter**: A monotonic counter is created in TPM NVRAM at OEM Factory Reset -2. **/boot stores hash**: SHA-256 hash of counter value is stored in `/boot/kexec_rollback.txt` -3. **Counter increments on update**: Every `kexec-sign-config` run increments the counter and updates the hash +1. **TPM stores counter**: A monotonic counter is created in TPM NVRAM at OEM Factory Reset, at TPM reset, or by signing when `kexec_rollback.txt` is missing +2. **/boot stores hash**: the sha256sum of the counter state file (`counter-`, index and value) is stored in `/boot/kexec_rollback.txt` +3. **Counter increments on signing**: Every `kexec-sign-config` run with rollback enabled increments the counter and updates the hash 4. **Verification at boot**: `kexec-select-boot` verifies the counter matches the stored hash +A missing rollback record blocks boot only when `CONFIG_BOOT_REQ_ROLLBACK=y`; +no board config enables that requirement. An existing record mismatch aborts +boot unless `CONFIG_IGNORE_ROLLBACK=y`. + ```text ┌─────────────────────────────────────────────────────────────────────────────┐ │ ROLLBACK COUNTER LIFECYCLE │ @@ -352,10 +365,10 @@ and the /boot disk, preventing swap attacks. │ ───────────────── ──────────── │ │ │ │ 1. Create counter in TPM NVRAM 1. Read counter from TPM │ -│ └─▶ counter_value = 0 │ │ +│ └─▶ create counter, then increment to 1 │ │ │ 2. Hash counter → /boot ▼ │ │ └─▶ kexec_rollback.txt 2. Hash counter │ -│ contains hash of "0" │ │ +│ contains hash of "1" │ │ │ ▼ │ │ 3. Compare with /boot hash │ │ │ │ @@ -388,8 +401,8 @@ creating additional hardware binding: │ ┌─────────────────────────────────────────────────────────────────────┐ │ │ │ TOTP/HOTP Secret Seal Policy: PCRs 0,1,2,3,4,7 │ │ │ │ │ │ -│ │ PCR 0,1,2,3: Platform configuration (unused but anchored as zero) │ │ -│ │ PCR 4: Boot mode (normal/recovery/usb) │ │ +│ │ PCR 0,1,3: Normally zero PCR 2: coreboot SRTM │ │ +│ │ PCR 4: Boot path ("usb"/"generic"/"recovery") │ │ │ │ PCR 7: CBFS/ROM files (user-injected) │ │ │ │ │ │ │ │ NOT included: PCR 5 (kernel modules), PCR 6 (LUKS headers) │ │ @@ -399,8 +412,8 @@ creating additional hardware binding: │ ┌─────────────────────────────────────────────────────────────────────┐ │ │ │ LUKS DUK Seal Policy: PCRs 0,1,2,3,4,5,6,7 │ │ │ │ │ │ -│ │ PCR 0,1,2,3: Platform configuration │ │ -│ │ PCR 4: Boot mode │ │ +│ │ PCR 0,1,3: Normally zero PCR 2: coreboot SRTM │ │ +│ │ PCR 4: Boot path ("usb"/"generic"/"recovery") │ │ │ │ PCR 5: Kernel modules (if loaded) │ │ │ │ PCR 6: LUKS header (measured at seal time) │ │ │ │ PCR 7: CBFS/ROM files │ │ @@ -409,13 +422,6 @@ creating additional hardware binding: │ │ → Changing kernel modules or LUKS headers requires resealing DUK │ │ │ └─────────────────────────────────────────────────────────────────────┘ │ │ │ -│ ┌─────────────────────────────────────────────────────────────────────┐ │ -│ │ PCR 16 (Scratch) │ │ -│ │ │ │ -│ │ Used internally for calcfuturepcr (pre-computing future values) │ │ -│ │ Not part of any sealing policy - purely for calculation │ │ -│ └─────────────────────────────────────────────────────────────────────┘ │ -│ │ └─────────────────────────────────────────────────────────────────────────────┘ ``` @@ -439,8 +445,9 @@ to prompting for the DRK passphrase. The DRK is always a valid recovery path. ## Integrity gate before sealing -Before any operation that seals new TPM secrets, `gate_reseal_with_integrity_report` -in `gui-init` verifies: +When a prior TOTP/HOTP failure has set `INTEGRITY_GATE_REQUIRED`, +`gate_reseal_with_integrity_report` in `gui-init` runs before sealing new TPM +secrets and verifies: 1. TPM is not in a reset-required state. 2. No prior TOTP/HOTP failure is recorded (`INTEGRITY_GATE_REQUIRED` is unset). @@ -450,7 +457,8 @@ in `gui-init` verifies: 6. User explicitly confirms proceeding. If any check fails, the sealing operation is aborted. This prevents new -secrets from being sealed against a potentially compromised `/boot`. +secrets from being sealed against a potentially compromised `/boot`. If the +flag is not set, only the reset-required check runs. For the UNKNOWN_KEY scenario and correct error messaging, see [ux-patterns.md](ux-patterns.md#security-ux--integrity-report-and-unknown-keys). @@ -470,9 +478,9 @@ For the UNKNOWN_KEY scenario and correct error messaging, see 3. **TPM rollback counter creation** — creates a new monotonic counter and stores its initial hash in `/boot/kexec_rollback.txt`. 4. **`/boot` signing** — hashes and GPG-signs the initial `/boot` state. -5. **TOTP/HOTP and LUKS DUK sealing** — TOTP/HOTP secrets are sealed - immediately; LUKS DUK sealing is performed by the user on the next boot - via the GUI menu. +5. **TOTP/HOTP and LUKS DUK sealing** — the HOTP counter file is created, but + TOTP/HOTP secrets are generated and sealed on the next boot; LUKS DUK + sealing is performed by the user from the GUI menu. --- @@ -482,8 +490,13 @@ All verification failures are fatal by default: - GPG signature mismatch → `die` (recovery shell) - Hash mismatch → `die` (recovery shell) -- TPM counter mismatch → `die` (recovery shell) +- TPM counter mismatch (when `CONFIG_IGNORE_ROLLBACK` is not set and the + rollback file exists) → `die` (recovery shell) - TOTP unseal failure → error menu (no unattended boot) - LUKS DUK unseal failure → OS prompts for DRK passphrase (no silent failure) -There is no "continue anyway" path for integrity failures. +Some failures remain overridable: the TOTP/HOTP error menus offer an ignore +option, and the boot options menu offers an unsafe forced boot. Overrides +stay on screen in their error or warning color; for TOTP failures and +invalid HOTP codes the integrity gate stays set, and ignoring a dongle +communication error clears it. diff --git a/doc/tpm.md b/doc/tpm.md index 8cecfb55b4..2c9ea10499 100644 --- a/doc/tpm.md +++ b/doc/tpm.md @@ -26,7 +26,7 @@ scripts call `tpmr.sh` rather than invoking `tpm` or `tpm2` directly. | --- | --- | | `pcrread` | Read a PCR value | | `pcrsize` | Print PCR byte size (20 or 32) | -| `calcfuturepcr` | Replay PCR extension to compute a future value | +| `calcfuturepcr` | Compute a PCR value by replaying the firmware event log | | `extend` | Extend a PCR with a hash or file | | `seal` | Seal a file to TPM NVRAM with a PCR policy | | `unseal` | Unseal from TPM NVRAM | @@ -36,7 +36,7 @@ scripts call `tpmr.sh` rather than invoking `tpm` or `tpm2` directly. | `counter_create` | Create a new monotonic counter | | `destroy` | Destroy an NVRAM index | | `reset` | Reset the TPM | -| `kexec_finalize` | Finalize PCR state before kexec (TPM2 only) | +| `kexec_finalize` | Flush TPM2 sessions, lock platform hierarchy (TPM2 only) | | `shutdown` | Orderly shutdown (TPM2 only) | --- @@ -50,10 +50,10 @@ optional coreboot measured-boot features. Coreboot supports several modes: | coreboot mode | PCRs used | Status in Heads | | --- | --- | --- | -| SRTM (Static Root of Trust for Measurement) | PCR 2 (`CONFIG_PCR_SRTM=2`) | **Active on all boards with TPM hardware and `CONFIG_TPM_MEASURED_BOOT=y`** | +| SRTM (Static Root of Trust for Measurement) | PCR 2 (`CONFIG_PCR_SRTM=2`) | **Active on TPM boards with measured boot — current coreboot uses `CONFIG_TPM_MEASURED_BOOT=y`; older forks (KGPE-D16, Librem L1UM) use the legacy `CONFIG_TPM_INIT=y`** | | Boot mode measurement | PCR 1 (`CONFIG_PCR_BOOT_MODE=1`) | Not enabled | | Hardware ID measurement | PCR 1 (`CONFIG_PCR_HWID=1`) | Not enabled | -| Runtime data | PCR 3 (`CONFIG_PCR_RUNTIME_DATA=3`) | Not enabled — coreboot's default slot for runtime data, but the feature is not activated in Heads; PCR 3 remains zero | +| Runtime data | PCR 3 (`CONFIG_PCR_RUNTIME_DATA=3`) | Not enabled — `CONFIG_TPM_MEASURE_MRC_CACHE` is off and `CONFIG_TPM_MEASURED_BOOT_RUNTIME_DATA` is empty, so PCR 3 stays zero | | Firmware version | PCR 10 (`CONFIG_PCR_FW_VER=10`) | Not enabled | ### Root of Trust and SRTM chain @@ -96,7 +96,7 @@ stack. Any modification to any of these stages produces a different PCR 2 value, causing unseal operations to fail. Under the active Heads configuration, only PCR 2 is extended by coreboot. -PCRs 0, 1, and 3 remain at zero and are anchored as zero in sealing policies. +PCRs 0, 1, and 3 are read live at seal time and are normally zero. #### Boards with different or absent coreboot measured boot @@ -156,19 +156,24 @@ unchanged; the TXT mechanism adds the DRTM capability on top of it. | PCR | Extended by | Content | | --- | --- | --- | -| 0 | unused | Zero; anchored in sealing policies | -| 1 | unused | Zero; anchored in sealing policies | -| 2 | coreboot SRTM | Boot block, ROM stage, RAM stage, Heads Linux kernel + initrd | -| 3 | unused | Zero; anchored in sealing policies | -| 4 | Heads (`usb-init.sh`, `kexec-insert-key.sh`, `initrd/etc/functions.sh`) | Boot mode tracking: `"usb"` during USB init, `"generic"` after DUK unsealed, `"recovery"` when recovery shell entered | +| 0 | unused by Heads | Read live at seal time — normally zero; BootGuard Measured Boot, if enabled, measures the IBB into PCR 0 before coreboot | +| 1 | unused by Heads | Read live at seal time — normally zero; coreboot's boot mode and HWID measurement features are not enabled | +| 2 | coreboot SRTM | Boot block, ROM stage, RAM stage, Heads Linux kernel + initrd (payload), plus other loaded CBFS files (`bootsplash.jpg`, `fallback/*`) | +| 3 | unused by Heads | Read live at seal time — normally zero; MRC cache runtime measurement is disabled | +| 4 | Heads (`usb-init.sh`, `kexec-insert-key.sh`, `kexec-select-boot.sh`, `initrd/etc/functions.sh`) | Boot path: `"usb"` on USB boot, `"generic"` on normal boot (after the DUK is unsealed, to block further unsealing), `"recovery"` on entering the recovery shell. Sealing records the value before any of these extensions | | 5 | Heads `insmod` wrapper | Each loaded kernel module: parameters + binary content (default `MODULE_PCR=5`) | | 6 | Heads `qubes-measure-luks.sh` | LUKS header dump for each encrypted drive | -| 7 | Heads `cbfs-init.sh`, `uefi-init.sh` | Each CBFS/UEFI file: filename then content (default `CONFIG_PCR=7`) — covers `config.user`, GPG keyring, user CBFS files | -| 16 | `tpmr.sh calcfuturepcr` (scratch use only) | Resettable debug PCR used as scratch pad during pre-computation of future PCR values; not part of any sealing policy | +| 7 | Heads `cbfs-init.sh`, `uefi-init.sh` | Each CBFS/UEFI file: filename then content (default `CONFIG_PCR=7`) — covers `config.user`, GPG keyring, user CBFS files, not UEFI Secure Boot state | -PCRs 0-3 are read at seal time and included in sealing policies. The zero -state of PCRs 0, 1, and 3 is intentional — any unexpected extension of those -PCRs (e.g. enabling an optional coreboot feature) would break the seal. +PCRs 0 through 3 are read at seal time and included in sealing policies. PCRs 1 +and 3 are zero while their coreboot features stay disabled; PCR 0 is zero unless +BootGuard Measured Boot records the IBB before coreboot. Any extension of these +PCRs changes the value recorded in the policy and breaks the seal. + +Only PCRs 0 through 7 are extended or sealed against by Heads; other PCRs are not +used (the integrity report may still read and display all PCRs). PCR 16 is not +used: `calcfuturepcr` replays the `cbmem -L` event log (`replay_pcr` rejects +`pcr >= 8`), so no scratch PCR is needed. ### Sealing policies @@ -185,7 +190,7 @@ to a dedicated LUKS key slot and sealed to TPM NVRAM with the policy below. | 1 | `pcrread` (current value) | Platform state at seal time | | 2 | `pcrread` (current value) | coreboot SRTM measurement | | 3 | `pcrread` (current value) | Platform state at seal time | -| 4 | `calcfuturepcr` | Pre-computed normal-boot path (before any USB init or recovery) | +| 4 | `calcfuturepcr` | Replayed from the event log: PCR 4 before any Heads extension, normally zero | | 5 | `pcrread` or `calcfuturepcr 5` | Actual if extra modules loaded; zeroed future value if no extra modules | | 6 | `calcfuturepcr 6 /tmp/luksDump.txt` | Pre-computed LUKS header measurement | | 7 | `pcrread` (current value) | User CBFS files | @@ -211,7 +216,7 @@ the LUKS header changes (key slot added/removed), the DUK unseal fails. | 1 | Yes | Platform state | | 2 | Yes | coreboot SRTM measurement | | 3 | Yes | Platform state | -| 4 | Yes | Pre-computed normal-boot value | +| 4 | Yes | PCR 4 before any Heads extension, normally zero | | 5 | **No** | Kernel modules are not firmware integrity attestation | | 6 | **No** | LUKS header consistency is not firmware integrity attestation | | 7 | Yes | User CBFS files | @@ -227,17 +232,18 @@ ROM configuration integrity, not disk state. `tpmr.sh extend -ix -ic ` extends a PCR with the hash of a string. `-if ` extends with the hash of a file. -`calcfuturepcr` replays the expected extend sequence to compute what a PCR -will contain after the normal boot path, without actually extending it. -This is used to seal secrets against a known-future PCR state (e.g. PCR 4 -after normal init, before any recovery shell entry). +`calcfuturepcr` replays the firmware event log (`cbmem -L`) to compute a PCR +value without reading or extending the TPM. Any file or hash arguments are +folded in after the log entries, which is how PCR 5 and PCR 6 are modeled. +Sealing uses it to record the value a PCR will hold at unseal time, before any +Heads extension. ### Recovery PCR extension When a recovery shell is entered, `initrd/etc/functions.sh` extends PCR 4 with the string `"recovery"`. This permanently invalidates TOTP and LUKS DUK unsealing for the rest of the boot session — the TPM will refuse to unseal -secrets that were sealed against the normal-boot PCR 4 value. +secrets that were sealed against the PCR 4 value from before any Heads extension. ### TPM event log @@ -280,8 +286,10 @@ The rollback counter prevents **TPM swap attacks** and **/boot disk swap attacks ### How it works -The counter is stored **in the TPM** (NVRAM index `0x3135106223`), ensuring -hardware binding. A SHA-256 hash of the counter value is stored on **/boot** +The counter is stored **in the TPM** NVRAM: on TPM 1 the TPM assigns the counter +ID at creation (the `-la` label is only a caller supplied tag), and on TPM 2 +Heads generates the NV index at creation time. Both bind the counter to that TPM. +A SHA-256 hash of the counter value is stored on **/boot** (`/boot/kexec_rollback.txt`). This creates a two-way binding: - Cannot swap TPM without breaking /boot consistency @@ -292,18 +300,43 @@ counter hash matches. Before presenting TOTP/HOTP prompts, `preflight_rollback_c validates the counter is readable from TPM, ensuring secrets can actually be unsealed. -The counter is created during OEM Factory Reset by `check_tpm_counter` in -`initrd/etc/functions.sh`. +The counter is created via `tpmr.sh counter_create` during OEM Factory Reset +(`initrd/bin/oem-factory-reset.sh`), or by `check_tpm_counter` +(`initrd/etc/functions.sh`) on the `kexec-sign-config` / `gui-init` paths. + +### NV index selection + +On TPM 2, Heads generates the rollback counter's NV index when it creates the +counter (`tpm2_counter_create` in `initrd/bin/tpmr.sh`): a `1` prefix plus 3 +random bytes, yielding a valid NV handle (`0x01` handle type prefix) in +`0x01000000` through `0x01FFFFFF`. + +Only `0x01800000` through `0x01BFFFFF` is allocatable by the owner; the +generated range also overlaps the TPM manufacturer and platform manufacturer +ranges (`0x01000000` through `0x017FFFFF`) and the TCG/global range +(`0x01C00000` through `0x01FFFFFF`). The TPM does not enforce these allocation +ranges, so an index authorized by the owner but outside the owner range is +normally accepted — but it can collide with an index provisioned by the +manufacturer or by the TCG; if that index already exists, creation fails with +`TPM_RC_NV_DEFINED` (`TPM_RC_NV_SPACE` if NV space is exhausted). + +References: + +- TCG, [Registry of Reserved TPM 2.0 Handles and Localities](https://trustedcomputinggroup.org/wp-content/uploads/Registry-Of-Reserved-TPM2-Handles-And-Localities-Version-1.2-Revision-0.91_8September2023.pdf) — NV index ranges; "The TPM does not enforce the conventional usage of NV indices". +- TCG, [TPM 2.0 Part 3: Commands](https://trustedcomputinggroup.org/wp-content/uploads/TCG_TPM2_r1p64_Part3_Commands_code_15may2021.pdf), §31.3 `TPM2_NV_DefineSpace` — error codes. ### Counter state file `read_tpm_counter` in `initrd/etc/functions.sh` reads the counter from the TPM and writes the result to `/tmp/counter-`. The format is -`: `. +`: `: TPM 1 writes the decimal counter ID, TPM 2 the +generated hex index. `/boot/kexec_rollback.txt` stores the SHA-256 hash of that counter file. At boot, `kexec-select-boot` reads the counter, hashes the file, and checks -it against the stored hash. Any discrepancy aborts the boot. +it against the stored hash. A missing rollback record blocks boot only when +`CONFIG_BOOT_REQ_ROLLBACK=y`; an existing record mismatch aborts boot unless +`CONFIG_IGNORE_ROLLBACK=y`. No board config enables the missing record check. ### Rollback preflight: boot-time validation @@ -402,11 +435,11 @@ policy, or investigating why a seal/unseal operation fails. | Which coreboot version / fork a board uses | `modules/coreboot` + `boards//` | `CONFIG_COREBOOT_VERSION` in board config selects the coreboot source defined in `modules/coreboot` | | LUKS DUK sealing policy (which PCRs) | `initrd/bin/kexec-seal-key.sh` | `tpmr.sh seal` call and surrounding `pcrread` / `calcfuturepcr` calls; DEBUG comments explain each PCR | | TOTP/HOTP sealing policy (which PCRs) | `initrd/bin/seal-totp.sh` | `tpmr.sh seal` call; DEBUG messages explain why PCR 5 and PCR 6 are excluded | -| PCR 4 (boot mode) tracking | `initrd/bin/usb-init.sh`, `initrd/bin/kexec-insert-key.sh`, `initrd/etc/functions.sh` | `tpmr.sh extend` calls with `"usb"`, `"generic"`, `"recovery"` | -| PCR 5 (kernel modules) | `initrd/sbin/insmod` | `MODULE_PCR` variable; default `MODULE_PCR=5`; each `insmod` extends PCR 5 | +| PCR 4 (boot path) tracking | `initrd/bin/usb-init.sh`, `initrd/bin/kexec-insert-key.sh`, `initrd/bin/kexec-select-boot.sh`, `initrd/etc/functions.sh` | `tpmr.sh extend` calls with `"usb"`, `"generic"`, `"recovery"` | +| PCR 5 (kernel modules) | `initrd/sbin/insmod.sh` | `MODULE_PCR` variable; default `MODULE_PCR=5`; each `insmod` extends PCR 5 | | PCR 6 (LUKS header) | `initrd/bin/qubes-measure-luks.sh` | `tpmr.sh extend` call against `/tmp/luksDump.txt` | | PCR 7 (CBFS / ROM files) | `initrd/bin/cbfs-init.sh`, `initrd/bin/uefi-init.sh` | `CONFIG_PCR` variable; default `CONFIG_PCR=7`; each extracted file extends PCR 7 | -| Rollback counter logic | `initrd/etc/functions.sh` | `check_tpm_counter`, `read_tpm_counter`, `counter_increment` | +| Rollback counter logic | `initrd/etc/functions.sh` | `check_tpm_counter`, `read_tpm_counter`, `increment_tpm_counter` | ### Adding a new board @@ -435,9 +468,9 @@ To verify that a new board's coreboot config matches the expected RoT: | PCR hash | SHA-1 (20 bytes) | SHA-256 (32 bytes) | | Sealing | `tpm sealfile2 -ix ...` (specify PCRs and expected values) | `tpm2 nvdefine` + policy session | | Unsealing | `tpm unsealfile` (no PCR args — TPM enforces from baked blob) | `tpm2 unseal` with policy session | -| Counter | `tpm nv*` | `tpm2 nvincrement` | +| Counter | `tpm counter_create`, `counter_read`, `counter_increment` | `tpm2 nvdefine`, `nvread`, `nvincrement` | | Auth sessions | Not used | Required for policy-based unseal | -| `kexec_finalize` | No-op | Extends PCRs, then `tpm2 shutdown` | +| `kexec_finalize` | Does nothing | Flushes sessions and locks the platform hierarchy; does not extend PCRs | | `startsession` | No-op | Creates encryption session | --- diff --git a/doc/ux-patterns.md b/doc/ux-patterns.md index 08998243ab..bce159b86b 100644 --- a/doc/ux-patterns.md +++ b/doc/ux-patterns.md @@ -97,7 +97,7 @@ whiptail_error --title 'ERROR' \ ## `INPUT` — inline terminal prompts -`INPUT` (defined in `initrd/etc/functions`) is the standard way to prompt the user for typed +`INPUT` (defined in `initrd/etc/functions.sh`) is the standard way to prompt the user for typed input in non-whiptail contexts (e.g. recovery shell, passphrase entry, confirmation tokens). ```bash @@ -213,7 +213,7 @@ All GPG signing in Heads uses `--pinentry-mode=loopback` with cache file through the loopback channel. `initrd/.gnupg/gpg-agent.conf` sets `allow-loopback-pinentry` to permit this. -`confirm_gpg_card` in `initrd/etc/functions` is a thin wrapper around +`confirm_gpg_card` in `initrd/etc/functions.sh` is a thin wrapper around `cache_gpg_signing_pin`, which implements both key paths below. ### Priming the cache: test-sign in cache_gpg_signing_pin @@ -273,7 +273,7 @@ some_display_function() { `/tmp` is on tmpfs and is cleared at reboot, so the guard is automatically lifted on the next boot. No cleanup code is needed. -This pattern is used by `hotpkey_fw_display` in `initrd/etc/functions` to show +This pattern is used by `hotpkey_fw_display` in `initrd/etc/functions.sh` to show the USB security dongle firmware version at most once per session, regardless of how many times the function is called from different code paths. @@ -330,8 +330,9 @@ tab-prefixed line. Also normalize `fw_ver` to add a `v` prefix if absent so ### Reading counters -`read_tpm_counter` in `initrd/etc/functions` reads a TPM NV counter by index and writes the -output to `/tmp/counter-`. The format is `: `. +`read_tpm_counter` in `initrd/etc/functions.sh` reads a TPM NV counter by index and writes the +output to `/tmp/counter-`. The format is `: `: TPM 1 +writes the decimal counter ID, TPM 2 the generated hex index. **Pipeline exit status**: Never pipe `tpmr counter_read` through `tee` with `|| die` — the `||` checks the exit status of `tee` (always 0), not `tpmr`. Use a direct redirect: diff --git a/initrd/bin/seal-totp.sh b/initrd/bin/seal-totp.sh index 396efd0ef7..9c48dfdc40 100755 --- a/initrd/bin/seal-totp.sh +++ b/initrd/bin/seal-totp.sh @@ -15,7 +15,6 @@ HOST="$1" if [ -z "$HOST" ]; then HOST="TPMTOTP" fi -TPM_PASSWORD="$2" TOTP_SECRET="/tmp/secret/totp.key" TOTP_SEALED="/tmp/secret/totp.sealed" @@ -63,7 +62,7 @@ fi # or other TPM state issues. Avoid DO_WITH_DEBUG so interactive prompts # (TPM owner passphrase on TPM1) are not hidden from the user. STATUS "Sealing TOTP secret to TPM NVRAM" -if ! tpmr.sh seal "$TOTP_SECRET" "$TPM_NVRAM_SPACE" 0,1,2,3,4,7 "$pcrf" 312 "" "$TPM_PASSPHRASE"; then +if ! tpmr.sh seal "$TOTP_SECRET" "$TPM_NVRAM_SPACE" 0,1,2,3,4,7 "$pcrf" 312 ""; then # tpmr.sh already logged details; guide user generically to reset TPM DIE "Unable to seal TOTP secret to TPM NVRAM; reset the TPM (Options -> TPM/TOTP/HOTP Options -> Reset the TPM in the GUI) and try again." fi From ffe2bf2411c5f73555fc23ee6b434675e73a26ff Mon Sep 17 00:00:00 2001 From: Thierry Laurion Date: Thu, 17 Sep 2026 11:25:37 -0400 Subject: [PATCH 2/4] initrd: correct stale TPM comments The comments no longer described the code they sat in. The DUK seal always includes PCR 5, the TOTP/HOTP shared secret is sealed against PCRs 0,1,2,3,4,7, and the TPM 2 finalize step does not extend PCRs. Describe the counter split between the /boot HOTP file and the TPM rollback counter as it is actually implemented. Signed-off-by: Thierry Laurion --- initrd/bin/gui-init.sh | 8 ++++++-- initrd/bin/kexec-seal-key.sh | 9 ++++----- initrd/bin/seal-hotpkey.sh | 6 ++++-- initrd/bin/seal-totp.sh | 5 +++-- initrd/bin/tpmr.sh | 9 ++++++--- initrd/bin/unseal-hotp.sh | 9 +++++---- initrd/bin/unseal-totp.sh | 4 ++-- initrd/bin/wipe-totp.sh | 7 ++++--- initrd/etc/functions.sh | 2 +- 9 files changed, 35 insertions(+), 24 deletions(-) diff --git a/initrd/bin/gui-init.sh b/initrd/bin/gui-init.sh index 9fc4e6415f..6a37470b03 100755 --- a/initrd/bin/gui-init.sh +++ b/initrd/bin/gui-init.sh @@ -838,8 +838,12 @@ reset_tpm() { TRACE_FUNC # As a countermeasure for existing primary handle hash, we will now force sign /boot without it. - # NOTE: At seal time, PCR5 is IGNORED (not measured) - only used on HOTP board variants. So USB - # modules loading here don't affect DUK seal. GPG card needs USB to be enabled first. + # The DUK seal always includes PCR 5; it binds the live value when extra + # kernel modules are expected and the zeroed future value otherwise. + # The TOTP/HOTP shared secret (PCRs + # 0,1,2,3,4,7) is sealed by seal-totp.sh; HOTP unseals that shared + # secret and seals nothing of its own. GPG card needs USB to be + # enabled first. STATUS "Preparing USB and GPG signing key access for /boot signing" enable_usb if wait_for_gpg_card; then diff --git a/initrd/bin/kexec-seal-key.sh b/initrd/bin/kexec-seal-key.sh index 9c2674b8d7..896d4407cc 100755 --- a/initrd/bin/kexec-seal-key.sh +++ b/initrd/bin/kexec-seal-key.sh @@ -269,10 +269,8 @@ for dev in $key_devices; do STATUS_OK "$dev: LUKS TPM Disk Unlock Key added to slot $duk_keyslot" done -# Now that we have setup the new keys, measure the PCRs -# We don't care what ends up in PCR 6; we just want -# to get the /tmp/luksDump.txt file. We use PCR16 -# since it should still be zero +# Now that we have setup the new keys, measure the LUKS headers into PCR 6. +# The dump goes to /tmp/luksDump.txt for calcfuturepcr to use as input. STATUS "Measuring TPM Disk Unlock Key (DUK) for sealing policy (PCR[6])" echo "$key_devices" | xargs /bin/qubes-measure-luks.sh || DIE "Unable to measure the LUKS headers" @@ -284,7 +282,8 @@ tpmr.sh pcrread 0 "$pcrf" tpmr.sh pcrread -a 1 "$pcrf" tpmr.sh pcrread -a 2 "$pcrf" tpmr.sh pcrread -a 3 "$pcrf" -# Note that PCR 4 needs to be set with the "normal-boot" path value, read it from event log. +# PCR 4 is sealed at its value before the normal boot extend (read from the +# event log); "generic" is extended later, after unseal, to block further unsealing. tpmr.sh calcfuturepcr 4 >>"$pcrf" if [ "$CONFIG_USER_USB_KEYBOARD" = "y" ] || [ "$CONFIG_USB_KEYBOARD_REQUIRED" = "y" ] || [ -r /lib/modules/libata.ko ] || [ -x /bin/hotp_verification ]; then DEBUG "Sealing LUKS TPM Disk Unlock Key with PCR5 involvement (additional kernel modules are loaded per board config)..." diff --git a/initrd/bin/seal-hotpkey.sh b/initrd/bin/seal-hotpkey.sh index f9f1659379..d91f991bac 100755 --- a/initrd/bin/seal-hotpkey.sh +++ b/initrd/bin/seal-hotpkey.sh @@ -34,8 +34,10 @@ else STATUS_OK "HOTP secret derived from ROM hash" fi -# Store counter in file instead of TPM for now, as it conflicts with Heads -# config TPM counter as TPM 1.2 can only increment one counter between reboots +# Store the HOTP counter in a /boot file instead of the TPM. TPM 1.2 allows +# incrementing only one counter handle per boot; a different handle fails until +# the next TPM_Startup clear, so the HOTP counter cannot share the boot with the +# Heads rollback counter. # get current value of HOTP counter in TPM, create if absent mount_boot || exit 1 diff --git a/initrd/bin/seal-totp.sh b/initrd/bin/seal-totp.sh index 9c48dfdc40..3d68f8fb10 100755 --- a/initrd/bin/seal-totp.sh +++ b/initrd/bin/seal-totp.sh @@ -38,7 +38,7 @@ tpmr.sh pcrread -a 2 "$pcrf" tpmr.sh pcrread -a 3 "$pcrf" DEBUG "Sealing TOTP with boot state of PCR4 (Going to recovery shell extends PCR4)" # pcr 4 is expected to either: -# zero on bare coreboot+linuxboot on x86 (boot mode: init) +# zero on bare coreboot+linuxboot on x86 (before any boot path extend) # already extended on ppc64 per BOOTKERNEL (skiboot) which boots heads. # Read from event log to catch both cases, even when called from recovery shell. tpmr.sh calcfuturepcr 4 >>"$pcrf" @@ -49,7 +49,8 @@ DEBUG "Sealing TOTP without PCR6 involvement (LUKS header consistency is not fir # pcr 7 is containing measurements of user injected stuff in cbfs DEBUG "Sealing TOTP with actual state of PCR7 (User injected stuff in cbfs)" tpmr.sh pcrread -a 7 "$pcrf" -#Make sure we clear the TPM Owner Passphrase from memory in case it failed to be used to seal TOTP +# tpmr.sh seal prompts for the owner passphrase and caches it under +# /tmp/secret; the cache is shredded only after a failed attempt. # if the board has TPM2 tools, check for the primary handle before # attempting to seal; a missing handle is the most common reason for diff --git a/initrd/bin/tpmr.sh b/initrd/bin/tpmr.sh index 80bd605ebc..3a81d30556 100755 --- a/initrd/bin/tpmr.sh +++ b/initrd/bin/tpmr.sh @@ -202,7 +202,8 @@ $0 ~ pcr { # usage: replay_pcr [ | ... ] # Replays PCR value from CBMEM event log. Note that this contains only the # measurements performed by firmware, without those performed by Heads (USB -# modules, LUKS header etc). First argument is PCR number, followed by optional +# modules, LUKS header etc). The first argument is the hash algorithm and the +# second is the PCR number, followed by optional # hashes and/or files extended to given PCR after firmware. Resulting PCR value # is returned in binary form. replay_pcr() { @@ -686,7 +687,9 @@ tpm2_seal() { # - Exit code 2: index doesn't exist (normal on first seal after TPM reset) # - Exit code 3+: other errors (permission denied, bad passphrase, etc.) # -# PCR policy: At seal time, PCR5 is IGNORED (not measured) - only relevant for HOTP. +# PCR policy is set by the caller's pcrl argument; this function adds no +# PCRs. seal-totp.sh seals the TOTP/HOTP shared secret against 0,1,2,3,4,7; +# kexec-seal-key.sh seals the LUKS DUK against 0,1,2,3,4,5,6,7. tpm1_seal() { TRACE_FUNC file="$1" @@ -1109,7 +1112,7 @@ tpm1_reset() { DO_WITH_DEBUG tpm physicalsetdeactivated -c >/dev/null 2>&1 || LOG "tpm1_reset: unable to clear deactivated state (final)" } -# Perform final cleanup before boot and lock the platform heirarchy. +# Perform final cleanup before boot and lock the platform hierarchy. tpm2_kexec_finalize() { TRACE_FUNC diff --git a/initrd/bin/unseal-hotp.sh b/initrd/bin/unseal-hotp.sh index ad172626e7..f89b732227 100755 --- a/initrd/bin/unseal-hotp.sh +++ b/initrd/bin/unseal-hotp.sh @@ -1,5 +1,6 @@ #!/bin/bash -# Retrieve the sealed file and counter from the NVRAM, unseal it and compute the hotp +# Retrieve the sealed HOTP secret from the TPM NVRAM and read the counter from +# /boot, unseal the secret and compute the hotp . /etc/functions.sh @@ -17,9 +18,9 @@ mount_boot_or_die() { TRACE_FUNC -# Store counter in file instead of TPM for now, as it conflicts with Heads -# config TPM counter as TPM 1.2 can only increment one counter between reboots -# get current value of HOTP counter in TPM, create if absent +# Read the HOTP counter from the /boot file instead of the TPM, separate from +# the Heads rollback counter, to avoid sharing one counter. +# get the current value of the HOTP counter from the file mount_boot_or_die #check_tpm_counter $HOTP_COUNTER hotp \ diff --git a/initrd/bin/unseal-totp.sh b/initrd/bin/unseal-totp.sh index 1a0dd00d83..5d7f4e65e2 100755 --- a/initrd/bin/unseal-totp.sh +++ b/initrd/bin/unseal-totp.sh @@ -7,8 +7,8 @@ TOTP_SECRET="/tmp/secret/totp.key" fail_unseal_reset_required() { TRACE_FUNC - # A TPM-side unseal failure generally indicates that reset/re-ownership is - # required before allowing reseal/generate workflows again. + # The TPM2 primary handle is missing (the TPM was reset or replaced): + # mark reset required before allowing reseal/generate workflows again. set_tpm_reset_required "$*" "unseal-totp.sh:fail_unseal_reset_required" DEBUG "fail_unseal_reset_required: reason='$*'" fail_unseal "$@" diff --git a/initrd/bin/wipe-totp.sh b/initrd/bin/wipe-totp.sh index 220228ed74..f7a4544fd7 100755 --- a/initrd/bin/wipe-totp.sh +++ b/initrd/bin/wipe-totp.sh @@ -1,7 +1,8 @@ #!/bin/bash -# Wipe the sealed TOTP/HOTP secret. The secret is overwritten with all-0, -# rather than deleted, because deletion requires authorization. Wiping the -# secret will cause the next boot to prompt to regenerate the secret. +# Wipe the sealed TOTP/HOTP secret. TPM1 overwrites the blob with all zeros; +# TPM2 evicts the object. TPM1 deletion needs authorization, so the blob is +# overwritten instead. Wiping the secret will cause the next boot to prompt +# to regenerate the secret. . /etc/functions.sh diff --git a/initrd/etc/functions.sh b/initrd/etc/functions.sh index f2f19ffae9..b8d5e78407 100644 --- a/initrd/etc/functions.sh +++ b/initrd/etc/functions.sh @@ -1971,7 +1971,7 @@ check_tpm_counter() { else DEBUG "$1 does not exist - creating new TPM counter" # Create TPM counter with empty counter auth per TCG spec (no secret). - # Owner passphrase is not needed for the counter auth itself. + # The owner passphrase is still needed to define the counter, but not to increment it. DEBUG "Invoking tpmr.sh counter_create with label $LABEL" # run it, then record the exit status explicitly; the '!' operator # cannot be used because it would hide the real return code. From 46504c9b47c0e0630f022aa9fc00b947e015b0e9 Mon Sep 17 00:00:00 2001 From: Thierry Laurion Date: Thu, 17 Sep 2026 14:04:34 -0400 Subject: [PATCH 3/4] doc: cross-reference tpm.md and qualify the BootGuard IBB claim The PCR map, seal policies and rollback binding were restated in several documents and could drift, so point at tpm.md as the maintained source instead of repeating them. The BootGuard sentence also read as unconditional, which is wrong on CBnT boards where the IBB digest comes from the Boot Policy Manifest rather than PCR 0 alone, as raised in #1172. Signed-off-by: Thierry Laurion --- doc/architecture.md | 2 +- doc/boot-process.md | 2 +- doc/keys.md | 23 +------ doc/security-model.md | 152 +++++++++++++----------------------------- doc/tpm.md | 30 ++++++--- 5 files changed, 72 insertions(+), 137 deletions(-) diff --git a/doc/architecture.md b/doc/architecture.md index 2d1e8d96c5..d07ab288e0 100644 --- a/doc/architecture.md +++ b/doc/architecture.md @@ -132,7 +132,7 @@ The CI pipeline's workspace and cache behavior is documented in ## Key design principles - **No network at boot** — all verification is local; no certificate authorities -- **Hardware root of trust** — the coreboot bootblock (IBB) is the Static Core Root of Trust for Measurement (S-CRTM): the first code executed by the CPU, directly from SPI flash. Coreboot implements a transitive measurement chain: the CRTM measures FMAP and the bootblock image into the preram log, then each subsequent stage measures the next before executing it — bootblock measures romstage, romstage measures ramstage, ramstage measures the Heads payload. Measurements are taken during CBFS file loading, before decompression, and are recorded in TPM PCR 2 (SRTM) once the TPM hardware is initialized (`tpm_setup()`). Measurements taken before TPM init are cached in the preram log and flushed to PCR 2 by `tspi_measure_cache_to_pcr()` during `tpm_setup()`. The full chain — bootblock → romstage → ramstage → Heads Linux kernel + initrd — is recorded into PCR 2. PCRs 1 and 3 are read live at seal time and are zero while their coreboot features stay disabled; PCR 0 is normally zero but may be populated by BootGuard Measured Boot. See [tpm.md](tpm.md#root-of-trust-and-srtm-chain) for TPM init timing per board. See [wp-notes.md](wp-notes.md#pr0-chipset-locking) for SPI write protection and PR0 chipset locking details. +- **Hardware root of trust** — the coreboot bootblock (IBB) is the Static Core Root of Trust for Measurement (S-CRTM): the first code executed by the CPU, directly from SPI flash. Coreboot implements a transitive measurement chain: the CRTM measures FMAP and the bootblock image into the preram log, then each subsequent stage measures the next before executing it — bootblock measures romstage, romstage measures ramstage, ramstage measures the Heads payload. Measurements are taken during CBFS file loading, before decompression, and are recorded in TPM PCR 2 (SRTM) once the TPM hardware is initialized (`tpm_setup()`). Measurements taken before TPM init are cached in the preram log and flushed to PCR 2 by `tspi_measure_cache_to_pcr()` during `tpm_setup()`. The full chain — bootblock → romstage → ramstage → Heads Linux kernel + initrd — is recorded into PCR 2. See [tpm.md](tpm.md#root-of-trust-and-srtm-chain) for the PCR map and TPM init timing for each board. See [wp-notes.md](wp-notes.md#pr0-chipset-locking) for SPI write protection and PR0 chipset locking details. - **Fail-closed** — failed integrity verification drops to a recovery shell. Recovery shell authentication via GPG smartcard is enforced when GPG key backup has been configured (`CONFIG_HAVE_GPG_KEY_BACKUP=y`), which is set by answering "y" to `"Would you like to format an encrypted USB Thumb drive to store GPG key material? (Required to enable GPG authentication)"` during OEM Factory Reset / Re-Ownership. Otherwise the recovery shell is unauthenticated. An "Ignore tampering and force a boot (Unsafe!)" option is available to override this. - **Separation of duties** — the public key that verifies `/boot` signatures is stored in CBFS (ROM). The private key that signs `/boot` stays on a USB security dongle and never leaves it. - **Auditability** — all source is open, builds are reproducible, ROM images are verifiable diff --git a/doc/boot-process.md b/doc/boot-process.md index 089b759a51..e70ac9f3ef 100644 --- a/doc/boot-process.md +++ b/doc/boot-process.md @@ -312,7 +312,7 @@ counter is read from the TPM. The SHA-256 of the counter file is then checked against the hash stored in `kexec_rollback.txt`. A missing rollback record blocks boot only when `CONFIG_BOOT_REQ_ROLLBACK=y`; an existing record mismatch aborts boot unless `CONFIG_IGNORE_ROLLBACK=y`. No board config enables the -missing record check. +missing record check; the counter mechanics are in [tpm.md](tpm.md#rollback-counter). ### OS boot execution (`do_boot`) diff --git a/doc/keys.md b/doc/keys.md index ec64d0b423..e659fb88b4 100644 --- a/doc/keys.md +++ b/doc/keys.md @@ -18,7 +18,7 @@ Key passphrase. ## TPMTOTP / HOTP Shared Secret A random 20-byte value generated when a new TOTP/HOTP secret is created, -normally on the first boot after OEM Factory Reset / Re-Ownership. +normally on the first boot after OEM Factory Reset / Reownership. - **TOTP (smartphone):** sealed into TPM NVRAM against PCR values; on each boot Heads unseals it if PCRs match and displays the current TOTP code for @@ -79,20 +79,7 @@ firmware image and used to verify `/boot` signatures on every boot. ## TPM PCR Map -| PCR | Content | -|-----|---------| -| 0 | (unused by Heads; zero unless BootGuard's Measured Boot policy populates it before coreboot) | -| 1 | (reserved) | -| 2 | coreboot bootblock, ROM stage, RAM stage, Heads Linux kernel + initrd | -| 3 | (reserved) | -| 4 | Boot path (`"usb"` = USB boot, `"generic"` = normal boot, `"recovery"` = recovery shell; precomputed at seal time from the firmware event log) | -| 5 | Heads Linux kernel modules | -| 6 | Drive LUKS headers | -| 7 | Heads user-specific CBFS files (config.user, GPG keyring, etc.) | - -TOTP/HOTP is sealed against PCRs 0,1,2,3,4,7; the LUKS DUK against PCRs -0,1,2,3,4,5,6,7. A firmware, kernel module, LUKS header, or CBFS config change -breaks the relevant unseal until secrets are sealed again. +Heads extends and seals only PCRs 0 through 7; the assignments are in [tpm.md](tpm.md#pcr-assignments) and the seal policies in [tpm.md](tpm.md#sealing-policies). ## TPM Unseal Errors @@ -103,11 +90,7 @@ A different TPM_Unseal error can have several causes, including a decryption failure or TPM dictionary attack lockout. Check the event log (`cbmem -L`) and the TPM state before assuming tampering. -Review the PCR2 TCPA event log from Recovery Shell: - -``` -cbmem -L -``` +See [tpm.md](tpm.md#tpm-event-log) for the event log and unseal errors. ## LUKS Key Derivation diff --git a/doc/security-model.md b/doc/security-model.md index eb08a962d4..2bc8b6f04a 100644 --- a/doc/security-model.md +++ b/doc/security-model.md @@ -58,6 +58,7 @@ verify each other, preventing single points of failure. │ │ └─────────────────────────────────────────────────────────────────────────────┘ ``` +Seal policies are listed in [tpm.md](tpm.md#sealing-policies). --- @@ -143,32 +144,9 @@ On boards with `CONFIG_TPM_MEASURED_BOOT=y` + `CONFIG_TPM_INIT_RAMSTAGE=y` (the majority of maintained boards), ramstage initializes the TPM, reads each prior stage from CBFS, and extends PCR 2. Older coreboot versions (4.11) used `CONFIG_TPM_INIT=y` before this config key existed; some boards have no TPM -hardware. See [tpm.md](tpm.md) for the full breakdown. +hardware. See [tpm.md](tpm.md#pcr-assignments) for the PCR map and the +PCR 4 boot path values. -PCRs 0, 1, and 3 are unused — the `CONFIG_PCR_*` entries for those registers -are slot assignments for optional coreboot features that are not enabled. They -are read live at seal time and are normally zero (BootGuard Measured Boot, if -enabled, populates PCR 0 before coreboot). On boards with coreboot measured -boot, PCR 2 is not zero: it carries the SRTM chain. - -Heads extends additional PCRs during userspace boot: - -- **PCR 4** — boot path tracking; see below -- **PCR 5** — each kernel module loaded via the `insmod` wrapper (binary + parameters) -- **PCR 6** — LUKS header dump (by `qubes-measure-luks`) before disk unlock -- **PCR 7** — each CBFS/UEFI file extracted from ROM (by `cbfs-init`/`uefi-init`) - -Heads extends PCR 4 further depending on execution path: - -- **USB boot**: PCR 4 is extended with `"usb"`, locking out unsealing on the USB - boot path. -- **Normal boot**: `calcfuturepcr 4` pre-computes the expected value and secrets - are sealed against it; the running path then extends `"generic"` to lock out - further unsealing. -- **Recovery shell**: PCR 4 is extended with `"recovery"`, invalidating - normal-boot unsealing for the rest of the session. - -See [tpm.md](tpm.md) for the full PCR table and sealing policies. For board-specific RoT configuration and the files that control each PCR, see [tpm.md — Configuration reference for developers](tpm.md#configuration-reference-for-developers). @@ -184,7 +162,7 @@ which the user observes as a TOTP/HOTP mismatch. ### TOTP A 20-byte random secret is generated when a new TOTP/HOTP secret is created, -normally on the first boot after OEM Factory Reset / Re-Ownership, and sealed +normally on the first boot after OEM Factory Reset / Reownership, and sealed to TPM NVRAM. At each boot, `unseal-totp` retrieves it and generates the current 30-second code. The user compares this against their authenticator app. @@ -300,7 +278,7 @@ and the /boot disk, preventing swap attacks. ```text ┌─────────────────────────────────────────────────────────────────────────────┐ -│ ROLLBACK COUNTER ATTACK PREVENTION │ +│ ROLLBACK COUNTER ATTACK PREVENTION │ ├─────────────────────────────────────────────────────────────────────────────┤ │ │ │ ┌─────────────┐ ┌─────────────┐ │ @@ -312,15 +290,15 @@ and the /boot disk, preventing swap attacks. │ │ │ │ │ │ │ │ │ ▼ ▼ │ -│ ┌─────────────────────────────────────────────────────────┐ │ -│ │ ATTACK SCENARIO: Old TPM + Old /boot │ │ -│ │ │ │ -│ │ Attacker uses old TPM (counter=5) with old /boot │ │ -│ │ (hash=5). This would bypass security updates! │ │ -│ │ │ │ -│ │ → BLOCKED: TPM unseal requires current PCR values │ │ -│ │ → BLOCKED: GPG signature must match current /boot │ │ -│ └─────────────────────────────────────────────────────────────┘ │ +│ ┌─────────────────────────────────────────────────────────┐ │ +│ │ ATTACK SCENARIO: Old TPM + Old /boot │ │ +│ │ │ │ +│ │ Attacker uses old TPM (counter=5) with old /boot │ │ +│ │ (hash=5). This would bypass security updates! │ │ +│ │ │ │ +│ │ → BLOCKED: TPM unseal requires current PCR values │ │ +│ │ → BLOCKED: GPG signature must match current /boot │ │ +│ └─────────────────────────────────────────────────────────┘ │ │ │ │ ┌─────────────┐ ┌─────────────┐ │ │ │ NEW TPM │ │ OLD /boot │ │ @@ -332,25 +310,20 @@ and the /boot disk, preventing swap attacks. │ │ │ │ │ │ │ │ │ ▼ ▼ │ -│ ┌─────────────────────────────────────────────────────────┐ │ -│ │ ATTACK SCENARIO: New TPM + Old /boot │ │ -│ │ │ │ -│ │ Attacker swaps TPM. New TPM has no sealed secrets. │ │ -│ │ Old /boot has old counter hash. │ │ -│ │ │ │ -│ │ → BLOCKED: TOTP/HOTP/DUK unseal fails (no secrets) │ │ -│ │ → BLOCKED: Rollback counter mismatch detected │ │ -│ └─────────────────────────────────────────────────────────────┘ │ +│ ┌─────────────────────────────────────────────────────────┐ │ +│ │ ATTACK SCENARIO: New TPM + Old /boot │ │ +│ │ │ │ +│ │ Attacker swaps TPM. New TPM has no sealed secrets. │ │ +│ │ Old /boot has old counter hash. │ │ +│ │ │ │ +│ │ → BLOCKED: TOTP/HOTP/DUK unseal fails (no secrets) │ │ +│ │ → BLOCKED: Rollback counter mismatch detected │ │ +│ └─────────────────────────────────────────────────────────┘ │ │ │ └─────────────────────────────────────────────────────────────────────────────┘ ``` -### How the binding works - -1. **TPM stores counter**: A monotonic counter is created in TPM NVRAM at OEM Factory Reset, at TPM reset, or by signing when `kexec_rollback.txt` is missing -2. **/boot stores hash**: the sha256sum of the counter state file (`counter-`, index and value) is stored in `/boot/kexec_rollback.txt` -3. **Counter increments on signing**: Every `kexec-sign-config` run with rollback enabled increments the counter and updates the hash -4. **Verification at boot**: `kexec-select-boot` verifies the counter matches the stored hash +The counter mechanics are in [tpm.md](tpm.md#rollback-counter). A missing rollback record blocks boot only when `CONFIG_BOOT_REQ_ROLLBACK=y`; no board config enables that requirement. An existing record mismatch aborts @@ -364,66 +337,33 @@ boot unless `CONFIG_IGNORE_ROLLBACK=y`. │ OEM FACTORY RESET NORMAL BOOT │ │ ───────────────── ──────────── │ │ │ -│ 1. Create counter in TPM NVRAM 1. Read counter from TPM │ -│ └─▶ create counter, then increment to 1 │ │ -│ 2. Hash counter → /boot ▼ │ -│ └─▶ kexec_rollback.txt 2. Hash counter │ -│ contains hash of "1" │ │ -│ ▼ │ -│ 3. Compare with /boot hash │ -│ │ │ -│ ▼ │ -│ OS UPDATE 4. Match? → Continue │ -│ ────────── 5. Mismatch? → Die │ +│ 1. Create counter in TPM NVRAM 1. Read counter from TPM │ +│ └─▶ create counter, then increment to 1 │ │ +│ 2. Hash counter → /boot ▼ │ +│ └─▶ kexec_rollback.txt 2. Hash counter │ +│ │ │ +│ ▼ │ +│ 3. Compare with /boot hash │ +│ │ │ +│ ▼ │ +│ OS UPDATE 4. Match? → Continue │ +│ ────────── 5. Mismatch? → Die │ +│ │ +│ 1. kexec-sign-config runs TPM SEALED SECRETS │ +│ │ ────────────────── │ +│ ▼ TOTP/HOTP/DUK can only unseal │ +│ 2. Increment TPM counter if: │ +│ └─▶ counter_value = 1 - PCRs match seal policy │ +│ 3. Hash new value → /boot - TPM is the SAME TPM │ +│ └─▶ kexec_rollback.txt - /boot is the SAME /boot │ │ │ -│ 1. kexec-sign-config runs TPM SEALED SECRETS │ -│ │ ────────────────── │ -│ ▼ TOTP/HOTP/DUK can only unseal │ -│ 2. Increment TPM counter if: │ -│ └─▶ counter_value = 1 - PCRs match seal policy │ -│ 3. Hash new value → /boot - TPM is the SAME TPM │ -│ └─▶ kexec_rollback.txt - /boot is the SAME /boot │ -│ updates hash of "1" │ │ │ └─────────────────────────────────────────────────────────────────────────────┘ ``` ### PCR binding in TPM sealing -TPM-sealed secrets (TOTP, HOTP, LUKS DUK) are bound to specific PCR values, -creating additional hardware binding: - -```text -┌─────────────────────────────────────────────────────────────────────────────┐ -│ TPM SEALING PCR POLICIES │ -├─────────────────────────────────────────────────────────────────────────────┤ -│ │ -│ ┌─────────────────────────────────────────────────────────────────────┐ │ -│ │ TOTP/HOTP Secret Seal Policy: PCRs 0,1,2,3,4,7 │ │ -│ │ │ │ -│ │ PCR 0,1,3: Normally zero PCR 2: coreboot SRTM │ │ -│ │ PCR 4: Boot path ("usb"/"generic"/"recovery") │ │ -│ │ PCR 7: CBFS/ROM files (user-injected) │ │ -│ │ │ │ -│ │ NOT included: PCR 5 (kernel modules), PCR 6 (LUKS headers) │ │ -│ │ → Allows disk updates without resealing TOTP/HOTP │ │ -│ └─────────────────────────────────────────────────────────────────────┘ │ -│ │ -│ ┌─────────────────────────────────────────────────────────────────────┐ │ -│ │ LUKS DUK Seal Policy: PCRs 0,1,2,3,4,5,6,7 │ │ -│ │ │ │ -│ │ PCR 0,1,3: Normally zero PCR 2: coreboot SRTM │ │ -│ │ PCR 4: Boot path ("usb"/"generic"/"recovery") │ │ -│ │ PCR 5: Kernel modules (if loaded) │ │ -│ │ PCR 6: LUKS header (measured at seal time) │ │ -│ │ PCR 7: CBFS/ROM files │ │ -│ │ │ │ -│ │ Includes: PCR 5, PCR 6 → More restrictive │ │ -│ │ → Changing kernel modules or LUKS headers requires resealing DUK │ │ -│ └─────────────────────────────────────────────────────────────────────┘ │ -│ │ -└─────────────────────────────────────────────────────────────────────────────┘ -``` +The seal policy for each secret is in [tpm.md](tpm.md#sealing-policies). --- @@ -432,7 +372,7 @@ creating additional hardware binding: The LUKS Disk Unlock Key (DUK) is a random binary key that: 1. Is generated from `/dev/urandom` by `kexec-seal-key` (128 bytes — 1024 bits of entropy, i.e. a $2^{1024}$ brute-force space). -2. Is sealed to TPM NVRAM with PCR policy `0,1,2,3,4,5,6,7`. +2. Is sealed to TPM NVRAM with the LUKS DUK seal policy in [tpm.md](tpm.md#sealing-policies). 3. Is added as a LUKS key slot alongside the user's Disk Recovery Key (DRK). 4. At boot, `kexec-insert-key` unseals it and injects it into a minimal initrd prepended to the OS initrd. The OS kernel unlocks LUKS without @@ -458,7 +398,7 @@ secrets and verifies: If any check fails, the sealing operation is aborted. This prevents new secrets from being sealed against a potentially compromised `/boot`. If the -flag is not set, only the reset-required check runs. +flag is not set, only the reset required check runs. For the UNKNOWN_KEY scenario and correct error messaging, see [ux-patterns.md](ux-patterns.md#security-ux--integrity-report-and-unknown-keys). diff --git a/doc/tpm.md b/doc/tpm.md index 2c9ea10499..a41d5145cc 100644 --- a/doc/tpm.md +++ b/doc/tpm.md @@ -134,14 +134,17 @@ IBB is self-referential — it asserts its own integrity. To address this, processor vendors provide external RoT mechanisms that validate the IBB via hardware before execution: -- **Intel BootGuard** — validates the bootblock against a signed manifest fused - into the CPU/PCH before any code runs +- **Intel BootGuard** — validates the IBB against a signed manifest fused into + the CPU/PCH at reset. On the legacy Intel TXT path the IBB is the CBFS file + or files referenced by FIT type 7; on CBnT boards coreboot does not use FIT + type 7 for the IBB and the digest comes from the signed Boot Policy Manifest - **AMD Hardware Validated Boot (HVB)** — equivalent AMD mechanism These are hardware features of the platform, not coreboot configuration choices. -Where a board's CPU supports BootGuard or HVB, that hardware layer sits below -the coreboot SRTM chain and provides additional assurance for the S-CRTM -integrity. +Where a board's CPU supports BootGuard or HVB, that hardware layer validates the +IBB below the coreboot SRTM chain. A BootGuard measurement reaches PCR 0 only +when the platform is provisioned with a boot profile that includes measurement; +see [PCR assignments](#pcr-assignments) for what is measured and when. #### Intel TXT path (OptiPlex 7019/9010 TXT only) @@ -156,7 +159,7 @@ unchanged; the TXT mechanism adds the DRTM capability on top of it. | PCR | Extended by | Content | | --- | --- | --- | -| 0 | unused by Heads | Read live at seal time — normally zero; BootGuard Measured Boot, if enabled, measures the IBB into PCR 0 before coreboot | +| 0 | unused by Heads | Read live at seal time — normally zero; a BootGuard measurement lands in PCR 0 only when the platform is provisioned with a boot profile that includes measurement | | 1 | unused by Heads | Read live at seal time — normally zero; coreboot's boot mode and HWID measurement features are not enabled | | 2 | coreboot SRTM | Boot block, ROM stage, RAM stage, Heads Linux kernel + initrd (payload), plus other loaded CBFS files (`bootsplash.jpg`, `fallback/*`) | | 3 | unused by Heads | Read live at seal time — normally zero; MRC cache runtime measurement is disabled | @@ -166,9 +169,18 @@ unchanged; the TXT mechanism adds the DRTM capability on top of it. | 7 | Heads `cbfs-init.sh`, `uefi-init.sh` | Each CBFS/UEFI file: filename then content (default `CONFIG_PCR=7`) — covers `config.user`, GPG keyring, user CBFS files, not UEFI Secure Boot state | PCRs 0 through 3 are read at seal time and included in sealing policies. PCRs 1 -and 3 are zero while their coreboot features stay disabled; PCR 0 is zero unless -BootGuard Measured Boot records the IBB before coreboot. Any extension of these -PCRs changes the value recorded in the policy and breaks the seal. +and 3 are zero while their coreboot features stay disabled. PCR 0 is normally +zero and holds a measurement only when the platform is provisioned with a +BootGuard boot profile that includes measurement; in that case the BootGuard ACM +measures the Key Manifest, Boot Policy Manifest, IBB and policy data into PCR 0 +at locality 3. Historically this came from the server TXT path, but BootGuard and +CBnT can measure on client silicon as well; most client machines ship verified +boot only, so PCR 0 stays zero. Any extension of these PCRs changes the value +recorded in the policy and breaks the seal. + +For the measurement behavior and its history see the [heads PR #1172 +discussion](https://github.com/linuxboot/heads/pull/1172) and the [Dasharo PCR +measurements knowledge base](https://docs.dasharo.com/kb/pcr-measurements/). Only PCRs 0 through 7 are extended or sealed against by Heads; other PCRs are not used (the integrity report may still read and display all PCRs). PCR 16 is not From 4043ff2198997d050e15b7071965323299a70c10 Mon Sep 17 00:00:00 2001 From: Thierry Laurion Date: Thu, 17 Sep 2026 17:24:03 -0400 Subject: [PATCH 4/4] doc: add IBB measurement and PCR 0 prerequisites The IBB and the prerequisites for a PCR 0 measurement are scattered across the Intel TXT and CBnT specifications, the Dasharo fork and the review history of the PCR measurement work. Document them in one place so the PCR 0 row in tpm.md no longer has to stand alone, and point tpm.md at the new page from the PCR assignments section. Signed-off-by: Thierry Laurion --- doc/ibb-measurement.md | 236 +++++++++++++++++++++++++++++++++++++++++ doc/index.md | 1 + doc/tpm.md | 4 + 3 files changed, 241 insertions(+) create mode 100644 doc/ibb-measurement.md diff --git a/doc/ibb-measurement.md b/doc/ibb-measurement.md new file mode 100644 index 0000000000..67e7ffff6e --- /dev/null +++ b/doc/ibb-measurement.md @@ -0,0 +1,236 @@ +# IBB measurement and PCR 0 + +This page covers the Initial Boot Block (IBB) and how hardware measures it into +TPM PCR 0 on Intel boards. PCR assignments, the PCRs Heads seals against, and +the software SRTM chain are documented in [tpm.md](tpm.md); this page does not +repeat them. Read that page for what Heads does with a PCR value, and this page +for what makes PCR 0 carry a firmware measurement at all. + +## The IBB and the root of trust + +The IBB is the first code executed at the reset vector. In coreboot it is one +or more CBFS files, and the bootblock is always one of them. The IBB must +contain the reset vector and the FIT table, and its size must be a multiple of +16 (coreboot `Documentation/security/intel/txt_ibb.md`). Once measured, the IBB +is the static core root of trust for measurement (SCRTM, reported as +`scrtm_status` in the coreboot CBnT registers). + +Two mechanisms can measure the IBB: + +* Legacy Intel TXT publishes the IBB as FIT records. +* Intel CBnT (Converged Boot Guard and TXT) carries the digest inside a signed + manifest and runs a Startup ACM. + +Coreboot's own software measurements are a separate chain and land in PCR 2, +not PCR 0 (see [tpm.md](tpm.md)). + +## Path 1: legacy Intel TXT + +CBFS files can be tagged as part of the IBB when the build has `INTEL_TXT=y`. +The top level Makefile adds `--ibb` to the relevant stages +(`Makefile.mk:884,1406`), and cbfstool then attaches the IBB attribute with a +minimum alignment of 16 (`util/cbfstool/cbfstool.c:1007-1012`). Coreboot adds +the tagged files plus the bootblock to the FIT as type 7, using the bootblock +addition at `src/security/intel/txt/Makefile.mk:46` and the ifittool call at +`:49`; type 7 is `FIT_TYPE_BIOS_STARTUP` in cbfstool +(`util/cbfstool/fit.h:19`). Coreboot's own description states that each IBB is +measured into PCR 0 before the reset vector executes +(`Documentation/security/intel/txt_ibb.md`). + +The Dasharo fork used by the NovaCustom boards moved this block to +`src/security/intel/acm/Makefile.mk:30-43`, guarded by +`ifneq ($(CONFIG_INTEL_CBNT_SUPPORT),y)`: on a CBnT board the type 7 IBB +records are deliberately not emitted. + +## Path 2: Intel CBnT + +On CBnT boards the measured path works differently. Coreboot puts the Startup +ACM in the FIT as type 0x02 when a BIOS ACM file is configured +(`src/security/intel/acm/Makefile.mk:5-16`). Type 0x07 is the legacy BIOS +Startup Module entry and is not used for the IBB here +(`src/arch/x86/include/arch/fit_table.h:18,23`; `util/cbfstool/fit.h:17,19`). +The IBB digest is carried in the signed Boot Policy Manifest instead. Coreboot +can generate an unsigned BPM with a digest list over the image +(`src/security/intel/cbnt/Makefile.mk:58-74`), and the provisioning tool +derives the digest from the CBFS files `bootblock`, `fallback/verstage` and +`fspt.bin` (`3rdparty/intel-sec-tools/pkg/provisioning/cbnt/tools.go:317-331`). + +For PCR 0 to receive a measurement, all of the following must be true. None of +them is a Heads or coreboot build option. + +1. The platform fuses (FPF) contain Boot Guard with a profile that measures. + The repository only shows the fuse coupling it consumes: the Key Manifest ID + and security version number must match the fuses + (`src/security/intel/cbnt/Kconfig:157-180`). +2. A signed Key Manifest and Boot Policy Manifest are present in the FIT as + types 0x0b and 0x0c (`src/arch/x86/include/arch/fit_table.h:27-28`), and the + BPM digest matches the exact image being booted. +3. A Startup ACM is present in the FIT at reset (type 0x02). +4. The ACM extends PCR 0. Coreboot cannot do this part; it can only observe the + ACM status. `intel_cbnt_inject_ibg_measurements()` returns early unless + `scrtm_status` is set and the applied policy carries the measured bit + `CBNT_BP_TYPE_M` (`src/security/intel/cbnt/measurement.c:641-647`, + `cbnt.h:15-16`). +5. Coreboot reconstructs the event log on Meteor Lake and newer so that + `cbmem -L` or `tpm2_eventlog` replay matches the PCR 0 value + (`measurement.c:748-823`; Dasharo fork commits a74cb058c3 and b577aaac21). + The CRTM version and IBB digest are log only (`measurement.c:777` and + `:786`); the one PCR 0 value coreboot itself extends is POLICY_DATA + (`measurement.c:819`). The log helper never extends + (`src/security/tpm/tspi.h:155-166`). + +Things that do not enable a PCR 0 measurement: + +* An ACM alone is not sufficient. Without the measured policy bit the code + returns before doing anything (`measurement.c:646-647`). +* A fused profile that only verifies runs the ACM but measures nothing. The + Dasharo BGS test documentation reports measured and verified only for + profiles 3 and 5. +* No Kconfig enables it. `INTEL_CBNT_IBB_FLAGS` only feeds BPM generation + (`src/security/intel/cbnt/Makefile.mk:63`), and its bit 2 maps to the + optional PCR 7 auth measurement (`BPM_IBBS_FLAG_AUTH_MEASURE`, + `measurement.c:24` and `:204`). The PCR 0 gate is the ACM policy word, not a + build option. +* Intel TXT is not required. CBnT builds select ACM support without TXT + (`src/security/intel/cbnt/Kconfig:8`; Dasharo fork commit a57a691f20). +* ME state is not an input, and nothing in the measurement path reads it. The + two ME disable mechanisms are different and neither one is a PCR 0 switch: + * HAP is a descriptor bit that stops the ME after the platform has started + (`src/soc/intel/common/block/cse/cse.c:1256-1316`; Meteor Lake U and H + offset in `include/intelblocks/me_18.h:6-8`). Its state is part of the + policy word that is hashed into PCR 0, so changing HAP changes the PCR 0 + value, but it does not turn measurement on or off. + * Soft disable is sent over HECI later in boot and cannot affect a + measurement that already happened (`cse.c:1167-1223`). + +Who does what: the hardware ACM performs the PCR 0 extends, and coreboot only +reconstructs the event log on Meteor Lake and newer. Coreboot's own SRTM +measurements are unchanged and land in PCR 2 +(`src/security/tpm/Kconfig:153-155`; see [tpm.md](tpm.md)). + +## Provisioning and key material + +ACMs are Intel signed. They are not buildable from source and are obtained +under NDA (`Documentation/mainboard/ocp/deltalake.md:52`). The public coreboot +CI config for CBnT points at a fake ACM +(`configs/config.ocp_deltalake_cbnt:3`), and the Dasharo blobs repo ships only +zero filled placeholder manifests +(`3rdparty/dasharo-blobs/cbnt/km_sample.bin` and `bpm_sample.bin`), which the +NovaCustom configs point at (`configs/config.novacustom_v540tu:50-51` in the +Dasharo coreboot tree). That tree used to reference signed ACM files; commit +231257b2c7 removed +`INTEL_TXT_BIOSACM_FILE="MTL_BIOSAC_REL_NT_O1.PW_signed.bin"` and the SINIT +file with the message "ACMs are added at provisioning time by the provisioning +scripts". Coreboot can still carry an ACM when a file is supplied +(`src/security/intel/acm/Makefile.mk:5-16`), but a source build of these boards +does not. + +NovaCustom publishes signed production images (file names containing +`btg_prod` and `btg_provisioned`) with hashes at +novacustom.com/novacustom-security. The published V540TU image +`novacustom_v54x_mtl_igpu_v1.0.1_btg_prod.rom` (32 MiB, sha256 +`e915ed1eae8b7b91a7a94ad7a75d57a4a077c0e7c6379234755788ca72fb1cd9`, matching +the vendor published hash) does carry the signed material. `cbnt-prov +fit-show` reports a Startup ACM entry (type 0x02) at address `0xffc40000`, a +Key Manifest record (0x0b at `0xffaaaf00`, 853 bytes) and a Boot Policy +Manifest (0x0c at `0xffaaa880`, 913 bytes). `cbnt-prov acm-export` writes the +ACM out as 132096 bytes (sha256 +`e9ddab7d96e5cbade4f79a5c5a4dfb5e2a6ebf819400d15398d949eb1ea569a6`, at file +offset 0x1c40000), header date 2024-05-01, TxtSVN 2, SeSVN 5. The ACM header +size field is in dwords, so 33024 dwords is 132096 bytes. The tool's +`acm-show` subcommand cannot parse this ACM because it assumes an RSA 2048 +public key while Meteor Lake uses a 384 byte (RSA 3072) key; read the security +version numbers from the raw header instead. + +Key material: the FPF stores a SHA 384 hash of the OEM RSA public key. On +NovaCustom TrustRoot units the production key is NovaCustom's own. The +provisioning tool used by 3mdeb prints "Key matches NovaCustom Meteor Lake +signing key", and the 3mdeb advisory post of 2025-12-18 describes the +`eom-key-issue`. + +The rule that you must be the OEM to sign manifests is not universal, and the +Clevo leak shows why. Clevo firmware packages shipped the private RSA keys that +sign the Key Manifest and Boot Policy Manifest: `B10717.exe` and +`CreateDeleteBIOSKey.keyprivkey.pem` inside `BootGuardKey.exe`. Binarly +verified that the leaked keys match production Clevo manifests (advisory +BRLY-2025-002, 2025-03-20; CERT VU#538470, 2025-10-13; CVE-2025-11577), with +10 affected devices including Gigabyte and XPG models; initial reporting was by +Thierry Laurion on the Win Raid forum in February 2025. On a machine fused to a +Clevo key, a third party can sign their own Key Manifest and Boot Policy +Manifest and pass Boot Guard. The FPF is one time programmable, so affected +units cannot be rekeyed and no revocation mechanism exists. This does not help +on NovaCustom keyed units, where the production key is held by NovaCustom. + +## What an owner can check + +All of these are read only and need no special build: + +* `pcr0tool dump_registers` prints `ACM_POLICY_STATUS` (measured and verified + bits, profile, Key Manifest ID, TPM status), `ACM_STATUS` and + `BTG_SACM_INFO`. It needs access to `/dev/mem` for the ACM status registers; + see `3rdparty/intel-sec-tools/cmd/pcr0tool/README.md`. +* `tpm2_pcrread` reads the current PCR 0 value. +* `tpm2_eventlog` from an OS, or `cbmem -L` from the recovery shell, shows the + event log. The Boot Guard entries coreboot records should be present and + should replay to the PCR 0 value. +* `cbnt-prov show-all` prints the FIT, Key Manifest, Boot Policy Manifest and + ACM of a firmware image + (`3rdparty/intel-sec-tools/cmd/cbnt-prov/README.md`). +* On a full SPI flash image use `cbnt-prov fit-show` rather than `pcr0tool + dump_fit`, which expects a UEFI or CBFS image. +* The vendor firmware setup menu shows Boot Guard register values in the Intel + ME menu when the platform is fused + (docs.dasharo.com/dasharo-menu-docs/dasharo-system-features). + +Ask the vendor: is the unit fused, and with which profile number; does the +vendor image embed the signed ACM, Key Manifest and Boot Policy Manifest; and +who holds the signing key. Per unit fuse state is not published. + +## A different trust model: ownerboot + +Adam M. Joseph's ownerboot (codeberg.org/amjoseph/ownerboot) is the opposite +approach. It targets the ASUS KGPE-D16, the MSI AM1-I and ARM64 RK3399 only, +has no Intel target, and does no measured boot at all: the TPM is disabled +(`0023-kgpe-d16-disable-TPM.patch`, `TPM_DEACTIVATE = lib.mkForce yes`). Trust +is anchored in reproducible source builds (`allowNonSource=false`, no +binaries), flash write protection, and owner held OpenBSD `signify` keys; the +term "owner controlled" comes from its `doc/owner-controlled.md`. Caveat: the +signing scripts are declared but not yet published. The contrast matters +because ownerboot removes the vendor, fuse and provisioning dependencies by +removing measured boot, while Heads keeps measured boot and therefore inherits +those dependencies. + +## Unknowns + +* Whether a platform without fuses runs the ACM and extends an asserted digest. + Needs the Intel CBnT BWG (document 575623). +* CSME behaviour under HAP on Meteor Lake. No published data. +* Per unit fuse and profile state. +* Whether the signed Key Manifest and Boot Policy Manifest in the published + images chain to the key hash fused into production units. The images carry + signed manifests, but the fused key hash is not published. + +## References + +* coreboot `Documentation/security/intel/txt_ibb.md` and + `Documentation/security/vboot/measured_boot.md` +* coreboot `Documentation/mainboard/ocp/deltalake.md` ( "ACM binaries ... are + only required for CBnT enablement. Available under NDA with Intel" ) +* Legacy TXT IBB path: `Makefile.mk:884,1406`, + `util/cbfstool/cbfstool.c:1007-1012`, `util/cbfstool/fit.h:17,19`, + `src/security/intel/txt/Makefile.mk:39-52` +* CBnT path: `src/arch/x86/include/arch/fit_table.h`, + `src/security/intel/cbnt/Makefile.mk`, + `src/security/intel/cbnt/Kconfig`, + `src/security/intel/cbnt/measurement.c`, + `src/security/intel/acm/Makefile.mk`, `src/security/tpm/tspi.h`, + `src/soc/intel/common/block/cse/cse.c` +* Dasharo coreboot fork commits: 231257b2c7, a74cb058c3, b577aaac21, a57a691f20 +* Intel documents: CBnT BWG 575623, FIT specification 599500, CSME Security + Technical White Paper 631900 +* Binarly advisory BRLY-2025-002; CERT VU#538470; CVE-2025-11577 +* Dasharo BGS test documentation; Dasharo PCR measurements knowledge base; + Dasharo setup menu documentation +* NovaCustom security page (novacustom.com/novacustom-security) and firmware + flashing knowledge base +* ownerboot: codeberg.org/amjoseph/ownerboot diff --git a/doc/index.md b/doc/index.md index 0be106bb13..242d231cc7 100644 --- a/doc/index.md +++ b/doc/index.md @@ -31,6 +31,7 @@ Quick reference: read the relevant doc when working on a topic. | `configuring-keys.md` | Setting up GPG keys for signing firmware updates | | `gpg.md` | GPG tool operation for firmware signing and verification | | `hotp.md` | HOTP-based remote attestation of firmware state | +| `ibb-measurement.md` | IBB measurement paths, PCR 0 prerequisites, provisioning and signing keys | | `keys.md` | Key management for firmware signing | | `security-model.md` | TPM measured boot, trust chain, flash write protection | | `TPM_GPIO_Reset_Approaches.md` | Eight approaches for resetting TPM via GPIO | diff --git a/doc/tpm.md b/doc/tpm.md index a41d5145cc..af98bc24eb 100644 --- a/doc/tpm.md +++ b/doc/tpm.md @@ -187,6 +187,10 @@ used (the integrity report may still read and display all PCRs). PCR 16 is not used: `calcfuturepcr` replays the `cbmem -L` event log (`replay_pcr` rejects `pcr >= 8`), so no scratch PCR is needed. +The prerequisites for a PCR 0 measurement (fuses, signed manifests, the +Startup ACM, and coreboot's role) are described in +[ibb-measurement.md](ibb-measurement.md). + ### Sealing policies #### LUKS Disk Unlock Key (DUK) — kexec-seal-key