Posts Tagged ‘fpga mcu source code break’
Three Protection Layers With an Order Dependency
A protection scheme that works is not a single lock. It is a small set of measures that have to be applied in a particular sequence, and the sequence matters because each layer constrains what the next one can do.
The three layers are: the debug interface, the read path to the program memory, and the confidentiality of the image itself. They are applied in that order, and each one exists to close an access that the previous one leaves open. Getting the order wrong produces a product that looks protected, passes a spot check, and fails the first time someone looks at the boot sequence.
Layer one: the debug interface
The debug interface is first because it subsumes everything. A port that can halt the core and read memory is a port through which every other protection can be examined, and in many cases rewritten.
Disabling it is done by a configuration bit, a fuse, or a permanent one-time write, depending on the part. On most modern parts the mechanism is a debug lock whose removal requires a mass erase, which provides the coupling that makes the lock meaningful.
The layer is effective only when it is applied before anything else is written. A device whose debug port is disabled at the end of production has a window between the first programming operation and the disable, and during that window the port is open and the array is full.
| Mechanism | Reversible | Applied by |
|---|---|---|
| Debug lock bit plus mass erase | Yes, destructively | Production programmer |
| One-time fuse | No | Factory or field programming |
| Physically removed pad | No | Package design |
| Debug disabled in a ROM option | Yes | Boot configuration |
Layer two: the read path
The second layer stops the program memory from being read by any interface, whether or not the debug port is disabled.
On most parts this is a bit that gates the read command, and clearing it requires a mass erase. That coupling is the same one that appears everywhere in this subject: the only way to remove the read barrier is to destroy what it protects.
The layer is effective only if it is applied after the debug port is closed, and this is the first ordering constraint. A part whose read protection is set while its debug port is open is a part whose array can be read through the port, because the port’s memory access does not necessarily consult the read-protection bit.
| If read protection is set | And the debug port is | Then the array is |
|---|---|---|
| First | Still open | Readable through the port |
| After the port is closed | Closed | Not readable |
| First, then the port is closed | Closed | Not readable, but the window existed |
| Never | Closed | Not readable electrically |
The third row is the one that describes most correct implementations, and the fourth is a surprising number of shipping products. A part whose debug port is disabled and whose read protection was never set is protected against electrical reads by exactly one measure, and that measure is a single bit with a documented disable path.
Layer three: the image itself
The third layer is the one most often skipped and the one that survives when the first two fail. It protects the image rather than the memory: encryption of the code at rest, or a signature that the boot process verifies.
Encryption at rest is rare on microcontrollers, because the core executes from flash and decryption has to happen in the fetch path. Where it exists, it means that a physical read of the array yields ciphertext rather than code, which converts a successful read into an unsuccessful one.
| Third layer | Defeats | Cost |
|---|---|---|
| None | Nothing | Zero |
| Signature over the image | Modified images | A key and a verifier |
| Bus encryption | Reading the external flash | A decrypting controller |
| On-die fetch decryption | Reading the array physically | Dedicated silicon |
The fourth row is the only measure that defeats a decapsulation, and it is why the most protected parts are the ones whose code is unreadable even when the die is in your hand.
The ordering constraints
The three layers impose constraints on each other, and the constraints are what an assessment looks for.
The debug port must be closed before the read protection is set, or the read protection is decorative while the port is open. This is the constraint most often violated, and it is violated in a specific way: the production programmer sets the read protection as part of the programming operation and disables the debug port as a separate step at the end of the line. Between those two steps the device is on a bench with an open port and a full array.
The read protection must be set before the application runs for the first time, or the application has an opportunity to read the array and transmit it. A design whose protection is applied at the end of a self-test that reads the array is a design that must trust the self-test.
The image protection, where present, must be in place before the first boot, because the boot process is what consumes it. A signature verified by the application is not a boot-time protection; it is an application-level check that a modified boot stage would bypass.
| Constraint | Violation symptom |
|---|---|
| Port closed before read protection | Array readable during production |
| Read protection before first run | Array readable by the application |
| Image protection before first boot | Boot stage trusted without verification |
What the window looks like in practice
A window produced by misordering is not hypothetical, and it has a recognisable shape.
The device is programmed, and the read protection is written. Some milliseconds later, the programmer writes the debug lock. If the device is reset between those two operations — and a reset is normal during a programming session — the boot code runs with the read protection set and the debug port open. On a part where the port’s memory access ignores the read bit, that is a complete bypass for anyone who can hold the device in reset at the right moment.
| Window | Duration | Exploitable by |
|---|---|---|
| Between programming and lock | Milliseconds to seconds | A programmer under attacker control |
| Before the first boot configuration | Until first power-up | Anyone with the device |
| During a firmware update | The update duration | Anyone who can interrupt it |
| After a partial erase | Until the erase completes | Anyone who can cut power |
The fourth row is the one that produces the most reliable bypasses in the field, and it is a consequence of the coupling described in breaking IC flash: an erase that is interrupted leaves a device whose protection state is indeterminate, and the state after the next reset is not always the state the designer intended.
How an assessment checks the order
The check is behavioural and it takes a day.
The device is observed at power-up with a debugger attached and the read protection set. If the debugger connects, the port was not closed before the protection was applied, and the window exists.
The boot sequence is then observed with the debugger connected but not halted, and the first memory access by the boot code is noted. If the boot code reads the application region before any protection check, the application is trusted by the boot stage rather than verified by it.
| Observation | Conclusion |
|---|---|
| Debugger connects with protection set | Ordering violation |
| Boot code reads without checking | Boot stage trusts the image |
| Reset during programming leaves the port open | The window is real |
| Interrupted erase leaves the device readable | The coupling has a hole |
Where this sits in the work
The ordering analysis is what turns a list of protections into a plan. A device with three layers applied in the right order is a device whose only remaining route is physical. A device with three layers applied in the wrong order is a device whose route is the window, and the window is usually cheaper than any of the alternatives.
The permission model that each layer implements is set out in programming port permissions, and the surface selection that follows from it is in MCU attack surfaces. Where the third layer exists and is implemented on the die, the physical route is defeated and the analysis in decrypting IC flash explains why a successful read produces nothing.
What we deliver for this layer is the ordering report: each layer, how it is implemented, when it is applied, and whether the sequence creates a window. Where a window exists we describe the operation that reaches through it, and where no window exists we say that the only remaining route is the one that destroys the device.