Modern processors are caught in a fundamental tug-of-war between performance and security. To maximize instruction throughput, CPUs do not wait for slow operations—like fetching data from main memory or verifying security permissions—to complete before moving forward. Instead, they guess the most likely path of execution and aggressively compute ahead. This optimization is known as speculative execution.
If the CPU guesses correctly, it achieves a massive speedup. If it guesses incorrectly, it discards the results and rolls back its state. As Zecheng He et al. observe in New Models for Understanding and Reasoning about Speculative Execution Attacks, this design creates a fundamental race condition: instructions are allowed to execute along a "transient" path before their authorization or correctness can be architecturally confirmed.
The security vulnerability arises because of a mismatch between what the processor cleans up and what it leaves behind.
Architectural Rollback vs. Microarchitectural Persistence
To understand why speculative execution leaks information, we must distinguish between two layers of a computer processor:
- The Architectural State: This is the software-visible contract of the processor, including registers, the program counter, and RAM. When a speculative misprediction occurs, the CPU completely resets this state. To the programmer, it appears as though the transient instructions never happened.
- The Microarchitectural State: This consists of the underlying physical structures used to accelerate execution, such as CPU caches, fill buffers, and branch predictors. When the CPU rolls back the architectural state, it frequently leaves the microarchitectural state untouched.
As highlighted by Guangyuan Hu et al. in SoK: Hardware Defenses Against Speculative Execution Attacks, these lingering microarchitectural changes serve as a covert channel. An attacker can trick a processor into speculatively executing a malicious sequence of instructions—a "gadget"—that accesses a secret value and encodes that secret into the microarchitectural state before the speculation is squashed.
The Anatomy of a Transient Leak
Consider a classic speculative leak. An attacker wants to read a secret byte located in a restricted memory region. They execute a program that triggers a conditional branch check (e.g., verifying if an array index is within bounds). By training the CPU's branch predictor with valid inputs, the attacker tricks the hardware into guessing that the check will pass, even when given an out-of-bounds index that points directly to the secret.
During this transient window, the CPU executes the gadget:
- It reads the secret byte from the unauthorized memory location.
- It uses the value of that secret byte as an index to perform a second memory load from a completely benign, user-accessible array (e.g., loading
array[secret_byte * 4096]).
When the CPU finally realizes the index check failed, it squashes the transient instructions. The secret byte is wiped from the registers. However, the specific cache line corresponding to array[secret_byte * 4096] has already been fetched into the CPU cache.
The attacker can now measure the time it takes to read each page of the benign array. The page that loads significantly faster (a cache hit) reveals the exact value of the secret byte.
Expanding the Leakage Mediums
Caches are not the only hardware structures vulnerable to this phenomenon. The threat landscape extends to almost any shared microarchitectural optimization:
- Fill Buffers: Michael Schwarz 0001 et al. demonstrate in ZombieLoad: Cross-Privilege-Boundary Data Sampling that transient execution can sample data directly from internal processor fill buffers, leaking sensitive information across privilege boundaries and even between CPU cores.
- Cache LRU States: Traditional cache attacks rely on measuring cache misses, which require slow memory cycles. However, Wenjie Xiong 0001 et al. show in Leaking Information Through Cache LRU States that transient execution can alter the internal Least-Recently Used (LRU) state of a cache during a cache hit. This creates a much faster, stealthier covert channel that evades standard security monitors.
- Memory Tagging Extensions: Hardware security features themselves can be subverted. Juhee Kim et al. reveal in TikTag: Breaking ARM's Memory Tagging Extension with Speculative Execution that speculative tag checks can alter microarchitectural states to leak memory tags before an architectural fault ever triggers, neutralizing memory safety defenses.
- Remote Network Exploitation: The threat is not confined to local attackers. Michael Schwarz 0001 et al. demonstrate in NetSpectre: Read Arbitrary Memory over Network that these microarchitectural changes can be triggered and measured remotely over a network, eliminating the requirement for local code execution.
Widening the Speculative Window
The severity of a transient execution attack depends heavily on the size of the speculative window—the number of instructions the CPU can execute before realizing it mispredicted. Normally, this window is bounded by physical hardware structures like the Reorder Buffer (ROB).
However, advanced performance optimizations can inadvertently blow these boundaries wide open. Chaoqun Shen et al. explore this in SPECRUN: The Danger of Speculative Runahead Execution in Processors, analyzing "runahead execution"—a technique where a processor pre-fetches data during long memory stalls. The authors find that combining runahead execution with branch prediction creates a nested speculation environment. This allows secondary speculative processes to execute using invalid data, effectively bypassing the physical size limits of the ROB and allowing attackers to execute significantly longer, more complex gadgets.
Formalizing Speculative Information Flow
To move beyond ad-hoc patches, the computer security community has developed formal semantic definitions to reason about what makes a system secure against speculation.
Kevin Cheang et al. introduce a framework in A Formal Approach to Secure Speculation based on Trace Property-Dependent Observational Determinism (TPOD). This approach isolates speculative vulnerabilities by mathematically comparing speculative execution traces against a non-speculative baseline, identifying leaks when misspeculation introduces variations in what an observer can see.
Similarly, Marco Guarnieri et al. propose Speculative Non-Interference (SNI) in Spectector: Principled Detection of Speculative Information Flows. SNI ensures that secret data accessed during transient execution cannot influence observable microarchitectural states. To enforce these properties across the hardware-software boundary, Marco Guarnieri et al. formalize Hardware-Software Contracts for Secure Speculation (Hardware-Software Contracts for Secure Speculation), providing a principled framework for co-designing secure processors and compilers.
Mitigations and Their Limitations
Defenses against transient execution attacks operate at both the software and hardware levels, but each introduces distinct trade-offs.
Software and Compiler Defenses
Compilers can inject defenses directly into binaries. For instance, Nicholas Mosier et al. introduce Serberus: Protecting Cryptographic Code from Spectres at Compile-Time, which enforces a strict static constant-time programming model across major speculation primitives.
Another common approach is speculative data masking, which tracks a speculation state flag and uses it to mask sensitive pointers during transient execution. However, Xaver Fabian et al. note in Do You Even Lift? Strengthening Compiler Security Guarantees Against Spectre Attacks that the security of this approach relies on the flawless propagation of the state flag across complex control flows, including indirect jumps and returns, which is difficult to formally guarantee.
Hardware Defenses and Invisible Speculation
Hardware defenses often attempt to enforce "transient non-observability," a principle formalized by Kevin Loughlin et al. in DOLMA: Securing Speculation with the Principle of Transient Non-Observability. The goal is to ensure that no speculative instruction can alter any microarchitectural state that is visible to an attacker.
One way to achieve this is through "invisible speculation" schemes. Lichen Jia et al. propose SpecBox: A Label-Based Transparent Speculation Scheme Against Transient Execution Attacks, which partitions the cache into temporary (speculative) and persistent domains, preventing speculative footprints from modifying the main cache until the instruction commits.
Alternatively, hardware can selectively restrict speculation based on data dependencies. Lutan Zhao et al. design a hardware defense in Exploiting Security Dependence for Conditional Speculation Against Spectre Attacks that dynamically identifies an "S-Pattern"—a specific sequence where a load instruction depends on a prior secret-accessing load. By conditionally blocking only these high-risk speculative memory accesses, the processor maintains high performance for safe code paths.
The Cat-and-Mouse Game
Despite these innovations, defenses often fall short because microarchitectural interactions are incredibly complex. Josep Torrellas et al. demonstrate in Speculative interference attacks: breaking invisible speculation schemes that even if a defense completely prevents speculative instructions from modifying the cache state, an attacker can still succeed. In a speculative interference attack, mis-speculated instructions subtly alter the timing of older, non-speculative instructions, creating a side channel that completely bypasses invisible speculation schemes.
Furthermore, as designers propose future microarchitectural optimizations to squeeze more speed out of silicon, the attack surface grows. Marcel Böhme et al. demonstrate in Testing side-channel security of cryptographic implementations against future microarchitectures that proposed hardware speed-ups can inadvertently combine with speculative execution to break real-world cryptographic libraries that are currently considered secure on existing hardware.
To break this cycle, tools like the one developed by Wubing Wang et al. in Specularizer : Detecting Speculative Execution Attacks via Performance Tracing shift the focus from blocking side effects to monitoring root causes. By tracing the architectural triggers of speculation—such as branch mispredictions and forced exceptions—defenses can detect attacks regardless of whether the data is exfiltrated through the cache, the TLB, or execution ports.
Key Foundational Work
A Systematic Evaluation of Transient Execution Attacks and Defenses (2019) — contributed 3 concept elements to this direction.
Spectector: Principled Detection of Speculative Information Flows (2020) — contributed 2 concept elements to this direction.
A Formal Approach to Secure Speculation (2019) — contributed 2 concept elements to this direction.