Section 8.30

Boot validation versus arrival authentication

Definition

Arrival authentication is the check a device makes when an update arrives: it verifies a cryptographic tag, such as a digital signature §5.14, over the received bytes, showing that a holder of the right key produced them. Boot validation is the check made at each start-up on the stored copy, before it is run or loaded. The difference is time: arrival authentication vouches for the bytes received at one moment; boot validation decides about the bytes stored now, which equal the received bytes only if nothing has changed them since.

The idea

An update is received, its signature checks out, and it is written to flash memory §6.6, where it stays for years and is started at every reset. Between the arrival and each later start, many things can happen to the stored bytes. Power can fail in the middle of writing them. A flash cell can lose its charge. A software fault can write into the wrong region. An attacker can reach the flash through a debug interface, or through a flaw that lets the attacker’s code write storage. The check at arrival happened before all of these and says nothing about them.

Airport security is a fair picture. Passengers are screened once at the checkpoint, and inside the secure area nobody screens them again; the area is trusted because there is no way in except through the checkpoint. A device can work the same way, trusting what is in its flash because nothing can write the flash except through the checked update path. Or it can screen again at the gate, by checking the stored copy again at every start-up. The picture stops at cost. Screening every passenger again at every gate would be slow, whereas checking a stored image again usually costs one hash computation and one signature check per start-up, and the design must weigh that cost against what can reach the flash.

How it works

Follow an update through three moments.

  1. Arrival, at time t1t_1. The bytes sit in a receive buffer in RAM. Arrival authentication computes their cryptographic hash §5.1, a short fixed-length digest of the bytes, and verifies the signature over that hash with a public key the device trusts.

  2. Storage, at time t2t_2. The bytes are written into flash. The device then reads them back and checks them again, because a write can fail silently, and the checked bytes in the buffer and the stored bytes in flash are different copies.

  3. Boot, at time t3t_3 and every later start. The bootloader §6.30, the first program to run after reset, reads the selection record §8.21 that names the image to start, and starts that image.

At step 3 a design takes one of two approaches.

A middle way exists. At arrival, after verifying the vendor’s signature, the device computes a message authentication code §5.7 (MAC) over the image with a secret key that only the device holds, and stores the MAC with the image. At boot it recomputes the MAC and compares, which is usually cheaper than verifying a public-key signature. An attacker who can write the flash but cannot read the device key cannot produce a matching MAC for altered bytes.

Boot also needs checks that are not about origin. A magic number, a fixed value at the start of the image header, and a length that fits the slot confirm the layout. A cyclic redundancy check §4.32 (CRC) or another checksum detects accidental damage. A comparison with the stored version floor refuses rollback. Compatibility checks confirm that the image fits the hardware and the stored data. None of these establishes origin: an attacker who can write flash can also write a matching magic number, length and CRC. Conversely, a valid signature does not make an image safe to load if it is too large for its slot or expects a different data format.

Worked example

Image X is 200 KiB long. At t1t_1 it arrives with a signature over its SHA-256 §5.2 (Secure Hash Algorithm with a 256-bit output) hash, and the signature verifies. At t2t_2 it is written to slot B, together with a header outside the signed bytes that holds a flag verified = 1 and a CRC-32 checksum of the image. Later, an attacker who has found a flaw that writes flash changes 4 bytes of the stored image, which turns it into image Y, and recomputes the CRC-32. At t3t_3 the device restarts.

Now change the failure. Power dips at t2t_2, and one 4 KiB flash sector of the image stays erased, so it reads as bytes 0xff. No attacker is involved. A bootloader that trusts only the flag starts a broken image. A bootloader that checks the CRC, or repeats the signature check, refuses it. Reading the image back at t2t_2 would have caught the failure before the flag was ever written.

