Section 8.29

Recovery fallback

Definition

A recovery fallback is a defined alternative that a system switches to when its normal state cannot be used, together with the rule that decides when to switch. Typical fallbacks are the previous firmware image in a second slot, a separate recovery image, factory default settings and a recovery mode that waits for a new image. A fallback helps only if, at the moment it is needed, it is present, undamaged, still allowed by the device’s current security rules and able to work with the data it finds.

The idea

A new firmware image fails at start-up, and the bootloader §6.30, the small program that runs first after every reset, switches to the previous image. That is the plan. The previous image was put in place weeks earlier, and the device has changed since. The update may have used the old image’s storage for something else. A flash fault may have damaged it. The new image may have converted the stored settings into a format the old image cannot read, or the device may no longer trust the key that signed the old image. The fallback was arranged at one time and is called on at a later time, and every change in between can break it.

A spare wheel is a fair picture. It helps only if it is in the car, holds air and fits the car as it is now; a spare kept for the old wheels does not fit once the car has wheels of a different size. The picture stops at security. A spare wheel is never refused for being old, whereas a device’s fallback must still pass checks that may have become stricter since it was stored, and a fallback that is let through without those checks becomes a way around them.

How it works

A recovery fallback is specified by five parts.

  1. Triggers: the conditions that count as failure, such as an image that fails its check, a new image that resets a set number of times without confirming that it works, a watchdog timer §6.16 (a hardware timer that resets a device that stops responding) that keeps expiring, or stored data that fails its check.

  2. Candidates in order: what to try, for example first the last-known-good state §8.25 (the most recent image and settings known to have worked), then a separate recovery image, then a recovery mode in the bootloader or in read-only memory that waits for a new image.

  3. A usability check at the moment of use: each candidate is checked when it is about to be used, not when it was stored.

  4. A final safe state: what to do when no candidate passes. The safe choice is to stop in a recovery mode that runs only checked code and accepts only authenticated images, the choice called fail closed §1.13. Running bytes that failed their checks is never a fallback.

  5. A limit on attempts: a bound on how often each candidate is tried, so that a fallback that also fails leads to the final safe state, not to an endless cycle of restarts.

The usability check has four conditions, and all four must hold.

Keeping the fallback usable. Every update step that could falsify one of the four conditions for the current fallback must wait until a new fallback exists. The order is: install the new image; during its trial, keep the old key trusted, keep the old data format readable and keep the floor at the old version; let the new image confirm itself; only then retire the old key, discard the old data and raise the floor; finally, name the new fallback, which may be the confirmed new image itself or a refreshed recovery image signed with the current key. The rule is make before break: never remove the last usable fallback before its replacement is confirmed.

Independence. A fallback that shares the cause of the failure is no fallback. A recovery image in the flash sector that the update erases, or a recovery mode in a bootloader that the update replaces, fails together with what it was meant to replace. Code in read-only memory, which no update can change, is the most independent fallback, and for the same reason it can never be repaired.

Testing. Fallback paths run rarely, so their faults stay hidden until the moment they are needed. They are tested on purpose, by forcing each trigger, for example with reset injection §8.37 and power-loss injection §8.38, and checking that the expected candidate starts or that the device stops in its safe state.

Worked example

A device has two slots. Image A, version 8, is signed with key K1K_1 and reads its settings in format 1. Image B, version 9, is signed with key K2K_2. When image B first starts, it converts the stored settings to format 2 and tells the bootloader to stop trusting K1K_1. Image B then crashes at its third start, before confirming itself, and the bootloader falls back to slot A. Check the four conditions for image A.

  1. Present: yes. The update did not touch slot A.

  2. Intact: yes. Its hash matches the reference.

  3. Authorized: no. Image A is signed with K1K_1, which is no longer trusted, so the bootloader refuses it. Neither slot may start, and the device stops in recovery mode, or does not run at all if it has none.

  4. Compatible: no. Even if K1K_1 were still trusted, image A would find settings in format 2, which it cannot read. It would crash, which starts a cycle of restarts, or discard the settings and lose, for example, its network credentials.

The repair is to reorder the steps. During the trial, image B writes the format 2 settings next to the format 1 copy instead of over it, and the instruction to stop trusting K1K_1 waits. If image B fails, image A starts with K1K_1 still trusted and its format 1 settings intact. If image B confirms itself, it then retires K1K_1 and discards the format 1 copy. From that moment image A fails the authorized condition, and correctly so, because the old key was retired on purpose. The fallback is now the confirmed image B, and any separate recovery image must be re-signed with K2K_2 or replaced.

Stated precisely

For a candidate fallback FF at time tt, write Usable(F,t)=Present(F,t)∧Intact(F,t)∧Authorized(F,t)∧Compatible(F,t),\mathrm{Usable}(F, t) = \mathrm{Present}(F, t) \wedge \mathrm{Intact}(F, t) \wedge \mathrm{Authorized}(F, t) \wedge \mathrm{Compatible}(F, t), where ∧\wedge means and, and each condition is evaluated against the device’s state at time tt, not at the time FF was stored. Contract: when a trigger occurs at time tt, the device starts the first candidate FF in its list for which Usable(F,t)\mathrm{Usable}(F, t) holds. If there is none, it enters a recovery mode that runs only code whose authenticity it has checked and accepts only authenticated images.

The contract gives two guarantees.

Limits and common mistakes

Falling back to old code does not bring back old data. Stored data that a new image converted stays converted; the Schema migration §8.36 entry treats how to keep the old format readable until the new image is confirmed.

A fallback that skips checks in order to recover more often becomes a way around them. An attacker who can make the normal image fail, for example by sending it input that crashes it, then reaches the weaker path. Every path that starts code must apply the same authenticity and version checks.

A strict security rule can make a fallback unusable on purpose. After a key is retired or the version floor is raised, the old image is refused, and that is correct. The design must then say what the new fallback is, rather than discover the gap after a failure.

A fallback to an older version reopens that version’s known flaws for as long as it runs. The Rollback versus anti-rollback §8.26 entry treats how long an old version may stay permitted.

Factory default settings as a fallback restore operation but may discard what the device received after manufacture, such as keys and network credentials. The device may then need to be provisioned again before it can do its job.

A fallback that has never been exercised should be assumed broken. Recovery code runs least often and is tested least.

Questions answered

Can fallback itself be missing, corrupted, or incompatible with current keys?

Yes. A recovery fallback can be missing, corrupted or incompatible with the keys the device currently trusts, so each of these must be checked at the moment the fallback is used, not assumed from the time it was stored. A recovery fallback is the alternative, such as the previous firmware image or a separate recovery image, that a device switches to when its normal image or state cannot be used.

The defense has three parts. Check that the fallback is present, intact, authorized and compatible each time it is about to be used. Order every update so that the old key, the old data format and the old version floor are retired only after the new image has confirmed that it works, so that a usable fallback exists at every instant. And define a final safe state for the case where no fallback passes: a recovery mode that runs only checked code and accepts only authenticated images.

Related entries: Last-known-good state (§8.25), Rollback versus anti-rollback (§8.26), Schema migration (§8.36), Bootloader (§6.30), Key revocation (§5.32), A/B update (§8.10), Power-loss injection (§8.38).