Skip to content
Info disclosure Write-up Advanced

No More Speculation: Exploiting CPU Side-Channels for Real

The authors show that two CPU side-channel bugs (MFBDS and MLPDS) can be used in practice to leak the private key of a server running an elliptic-curve Diffie-Hellman handshake, allowing an attacker to later impersonate that server. The attacker needs to run unprivileged code on the same physical machine and the same CPU core as the victim process.

bughunters.google.com

Published on bughunters.google.com

CPU vulnerabilities are a widespread problem, yet they are not well understood and are generally hard to mitigate. Some of these vulnerabilities affect nearly all modern processors, regardless of running software, so we decided to explore their impact on real-life systems.

The author, on bughunters.google.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 14 min read.

Context

This write-up looks at Microarchitectural Data Sampling (MDS), a class of CPU speculative execution vulnerabilities disclosed by Intel in May 2019, and asks a practical question: can they be exploited against real production software, not just in a lab? The author chose two variants, Microarchitectural Fill Buffer Data Sampling (MFBDS) and Microarchitectural Load Port Data Sampling (MLPDS), and targeted a network protocol that negotiates a shared secret during the handshake using elliptic-curve Diffie-Hellman (ECDH). The goal was to leak the server private key so the attacker could later impersonate the server.

The attacker model is narrow: the attacker can run code as an unprivileged user on the same machine as the victim process. No special privileges are assumed. The author notes that additional work may be required to cross other boundaries such as sandboxing or a VM.

To make the proof of concept reproducible without depending on internal software, the author provides a custom target that simply calls boringssl's X25519() function in a loop. The code is at https://github.com/google/security-research/tree/master/pocs/cpus/mds-x25519.

Setup

The exploit requires:

  1. The victim and the attacker running on the same machine.
  2. A vulnerable Intel CPU with TSX enabled.
  3. For the single-threaded MFBDS version, both processes running on the same core.

The author gives an example command for a 56-core system when describing how to force co-location.

Finding it

MDS is widespread (it works on all mainstream Intel CPUs released between 2008 and 2018), hard to mitigate and not well understood. The root cause is that microarchitectural structures are shared between both hyperthreads of the same core. MFBDS abuses Line Fill Buffers (LFBs), which sit between L1 and L2 and merge multiple loads and stores from the same cache line. While the CPU is stalled waiting for memory, or on a mispredicted branch, it continues executing speculatively, and it will use data from the LFB as if it were correct even though it may be stale. For a short window it operates on memory that may belong to another process.

A simplified model of the leak looks like this:

C
char leak = *addr;
volatile char *ptr = probe + 512 * leak;
*ptr;
for (int i = 0; i < 256; i++) {
  int start = rdtsc();
  *(probe + 512 * i);
  int delta = rdtsc() - start;
  if (delta < 150)
    ++results[i];
}

Assuming addr and probe are flushed beforehand, the CPU speculates using the LFB value as leak and accesses the dependent location *ptr. The loop then times every candidate byte value and records which location is fast to access. Two locations end up cached: the leaked one and the one eventually delivered as the correct *addr.

The code works even when the access is invalid, for example a null pointer, provided the crash is suppressed. The report names three mechanisms: SIGSEGV signal handlers, Transactional Synchronization Extensions (TSX), and running the whole code speculatively in a mispredicted branch. TSX works very well here: xbegin and xend wrap a transaction region, and code inside cannot crash, it simply aborts and jumps to the handler. The limitation is that only a few fast arithmetic operations can run after the leak.

The hard problem is that the attacker leaks whatever happens to be in the LFB, and the CPU touches enormous amounts of memory during normal operation. The attacker can at least choose which of the 64 LFB bytes to access by changing the last 6 bits of the address. The real solution is filtering: if the prefix of the secret or surrounding bytes is known, the exploit can check during speculation whether the leak matches and only then touch the probe array:

ASM
mov rax, [addr]
xor rax, prefix
and rax, mask
shl rax, 9
prefetchnta [rax+probe]

Incorrect leaks produce an out-of-bounds probe access and are not cached, so they are filtered out.

For deeper background, the author points to the original RIDL paper and the authors' presentation.

Or watch on YouTube
From the original on bughunters.google.com

MLPDS

MLPDS is described briefly in the addendum to the RIDL paper. It is similar to MFBDS, but the shared structure is a load port rather than an LFB. The leak happens during cache line split loads, accesses that touch two 64-byte lines because of an unaligned address. The exploit is built around one instruction:

ASM
mov rax, [-1]

Run inside a TSX transaction, the fault is swallowed, and for a short speculative window rax may contain 8 bytes that happen to be in the load port, potentially placed there by another process. The key difference from MFBDS is that there is no 64-byte offset control: the attacker gets 8 bytes at once, and the victim, not the attacker, determines which bytes they are.

Exploitation

Step 1: choosing the victim code

The author selected the private key and the cryptographic code that manipulates it, based on two criteria:

  1. Frequency of access: the victim must repeatedly read or write the secret, or data in the same cache line.
  2. A fixed format or known neighbouring data, which helps filtering (helpful but not strictly necessary).

Step 2: increasing the frequency of access

