InSpectre Gadget: Inspecting the Residual Attack Surface of Cross-privilege Spectre v2
Sander Wiebing
33rd USENIX Security Symposium · Day 1 · USENIX Security '24 · USENIX Security '24
Overview
In the realm of modern CPU architecture, speculative execution vulnerabilities like Spectre continue to pose a significant threat to system security. This talk, "InSpectre Gadget: Inspecting the Residual Attack Surface of Cross-privilege Spectre v2," presented by Sander Wiebing, delves into the persistent challenge of identifying and exploiting Spectre v2 gadgets within privileged code, specifically the Linux kernel. The research introduces InSpectre Gadget, a novel tool capable of performing a precise, fine-grained exploitability analysis of these elusive gadgets, moving beyond the limitations of prior approximation-based or over-constraining detection methods.

Key moments
- 0:15 Introducing InSpectre Gadget: precise Spectre v2 analysis
- 2:00 Limitations of prior Spectre gadget finding approaches
- 4:00 InSpectre Gadget's symbolic execution methodology
- 5:10 User workflow: finding and filtering gadgets
- 6:00 Key finding: 1500+ gadgets, native BHI exploit
- 6:30 Aggregating and querying InSpectre Gadget results
- 8:00 Exploit demonstration: leaking E-Shadow file
InSpectre Gadget: Inspecting the Residual Attack Surface of Cross-privilege Spectre v2
Speakers: Sander Wiebing
Conference: USENIX Security '24
YouTube: https://www.youtube.com/watch?v=bd7l-xhEtCE
Overview
In the realm of modern CPU architecture, speculative execution vulnerabilities like Spectre continue to pose a significant threat to system security. This talk, "InSpectre Gadget: Inspecting the Residual Attack Surface of Cross-privilege Spectre v2," presented by Sander Wiebing, delves into the persistent challenge of identifying and exploiting Spectre v2 gadgets within privileged code, specifically the Linux kernel. The research introduces InSpectre Gadget, a novel tool capable of performing a precise, fine-grained exploitability analysis of these elusive gadgets, moving beyond the limitations of prior approximation-based or over-constraining detection methods.
The core contribution of this work lies in its ability to not only detect potential Spectre v2 gadgets but also to provide detailed information about their exploitability, including attacker control requirements and specific exploitation techniques needed. Leveraging InSpectre Gadget, the researchers discovered over 1,500 Spectre v2 gadgets within the Linux kernel. Critically, one of these natively present gadgets enabled the development of native BHI (Branch History Injection), a new cross-privilege Spectre v2 attack capable of leaking arbitrary kernel memory on the latest Intel CPUs, bypassing all currently deployed software and hardware mitigations. This research underscores the ongoing and evolving nature of speculative execution attacks and the critical need for advanced analysis tools to understand and counter them.
Background
▶ Watch: Introducing InSpectre Gadget: precise Spectre v2 analysis (0:15)
The Spectre vulnerability, first disclosed in 2018, exposed a fundamental flaw in modern CPU design related to speculative execution. CPUs attempt to predict future execution paths to improve performance, but if a prediction is incorrect, the speculatively executed instructions might leave observable side effects (e.g., in the cache) that can be leveraged to leak sensitive data. Spectre v1 primarily targets conditional branches, where a branch condition might be mispredicted, leading to out-of-bounds memory accesses. Spectre v2, on the other hand, focuses on indirect branches, where the target address of a jump or call instruction is mispredicted.
A successful Spectre attack relies on finding a Spectre gadget – a sequence of instructions that, when speculatively executed, can transmit a secret value into a covert channel (typically the CPU cache) that an attacker can then observe. The "disclosure gadget" refers to the core part of this sequence responsible for transmitting the secret. For cross-privilege attacks, the challenge is to find such a gadget within a higher-privileged context (like the kernel) that an attacker can reliably trigger and exploit from a lower-privileged context.
Prior attempts to find Spectre gadgets faced significant limitations. Early high-level data flow approaches, such as those used by "The B-Arts" paper, aimed to detect sequences involving a first load followed by a subsequent dependent load. While this method identified over 1,000 potential gadgets, it was over-approximating, meaning it flagged many non-exploitable candidates, making manual verification extremely difficult. Indeed, "The B-Arts" could not manually find a single gadget for a native exploit from their findings. Conversely, Intel engineers, after the BHI disclosure, adopted a more stringent approach, adding requirements that the secret must be masked and shifted above cache line granularity. This method, while precise, proved to be over-constraining, leading to zero exploitable gadgets found. This is because non-standard gadgets, where the secret isn't shifted or masked in a conventional way, can still be exploitable if the attacker has additional control over the secret's base address (as shown by "The Rep-Lead Artist") or the secret itself ("BlindSide" paper). These prior works highlighted the need for a more nuanced and fine-grained analysis of potential Spectre gadgets to accurately determine their exploitability. The problem persisted: how to precisely identify exploitable Spectre v2 gadgets in complex codebases like the Linux kernel, considering all known and emerging exploitation techniques, without over-approximating or over-constraining the search.
Key Findings
▶ Watch: InSpectre Gadget's symbolic execution methodology (4:00)
The research presented in "InSpectre Gadget" delivers several critical findings that advance the understanding and mitigation of Spectre v2 vulnerabilities:
- InSpectre Gadget Tool: The primary contribution is the development of InSpectre Gadget, a novel analysis tool designed for the precise and fine-grained exploitability analysis of Spectre gadgets. Unlike previous tools, InSpectre Gadget leverages symbolic execution to reason about the exact conditions and attacker capabilities required to exploit a given gadget. This allows for a deeper inspection of the gadget's behavior, providing detailed information about secret transmission, attacker controllability, and required exploitation techniques.
- Precise Exploitability Reasoning: For the first time, researchers can precisely reason about the exploitability of Spectre gadgets. InSpectre Gadget overcomes the limitations of prior work by neither over-approximating (identifying too many false positives) nor over-constraining (missing legitimate, non-standard gadgets) the search. It provides specific details such as the range of attacker-controlled addresses, which secret bits are transmitted, their position relative to cache line granularity, and the level of control an attacker has over the base address.
- Discovery of Numerous Spectre v2 Gadgets: Applying InSpectre Gadget to the Linux kernel, the researchers successfully identified over 1,500 Spectre v2 gadgets. This significant number highlights the pervasive nature of these vulnerabilities even in highly scrutinized and patched codebases, demonstrating that existing mitigations may not fully address the residual attack surface.
- Native BHI Attack: From the multitude of discovered gadgets, one specific gadget, natively present in the Linux kernel, was leveraged to create a new cross-privilege Spectre v2 attack called native BHI. This attack demonstrates a practical exploitation scenario where arbitrary kernel memory can be leaked on the latest Intel CPUs. Crucially, this attack was shown to bypass all deployed software and hardware mitigations available at the time of the research, underscoring the ongoing challenge of securing systems against speculative execution attacks. The successful demonstration of leaking the
ET Shadow F(root password hash) serves as a potent proof of concept.
Technical Deep Dive
▶ Watch: User workflow: finding and filtering gadgets (5:10)
The fundamental mechanism behind a Spectre gadget typically involves a sequence that can be triggered speculatively. A classic Spectre v1 gadget starts with a conditional branch that is subject to misprediction. If mispredicted, the CPU might speculatively load data out-of-bounds in a subsequent instruction. This first load retrieves a secret value. For the secret to be effectively exfiltrated, the gadget usually needs to mask the secret to reduce its entropy and shift it to ensure it resides above cache line granularity. Finally, the masked and shifted secret is used as an offset in a second dependent load, which encodes the secret into the cache state. An attacker can then recover the secret using a flush+reload or prime+probe cache side-channel attack. While this example uses a Spectre v1 conditional branch, the "disclosure gadget" – the body of the gadget responsible for transmitting the secret – is generalizable across all speculation sources, including Spectre v2's indirect branch prediction.
InSpectre Gadget focuses its analysis on this disclosure gadget, performing an in-depth inspection to determine its precise exploitability. The tool employs symbolic execution, a powerful program analysis technique that treats program inputs as symbolic variables rather than concrete values.
Here's a breakdown of InSpectre Gadget's technical process:
- Configuration and Symbolic Execution:
- The user (either a defender assessing remaining attack surface or an attacker crafting an exploit) provides a kernel image and a list of target speculation openings (e.g., specific indirect branches in the Linux kernel).
- At the start of a potential disclosure gadget, the user configures which registers and memory locations are assumed to be under attacker control. This is a crucial step that allows InSpectre Gadget to model different attacker capabilities.
- The tool then symbolically executes the instructions of the disclosure gadget.
- Secret Transmission Detection and Expression Construction:
- During symbolic execution, InSpectre Gadget monitors for instances where a secret value is "transmitted," typically by being used in a second load or store operation that depends on the secret.
- When such a transmission is detected, the tool constructs a symbolic expression representing this transmission. This expression captures the relationship between the secret, its address, and the base address involved in the second load/store.
- Component Identification and Analysis:
- From the symbolic transmission expression, InSpectre Gadget identifies distinct components: the transmitted secret, the secret address, and the base address used in the dependent load.
- With these components identified, the tool applies component-specific analysis:
- Constraint Analysis: Determines any constraints on the attacker-controlled values necessary to trigger the gadget.
- Range Analysis: For attacker-controlled addresses or values, it determines the possible range of values that can be used.
- Secret Position Analysis: Crucially, it analyzes the bit positions of the transmitted secret to determine if it is above or below cache line granularity (e.g., if a 32-bit secret is transmitted, it might analyze if bits 3-34 are used, and how many bits are actually transmitted). This addresses the "shifting" requirement.
- Attacker Control Granularity: For the base address, it determines how much control the attacker has and at what granularity (e.g., byte, word, cache line). This addresses the "masking" requirement for non-standard gadgets.
- Output and Reasoner:
- All this detailed information is output into a database.
- A separate Reasoner component then processes this data. It annotates each gadget with whether it is exploitable, which specific exploitation techniques (e.g., those from "The Rep-Lead Artist" or "BlindSide") are required, and if not exploitable, the precise reason.
From a user perspective, InSpectre Gadget streamlines the analysis process. A researcher provides a Linux kernel image and a list of potential speculation openings. The tool then outputs a database of identified gadgets. For each gadget, it generates an annotated assembly file, which provides comments guiding the researcher through the critical instructions, highlighting attacker-controlled values, secret loads, and transmission points. For example, an annotation might show attacker controlled register eddi is used to load a second attacker controlled value, followed by a secret value is loaded with tech control value as address, and finally the secret value is used in a transmission... a 32-bit secret value and is also multiplied by eight with attacker controlled value as a base. Below the assembly, key information like bit positions of the transmitted secret from 3 up to 34 and number of bits that are actually transmitted: 32 is summarized. Researchers can then query and filter this database based on specific control requirements or gadget properties, ultimately selecting a suitable gadget to develop an end-to-end exploit. The power of InSpectre Gadget lies in its ability to provide this level of granular, actionable intelligence, moving beyond simple detection to precise exploitability assessment.
Demo / Proof of Concept
▶ Watch: Aggregating and querying InSpectre Gadget results (6:30)
The talk culminated in a compelling demonstration of the native BHI attack, leveraging one of the Spectre v2 gadgets discovered by InSpectre Gadget within the Linux kernel. The objective was to leak the ET Shadow F, which contains the password hash of the root user, from kernel memory.
The demonstration was conducted on a 13th Generation Intel CPU with all available software and hardware mitigations enabled at the time of the research. This is a critical detail, as it highlights the ability of native BHI to bypass the most advanced defenses.
The exploit proceeded through several high-level steps:
- Break KASLR (Kernel Address Space Layout Randomization): While not the focus of the talk, breaking KASLR is a prerequisite for many kernel exploits, as it allows the attacker to know the location of kernel data and code, including the native BHI gadget. For the demo, KASLR was already assumed to be broken.
- BHI-Specific Setup Phase: This phase involved the core of the Branch History Injection attack. The attacker's goal is to manipulate the CPU's branch predictor so that an indirect branch within the Linux kernel is mispredicted to point to the address of the identified native Spectre v2 gadget. This requires careful crafting of the branch history to influence the predictor.
- Leak Bytes and Find Target: Once the BHI setup was successful and the gadget was being speculatively executed, the system began to leak bytes of kernel memory via the cache side channel. The attacker then continuously swept through memory, searching for a specific signature: the
root::prefix. This prefix is characteristic of entries in theET Shadow Ffile, indicating the start of a user's password hash entry.
- Leak Password Hash: Upon successfully locating the
root::prefix in memory, the exploit then proceeded to leak the subsequent bytes, which constitute the password hash itself.
The live demonstration showcased the exploit in action. The presenter showed the system running, with KASLR already broken. The BHI setup phase was initiated, successfully mispredicting the indirect branch to the native kernel gadget. The system then visibly started leaking bytes. After a period of sweeping memory, the exploit successfully identified the root:: prefix. Finally, the password hash of the root user was successfully exfiltrated and displayed on screen. The entire process, from initiating the BHI setup to leaking the root password hash, took approximately 47 seconds. This tangible proof of concept unequivocally validated the findings of InSpectre Gadget and the severity of the native BHI attack.
Defensive Implications
▶ Watch: Exploit demonstration: leaking E-Shadow file (8:00)
The findings presented by InSpectre Gadget carry profound implications for system defenders and security engineers. The most critical takeaway is that despite years of effort and numerous software and hardware mitigations deployed against Spectre v2, a residual attack surface persists in critical codebases like the Linux kernel. The successful demonstration of native BHI bypassing all deployed mitigations on 13th Generation Intel CPUs is a stark reminder that current defenses are insufficient against sophisticated, precisely targeted speculative execution attacks.
Defenders should recognize that:
- Current Mitigations are Not Absolute: The assumption that existing mitigations (e.g., Retpolines, IBPB, IBRS, eIBRS, SBIB) fully protect against Spectre v2 is challenged. The existence of over 1,500 Spectre v2 gadgets in the Linux kernel and the exploitability of one via native BHI demonstrate that these mitigations leave gaps.
- Fine-Grained Analysis is Essential: Relying on high-level or overly constrained gadget detection methods is inadequate. Defenders need tools like InSpectre Gadget that can perform fine-grained, symbolic execution-based analysis to precisely identify exploitable gadgets. This includes understanding the specific bit positions of transmitted secrets, attacker control over addresses, and the exact exploitation techniques required.
- Proactive Vulnerability Assessment: Organizations responsible for maintaining critical software (e.g., kernel developers, cloud providers) should integrate tools like InSpectre Gadget into their security development lifecycle. After implementing new mitigations or updating code, InSpectre Gadget can be used to analyze the remaining attack surface, ensuring that new defenses haven't merely shifted the problem or introduced new, subtly exploitable gadgets. This continuous, precise assessment is vital for staying ahead of attackers.
- Non-Standard Gadgets are a Real Threat: The research emphasizes that gadgets not conforming to the "standard" masked and shifted pattern can still be exploitable with advanced attacker control. Defenders must account for these non-standard exploitation techniques when assessing risk.
- Re-evaluation of Trust Boundaries: The ability to leak arbitrary kernel memory from a less privileged context necessitates a re-evaluation of trust boundaries and the potential impact of even seemingly minor information disclosures. The long-term solution may require architectural changes or more robust isolation mechanisms that are not solely reliant on branch predictor behavior.
In summary, the research demands a more rigorous and continuous approach to identifying and mitigating speculative execution vulnerabilities. Defenders must move beyond broad-stroke mitigations and embrace precise analysis tools to truly understand and secure their systems against this persistent class of threats.
Key Takeaways
- InSpectre Gadget is a novel symbolic execution-based tool for precise, fine-grained exploitability analysis of Spectre v2 gadgets, overcoming limitations of prior over-approximating or over-constraining methods.
- The tool identified over 1,500 Spectre v2 gadgets within the Linux kernel, demonstrating a significant residual attack surface despite existing mitigations.
- A new cross-privilege Spectre v2 attack, native BHI, was developed using a natively present kernel gadget, capable of leaking arbitrary kernel memory on latest Intel CPUs.
- The native BHI attack successfully bypassed all deployed software and hardware mitigations, highlighting the ongoing challenge of securing systems against speculative execution.
- The demonstration successfully exfiltrated the root user's password hash (
ET Shadow F) in approximately 47 seconds on a 13th Generation Intel CPU. - Defenders must adopt precise analysis tools like InSpectre Gadget to proactively assess remaining attack surfaces and understand the nuanced exploitability of non-standard gadgets after implementing new mitigations.
About the Speaker(s)
The talk was presented by Sander Wiebing. This research is a collaborative effort, and the paper "InSpectre Gadget: Inspecting the Residual Attack Surface of Cross-privilege Spectre v2" is a joint work of Sander Wiebing and Offa, along with their professors Herbert and Christiano. While specific titles and affiliations for Sander Wiebing beyond being a researcher are not detailed in the provided transcript, the quality and depth of the work presented signify expertise in CPU architecture, speculative execution vulnerabilities, and system security.
Reviews
Dr. Zero (Offensive Security Researcher) — MUST SEE
This research delivers InSpectre Gadget, a precise symbolic execution tool for Spectre v2 gadget analysis, uncovering over 1,500 exploitable gadgets in the Linux kernel. The demonstrated native BHI attack, leveraging a discovered gadget, bypasses all current mitigations on 13th Gen Intel CPUs to leak arbitrary kernel memory. This unequivocally proves the Spectre v2 attack surface remains wide open.
Heather Calloway (CISO) — MUST SEE
This research presents a critical advancement in understanding speculative execution vulnerabilities, demonstrating that existing software and hardware mitigations for Spectre v2 are insufficient. The discovery of over 1,500 new gadgets and a native BHI attack capable of leaking arbitrary kernel memory on the latest Intel CPUs demands immediate re-evaluation of platform security assumptions and risk posture. This is a must-see for any security leader.