TExcelTAD

Firmware, Secure Boot and TPMs

Everything the operating system does to protect itself assumes that the operating system is the one that booted. Code that runs before it (firmware, the bootloader, option ROMs on expansion cards, a management controller) can hide from every tool that runs later. That is why firmware is a research field of its own and why platforms build a chain of trust from the first instruction: each stage checks or records the next one. This lesson explains that chain (secure boot, measured boot, TPMs and attestation) with a runnable model, and how firmware compromise is detected. The device side (UART, JTAG, firmware images of IoT devices) is in UART, JTAG, SWD and Secure Boot and Analysing a Synthetic Firmware Image.

Two ways to trust a boot chain

Verified (secure) boot Measured boot
each stage checks the signature of the next before running it hashes the next stage into a TPM register before running it
on a bad stage refuses to boot boots, but the record shows it
who decides the device, against keys in firmware a remote verifier (or a sealed secret) later
examples UEFI Secure Boot (keys PK, KEK, allowed db, forbidden dbx), Android Verified Boot, Apple's boot chain TPM-based measured boot, Windows Measured Boot, Linux IMA

The two complement each other: secure boot stops known-bad code from running; measured boot proves to someone else what ran, including stages that were validly signed but are not what you expected (an old, vulnerable, signed bootloader, for example).

TPMs and PCRs

A Trusted Platform Module (TPM 2.0 today, a separate chip or firmware inside the CPU) holds keys that never leave it and a set of Platform Configuration Registers (PCRs). A PCR cannot be written, only extended:

text
PCR_new = SHA-256(PCR_old || SHA-256(component))

