Section 1.13

Fail closed

Definition

Fail closed describes a component that denies a protected operation whenever it cannot complete the security decision. An error, a timeout §9.34, missing or damaged data and an unexpected value lead to the same result as an explicit deny: the protected effect does not happen. The opposite design, fail open §1.14, allows the operation when the check cannot complete. Failing closed protects the rule the check enforces at the cost of availability §1.10, the ability of authorized users to get service, so a design must also state which operations stay available.

The idea

A device receives a software update and must check its signature with a stored public key. The storage that holds the key returns a read error. The device can install the update anyway, on the theory that the error is probably harmless, or it can refuse. Installing would let anyone who can cause a read error, for example by corrupting the storage, install unsigned software. Failing closed refuses: evidence that could not be checked counts as missing, and missing evidence is never permission.

A bank vault door that stays locked when the power fails is a fair picture; door makers call this design fail-secure. The picture also shows the cost: while the power is off, nobody gets into the vault, including the people who should. And the picture shows that the right choice depends on what the door protects. A fire exit is built the other way and opens when the power fails, because a locked fire exit endangers lives. Safety engineers call that design fail-safe, meaning safe for people, which is the opposite of fail closed. In computer security, by contrast, the principle of fail-safe defaults means that access is denied unless it was explicitly granted, which is close to fail closed. The word fail-safe therefore needs its context every time.

How it works

A fail-closed check has three outcomes, not two: allow, deny, and could not decide. Only allow permits the effect.

  1. Start from deny. The variable that holds the decision starts as deny for every new request, and only the path on which every check has succeeded for this request sets it to allow.

  2. Map every failure to deny. A parse error, a read error, a timeout, a failed memory request, an unsupported option and an unknown return value all leave the decision at deny.

  3. Use only a fresh verdict. The decision must come from checks run on this request in this attempt. A stored allow from an earlier request, or from an earlier attempt that failed halfway, is not evidence for this one.

  4. Clean up. Release temporary memory and locks, discard staged data, and leave stored state either unchanged or in a state from which the system can recover.

  5. Refuse only what depends on the failed check. Refusing a new configuration can keep the previous validated configuration running. A status query, or a recovery channel with its own authorization §1.7, can stay available. These fallbacks must be designed; the word closed does not supply them.

Some failures show that the state the check depends on is itself damaged, for example when the stored record that holds the update key, or the highest version ever installed, fails its own consistency check. Refusing the operation only in working memory is then not enough. After the next reset the device may read the record again and get a wrong value by chance, or code that repairs damaged records may rewrite it with default values, and either way the operation would be accepted again on state that nobody can trust. A latch handles this case. It is a refusal state stored in non-volatile memory, memory that keeps its content without power; once set, it keeps the protected operation refused across every reset. Only a privileged path clears it, such as reprogramming through a wired debug connection by someone with physical access, or a recovery command authenticated with a separate key. That path also restores the damaged state from a trusted source.

Worked example

A verification function returns 1 when the signature is valid, 0 when it is invalid, and −1-1 when it could not run, for example because the key could not be read. The caller writes if (verify(m) != 0) install(m). A valid signature gives 1 and installs; an invalid one gives 0 and refuses; a read error gives −1-1, which is not 0, and installs. The check fails open by accident. The fail-closed version tests for the one success value, if (verify(m) == 1) install(m), and now 0, −1-1 and any value the function was never meant to return all refuse.

A second classic bug keeps the verdict in a variable that outlives the request. Yesterday’s check stored allow, the value 1, in a global variable. Today’s check fails with an error before it writes its own result. The caller reads the variable, finds 1 and acts. A fail-closed implementation keeps the verdict local to the request, starts it at deny, and lets only this request’s successful check set it.

For an update, version 4 runs and a new version 5 arrives in a second storage area. Validation of version 5 fails. A fail-closed design discards version 5 and keeps version 4 running, so the device stays useful. Had the device erased version 4 before validating version 5, the same correct refusal would leave it with no working software: the check failed closed, and the device still lost its service.

A latch, with numbers. A device stores the highest version it has ever installed, 7, together with a checksum §4.32. At start-up the checksum does not match. Treating the damaged value as 0 would fail open: the device would then accept version 3, an older release with a known flaw. Failing closed, the device sets its latch.

The last cost is why such a record is written so that a power cut leaves either the old value or the new value, never a damaged mixture.

Stated precisely

For a request rr, let v(r)v(r) be the verdict that the checks produce for rr in the current attempt. It takes one of three values: allow, deny, or none, where none means that the checks did not finish. The fail-closed contract is the protected effect happens for r⟹v(r)=allow.\text{the protected effect happens for } r \implies v(r) = \text{allow}. As a decision table:

verdict available for this request result
allow, produced for this request now the effect happens
deny refused
none (error, timeout, damaged data) refused
allow left over from another request refused

The contract depends on three assumptions. Every path by which the effect can happen passes through the check, which is called complete mediation §1.16. The verdict is bound to the request, so the bytes that were checked are the bytes that are acted on. And the verdict is deny on every path that does not explicitly set it to allow. A latch adds one rule: while the latch is set, the effect happens for no request, and only the designated privileged path can clear the latch.

Limits and common mistakes

Failing closed protects the rule that the check enforces, not every goal. It can deny service, leave staged data behind, and block the very update that would repair the fault.

An attacker who can make the check fail at will, by sending malformed input, exhausting memory or damaging stored data, turns fail closed into a denial of service §1.28, an attack that stops legitimate use. Designs limit which failures an outsider can trigger, and keep the recovery path out of the attacker’s reach.

One unhandled path makes the whole design fail open. Every error branch, exception and unexpected return value must lead to deny, which is why code starts from deny and grants allow in exactly one place.

A refusal after the effect undoes nothing. If memory was written or a message sent before the check failed, denying afterwards does not reverse it.

Where stopping is dangerous, as with the brakes of a moving car, a system must keep working through a fault, which is called fail-operational design, and fail closed is the wrong default for that function.

Fail open is sometimes the right choice for a component whose failure must not stop the whole system, such as a monitoring tool that only observes. The choice is made for each operation and written down.

A latch is only as sound as its two edges. If ordinary input can set it, the latch is a lever for denial of service. If ordinary input or a reset can clear it, it is no latch.

Questions answered

Which operations remain available after a failure?

After a failure, the operations that remain available are exactly those that the design lists as not depending on the failed check, each with its own authorization; every operation that depends on the failed check is refused. Typical operations that stay available are:

For each operation that stays available, the design must show that it cannot reach the refused effect by another route; otherwise the fallback is a bypass. If the failure leaves no state that can be trusted to keep running, the right outcome is a controlled stop, and the design must admit that cost to availability. When the failure shows that the protected state itself is damaged, a latch, a refusal stored in non-volatile memory, keeps the dependent operations refused across restarts until the privileged recovery path clears it.

Related entries: Fail open (§1.14), Recovery authority (§1.46), Fault-to-verdict mapping (§2.34), Last-known-good state (§8.25), Complete mediation (§1.16), Secure default (§1.47).