The cost of repeating the check: assume the processor computes SHA-256 at 20 megabytes per second, where a megabyte is 10610^{6} bytes. The image is 200×1024=204,800200 \times 1024 = 204{,}800 bytes, so hashing takes 204,800/20,000,000=0.01024204{,}800 / 20{,}000{,}000 = 0.01024 s, about 10 ms, at each start-up, plus one signature verification. Whether that is affordable depends on how often the device starts and how quickly it must be ready.

Stated precisely

Let RR be the bytes received and σ\sigma the signature that arrived with them, and let Verify(K,R,σ)\mathrm{Verify}(K, R, \sigma) be true when σ\sigma is a valid signature over RR under the public key KK. Let B(t)B(t) be the bytes stored at time tt in the location the bootloader will start. Arrival authentication establishes that Verify(K,R,σ)\mathrm{Verify}(K, R, \sigma) is true at time t1t_1. Starting B(t3)B(t_3) at time t3t_3 is justified by one of two conditions.

  1. Repeated check: Verify(K′,B(t3),σ)\mathrm{Verify}(K', B(t_3), \sigma) is true at t3t_3, where K′K' is a key the device trusts at t3t_3, and the other boot checks, such as the version floor and the layout, pass.

  2. Protected storage: B(t3)=RB(t_3) = R. This equality holds if (a) the write at t2t_2 stored exactly RR, confirmed by reading it back; (b) no party outside the trusted code can write that location at any time between t1t_1 and t3t_3, whether through software, a debug interface or physical reprogramming; and (c) the record that selects which location to start is protected in the same way.

Condition 2 rests on the storage, not on cryptography. Arrival authentication followed by a boot without a check is the stored form of the time-of-check to time-of-use §9.26 (TOCTOU) problem: the check at t1t_1 concerns RR, the use at t3t_3 concerns B(t3)B(t_3), and nothing in the check itself makes the two equal.

Limits and common mistakes

Repeating the check at boot detects damage; it does not repair it. A refused image needs a recovery fallback §8.29, such as a second slot or a recovery mode, or the device does not start at all.

Repeating the check uses the trust rules in force at boot time. After a key rotation §5.29 that retires the old signing key, every stored image signed with that key is refused at the next start-up. That is the point of retiring a key, but the device must hold an image signed with a current key before the old key is retired.

A checksum or CRC is not authentication §1.6. It detects accidental damage, and anyone who can change the bytes can recompute it.

Authenticity is not safety. A correctly signed image can still be too large for its slot, expect a different data format or contain a fault; the boot checks of layout, version and compatibility are needed whether or not the signature is checked again.

Every boot check is only as trustworthy as the bootloader that runs it and the key it uses. Both belong in storage that no update and no attacker can change, which makes them the root of trust §1.33 of the device.

An image executed in place, meaning read directly from flash while it runs, is covered by a check at boot only if nothing can write that flash while the image runs. A check made at start-up covers the bytes at that instant only.

Arrival authentication is still needed when boot repeats the check. Without it, anyone who can reach the update path can fill the update slot with unchecked bytes: each attempt wears the flash, may overwrite a fallback image, and is discovered only at the next start-up.

Questions answered

Does boot repeat the origin tag check or rely on trusted flash contents?

It depends on the design: both approaches are in use, and they promise different things. The origin tag is the digital signature or message authentication code that shows who produced an update. A device checks it when the update arrives; the question is whether the bootloader, the first program to run at each start-up, checks it again on the stored copy.

Which approach a given device uses has to be read from its boot code; it cannot be inferred from the fact that updates are authenticated on arrival. If an attacker or a fault can change flash between arrival and boot, only a repeated check keeps the guarantee that what runs is what was authenticated. That check can be the original signature, or a message authentication code computed at arrival with a key that only the device holds.

Related entries: Authentication coverage (§5.41), Time-of-check to time-of-use (TOCTOU) (§9.26), Commit record and selector (§8.21), Secure boot (§6.31), Root of trust (§1.33), Checksum versus CRC (§4.32), Recovery fallback (§8.29).