The handshake protocol caches generated shared secrets in a hash map, so a returning client reuses the secret without re-running Diffie-Hellman. A normal client makes the victim access the private key only once. A malicious client can pretend to connect for the first time, forcing the full handshake path where the private key is copied into a stack buffer. A simple client making repeated requests achieves a couple of thousand calls per second on a single-threaded server. A custom client that breaks the connection after the initial message speeds this up slightly.

Following the boringssl call chain, the function that ultimately performs the operation is x25519_scalar_mult_generic, where the private key is kept in the scalar variable. The code makes 255 iterations of a loop and accesses the secret (copied to a buffer named e) each time, giving several hundred thousand accesses per second.

Step 3: finding a known prefix

The secret itself is 32 random bytes, but several bits are discarded at the start of the function:

C
e[0] &= 248;
e[31] &= 127;
e[31] |= 64;

The author dumped the server memory while in the target function and labelled the variable offsets. The variables immediately before and after the key change at each iteration, so they cannot be filtered on directly. Closer inspection showed they have a maximum value of 0x1a666666666664, so in practice the three most significant nibbles are always zero, giving another 12 bits to filter on.

Combining these, the first byte of the secret has its three lowest bits zeroed, and the preceding word has its top three nibbles zeroed. But these characteristics are common for pointers: a stack pointer 0x00007ff69cfc71c0, a code pointer 0x00005653bb45775c, and a heap pointer 0x000044fa7f5eaaa0 all match. Memory containing two adjacent pointers, or memory memset to zero, also matches, producing too many false positives. The fix was to additionally guess that the next bit of the x3l limb is 1 (i.e. 0x0008...). This is true only half the time, halving the leak speed, but userspace pointers generally do not have that bit set, and the reduction in false positives outweighed the cost.

Step 4: improving the leak primitive

The author made two changes to the VUSec proof of concept.

First, instead of isolating the unknown byte and using it as an index into the probe array (which requires priming and probing 256 cache lines even when nothing is leaked), the exploit brute forces the unknown byte and filters on that guess, prefetching a single cache line on a hit. The byte with the most hits wins. The author conjectured this works better because less memory is touched (one cache line, 64 bytes, versus 256 cache lines, 16kB, half the L1 cache) and the TSX code is shorter. The time to leak one byte is O(8/n * 2^n) for n bits at a time; 1 and 2 bits are both optimal, and the exploit uses 2.

Second, the attacker can evict the secret from cache. An eviction set of several cache lines (24 in this exploit) in the same cache set as the secret is accessed just before the attack, evicting anything the victim cached. This also lets the attacker select the leak location up to the page offset: the LFB offset equals the cache line offset, and eviction selects the cache set, for 6+6=12 bits of control.

Step 5: stage 1 and 2, leaking a stack pointer

To build an eviction set, the exploit needs the secret's address, at least modulo 4096. The attacked function calls subroutines, and in the prologue of fe_mul_imp some registers are pushed to the stack, in particular rbp (the stack pointer) and r15 (the constant 0x001a666666666665). The constant serves as the filter to leak the stack pointer.

Eviction was not used at this stage for two reasons: the targeted memory is often overwritten by the victim calling other functions, so it evicts itself, and there is a much more reliable prefix to filter on. The server was multithreaded, so there were several potential stack pointers, but all relevant threads had the same call stack, so the variables had the same offset within the page. Only the least significant bits of the stack pointer were needed.

Because the Linux ABI aligns the stack to 16 bytes, only four offsets (0, 16, 32, 48) had to be brute forced to find the constant. Stage 1 did that; stage 2 leaked the least significant three nibbles of the stack pointer at the known offset:

Text
        [----- constant ------]  [--- stack pointer ---]
memory: 65 66 66 66 66 66 1a 00  90 31 f8 f5 ff 7f 00 00
stage1 mask : ff ff ff ff ff ff  0f 00 (brute force offset only: 0, 16, 32, 48)
stage2 mask1: ff ff ff ff ff ff  3f 00 (brute force two bits)
stage2 mask2: ff ff ff ff ff ff  ff 00 (brute force two bits)
stage2 mask3: ff ff ff ff ff ff  ff 03 (brute force two bits)
stage2 mask4: ff ff ff ff ff ff  ff 0f (brute force two bits)

Step 6: stage 3, guessing the first secret byte

With the secret location known, stage 3 guessed the first byte of the secret (three bits known to be zero) and found candidates. There are usually three or four plausible false positives. To choose, the exploit repeats the leak while evicting a different location, real_offset+0x140: same within-cache-line offset, different cache set. The secret is not properly evicted, so the hit count drops, while false positives stay constant. The byte with the biggest ratio between the two leak speeds is chosen.

Step 7: stage 4, leaking the rest of the key

Stage 4 leaks the secret 2 bits at a time, filtering on what is already known, moving the leak offset once the first 6 bytes are known:

Text
        [-- crypto variable --]  [-- 32 byte secret key  ... ]
