Posts Tagged ‘reverse engineering avr mcu ic bin code’

PostHeaderIcon Glitch Attacks as a Search Problem: Sweep, Fitness, and the Two-Parameter Window

Two glitch parameters have to be right at the same time: when the disturbance arrives relative to the instruction, and how long it lasts. Miss either and nothing happens. The set of pairs that works is a thin ridge in a grid that is typically tens of thousands of points in area, and finding that ridge is an optimisation problem with a very sparse reward.

Most failed glitch projects fail here rather than in the electronics. The rig works, the waveform is correct, the board is reachable, and the operator tries a dozen settings, sees nothing, and concludes that the part is protected. A dozen samples from a space of ten thousand is not an experiment.

The shape of the space

The two axes are not symmetric. The timing offset has a natural period: the instruction cycle. Beyond one cycle the same relative position repeats, so the search only has to cover one cycle divided by the timing resolution. On a 16 MHz part that is 62.5 ns, and a 1 ns resolution gives 63 points.

The width axis is bounded below by the pulse generator’s minimum pulse and above by the point at which the disturbance is long enough to be seen as a supply or clock failure rather than a fault. That range is typically one to thirty nanoseconds for a clock glitch, and one to several hundred nanoseconds for a voltage dip.

The product is a few thousand points at coarse resolution and tens of thousands at fine resolution. Attempts take between a tenth of a second and two seconds each, depending on how long the device needs to reboot and how the result is read out. That places a full coarse sweep between ten minutes and a few hours.

Parameter Natural range Resolution that matters Points
Offset, clock glitch One instruction cycle 1 ns 40–70
Offset, voltage dip Several cycles 10 ns 50–200
Width, clock glitch 1–30 ns 1 ns 30
Width, voltage dip 10 ns–2 µs 10 ns 200

Why bisection does not work

The instinct of an engineer facing a one-dimensional sweep is to bisect: test the ends, test the middle, narrow down. That instinct is wrong here, and understanding why saves a week.

Bisection requires monotonicity: a predicate that is false on one side and true on the other, with a single crossing. The glitch response is not monotonic. Moving the offset later produces, in order: no effect, target fault, hang, reset, no effect again. There are two sign changes and a plateau, and the ordering of the middle two depends on which structure is being hit.

What the response does have is locality. A setting that produces a hang is within a few nanoseconds of a setting that produces the target fault, because both are manifestations of the same path failing at slightly different points. That locality is what makes a hill-climbing refinement work, but only after a coarse sweep has found the neighbourhood.

Grading the outcome instead of counting it

A binary success metric wastes most of the information each attempt produces. Four outcomes are distinguishable, and they carry an ordering.

Outcome Grade Inference
No effect, normal operation 0.0 Disturbance too small or offset wrong
Reset or reboot 0.1 Too deep; window is on the other side
Hang, no restart 0.4 Fault landed, wrong target
Wrong decision, no other symptom 1.0 Target reached

Grading turns the sweep into a landscape rather than a needle hunt. A region of 0.4 tells the operator that the fault mechanism is working and only the target is wrong, which means the offset should move by a few nanoseconds rather than the amplitude being changed. A region of 0.1 tells the opposite: reduce the disturbance and come back.

The grading also protects against a specific error that produces false success. Some glitches corrupt a status register that the readout path uses, so the reported result looks like the desired outcome while the device is in fact merely broken. Requiring that the device perform a second, independent operation correctly after the fault is the cheapest way to exclude that case, and it is worth building into the acceptance criterion from the start.

Hit rate and the number of samples

If the usable set is one percent of the grid, a random search needs about a hundred attempts to have a two-thirds chance of one hit. If it is a tenth of a percent, the same confidence needs a thousand. Those numbers decide whether a campaign is a morning or a fortnight.

The hit rate is not knowable in advance, but it is bounded by the geometry. The ridge width in the offset axis is set by the propagation delay spread across the target structure, typically one to three nanoseconds; the ridge width in the width axis is set by how much of the cycle needs to be lost, typically two to five nanoseconds. So the usable area is a few tens of points out of a few thousand, which is around one percent, and a coarse sweep of the entire space is the only reliable way to find it.

Repeating a successful setting ten times and requiring all ten to succeed is the validation step. A setting that works six times out of ten is on the edge of the ridge and will not survive a temperature change; a setting that works ten of ten is inside it.

When the ridge becomes a surface

A third parameter is usually present and usually ignored: the supply voltage during the attempt, or the temperature, or both. Each of them shifts the ridge rather than widening it.

The consequence is that a two-dimensional sweep performed at one voltage produces a ridge that does not exist at another voltage. This is why a setting found on a bench at 3.30 V can fail on the same board at 3.25 V, and why a rig that drifts by fifty millivolts over an afternoon appears to lose its successful setting.

There is a disciplined way to handle it. Fix the voltage at the nominal value of the target’s own regulator and map the ridge there, because that is the condition the customer’s device actually runs in. Then test the ridge at the two extremes of the regulator’s tolerance — typically plus and minus two percent — and record how far it moves. If the ridge shifts by more than half its width across that range, the setting is not stable enough to be reported as a method, and the work is not finished.

Temperature behaves differently and more kindly. Delay is monotonic in temperature over the operating range for most processes, so the ridge moves in one direction as the device warms. That monotonicity allows a bisection on temperature, which is not available on the offset axis. In practice a rig that can hold the device at a fixed temperature is worth more than one that can sweep it quickly.

Parameter Effect on the ridge Handling
Supply voltage Shifts laterally Map at nominal, verify at tolerance
Temperature Shifts monotonically Hold fixed; bisect if needed
Clock frequency Changes ridge width and position Fix at the target’s setting
Decoupling Attenuates the disturbance Measure at the die, not the generator

The sweep is not the deliverable

Once the ridge is mapped, the useful output is a description rather than a number: the centre of the ridge, its width in each axis, and its sensitivity to temperature and supply. That description is what allows the technique to be repeated next month on a different board of the same design, and it is what makes the result transferable to a second unit.

A single successful setting is a curiosity. A mapped ridge with documented sensitivity is a method, and it is the only form in which this work has lasting value.

How this connects to the physics

The search assumes that a fault is possible at all, which is a question about the chip rather than the algorithm. Whether the disturbance can reach a vulnerable path is decided by the injection topology, covered in clock glitch injection points, and whether the path in question has enough margin to fail is covered in clock glitch application. The voltage-side equivalent, where the window is bounded by a brown-out detector rather than a cycle, is in power glitches.

In recovery work this methodology is applied to one narrow goal: making a protected device accept a read command without erasing what it holds. We map the ridge on the customer’s board, report the usable region and its stability, and state plainly when the ridge does not exist — which happens on parts with an internal regulator and no accessible clock node, and on parts whose protection is enforced in hardware rather than by a branch. Where no ridge exists, the honest alternative is the physical route in extracting IC flash. The service is the measurement and the map, not a promise that every part has a window.