S4 · Lesson 37 · Hardware security and side channels
Cache timing channels, transient execution attacks, Rowhammer and the cost of mitigations
The features that make processors fast also leak. A cache hit takes fewer cycles than a miss, so whether another program touched a line can be measured with a timer. Speculative execution runs instructions that are later squashed, yet the lines they loaded stay in the cache, so a secret read speculatively can be recovered by timing. DRAM rows hammered with activations can flip bits in their neighbors. These are architecture problems with architecture numbers: channel bandwidths, error rates, activation counts and the performance cost of each defense.
- The curve is the capacity of a timing channel, in bits per measured symbol, against the probability of misreading a symbol: with the binary entropy .
- A channel that's right 95% of the time still carries 71% of a bit per symbol; at 50% it carries nothing.
- Defenses that add noise must push the error rate very close to one half to close a channel: halving its capacity isn't enough.
Predict
A covert channel sends one bit by touching or not touching a cache line; each bit takes 2000 cycles at 3 GHz, and the receiver misreads 5% of them. About how fast can it send information?
The raw rate is million symbols a second. With 5% errors each symbol carries bits, so error-correcting codes can push about 1.07 Mb/s through: plenty to leak a key in milliseconds.
Name it
Cache timing channels
- Flush+Reload (shared memory): the attacker flushes a line, waits, then times a reload; a fast reload means the victim touched it.
- Prime+Probe (no shared memory): the attacker fills a cache set, waits, then times its own lines; slow ones were evicted by the victim.
The receiver tells hits from misses with a threshold. With Gaussian timing noise σ around hit and miss times h and m, the error rate is about , and the channel carries bits per symbol.
Transient execution
A mispredicted branch or a faulting load lets later instructions run before being squashed (lesson 10). Spectre trains a branch predictor so the victim speculatively reads a secret out of bounds and uses it as an index into a probe array; the squashed load's cache line stays, and timing 256 probe lines reveals the byte. Meltdown read kernel memory speculatively before the permission check took effect.
Rowhammer
Repeatedly activating a DRAM row can disturb charge in adjacent rows. Within a refresh window W, a bank can activate a row up to times, over a million in 64 ms, while vulnerable cells may flip after tens of thousands. Defenses refresh victims early (target row refresh) or count activations.
The cost of defenses
Fences after bounds checks stop speculation past them; kernel page-table isolation switches address spaces on every system call; partitioned or randomized caches block eviction channels. Each costs time in proportion to how often it triggers: events per second × cost per event.
Worked example
A Spectre attack leaks one byte per round: setting up costs 10 000 cycles and probing the 256 lines of the probe array takes about 300 cycles each. How fast does it read secrets at 3 GHz?
Show the solution
- Cycles per round.
- Leak rate. about 34 KB/s, before error correction.
- Why the probe lines are a page apart. The spacing keeps the hardware prefetcher from pulling in neighbors and blurring the result.
Answer the attack reads secrets at about 34 KB/s (34,600 bytes a second) before error correction.
Worked example
DRAM rows take 45 ns to cycle, and the refresh window is 64 ms. How many activations can an attacker aim at one row between refreshes?
Show the solution
- Activations per window.
- What an attack needs. If neighboring cells flip after 20 000 activations, an attacker needs well under 2% of the window.
- The defense. That's why DRAM and memory controllers now track activation counts and refresh victim rows early.
Answer about 1.4 million activations fit between refreshes.
Worked example
Kernel page-table isolation adds about 200 ns to each system call. What does it cost a server making 500 000 system calls a second?
Show the solution
- Time per second. of each second, which is 10% of a core.
- Cutting the cost. Processors with address-space tags in the TLB (lesson 25) cut the cost by avoiding a full TLB flush on each switch.
- Removing it. Newer processors fixed the Meltdown flaw in hardware, removing the need.
Answer page-table isolation costs the server 10% of a core.
Check
A covert channel sends one symbol every 500 cycles at 3 GHz, and 0.2 of symbols are misread.
(a)
What is its raw symbol rate?
(b)
How much information does each symbol carry?
(c)
What information rate can it reach with ideal coding?
Check
A Spectre round costs 5000 cycles of setup and probes 256 lines at 200 cycles each, on a 4 GHz core.
(a)
How long does each byte take?
(b)
How fast does it leak?
Check
DRAM rows cycle in 45 ns, the refresh window is 32 ms, and a vulnerable row flips after 50000 activations of a neighbor.
(a)
How many activations fit in one refresh window?
(b)
How long does it take to reach the flipping threshold?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
Check
A mitigation costs 30 ns each time it triggers, 100000 times a second.
(a)
What fraction of a core does it take?
Check
A Spectre attack's speculative instructions are squashed when the branch resolves. Why does the secret still leak?
Check
A receiver times cache accesses: hits average h cycles and misses m, each with Gaussian noise of standard deviation s, and it splits them at the midpoint.
Step 1
Where is the threshold?
Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.
Step 2
How many standard deviations separate each mean from it?
Step 3
What is the error rate?
Check
Write channel(h, m, sigma, cycles, ghz): for a hit/miss timing channel with Gaussian noise, return (error rate at the midpoint threshold, bits per symbol , information rate in bits per second at one symbol per cycles cycles).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Explain why
Why does a cache make a side channel, even when two programs never share data?
The cache is shared hardware whose state depends on what every program has done recently, and that state shows up in timing: a line that's present returns in tens of cycles, one that was evicted takes hundreds. If a victim's memory accesses depend on a secret, say which table entry it looks up, then which cache sets it fills depends on the secret. An attacker who fills those sets with its own lines and later times reloading them can see which ones the victim evicted, without sharing any data or breaking any permission check. Only isolating or partitioning the shared state, or making the victim's accesses independent of the secret, closes such a channel.
Practice
Keep practicing
7 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.