memory: 9f c7 b4 72 52 16 0c 00  98 76 54 32 10 ab cd ef ...
stage3 mask :             f8 ff  ff 00 00 00 00 00 (guess first secret byte)
stage4 mask1:             f8 ff  ff 03 00 00 00 00 (leak two bits)
stage4 mask2:             f8 ff  ff 0f 00 00 00 00 (leak two bits)
stage4 mask3:             f8 ff  ff 3f 00 00 00 00 (leak two bits)
...
stage4 mask21:               ff  ff ff ff ff ff ff 03 (leak two bits)
stage4 mask22:               ff  ff ff ff ff ff ff 0f (leak two bits)
…

Because the number of iterations needed is hard to compute statically, the loop breaks when one guess has at least 3x more hits than the others and at least 20. This heuristic broke at secret offset 16, where results were noisier, so a separate trigger after a fixed number of iterations was added. At the end, the exploit verifies the key by checking that the public key generated from it matches the server's public key.

Step 8: scheduling

To get the victim and attacker on the same core on a many-core server, the author runs hundreds of busy loops pinned to all cores but one, forcing the victim onto the free core:

Bash
for i in {1..400}; do taskset -a -c 0,2-56,58-111 /tmp/busy& done

The exploit is then pinned to a hyperthread on the same core.

Step 9: the MLPDS alternative

The MFBDS exploit required reverse-engineering the victim stack layout for each server and was less reliable on busy machines than expected. MLPDS has no offset control, which is both a curse and a blessing: the exploit must work without it, but it works across server recompilations and versions. The same x25519_scalar_mult_generic function is attacked. Each of the 255 iterations depends only on the n-bit prefix of the private key, so the internal state after the first iteration is the same for keys 0x8000... and 0x8f73.... This allows leaking bit by bit.

The primitive was extended:

ASM
mov rax, [-1]
xor rax, rbx
prefetchnta [rax]

rbx is set to a known value Q. The code prefetches leak ^ Q, generally an unmapped address that would fault outside TSX. Choosing Q equal to P ^ probe, where probe is mapped and otherwise unused, means that if the leak is P, the prefetched address is leak ^ Q == P ^ P ^ probe == probe, detectable by timing access to probe. The primitive must be repeated thousands of times to catch P while it is in the load port. This builds an oracle answering: does the victim ever load P to a register? A positive answer can take several seconds, a negative answer is only detectable by timing out, and false positives happen, so statistics are used to filter noise.

Step 10: the MLPDS exploit loop

The author ran the first iteration of X25519 twice, assuming the first bit is 0 or 1, and dumped the internal variable z3 at the end of the loop (chosen empirically). The oracle was run with P=z3_assuming_0 and P=z3_assuming_1. Leaking one of them is evidence for that bit. Then the first two iterations were run assuming the first two bits are 10 or 11, z3 dumped, and the exploit repeated until all secret bits were leaked.

Leaking bits visualization
Leaking bits visualization From the original on bughunters.google.com

Step 11: parallelisation

The MLPDS exploit is slow because it leaks from a single X25519 iteration at a time, while MFBDS could use all. Multiple exploit processes can be spawned, each pinned to a separate core, reporting to a master. Pinning is essential: if two workers run on the same core they leak from each other, and since both load the tested value, many false positives result. The parallelised exploit is reliable and takes about 15 minutes to leak the whole key on a typical machine under normal server load. It works across recompilations, is shorter than the MFBDS version (not counting boringssl), and does not need the victim and attacker on the same cores because it runs on all cores anyway.

Root cause

The root cause is that microarchitectural structures (LFBs and load ports) are shared between both hyperthreads of a core, and speculative execution uses their contents as if correct even when the data is stale. The existing defences did not stop it: microcode updates only add an instruction to flush internal buffers, which the kernel uses on syscalls or context switches, and that is not enough with hyperthreading because the attacker can grab the buffer contents before the flush. Intel's original response was to disable SMT, which is expensive; the alternative is group scheduling (core scheduling, core tagging, gang scheduling), where two processes share a core only if they have a compatible trust domain, such as processes of the same user.

Impact

The write-up demonstrates that MDS can be exploited against a live system to leak data that permits privilege elevation and further control over the system. The attacker can leak the server private key and later impersonate the server. The general technique extends to stack cookies or code pointers to defeat ASLR, other cryptographic keys (potentially allowing forging other tokens), (CS)PRNG state, or any other private data. The conditions are the attacker model above: unprivileged code on the same machine, a vulnerable Intel CPU with TSX, and, for the single-threaded MFBDS version, co-location on the same core. Additional work may be needed to cross sandboxing or VM boundaries.

Fix

These issues have been addressed in the design of recent processor generations; Intel guidance lists processors affected by MDS, generally those introduced before 2019. Current generations remain vulnerable to other attacks such as Spectre variants. For older generations, Intel provided microcode updates, but as noted these are insufficient with hyperthreading. Intel now suggests group scheduling. In Google Cloud, core tagging has been implemented in a stronger form, where vCPUs reported to the VM as occupying different virtual cores never share the same physical core, allowing guests to implement core tagging as well.

