Posts Tagged ‘mram firmware break’

PostHeaderIcon Secure Boot: The Root of Trust Is the Whole Game

A secure boot implementation is a chain of verifications. Each stage checks the next before handing control to it, so that a modified stage is detected before it runs. The chain is a good design and it is the right design, and it has one structural property that determines everything about its strength: the first link cannot be verified by anything.

Whatever verifies the first stage would itself need verification, and the regress has to stop somewhere. It stops in ROM or in a one-time-programmable area, and that is the root of trust. Everything above it is only as trustworthy as that, which is why attacks on secure boot concentrate there.

The shape of a chain

A typical implementation has three or four stages.

The ROM boot code runs first, from mask ROM that cannot be modified. It reads a first-stage image from flash, verifies it, and jumps to it.

The first-stage bootloader verifies the second stage, which may be the application or an update agent. The application may verify its own resources — keys, tables, configuration — before using them.

Stage Stored in Modifiable Verified by
ROM boot Mask ROM No Nothing
First-stage bootloader Flash or OTP With difficulty ROM
Application Flash Yes First stage
Resources Flash or external Yes Application

The fourth row is where many implementations stop verifying, and it is a legitimate design choice for code but not for data that carries security decisions. A key table loaded without verification is a key table that can be replaced.

Where the root actually is

The root of trust is not the ROM code itself in most designs. It is a value that the ROM code trusts: a public key, or a hash of a public key, or a symmetric key.

That value has to be immutable, or the root moves. If the key is in flash, an attacker who can write flash can replace the key and sign his own images, and the chain verifies them correctly. The root is then wherever that key is, and the ROM code is merely the mechanism that reads it.

Root location Immutable Consequence if writable
Key hash in mask ROM Yes Root is genuinely in the ROM
Key hash in OTP Yes, once written Root is in the OTP
Public key in a protected flash page Only if protection holds Root moves with the protection
Public key in ordinary flash No No root at all

The third row is common and is acceptable when the protection is real. The fourth is a design that looks like secure boot and provides none, and it is discovered by reading the boot code rather than by reading the marketing.

Why breaking the root breaks everything

Once the root is compromised, every downstream verification becomes an assertion that the attacker’s image is valid.

If the root is a key hash and the attacker can replace the hash, he generates a key pair, signs his image, and writes his public key’s hash into the location. The ROM verifies, the first stage verifies, the application verifies, and every stage reports success. There is no partial compromise in this structure: the chain either holds at the root or it does not hold at all.

Compromised element Chain result
Root key or hash Entire chain accepts attacker images
First-stage bootloader All above it accepts attacker images
Application Only the application is affected
Resource table Only the resources are affected

The table is the reason an assessment should identify the root before anything else. Attacking the application is a local win; attacking the root is a total one, and the effort is often comparable because the root is small and simple.

Weakness one: verifying a hash of a key

The first recurring weakness is a verification that checks the integrity of a key rather than the authenticity of an image.

The design intent is to save space: store a thirty-two-byte hash instead of a four-hundred-byte public key. The implementation reads the hash, compares it against a stored value, and then uses the key from flash. If the hash matches, the key is trusted.

The flaw is that the hash and the key are both in flash. An attacker who can write flash replaces both, and the comparison succeeds because he made it succeed.

Design What is verified Writable by an attacker
Hash of key compared against a constant Key integrity Yes, both sides
Hash in ROM compared against a key in flash Key authenticity No
Signature verified against a key in ROM Image authenticity No
Signature verified against a key in flash Nothing Yes

The second row is the correct version of the same idea and the difference is one word: where the hash lives. A hash in ROM is a root; a hash in flash is a value the attacker controls.

Weakness two: fail-open

The second weakness is a verification path that continues when verification fails.

It is almost always accidental. A function returns an error code, the caller checks it with a comparison that is inverted, or the error path falls through to the success path because the developer assumed the failure case was unreachable. The result is a boot that proceeds with a modified image and reports success.

Implementation Behaviour on failure Detectable by
Return code checked and branched to a halt Refuses to boot Observation
Return code checked and branched to a recovery mode Refuses the image Observation
Return code ignored Boots the image Reading the code
Error path falls through Boots the image Reading the code

The third and fourth rows cannot be detected from behaviour, because the device boots normally. They are found by reading the boot code, which is why the assessment of a secure boot implementation is a code review rather than a test.

Weakness three: verify once, run forever

The third weakness is a verification performed at load time on an image that is later modified in place.

The mechanism differs by platform. On a device that executes from RAM, an attacker with any write capability can modify the running image after verification. On a device with an external memory and an unprotected bus, the image can be replaced after the loader has read it. On a device with an update mechanism, the update can be applied to a region that is verified only at the next boot.

Execution model Post-verification exposure
Execute in place from internal flash Low; flash writes are gated
Copy to RAM and execute High; RAM is writable
Execute from external memory High; the bus is exposed
Verified at boot, updated at run time High until the next boot

The second row explains why some designs verify and then lock the RAM region containing the code, which is the correct mitigation and adds a memory protection unit requirement that some parts cannot meet.

What an audit produces

The deliverable is a chain diagram with three annotations per link: where the code lives, what verifies it, and what happens when verification fails.

That diagram is the difference between a claim and a finding. A vendor who says the product has secure boot has made a claim; a diagram that shows a hash compared against a constant in flash has produced a finding.

Link Code location Verifier Failure behaviour
ROM Mask ROM Nothing —
First stage Flash ROM, key hash in ROM Halt
Application Flash First stage, signature Halt
Resources Flash Application Halt

Where this fits

The boot chain is the reason a modified image can be refused even when the array has been read successfully, which is the distinction drawn in patching IC code. Where the chain is intact and the root is in ROM, the only remaining approaches are the ones that do not go through the verification at all: a fault injected into the comparison, discussed in glitch attacks as a search problem, or a physical intervention on the die.

Where the failure is a hash in flash rather than in ROM, the root has moved and the work becomes a write rather than an attack, which is why the location of the root is the first question in the audit. The ordering problems that make some chains weaker than their design suggests are in three protection layers.

What we deliver is the diagram and a statement of the weakest link. Where the weakest link is the root in ROM, we say that the chain is sound and that the remaining routes are physical or fault-based, because a customer who is told that secure boot is present deserves to know whether it is doing anything.