Posts Tagged ‘decode avr mcu ic flash content’

PostHeaderIcon Clock Glitch Injection Points: External Source, PLL, and Reset

Most discussions of clock glitching begin with the waveform and never mention where the waveform is applied. That order is backwards. On a real product, the question of whether a clock can be disturbed at all is settled by the schematic, and it is settled before any equipment is unpacked. A board whose clock is generated inside the package and never leaves it is not a harder target; it is not a target.

Three nodes can carry a clock disturbance, and they are not equivalent. Each has a different insertion cost, a different side effect, and — most importantly — a different way of telling you that it worked.

Node one: the external clock input

The easiest case by a wide margin is a board with an external crystal or oscillator feeding a clock input pin. The disturbance is injected in series with the clock line, either by driving the pin from a generator instead of the oscillator, or by capacitively coupling a fast edge onto the existing clock.

Driving the pin directly is cleaner but requires removing or disabling the oscillator, which is destructive to the board and therefore unacceptable when the device must be returned working. Capacitive coupling leaves the board intact and works because the clock input is a high-impedance CMOS gate with a switching threshold around half the supply; a coupled edge of a few volts is enough to force an extra transition.

The side effect is that the whole chip sees the disturbed clock, including the watchdog, the timers and any communication peripheral. A glitch that lands on the target instruction also disturbs the UART that was going to report the result, so the observation channel has to be something other than the one being glitched. This is the single most common practical mistake: the glitch works and the result is invisible because the reporting path was corrupted by the same event.

Node two: after the PLL

If the device runs from an internal PLL, the clock that the core sees is not the clock on any pin. Injecting after the PLL means getting inside the package, which in practice means the optical route rather than an electrical one.

There is, however, a variant that is often overlooked: the PLL’s reference divider and feedback divider are configured through registers, and on some parts those registers are writable at run time through the debug interface. Changing the feedback divider produces a frequency step rather than a single-cycle glitch, which is a different kind of fault — it stretches or compresses many cycles rather than one — but it can still violate the timing of a specific operation. This is a register write, not an injection, and it requires a debug session, which is exactly what a protected part will not give.

The PLL’s own behaviour is the reason this node is discussed at all. A phase-locked loop has a lock detector, and the lock detector is the only active feedback signal in the entire clock path.

The lock detector is the one honest signal

When the reference clock is disturbed badly enough, the PLL loses lock. Most devices respond in one of three ways, and the response tells the operator what happened.

PLL response Observed behaviour What it means
Holds last frequency Device keeps running at the old rate Lock not lost; glitch too small
Switches to internal RC Device slows down, keeps running Lock lost, fallback engaged
Holds core in reset Device stops until clocks stabilise Lock lost, reset engaged

The second row is the useful diagnostic. A device that suddenly runs at a different baud rate, or whose timing loops stretch, has told you that the PLL unlocked and the fallback oscillator took over. That is a positive indication that the disturbance reached the clock tree, even though the fault did not land where it was wanted. Without this signal, an operator sweeping offsets on a board with no observable output has no way to distinguish “the glitch never arrived” from “the glitch arrived and did nothing”, and those two require opposite corrections.

The third row is the failure mode that ends projects. If the PLL holds the core in reset on every attempt, the glitch amplitude has to come down, but the useful window may be below the level at which the clock tree can be disturbed at all. On such a part the clock route is closed and the voltage route is the alternative.

Node three: reset and enable pins

The third node is not a clock at all, but it behaves like one. The reset pin, and on some parts a clock-enable or standby pin, gates the core’s clock internally. A short pulse on reset does not reset the device if it is shorter than the reset filter’s time constant, but it can suppress one clock edge.

This is attractive because the reset pin is almost always brought out to a header or a test pad, even on boards that hide everything else. It is also the node with the widest side effects, because the reset supervisor, the watchdog and the brown-out detector all watch it.

The window is narrow in a different dimension: the pulse has to be short enough to escape the digital filter and long enough to suppress an edge. On parts with a 100 ns glitch filter, that leaves a working window of tens of nanoseconds, which is achievable with a fast driver but demands a short ground return. A long ground lead turns a 20 ns pulse into a 60 ns one with ringing, and the ringing is what trips the reset.

Reading the board before injecting

The topology question is answered on the bench, with a probe rather than a generator, and it takes about twenty minutes.

The first measurement is a frequency count on every pin that could be a clock. A crystallised oscillator shows a clean sinusoid of a few hundred millivolts to a volt on one pin of a four-pad package, with the other three being supply, ground and either a second crystal terminal or no connection. An active oscillator in a metal can shows a rail-to-rail square wave on its output pin. A clock distributed from the microcontroller to a peripheral shows a square wave on a trace, and its frequency is the peripheral’s, not the core’s.

The second measurement is continuity from that node to the device’s clock input. On a board with a series damping resistor, the resistor is where the injection will go, and its value — typically 22 to 100 ohms — sets how much a coupled edge will be attenuated.

The third measurement is the one that saves the most time later: probe the clock input while the device runs normally and look at the rise time. A clock that arrives with a 5 ns rise means the node is being driven by a fast gate and a coupled injection will produce a clean edge. A clock that arrives with a 40 ns rise means the node is heavily loaded, and an injection will produce a slow edge that the input may not even recognise as a transition. In that case the injection has to be stronger, which moves it towards the reset side effects described above.

A board that yields no clock on any pin has its clock inside the package. That is the end of the analysis for this technique, and it is worth saying so to the customer in the same conversation rather than after a week of attempting.

Choosing between them

The choice is made by three questions, in order.

Is there a clock pin? If yes, node one is available and is the default. If the clock is internal and no pin carries it, node three is the fallback, and node two is not a real option without decapsulation.

Does the observation channel survive the glitch? If the only way to read the result is a UART or an SPI port clocked from the same tree, the answer is no, and the observation has to move to a current measurement or a spare GPIO.

Does the device recover? A node that leaves the part in reset on every attempt is worse than useless, because it consumes samples and produces no information.

What the injection point does not change

One thing is worth stating because it is frequently assumed otherwise: the injection point does not change which instruction is vulnerable. It changes only whether the disturbance arrives and what else it disturbs. The vulnerable instruction is decided by the design’s timing margin, and finding it is a separate problem treated in clock glitch application. The relationship between offset and instruction is a search, and the search strategy is in glitch attacks as a search problem.

Nor does the injection point change the fundamental comparison with supply manipulation. A voltage dip needs no clock pin, which makes it the only option on fully integrated parts; the trade-off is that it disturbs the analog domain as well, as described in power glitches.

In recovery work, the practical value of this analysis is that it produces a go or no-go answer in about an hour. We inspect the board, identify whether a clock node is reachable, and test the PLL’s fallback behaviour with a harmless disturbance before committing to a campaign. When the answer is no-go, the work moves to the physical route in extracting IC flash, and the customer is told early rather than after a week of sweeping. That early answer is the service at this layer: topology assessment, not waveform generation.