Variants to test

  1. Other ECDH or key-exchange implementations. Look for loops that touch the private key many times per operation, as x25519_scalar_mult_generic does with 255 iterations. A positive result is a measurable, repeatable hit count above the noise floor when filtering on a known prefix.
  2. Protocols with handshake caching. Test whether a client can force the full handshake path by pretending to connect for the first time, increasing secret access frequency. A positive result is a higher call rate than a normal client achieves.
  3. Secrets with known structure. Look for keys with masked bits, fixed-format fields, or adjacent constants with a bounded maximum value, as with 0x1a666666666664. A positive result is a filter that reduces false positives enough to distinguish the secret from pointers and zeroed memory.
  4. Stack layout leakage via function prologues. Check whether a called function pushes a register holding a known constant next to the stack pointer. A positive result is a reliable leak of the constant at one of the 16-byte-aligned offsets.
  5. Eviction-based offset selection. Build an eviction set for the target cache set and compare hit rates with a deliberately wrong eviction offset. A positive result is a large ratio between the two rates for the true byte and a constant rate for false positives.
  6. MLPDS prefix oracle. For code whose internal state depends only on a prefix of the secret, run the oracle with candidate values of an internal variable. A positive result is a leak of the candidate within a few seconds, repeated across trials.
  7. Parallel workers. Spawn one exploit process per core, each pinned, reporting to a master. A positive result is a speed-up roughly proportional to the number of cores, with no cross-worker false positives.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 22 min read.

What happened, in plain words

Every modern computer has a processor (CPU) that does many things at once to run fast. To do that, it sometimes guesses what is coming next and starts working on the guess before it knows whether the guess is right. This is called speculative execution. When the guess turns out to be wrong, the computer throws away the results, so from the outside nothing seems to have happened. But the processor keeps small traces of the work it did in tiny internal storage areas, and those traces can survive for a very short time.

A class of bugs called Microarchitectural Data Sampling (MDS) abuses exactly this. If two programs run on the same physical processor core at the same time, one program can, in the right circumstances, read leftover data that the other program was handling. Intel disclosed these bugs in May 2019. They affect a very wide range of Intel processors, roughly everything released between 2008 and 2018.

This write-up asks a practical question: can these bugs be used against real software running in production, not just in a laboratory demonstration? The author picked two variants, Microarchitectural Fill Buffer Data Sampling (MFBDS) and Microarchitectural Load Port Data Sampling (MLPDS), and aimed them at a network protocol that sets up a shared secret during its handshake using elliptic-curve Diffie-Hellman (ECDH). The prize was the server's private key, which would let an attacker later pretend to be that server.

The attacker in this story is not a wizard with special access. The assumption is simply that the attacker can run ordinary code as a normal user on the same machine as the victim program. No administrator rights are needed. The author notes that getting past other barriers, such as a sandbox or a virtual machine, might need extra work.

To make the demonstration reproducible without depending on any internal software, the author provides a small custom target program that just calls boringssl's X25519() function in a loop. The code is at https://github.com/google/security-research/tree/master/pocs/cpus/mds-x25519.

Background: the pieces you need to know

What a cache is, and why it matters

A processor is much faster than the main memory (RAM) it reads from. To hide that gap, processors keep small, very fast memory areas called caches close to each core. On most Intel processors there are three levels. L1 and L2 belong to a single core; L3 is shared. A cache stores data in fixed-size chunks called cache lines, usually 64 bytes each.

You can picture a cache as a set of pigeonholes. Each memory address maps to one pigeonhole (called a set), and each set has a few slots (called ways) where a line can sit. On Intel, some bits of the address directly decide which set is used. For example, the memory location 0xffa1c963 and its cache line 0xffa1c940 land in cache set 0x940/0x40 = 37, sharing that set's eight ways with something like 0x5573f940, because the low bits match. The total cache size is the line size times the number of sets times the number of ways: 64Bx64x8 = 32kB.

Why does this matter for the attack? Because an attacker who can watch how fast certain memory is accessed can learn which cache lines are loaded, and that is a way to observe what another program is doing.

What MDS is

MDS is the umbrella name for a set of CPU speculative execution vulnerabilities disclosed by Intel in May 2019. Researchers at VUSec studied them in depth and named their work RIDL. Depending on the variant, the bug targets one of several internal processor buffers. The general effect is that information can leak across hyperthreads (two logical processors sharing one physical core) or across context switches, meaning one program's memory, or even kernel memory, can be disclosed to another.

The root cause is that these internal structures are shared between the two hyperthreads of the same core. The MFBDS variant used here abuses Line Fill Buffers (LFBs). These sit between the L1 and L2 caches and are used to merge several loads and stores that touch the same cache line, plus other small optimisations.

Processors also use speculative execution heavily. While stalled, for example waiting for memory to arrive, or after a mispredicted branch, they keep executing code as if the data were already there. Any changes made on that invalid path are undone when the mistake is noticed, but some microarchitectural effects remain observable. If the speculative code touched a memory location, the attacker can later measure how long accessing that location takes and discover that it is cached even though the program never really accessed it.

While waiting for a memory access to resolve, the processor can execute further code using data from the LFB. In other words, it assumes the LFB data is correct even when it may be stale. For a short window it operates on memory that may belong to another process. With carefully constructed code, that memory can be leaked:

C
char leak = *addr;
volatile char *ptr = probe + 512 * leak;
*ptr;
for (int i = 0; i < 256; i++) {
  int start = rdtsc();
  *(probe + 512 * i);
  int delta = rdtsc() - start;
  if (delta < 150)
    ++results[i];
}

