Every time your code reaches an if statement, the CPU faces a choice: wait until the condition resolves (stalling for several clock cycles), or guess which branch will be taken and start executing it right away. Modern processors chose to guess — and almost always get it right.
This technique, speculative execution, is one of the biggest reasons that today's processors run many times faster than a naive design would. The branch predictor learns your code's patterns over thousands of iterations and predicts with over 95% accuracy. When the guess is correct, the work is already done. When it is wrong, the processor squashes everything it computed speculatively, rolls back the architectural state, and takes the correct path instead. No harm done — or so it seemed.
In January 2018, researchers from Google Project Zero and several universities disclosed Spectre and Meltdown, two families of attacks that exploit exactly what happens during that squash. The architectural state is rolled back perfectly — but the microarchitectural state, most importantly the cache, is not. The discarded speculative work leaves a footprint in the cache that an attacker can measure, one memory access at a time. Data that was never supposed to be readable can be extracted byte by byte.
The gap between what the architecture promises and what the microarchitecture actually does turned out to be one of the most consequential security flaws in hardware history.
Comments
Loading comments...