Section 16.8

Provisioning power-failure safety

Definition

Provisioning power-failure safety is the property that a device which loses power at any moment while its credentials are installed restarts in a state it can safely act on. The credentials are its keys and the values that belong with them, such as its identity and a minimum accepted software version, held in storage that keeps its content without power. After any interruption, the device runs with one complete credential set from a single installation attempt, or it refuses every operation that needs a credential; it never mixes attempts.

The idea

A device is to receive a new credential set: a 32-byte key; a key identifier, which tells a server which key the device holds; the device’s identity; and a version floor, the lowest software version the device will accept. A simple program overwrites the four values in place, one after another. If power fails after the new key is written but before the new identifier, the device restarts with the new key under the old identifier. The server uses the old key, every message the device authenticates fails, and the device is locked out. A cut inside a write is worse: it leaves a half-written key, a value nobody chose.

Moving house is a fair picture: you live in the old house until the new one is ready, then move in one step. Software leaves the old complete credential set untouched, builds the new set where it has no effect yet, checks it, and switches with one small final write, the commit. The picture stops at the switch. A write to storage takes time and can itself be cut, so a half-finished commit must read as not done. A first provisioning has no old house: after an interruption, the only safe result is a device that knows it is unprovisioned.

How it works

A common design, the two-slot scheme that an A/B update §8.10 uses for firmware, keeps two storage areas, called slots, each holding one complete credential set, called a bundle. One slot holds the bundle in force; the other receives the candidate, the bundle being installed. Besides the keys, identifiers, policy settings and version floor, a bundle holds:

The same design serves key provisioning §5.28, which gives a device its first credentials, and a replacement, such as a key rotation §5.29.

Installation runs in this order:

  1. Erase the inactive slot. Erasing flash memory §6.6 sets every bit of a page, its smallest erasable unit, to 1, so erased bytes read as 0xff; writing can only change bits from 1 to 0.

  2. Write the candidate, every field except the marker.

  3. Read the slot back, compare it with the intended bundle and recompute the check value. On a mismatch, stop; the old bundle stays in force.

  4. Once the hardware reports that every write has finished, write the marker. This one write is the commit.

At every restart, recovery decides from the storage contents alone:

  1. A slot is valid only if its marker has exactly the valid value and its check value matches its contents.

  2. Recovery selects the valid slot with the highest generation number.

  3. If no slot is valid, the device enters the unprovisioned state: it refuses every operation that needs a credential and accepts only a new installation.

One slot holds the fields of one attempt under one check value, so recovery cannot combine fields of two attempts. Recovery only reads, so it is idempotent §8.31: an interrupted recovery reaches the same decision at the next restart.

Worked example

Slot A holds generation 7, valid and in force; slot B receives generation 8. Installation has four operations: erase B, write B, verify B, write B’s marker. Cuts between operations give 4+1=54 + 1 = 5 cut points, and cuts inside the four operations add 4 classes of torn states, the partial contents that a torn write §8.19 (a write cut while in progress) or a cut erase leaves, for 5+4=95 + 4 = 9 classes. Recovery gives:

On a first provisioning slot A is empty. The same nine classes give the unprovisioned state in the first eight and generation 1 in the ninth, and in each of the eight the installation can simply run again. No class yields a mixture, because the only route to a new bundle is a marker written after the whole bundle was written and checked.

Stated precisely

Let nn be the number of ordered storage operations in one installation. Cuts between operations give n+1n + 1 cut points. If each operation can also be cut while it runs, each adds one class of torn states, for 2n+12n + 1 classes. Recovery must handle every concrete storage content in every class.

Let R(S)R(S) be the outcome of recovery on storage contents SS: a bundle, or the unprovisioned state. Installation is power-failure safe when, for every SS that an interruption can leave, two conditions hold.

  1. R(S)R(S) is the old bundle, the new bundle or the unprovisioned state, and nothing else.

  2. R(S)R(S) is the new bundle only if its commit marker was completely written.

For a replacement, availability §1.10 adds a third condition: R(S)R(S) is never the unprovisioned state while the old bundle is intact.

The guarantee rests on five assumptions.

  1. Failure model §1.30: the list of possible interruptions, and of what each leaves behind, is right. For flash memory it includes erased bits, written bits and, after a cut, bits of uncertain value.

  2. Write ordering §8.20 and durability §8.2: a write that the hardware reports finished survives power loss, and no later write reaches storage before an earlier one.

  3. Detection: the marker and the check value reject every incomplete state that the failure model allows. A CRC detects accidental damage with high probability, not deliberate change.

  4. Read-only recovery: recovery writes nothing, or its writes are safe to interrupt.

  5. One writer: only the installation writes the slots. An attacker who can write storage can compute a matching CRC; resisting that needs a MAC (message authentication code §5.7), a check value that only a holder of a secret key can compute, or a digital signature §5.14 over the bundle.

Limits and common mistakes

A successful normal run tests no cut point. Power-loss injection §8.38 does: it cuts the power at each cut point and inside each operation, then checks what recovery selects.

Safe is not the same as usable. An interrupted first provisioning leaves a device that refuses service until it is provisioned again.

Erased storage must never pass as a credential. A key of all 0xff bytes, the erased value, or of all zeros is guessed at once, so neither the marker nor the check value may accept erased or zeroed storage.

Falling back can revive a revoked key. If the new slot is damaged after the commit, recovery selects the older bundle, perhaps one whose key had leaked. Anti-rollback §8.26 protection, a minimum accepted generation kept outside the slots, for example in a monotonic counter §8.28 (a counter that can only increase), blocks that fallback, and with it the availability the fallback gave. The design must choose.

An uncertain bit can read differently on different restarts. A marker cut while being written may read as valid once and as invalid later, so the device switches between bundles. The storage’s documented behavior under power loss is an assumption to state and to test.

Overwriting in place destroys the fallback. Keys held in a separate key store are written under new names, and the old ones are deleted only after the commit.

The device and the server can disagree. A device that committed generation 8 before the server learned of it holds a key the server does not use yet. Agreement needs a confirmation exchange, which power-failure safety on the device does not provide.

Questions answered

What usable and safe states remain after each interrupted write?

After each interrupted write, exactly three states are acceptable: the old complete credential set remains in force; the new complete credential set is in force because its final commit write finished; or, when no complete set exists, the device is in an explicit unprovisioned state, in which it refuses every operation that needs a credential and accepts only a new installation. The first two are usable. The third is safe but gives no service. A mixture of fields from different attempts, or a half-written key, is never acceptable.

Which state results depends on where the cut falls. Suppose the complete new set is written into a spare storage slot, checked, and committed by a marker written last. Then any cut before the marker is completely written leaves the old set in force during a replacement, and the unprovisioned state during a first provisioning; a cut after it gives the new set. A cut inside a write leaves torn data, which the marker and a check value over the whole set must classify as not committed. This list holds only under a stated failure model of the storage, and each cut is tested by cutting the power there and checking what recovery selects.

Related entries: Crash consistency (§8.4), Torn write (§8.19), Write ordering (§8.20), Commit record and selector (§8.21), Key provisioning (§5.28), Key rotation (§5.29), Power-loss injection (§8.38), Rollback versus anti-rollback (§8.26), A/B update (§8.10).