Line by line, in plain words:

  1. char leak = *addr; reads one byte from an address. The processor may not have the real value yet, so it speculates using whatever is in the LFB.
  2. volatile char *ptr = probe + 512 * leak; computes an address inside a large array called probe, offset by the leaked byte value. volatile tells the compiler not to optimise this access away.
  3. *ptr; touches that computed address. If the speculation was right, this leaves a trace in the cache.
  4. The for loop walks through all 256 possible byte values.
  5. int start = rdtsc(); records the processor's timestamp counter, a very precise clock.
  6. *(probe + 512 * i); touches the candidate location.
  7. int delta = rdtsc() - start; measures how long that touch took.
  8. if (delta < 150) ++results[i]; counts a hit when the access was fast, which means the location was already cached.

Assuming addr and probe were flushed from the cache beforehand, the processor speculates using the LFB value as leak and accesses the dependent location *ptr. The loop then times every candidate byte and records which location is fast. Two locations end up cached: the leaked one and the one eventually delivered as the correct *addr.

The code works even when the access is invalid, for example a null pointer, as long as the crash is suppressed. The author lists three ways to do that: SIGSEGV signal handlers (a program's way of catching a crash signal), Transactional Synchronization Extensions (TSX), and running the whole code speculatively inside a mispredicted branch. TSX works very well here. It provides xbegin and xend instructions that normally mark an atomic transaction region. For this attack, the important property is that code wrapped by them cannot crash: it simply aborts the transaction and jumps to the handler. The limitation is that only a few fast arithmetic operations can run after the leak.

The hard problem is that the attacker leaks whatever happens to be in the LFB, and the processor touches enormous amounts of memory during normal operation. The attacker can at least choose which of the 64 LFB bytes to access by changing the last 6 bits of the address. The real solution is filtering: if the prefix of the secret, or bytes around it, is known, the exploit can check during speculation whether the leak matches and only then touch the probe array:

ASM
mov rax, [addr]
xor rax, prefix
and rax, mask
shl rax, 9
prefetchnta [rax+probe]

Line by line:

  1. mov rax, [addr] loads the speculated value into a register.
  2. xor rax, prefix compares it with the known prefix. If they match, the result is zero in the relevant bits.
  3. and rax, mask keeps only the bits the attacker does not already know, discarding the rest.
  4. shl rax, 9 shifts the result left by nine bits, which multiplies it by 512, spacing candidate locations apart.
  5. prefetchnta [rax+probe] asks the processor to prefetch the resulting address. A correct guess lands inside the probe array and gets cached; a wrong guess lands outside it and is not cached.

Incorrect leaks therefore produce an out-of-bounds probe access and are filtered out.

For deeper background, the author points to the original RIDL paper and the authors' presentation.

Or watch on YouTube
From the original on bughunters.google.com

MLPDS

MLPDS, Microarchitectural Load Port Data Sampling, is described briefly in the addendum to the RIDL paper. It is similar to MFBDS, but the shared structure is a load port rather than an LFB. The leak happens during cache line split loads, accesses that touch two 64-byte lines because the address is unaligned. The exploit is built around a single instruction:

ASM
mov rax, [-1]

This instruction would normally cause a segmentation fault, but run inside a TSX transaction the fault is swallowed. For a short speculative window, rax may contain 8 bytes that happen to be in the load port, potentially placed there by another process. The key difference from MFBDS is that there is no 64-byte offset control: the attacker gets 8 bytes at once, and the victim, not the attacker, determines which bytes they are.

The attack, step by step

Step 1: choosing the victim code

The author selected the private key and the cryptographic code that manipulates it, based on two criteria:

  1. Frequency of access: the victim must repeatedly read or write the secret, or data in the same cache line.
  2. A fixed format or known neighbouring data, which helps filtering. This is helpful but not strictly necessary.

Step 2: increasing the frequency of access

The handshake protocol caches generated shared secrets in a hash map, so a returning client reuses the secret without re-running Diffie-Hellman. A normal client makes the victim access the private key only once. A malicious client can pretend to connect for the first time, forcing the full handshake path where the private key is copied into a stack buffer. A simple client making repeated requests achieves a couple of thousand calls per second on a single-threaded server. A custom client that breaks the connection after the initial message speeds this up slightly.

Following the boringssl call chain, the function that ultimately performs the operation is x25519_scalar_mult_generic, where the private key is kept in the scalar variable. The code makes 255 iterations of a loop and accesses the secret, copied to a buffer named e, each time. That gives several hundred thousand accesses per second.

Step 3: finding a known prefix

The secret itself is 32 random bytes, but several bits are discarded at the start of the function:

C
e[0] &= 248;
e[31] &= 127;
e[31] |= 64;

Line by line:

  1. e[0] &= 248; clears the three lowest bits of the first byte, because 248 in binary is 11111000.
  2. e[31] &= 127; clears the highest bit of the last byte.
  3. e[31] |= 64; sets the second-highest bit of the last byte.

These operations give the attacker a few known bits to filter on.

The author dumped the server memory while in the target function and labelled the variable offsets. The variables immediately before and after the key change at each iteration, so they cannot be filtered on directly. Closer inspection showed they have a maximum value of 0x1a666666666664, so in practice the three most significant nibbles are always zero, giving another 12 bits to filter on.

Combining these, the first byte of the secret has its three lowest bits zeroed, and the preceding word has its top three nibbles zeroed. But these characteristics are common for pointers: a stack pointer 0x00007ff69cfc71c0, a code pointer 0x00005653bb45775c, and a heap pointer 0x000044fa7f5eaaa0 all match. Memory containing two adjacent pointers, or memory memset to zero, also matches, producing too many false positives. The fix was to additionally guess that the next bit of the x3l limb is 1, that is 0x0008.... This is true only half the time, halving the leak speed, but userspace pointers generally do not have that bit set, and the reduction in false positives outweighed the cost.

Step 4: improving the leak primitive

The author made two changes to the VUSec proof of concept.

First, instead of isolating the unknown byte and using it as an index into the probe array, which requires priming and probing 256 cache lines even when nothing is leaked, the exploit brute forces the unknown byte and filters on that guess, prefetching a single cache line on a hit. The byte with the most hits wins. The author conjectured this works better because less memory is touched (one cache line, 64 bytes, versus 256 cache lines, 16kB, half the L1 cache) and the TSX code is shorter. The time to leak one byte is O(8/n * 2^n) for n bits at a time. Both 1 and 2 bits are optimal, and the exploit uses 2.

Second, the attacker can evict the secret from cache. An eviction set of several cache lines, 24 in this exploit, in the same cache set as the secret is accessed just before the attack, evicting anything the victim cached. This also lets the attacker select the leak location up to the page offset: the LFB offset equals the cache line offset, and eviction selects the cache set, for 6+6=12 bits of control.

Step 5: stages 1 and 2, leaking a stack pointer

To build an eviction set, the exploit needs the secret's address, at least modulo 4096. The attacked function calls subroutines, and in the prologue of fe_mul_imp some registers are pushed to the stack, in particular rbp (the stack pointer) and r15 (the constant 0x001a666666666665). The constant serves as the filter to leak the stack pointer.

Eviction was not used at this stage for two reasons: the targeted memory is often overwritten by the victim calling other functions, so it evicts itself, and there is a much more reliable prefix to filter on. The server was multithreaded, so there were several potential stack pointers, but all relevant threads had the same call stack, so the variables had the same offset within the page. Only the least significant bits of the stack pointer were needed.

Because the Linux ABI aligns the stack to 16 bytes, only four offsets, 0, 16, 32 and 48, had to be brute forced to find the constant. Stage 1 did that. Stage 2 leaked the least significant three nibbles of the stack pointer at the known offset:

Text
        [----- constant ------]  [--- stack pointer ---]
memory: 65 66 66 66 66 66 1a 00  90 31 f8 f5 ff 7f 00 00
stage1 mask : ff ff ff ff ff ff  0f 00 (brute force offset only: 0, 16, 32, 48)
stage2 mask1: ff ff ff ff ff ff  3f 00 (brute force two bits)
stage2 mask2: ff ff ff ff ff ff  ff 00 (brute force two bits)
stage2 mask3: ff ff ff ff ff ff  ff 03 (brute force two bits)
stage2 mask4: ff ff ff ff ff ff  ff 0f (brute force two bits)

Reading this diagram: the top line shows two adjacent pieces of memory, the known constant and the stack pointer. The memory line shows their bytes. Each mask line shows which bytes the filter checks (ff) and which it ignores (00). Stage 1 checks only the constant and tries the four possible alignments. Stage 2 keeps the constant fixed and progressively reveals the stack pointer two bits at a time.

Step 6: stage 3, guessing the first secret byte

With the secret location known, stage 3 guessed the first byte of the secret, three bits of which are known to be zero, and found candidates. There are usually three or four plausible false positives. To choose, the exploit repeats the leak while evicting a different location, real_offset+0x140: same within-cache-line offset, different cache set. The secret is not properly evicted, so the hit count drops, while false positives stay constant. The byte with the biggest ratio between the two leak speeds is chosen.

Step 7: stage 4, leaking the rest of the key

Stage 4 leaks the secret 2 bits at a time, filtering on what is already known, and moves the leak offset once the first 6 bytes are known:

Text
        [-- crypto variable --]  [-- 32 byte secret key  ... ]
memory: 9f c7 b4 72 52 16 0c 00  98 76 54 32 10 ab cd ef ...
stage3 mask :             f8 ff  ff 00 00 00 00 00 (guess first secret byte)
stage4 mask1:             f8 ff  ff 03 00 00 00 00 (leak two bits)
stage4 mask2:             f8 ff  ff 0f 00 00 00 00 (leak two bits)
stage4 mask3:             f8 ff  ff 3f 00 00 00 00 (leak two bits)
...
stage4 mask21:               ff  ff ff ff ff ff ff 03 (leak two bits)
stage4 mask22:               ff  ff ff ff ff ff ff 0f (leak two bits)
…

Again, the masks show which bytes are checked and which are ignored. Stage 3 checks the known bits of the first secret byte and guesses the rest. Each stage 4 mask keeps everything already learned and adds two more bits, until the whole key is known.

Because the number of iterations needed is hard to compute in advance, the loop breaks when one guess has at least 3x more hits than the others and at least 20. This heuristic broke at secret offset 16, where results were noisier, so a separate trigger after a fixed number of iterations was added. At the end, the exploit verifies the key by checking that the public key generated from it matches the server's public key.

Step 8: scheduling

To get the victim and attacker on the same core on a many-core server, the author runs hundreds of busy loops pinned to all cores but one, forcing the victim onto the free core:

Bash
for i in {1..400}; do taskset -a -c 0,2-56,58-111 /tmp/busy& done

Line by line:

  1. for i in {1..400}; do ... done repeats the command 400 times.
  2. taskset -a -c 0,2-56,58-111 pins the process to a chosen list of processor cores, here every core except core 1.
  3. /tmp/busy& starts a small program that does nothing but keep the core busy, in the background.

The exploit is then pinned to one of the hyperthreads on the same core.

Step 9: the MLPDS alternative

The MFBDS exploit required reverse-engineering the victim stack layout for each server and was less reliable on busy machines than expected. MLPDS has no offset control, which is both a curse and a blessing: the exploit must work without it, but it works across server recompilations and versions. The same x25519_scalar_mult_generic function is attacked. Each of the 255 iterations depends only on the n-bit prefix of the private key, so the internal state after the first iteration is the same for keys 0x8000... and 0x8f73.... This allows leaking bit by bit.

The primitive was extended:

ASM
mov rax, [-1]
xor rax, rbx
prefetchnta [rax]

Line by line:

  1. mov rax, [-1] triggers the load port leak, as before.
  2. xor rax, rbx combines the leaked value with a known value held in rbx.
  3. prefetchnta [rax] prefetches the resulting address.

rbx is set to a known value Q. The code prefetches leak ^ Q, generally an unmapped address that would fault outside TSX. Choosing Q equal to P ^ probe, where probe is mapped and otherwise unused, means that if the leak is P, the prefetched address is leak ^ Q == P ^ P ^ probe == probe, which is detectable by timing access to probe. The primitive must be repeated thousands of times to catch P while it is in the load port. This builds an oracle answering the question: does the victim ever load P to a register? A positive answer can take several seconds, a negative answer is only detectable by timing out, and false positives happen, so statistics are used to filter noise.

Step 10: the MLPDS exploit loop

The author ran the first iteration of X25519 twice, assuming the first bit is 0 or 1, and dumped the internal variable z3 at the end of the loop, chosen empirically. The oracle was run with P=z3_assuming_0 and P=z3_assuming_1. Leaking one of them is evidence for that bit. Then the first two iterations were run assuming the first two bits are 10 or 11, z3 dumped, and the exploit repeated until all secret bits were leaked.

Leaking bits visualization
Leaking bits visualization From the original on bughunters.google.com

Step 11: parallelisation

The MLPDS exploit is slow because it leaks from a single X25519 iteration at a time, while MFBDS could use all. Multiple exploit processes can be spawned, each pinned to a separate core, reporting to a master. Pinning is essential: if two workers run on the same core they leak from each other, and since both load the tested value, many false positives result. The parallelised exploit is reliable and takes about 15 minutes to leak the whole key on a typical machine under normal server load. It works across recompilations, is shorter than the MFBDS version, not counting boringssl, and does not need the victim and attacker on the same cores because it runs on all cores anyway.

Root cause

The root cause is that microarchitectural structures, LFBs and load ports, are shared between both hyperthreads of a core, and speculative execution uses their contents as if correct even when the data is stale. The existing defences did not stop it. Microcode updates only add an instruction to flush internal buffers, which the kernel uses on syscalls or context switches, and that is not enough with hyperthreading because the attacker can grab the buffer contents before the flush. Intel's original response was to disable SMT, which is expensive. The alternative is group scheduling, also called core scheduling, core tagging or gang scheduling, where two processes share a core only if they have a compatible trust domain, such as processes of the same user.

Impact

The write-up demonstrates that MDS can be exploited against a live system to leak data that permits privilege elevation and further control over the system. The attacker can leak the server private key and later impersonate the server. The general technique extends to stack cookies or code pointers to defeat ASLR, other cryptographic keys, potentially allowing forging other tokens, (CS)PRNG state, or any other private data. The conditions are the attacker model above: unprivileged code on the same machine, a vulnerable Intel CPU with TSX, and, for the single-threaded MFBDS version, co-location on the same core. Additional work may be needed to cross sandboxing or VM boundaries.

Fix

These issues have been addressed in the design of recent processor generations. Intel guidance lists processors affected by MDS, generally those introduced before 2019. Current generations remain vulnerable to other attacks such as Spectre variants. For older generations, Intel provided microcode updates, but as noted these are insufficient with hyperthreading. Intel now suggests group scheduling. In Google Cloud, core tagging has been implemented in a stronger form, where vCPUs reported to the VM as occupying different virtual cores never share the same physical core, allowing guests to implement core tagging as well.

Variants to test

  1. Other ECDH or key-exchange implementations. Look for loops that touch the private key many times per operation, as x25519_scalar_mult_generic does with 255 iterations. A positive result is a measurable, repeatable hit count above the noise floor when filtering on a known prefix.
  2. Protocols with handshake caching. Test whether a client can force the full handshake path by pretending to connect for the first time, increasing secret access frequency. A positive result is a higher call rate than a normal client achieves.
  3. Secrets with known structure. Look for keys with masked bits, fixed-format fields, or adjacent constants with a bounded maximum value, as with 0x1a666666666664. A positive result is a filter that reduces false positives enough to distinguish the secret from pointers and zeroed memory.
  4. Stack layout leakage via function prologues. Check whether a called function pushes a register holding a known constant next to the stack pointer. A positive result is a reliable leak of the constant at one of the 16-byte-aligned offsets.
  5. Eviction-based offset selection. Build an eviction set for the target cache set and compare hit rates with a deliberately wrong eviction offset. A positive result is a large ratio between the two rates for the true byte and a constant rate for false positives.
  6. MLPDS prefix oracle. For code whose internal state depends only on a prefix of the secret, run the oracle with candidate values of an internal variable. A positive result is a leak of the candidate within a few seconds, repeated across trials.
  7. Parallel workers. Spawn one exploit process per core, each pinned, reporting to a master. A positive result is a speed-up roughly proportional to the number of cores, with no cross-worker false positives.

Glossary

  • ASLR: Address Space Layout Randomisation, a defence that places programs and data at unpredictable memory addresses so an attacker cannot easily jump to a known location.
  • boringssl: A cryptographic library, a fork of OpenSSL maintained by Google, that implements protocols and algorithms such as X25519.
  • Cache: Small, very fast memory inside or near the processor that holds recently used data to avoid waiting for main memory.
  • Cache line: The fixed-size block, usually 64 bytes, in which a cache stores data.
  • Cache set: The pigeonhole in a cache that a given memory address maps to; each set has several slots called ways.
  • Core: A single processing unit inside a CPU. A modern CPU has many cores.
  • Core tagging: A scheduling technique that only lets processes share a physical core if they belong to a compatible trust domain.
  • CPU: Central Processing Unit, the main processor of a computer.
  • ECDH: Elliptic-curve Diffie-Hellman, a method by which two parties agree on a shared secret over a network without sending the secret itself.
  • Eviction set: A group of memory addresses chosen so that accessing them pushes a target cache line out of the cache.
  • False positive: A result that looks like a hit but is not the real secret.
  • Handshake: The opening exchange in a network protocol where the two sides agree on keys and parameters before sending data.
  • Hash map: A data structure that stores values under keys so they can be looked up quickly.
  • Heap pointer: A memory address pointing into the area where a program allocates dynamic memory.
  • Hyperthreading (SMT): A feature that lets one physical core appear as two logical processors, running two threads at once.
  • Kernel: The core part of an operating system that manages hardware and enforces isolation between programs.
  • L1, L2, L3: The three levels of processor cache, from smallest and fastest to largest and slowest.
  • LFB (Line Fill Buffer): A small internal buffer between L1 and L2 that holds cache lines being fetched or written.
  • Load port: An internal processor structure that handles memory read requests; MLPDS leaks data from it.
  • Mask: A value used to select which bits or bytes of data to keep and which to ignore.
  • MDS (Microarchitectural Data Sampling): The family of CPU bugs that let one program sample leftover data from internal processor buffers.
  • MFBDS (Microarchitectural Fill Buffer Data Sampling): The MDS variant that leaks from Line Fill Buffers.
  • Microcode: Low-level firmware inside the processor that can be updated to change its behaviour, including security fixes.
  • MLPDS (Microarchitectural Load Port Data Sampling): The MDS variant that leaks from load ports.
  • Nibble: Four bits, half a byte.
  • Oracle: A test that answers a yes or no question, here whether the victim ever loaded a particular value.
  • Page: A fixed-size block of memory, commonly 4096 bytes, used by the operating system.
  • Private key: The secret half of a cryptographic key pair, used to prove identity or decrypt data.
  • Prologue: The opening part of a function that sets up the stack and saves registers.
  • Public key: The shareable half of a key pair, derived from the private key.
  • Register: A tiny, very fast storage location inside the processor.
  • RIDL: Rogue In-Flight Data Load, the research name for the MDS attacks studied by VUSec.
  • Sandbox: An isolated environment that restricts what a program can do.
  • SIGSEGV: The signal a program receives when it accesses invalid memory, normally causing a crash.
  • Speculative execution: The processor's habit of guessing ahead and doing work before it knows the guess is correct.
  • Stack: The area of memory where a program keeps local variables and return addresses for function calls.
  • Stack cookie: A random value placed on the stack to detect certain memory corruption attacks.
  • Stack pointer: A register that tracks the current top of the stack.
  • TSX (Transactional Synchronization Extensions): A set of Intel instructions that let code run in a transaction that aborts safely instead of crashing.
  • vCPU: A virtual CPU presented to a virtual machine.
  • Virtual machine (VM): A software-simulated computer running inside a real one.
  • X25519: A widely used elliptic-curve key-exchange algorithm.

Similar reports

View all

Same bug class and techniques, clearest first.

Information disclosure

The lesson behind this report.

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.