so its final value depends on every measurement, in order, and no later code can set it back. Firmware measures itself and the bootloader, the bootloader measures the kernel, and so on; each measurement is also written to an event log. Two uses follow:

  • Sealing: a secret (a disk-encryption key) is bound to PCR values and released only if they match. Full-disk encryption that unlocks automatically with the TPM works this way: boot a modified bootloader and the TPM keeps the key.
  • Remote attestation: the TPM signs a quote (the PCR values plus the verifier's fresh nonce) with an attestation key; the verifier checks the signature, replays the event log to confirm it matches the PCR, and compares each measurement with a list of known-good values.

A boot chain in a model

The example models a three-stage boot chain. Release images are signed with a fixed lab vendor key (Ed25519); the "TPM" extends a PCR and signs quotes with a fixed attestation key; the verifier performs the three checks above. It boots a good chain and a chain with a modified bootloader, once with measured boot only and once with secure boot on. Keys and the nonce are fixed so the output is stable; real ones are generated and kept in hardware. It runs in your browser:

python · try it yourself
import hashlib
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey
from cryptography.exceptions import InvalidSignature

# Fixed lab keys so the output is stable; real keys are generated in an HSM and never printed.
vendor_key = Ed25519PrivateKey.from_private_bytes(bytes(range(32)))
ak_key = Ed25519PrivateKey.from_private_bytes(bytes(range(32, 64)))      # the TPM's attestation key

GOOD = {"bootloader": b"lab-boot v2.1", "kernel": b"lab-kernel 6.12", "initrd": b"lab-initrd 7"}
SIGS = {name: vendor_key.sign(img) for name, img in GOOD.items()}         # signed at release time

def boot(images, secure_boot):
    pcr, log = bytes(32), []                                             # PCR starts at zeros
    for name, img in images.items():
        if secure_boot:                                                  # VERIFIED boot: refuse
            try:
                vendor_key.public_key().verify(SIGS[name], img)
            except InvalidSignature:
                return None, log + [f"secure boot: {name} signature invalid, boot stopped"]
        digest = hashlib.sha256(img).digest()                            # MEASURED boot: record
        pcr = hashlib.sha256(pcr + digest).digest()                      # PCR extend
        log.append((name, digest.hex()))
    return pcr, log

def attest(pcr, nonce):
    """TPM quote: the attestation key signs the PCR value and the verifier's fresh nonce."""
    return ak_key.sign(pcr + nonce)

def verifier(log, pcr, quote, nonce, known_good):
    ak_key.public_key().verify(quote, pcr + nonce)      # 1. the quote is genuine and fresh
    replay = bytes(32)
    for name, digest in log:                             # 2. the event log matches the PCR
        replay = hashlib.sha256(replay + bytes.fromhex(digest)).digest()
    if replay != pcr:
        return "UNTRUSTED: event log does not match the quoted PCR"
    unknown = [name for name, digest in log if known_good[name] != digest]
    return f"UNTRUSTED: unknown {', '.join(unknown)}" if unknown else "trusted"   # 3. allow-list

expected = {n: hashlib.sha256(i).hexdigest() for n, i in GOOD.items()}
tampered = dict(GOOD, bootloader=b"lab-boot v2.1 + implant")
nonce = b"verifier-nonce-0001"                                          # fixed here; fresh for every quote in reality

for label, images in (("good chain", GOOD), ("tampered bootloader", tampered)):
    pcr, log = boot(images, secure_boot=False)
    print(f"{label}, measured boot only: PCR = {pcr.hex()[:16]}...")
    print("  event log:", ", ".join(f"{n} {d[:12]}" for n, d in log))
    print("  remote verifier:", verifier(log, pcr, attest(pcr, nonce), nonce, expected))
    pcr, log = boot(images, secure_boot=True)
    print(f"{label}, secure boot on: {'booted' if pcr else log[-1]}")
good chain, measured boot only: PCR = 2f4f6cf8b91607c2...
  event log: bootloader b4aa850a73f4, kernel 9f2652f1caec, initrd 77a6b07630d9
  remote verifier: trusted
good chain, secure boot on: booted
tampered bootloader, measured boot only: PCR = 104d99747bb34824...
  event log: bootloader 0cb8a918fb4d, kernel 9f2652f1caec, initrd 77a6b07630d9
  remote verifier: UNTRUSTED: unknown bootloader
tampered bootloader, secure boot on: secure boot: bootloader signature invalid, boot stopped
  • The two chains differ only in the bootloader, yet the PCR values differ completely: extend makes the final value depend on every byte of every stage.
  • With measured boot only, the tampered machine boots, but the remote verifier refuses to trust it: the event log is consistent with the quoted PCR (the record was not forged), and the bootloader's digest is not on the allow-list. A network could keep this machine out, or a disk key sealed to the good PCR value would stay locked.
  • With secure boot on, the tampered bootloader never runs: its signature fails.

Firmware as an attack surface

Component Why researchers care
UEFI firmware (DXE drivers, image parsers, SMM handlers) runs with the highest privileges before the OS; bugs in boot-time parsers (for example of boot logos) and in System Management Mode have been found in shared vendor code bases
bootloaders (shim, GRUB, Windows Boot Manager) signed and trusted by secure boot; a signed bootloader with a bug lets attackers bypass secure boot until it is revoked in dbx
option ROMs, device firmware (NICs, SSDs, GPUs) code from other vendors, often unsigned or weakly checked
management controllers (BMC, Intel ME/AMD PSP) separate computers with network access and full host control
firmware updates must be signed and protected against rollback to vulnerable versions

The revocation problem deserves attention: a vulnerable bootloader that was legitimately signed stays bootable on every machine that has not received the updated forbidden-signature list (dbx), and updating dbx on millions of machines is slow and can break old boot media. Several real secure-boot bypasses have been exactly this.

How firmware compromise is detected

  • Remote attestation and measured-boot logs compared with known-good values, as in the model.
  • Firmware integrity scanning: tools that dump and compare the SPI flash contents with vendor images (CHIPSEC is a widely used open-source framework for platform security checks), and vendor services that verify firmware at boot or from the BMC.
  • Configuration checks: secure boot on, dbx current, firmware write-protection and boot-guard features enabled, debug interfaces closed.
  • Behavioural signals: an endpoint agent seeing unexpected EFI variables, changes to the EFI system partition, or a disk-encryption key that suddenly needs the recovery password (PCRs changed).

How it is prevented and fixed

Keep firmware updated through the vendor's signed update channel (on Linux, fwupd and the LVFS), keep the dbx revocation list current, enable secure boot and hardware boot guards, seal disk keys to PCRs that cover the bootloader and its configuration, restrict physical access and debug ports, and require attestation for high-value machines. For vendors: sign everything, prevent rollback, minimise SMM and pre-boot parsers, fuzz them (UEFI code can be fuzzed in emulation), and coordinate fixes with the shared firmware suppliers whose code ends up in many brands.

Pitfalls

  • Secure boot without revocation. Signed-but-vulnerable bootloaders remain trusted until dbx is updated.
  • Sealing to too few PCRs. If the bootloader configuration is not measured, an attacker can change the kernel command line without changing the sealed PCRs.
  • Trusting the event log without the quote. The log is just a file; only its consistency with a signed, fresh PCR quote makes it evidence.
  • Ignoring the BMC. A management controller on the network is often the weakest part of a server.

Practice

1. Why can malware that runs after boot not reset a PCR to its good value?

PCRs can only be extended, and extend is a one-way hash chain: reaching a given value would require a SHA-256 preimage. Only a reboot resets the boot-time PCRs (a few PCRs, such as the debug PCR 16, are resettable by design and are not used for boot measurements), and then the firmware measures again from the start.

2. Why does the quote include the verifier's nonce?

Without it, an attacker could replay an old quote recorded while the machine was still clean. The fresh nonce proves the quote was made now.

3. A legitimately signed old bootloader with a known bug is used to bypass secure boot. Which part of the model would still catch it, and how?

Measured boot plus attestation: its digest is not on the verifier's current allow-list, so the machine is reported untrusted (and sealed keys stay locked) even though its signature is valid. The fix is to add it to dbx so secure boot also refuses it.

Test yourself

What is the difference between verified boot and measured boot?

  1. None
  2. Verified boot refuses unsigned stages; measured boot records hashes of what ran for later checking
  3. Measured boot is faster
  4. Verified boot needs a TPM

How is a PCR updated?

  1. Overwritten by the OS
  2. Extended: PCR_new = H(PCR_old || H(component))
  3. Reset by every program
  4. Incremented

In the model, why did the verifier trust the event log of the tampered machine but still reject it?

  1. The quote was invalid
  2. The log matched the quoted PCR, but the bootloader digest was not on the allow-list
  3. The nonce was missing
  4. Secure boot was on

Why is dbx (the forbidden-signatures list) important?

  1. It stores passwords
  2. It revokes signed-but-vulnerable boot components that secure boot would otherwise accept
  3. It speeds up boot
  4. It holds the TPM keys