Branch Privilege Injection: Compromising Spectre v2 Hardware Mitigations by Exploiting Branch Predictor Race Conditions

Sandro Rüegge

34th USENIX Security Symposium (USENIX Security '25) · Day 2 · Hardware Security 1: Microarchitectures

Overview

This talk, presented by Sandro Rüegge, delves into a critical vulnerability discovered in Intel processors that undermines hardware mitigations designed to protect against Spectre v2 (Branch Target Injection) attacks. Specifically, the research uncovers a novel race condition in Intel's Enhanced Indirect Branch Restricted Speculation (EIBRS), a key hardware defense introduced in 2018. While EIBRS was believed to effectively prevent cross-privilege Spectre v2 attacks for years by isolating branch predictions across privilege levels, Rüegge and his co-authors, Professor Kaveh Razavi and Dr. Daniel Wickner, demonstrate that asynchronous updates within the branch predictor unit can be exploited. This allows an attacker in user space to "inject" a malicious branch target into the supervisor mode's branch predictor, ultimately enabling speculative execution of arbitrary code gadgets in a higher privilege level, such as the kernel or hypervisor.

Watch on YouTube · Read the paper · Download the PDF (PDF) · Slides

Paper abstract

Recent advances in Large Language Models (LLMs) enable exciting LLM-integrated applications, which perform text-based tasks by utilizing their advanced language understanding capabilities. However, as LLMs have improved, so have the attacks against them. Prompt injection attacks are an important threat: they trick the model into deviating from the original application's instructions and instead follow user directives. These attacks rely on the LLM's ability to follow instructions and inability to separate prompts and user data. We introduce structured queries, a general approach to tackle this problem. Structured queries separate prompts and data into two channels. We implement a system that supports structured queries. This system is made of (1) a secure front-end that formats a prompt and user data into a special format, and (2) a specially trained LLM that can produce high-quality outputs from these inputs. The LLM is trained using a novel fine-tuning strategy: we convert a base (non-instruction-tuned) LLM to a structured instruction-tuned model that will only follow instructions in the prompt portion of a query. To do so, we augment standard instruction tuning datasets with examples that also include instructions in the data portion of the query, and fine-tune the model to ignore these. Our system significantly improves resistance to prompt injection attacks, with little or no impact on utility. Our code is released at .

Visual summary for Branch Privilege Injection: Compromising Spectre v2 Hardware Mitigations by Exploiting Branch Predictor Race Conditions by Sandro Rüegge
Visual summary for Branch Privilege Injection: Compromising Spectre v2 Hardware Mitigations by Exploiting Branch Predictor Race Conditions by Sandro Rüegge

Key moments

  1. 0:00 Introducing Branch Privilege Injection and Spectre V2
  2. 1:59 Explaining branch predictor mechanisms and basic exploitation
  3. 3:57 Describing Intel's EIBRS defense against Spectre V2
  4. 4:28 Discovering EIBRS flaw: system calls re-enable signal
  5. 5:00 Demonstrating and explaining branch predictor update delays
  6. 6:03 Visualizing branch predictor updates as an "assembly line"
  7. 7:00 How update delays and system calls bypass EIBRS

Branch Privilege Injection: Compromising Spectre v2 Hardware Mitigations by Exploiting Branch Predictor Race Conditions

Speakers: Sandro Rüegge

Conference: USENIX Security

YouTube: https://www.youtube.com/watch?v=op-5mefRYvk

Overview

This talk, presented by Sandro Rüegge, delves into a critical vulnerability discovered in Intel processors that undermines hardware mitigations designed to protect against Spectre v2 (Branch Target Injection) attacks. Specifically, the research uncovers a novel race condition in Intel's Enhanced Indirect Branch Restricted Speculation (EIBRS), a key hardware defense introduced in 2018. While EIBRS was believed to effectively prevent cross-privilege Spectre v2 attacks for years by isolating branch predictions across privilege levels, Rüegge and his co-authors, Professor Kaveh Razavi and Dr. Daniel Wickner, demonstrate that asynchronous updates within the branch predictor unit can be exploited. This allows an attacker in user space to "inject" a malicious branch target into the supervisor mode's branch predictor, ultimately enabling speculative execution of arbitrary code gadgets in a higher privilege level, such as the kernel or hypervisor.

The significance of this discovery cannot be overstated. Spectre v2 is arguably the most dangerous variant of speculative execution attacks, primarily due to its ability to control program flow across security boundaries. Intel's EIBRS was considered the robust, hardware-level answer to this threat, providing a crucial barrier between user and supervisor modes. The finding of "Branch Privilege Injection" reveals that this barrier is not impermeable, exposing a fundamental flaw in the timing and privilege tracking within the processor's branch prediction logic. This research not only re-opens a previously "fixed" attack vector but also highlights the subtle and complex interactions within modern CPU microarchitectures that can lead to profound security vulnerabilities. The implications extend to all Intel processors supporting EIBRS, impacting both operating system kernels and hypervisors.

Background

▶ Watch: Introducing Branch Privilege Injection and Spectre V2 (0:00)

The genesis of this research lies in the groundbreaking Spectre vulnerabilities, first disclosed in 2018. Among its variants, Spectre v2, or Branch Target Injection (BTI), proved particularly insidious. Spectre v2 exploits the processor's branch predictor unit (BPU), a microarchitectural component designed to guess the likely target of branches (e.g., JMP, CALL, RET) to keep the CPU's pipeline full and improve performance. If the BPU makes an incorrect prediction, the CPU speculatively executes instructions down the wrong path. While the CPU eventually detects the misprediction and rolls back architectural state changes, the effects of these speculative executions can leave observable traces in the microarchitecture, such as cache line accesses. An attacker can then use these side channels to infer sensitive data that was never meant to be accessed.

The core of Spectre v2 lies in its ability to train the branch predictor. An attacker can execute a branch instruction repeatedly, guiding the predictor to associate a specific branch source with an "evil" target address. Later, when a victim process executes a branch instruction that aliases with the attacker's trained branch (meaning they map to the same entry in the branch predictor due to hashing), the CPU might speculatively jump to the attacker-controlled evil target. The danger escalates when this occurs across privilege levels: an attacker in unprivileged user mode could train the predictor to point to a malicious gadget in supervisor mode (e.g., the kernel), causing the kernel to speculatively execute code that leaks its secrets.

To counter Spectre v2, Intel introduced Enhanced Indirect Branch Restricted Speculation (EIBRS). EIBRS was designed to create a "barrier" between privilege levels within the branch predictor. Conceptually, it associates predictions with the privilege level at which they were made. A prediction made in user mode would be "tagged" for user mode and, crucially, would not be used when the processor is operating in supervisor mode. This mechanism aimed to prevent cross-privilege prediction poisoning, ensuring that a user-mode attacker could not influence the speculative execution path of the kernel. For several years following its introduction, EIBRS was considered an effective and robust hardware mitigation, with no inherent flaws publicly identified.

The branch predictor unit itself comprises several components. The talk specifically mentions the Branch Target Buffer (BTB), a static predictor that maps branch source addresses to target addresses without using execution history. Additionally, the Indirect Branch Predictor (IBP) incorporates historical information to make more sophisticated predictions, especially for indirect branches where the target address is not known until runtime. A critical aspect for attackers is aliasing: the branch predictor uses hashing functions to determine where to store branch entries. If a user-mode branch and a supervisor-mode branch happen to hash to the same entry in the predictor, they can effectively "collide." Furthermore, branch predictors often store only partial addresses (e.g., the lowest 32 bits on Intel processors) for targets. This allows an attacker to craft an "evil gadget" in user space that has the same low-order bits as a desired target in kernel space, even if their full virtual addresses are vastly different. These foundational concepts of branch prediction, aliasing, and partial address storage are crucial to understanding how the new "Branch Privilege Injection" attack bypasses EIBRS.

Key Findings

▶ Watch: Describing Intel's EIBRS defense against Spectre V2 (3:57)

The research unveils several critical findings that collectively demonstrate the inadequacy of EIBRS and expose a fundamental flaw in Intel's branch prediction logic:

  1. Asynchronous Branch Predictor Updates: The most foundational discovery is that updates to the branch prediction structures (like the BTB) are not instantaneous but rather proceed asynchronously and with a measurable delay. Unlike the simplified model where a branch execution immediately updates the predictor, the researchers found that the processor inserts update requests into an internal "assembly line" or queue. It takes a significant number of CPU cycles or instructions for this update to be processed and finally committed to the branch predictor structures. This delay was observed on all Intel processors tested, dating back to 2012.
  1. Race Condition in EIBRS Privilege Tagging: Building on the asynchronous updates, the core finding is a race condition during the branch predictor update process that allows an attacker to bypass EIBRS. When a branch prediction update is in the "assembly line," it appears that the processor either fails to consistently track the original privilege level of the branch that generated the update, or it incorrectly applies the current privilege level when the update is finally committed. By carefully timing a system call (which inherently switches the processor from user mode to supervisor mode) immediately after training a branch in user mode, an attacker can exploit this race. The prediction, initiated in user mode, is then "inserted" into the branch predictor as if it originated from supervisor mode, effectively "injecting" a user-mode-trained target into the supervisor-mode predictor.
  1. Symmetric EIBRS Isolation is Compromised: The research shows that EIBRS, while intended to protect supervisor mode from user mode, actually attempts to isolate both modes symmetrically. However, the discovered race condition allows predictions to "land" in the wrong privilege domain. The experiments clearly demonstrate an inverse correlation: when the attack successfully injects a user-mode prediction into supervisor mode, the same prediction fails to be available in user mode, and vice-versa. This confirms a fundamental breakdown in the intended privilege separation.
  1. Widespread Impact Across Intel Processors and Scenarios: The vulnerability is not limited to specific processor generations. The asynchronous update behavior was observed on all Intel processors back to 2012. More critically, the EIBRS bypass via the system call race condition was found on all Intel processors since the introduction of EIBRS. Furthermore, the attack extends beyond user-to-supervisor mode transitions:
  • Virtual Machine to Hypervisor Attacks: The same race condition allows a malicious virtual machine (VM) to attack its hypervisor. This was demonstrated on all Intel performance cores since the introduction of EIBRS.
  • IBP (Indirect Branch Predictor Flushing) Vulnerability: Intel's IBP mechanism, used to isolate different security domains (e.g., virtual machines) not natively separated by the predictor, was also found vulnerable. This impacts all Intel performance cores since the introduction of EIBRS, and even older cores predating Spectre's public disclosure.

In summary, the research uncovers a fundamental microarchitectural timing vulnerability that undermines Intel's primary hardware mitigation for Spectre v2, re-enabling cross-privilege speculative execution attacks across a broad range of Intel platforms and security boundaries.

Technical Deep Dive

▶ Watch: Discovering EIBRS flaw: system calls re-enable signal (4:28)

The core of the "Branch Privilege Injection" attack lies in understanding and exploiting the non-instantaneous nature of branch predictor updates. Sandro Rüegge describes the process not as a direct, immediate write to the predictor, but as an "assembly line" or pipeline. When a branch is executed and its target is resolved, the information required to update the Branch Target Buffer (BTB) and Indirect Branch Predictor (IBP) is queued. This queuing and processing introduces a significant delay before the update is actually committed to the predictor structures.

The researchers empirically demonstrated this delay using a simple experiment on Intel Raptor Cove microarchitecture. They execute a branch, followed by a variable number of NOP (no operation) instructions to introduce a delay, and then execute the same branch again. By measuring the prediction accuracy of the second branch against the delay in NOP instructions, they observed a clear pattern: if the second branch executes too quickly after the first, it is mispredicted because the branch predictor update from the first execution has not yet completed. Only after a sufficient delay do predictions become consistently correct, confirming the asynchronous nature of the updates. This plot clearly showed prediction accuracy rising from near 0% to nearly 100% as the NOP delay increased, indicating a critical window during which the predictor is stale.

The critical insight for the EIBRS bypass emerged from observing a weak signal of mispredictions in supervisor mode, specifically when a system call immediately followed the user-mode training phase. System calls are crucial here because they trigger a privilege level switch from user mode to supervisor mode. The researchers hypothesized that the race condition occurs during this switch.

Their proposed model, based on extensive experimentation, suggests the following:

  1. User-Mode Training: An attacker in user mode executes a branch instruction, training the branch predictor to point to an "evil gadget." This initiates an update request that enters the branch predictor's internal "assembly line."
  2. System Call: Crucially, the attacker then executes a system call before the branch predictor update from the user-mode training completes and is committed to the BTB. The system call causes the CPU to transition from user mode to supervisor mode.
  3. Privilege Level Mismatch: While the update request is in the "assembly line," the processor's current privilege level changes. When the update finally reaches the end of the pipeline and is ready to be inserted into the BTB, the processor incorrectly associates it with the current privilege level (supervisor mode) rather than the original privilege level (user mode) where the branch instruction originated.
  4. Injection: As a result, the user-mode trained prediction is inserted into the supervisor-mode side of the BTB, effectively bypassing EIBRS's intended privilege separation.

The researchers further validated this by plotting the success rate of the misprediction attack in supervisor mode against the delay introduced between the user-mode training and the system call, again using NOP instructions. They observed that the attack is highly successful when the system call is very close to the training, demonstrating the tight timing window of the race condition. As the delay increases, the attack's success rate drops because the user-mode prediction update completes and is correctly tagged for user mode before the system call switches privilege. Conversely, they showed that user-mode prediction availability exhibits the exact opposite behavior, confirming the symmetric but flawed isolation.

The implications of this timing-dependent privilege tracking are profound. EIBRS relies on tagging predictions with their originating privilege level. If this tag is either not correctly propagated through the update pipeline or is overwritten with the current privilege level at the point of insertion, the entire isolation mechanism breaks down. The researchers acknowledge that without Intel's proprietary Register Transfer Level (RTL) designs, they cannot definitively pinpoint the exact microarchitectural component responsible. However, their experimental results strongly support this model of a race condition between prediction update completion and privilege level transition.

Another critical technical aspect for the attack is address aliasing. The branch predictor often stores only a partial address for its targets, specifically the lowest 32 bits on Intel. This allows an attacker to craft an "evil gadget" in user mode that shares the same low-order 32 bits as a legitimate, desired target address in supervisor mode. When the branch predictor is compromised by the privilege injection, it will then speculatively direct a supervisor-mode branch to this user-controlled evil gadget, even though the full 64-bit addresses are distinct. This combination of delayed updates, race conditions during privilege switching, and partial address storage forms the complete technical foundation of Branch Privilege Injection.

Demo / Proof of Concept

▶ Watch: Visualizing branch predictor updates as an "assembly line" (6:03)

The talk outlines the general methodology for exploiting this "Branch Privilege Injection" vulnerability, demonstrating its practical feasibility to leak sensitive information across privilege boundaries. The proof-of-concept hinges on a classic cache side-channel attack facilitated by the compromised branch predictor.

The attack proceeds in three main steps:

  1. User-Mode Training: The attacker first executes code in user mode to train a specific branch in the branch predictor. This training is designed to associate a particular branch instruction (which will later be executed in supervisor mode) with an "evil gadget" address chosen by the attacker. Crucially, this training phase is immediately followed by a system call, carefully timed to exploit the asynchronous update race condition discussed in the technical deep dive. This ensures that the user-mode-trained prediction is inadvertently committed to the supervisor-mode BTB.
  1. Supervisor-Mode Attack: Once the branch predictor is "poisoned," the attacker triggers the execution of a vulnerable branch instruction in supervisor mode (e.g., within the kernel). This branch, due to the aliasing and the injected prediction, will speculatively jump to the attacker's "evil gadget."
  1. Evil Gadget Execution and Data Leakage: The "evil gadget" is a carefully crafted sequence of instructions designed to perform two key actions:
  • Load Secret Data: It first attempts to load sensitive data from a secret location in memory. This secret location could be a kernel data structure, a cryptographic key, or any information the attacker wishes to exfiltrate.
  • Side-Channel Channel Operation: Based on the value of the loaded secret data, the gadget then performs a memory access to another location. For example, if the secret bit is '0', it might access memory[0x1000]; if it's '1', it might access memory[0x2000]. This conditional memory access creates a cache side channel.

After the speculative execution completes (and is eventually rolled back by the CPU), the attacker can measure the access times to memory[0x1000] and memory[0x2000]. If memory[0x1000] is faster to access (indicating it was brought into the cache), the attacker infers the secret bit was '0'. If memory[0x2000] is faster, the bit was '1'. By repeatedly executing this process and varying the target secret, the attacker can reconstruct the entire secret.

To make this proof-of-concept work in a real-world scenario, the researchers had to overcome several practical challenges:

  • Finding Attackable Branches: They needed to identify specific branch instructions within the supervisor mode (kernel or hypervisor) that could be reliably targeted and, ideally, where an attacker could control some registers to influence the secret loading process.
  • Finding Evil Gadgets: Crafting the evil gadget itself requires careful consideration of its functionality and ensuring its partial address aliases with a legitimate target.
  • Bypassing KASLR: Modern operating systems like Linux employ Kernel Address Space Layout Randomization (KASLR), which randomizes the base addresses of the kernel code and data structures at boot time. This means attackers cannot hardcode addresses. The researchers had to implement runtime techniques to discover the actual memory locations of the vulnerable branches, the evil gadget, the kernel's direct memory map, the secret data, and the reload buffer used for the side channel.

The researchers successfully demonstrated this attack across a wide range of Intel processors. Their findings confirm that:

  • The initial EIBRS bypass via the system call race condition works on all Intel processors since EIBRS was introduced.
  • The VM-to-hypervisor attack vector is viable on all Intel performance cores since EIBRS was introduced.
  • The IBP (Indirect Branch Predictor Flushing) mechanism, which is designed to isolate security domains such as different virtual machines, is also vulnerable to this race condition on all Intel performance cores since EIBRS was introduced, and even on older cores predating Spectre's public disclosure.

These results confirm that the "Branch Privilege Injection" is not a theoretical curiosity but a practical attack vector, capable of leaking sensitive data from higher privilege levels by subverting hardware mitigations.

Defensive Implications

▶ Watch: How update delays and system calls bypass EIBRS (7:00)

The discovery of Branch Privilege Injection necessitates a re-evaluation of the security posture against Spectre v2 and highlights the ongoing challenge of securing complex microarchitectural components. The primary defensive implication is that Intel's EIBRS mitigation, previously considered robust, is not sufficient on its own to prevent cross-privilege branch target injection attacks due to the inherent race conditions in its implementation.

Intel, after a nine-month disclosure period, released microcode updates to address this vulnerability. Microcode updates are low-level software patches that run on the CPU itself, often changing the behavior of internal CPU components. For a race condition like this, which is deeply embedded in the processor's timing and logic for handling branch predictor updates and privilege transitions, a microcode update is often the most direct and effective fix. Software-only mitigations at the operating system level are notoriously difficult to implement for such timing-sensitive microarchitectural flaws without incurring significant performance penalties or being incomplete. Therefore, the most immediate and critical action for defenders is to apply the latest microcode updates provided by Intel (typically distributed via BIOS/UEFI updates or operating system patches).

Beyond applying patches, the research underscores several broader defensive implications:

  • Continuous Vigilance for Microarchitectural Flaws: The fact that a critical hardware mitigation like EIBRS, which was considered secure for years, could be bypassed demonstrates that the security landscape for speculative execution attacks is still evolving. Defenders and security researchers must maintain continuous vigilance and scrutinize hardware designs for subtle timing vulnerabilities.
  • Layered Security: While hardware mitigations are crucial, they are not infallible. Operating systems and hypervisors should continue to employ a layered defense strategy, including techniques like KASLR (Kernel Address Space Layout Randomization) to increase the difficulty of finding gadgets, and potentially exploring retpoline-like software-based mitigations for indirect branches in critical code paths, even if EIBRS is present. However, the performance overhead of such software mitigations can be substantial.
  • Understanding Asynchronous Behavior: This research highlights that internal CPU operations, especially those related to performance optimizations like branch prediction, are often asynchronous. Security models need to account for these timing differences and potential race conditions, rather than assuming instantaneous or atomic operations.
  • Impact on Virtualization and Cloud Environments: The demonstrated vulnerability against hypervisors from guest VMs is particularly concerning for cloud providers. It means that a malicious tenant could potentially escape their virtual machine and access sensitive data or even gain control over the underlying hypervisor, impacting other tenants or the cloud infrastructure itself. Regular patching and careful monitoring of hypervisor integrity are paramount.
  • Open Research: The researchers also mentioned that they have proposed and evaluated software mitigations themselves, recognizing that waiting nine months for a microcode update is too long. While the talk does not detail these, this indicates an ongoing need for software-based countermeasures or detection mechanisms that can operate in parallel with hardware fixes, especially for legacy systems or environments where immediate microcode updates are not feasible.

In conclusion, the "Branch Privilege Injection" attack serves as a stark reminder that even seemingly robust hardware defenses can harbor subtle, exploitable flaws. The primary defense is timely application of vendor-provided microcode patches, complemented by continued research into robust software mitigations and a vigilant approach to microarchitectural security.

Key Takeaways

  • EIBRS is Compromised: Intel's Enhanced Indirect Branch Restricted Speculation (EIBRS) hardware mitigation for Spectre v2 is vulnerable to a novel "Branch Privilege Injection" attack.
  • Asynchronous Updates are Key: The vulnerability stems from asynchronous, delayed updates to the branch predictor unit, a previously unreported microarchitectural behavior.
  • Race Condition Exploited: A race condition occurs when a system call causes a privilege level switch (user to supervisor) during the branch predictor update pipeline, leading to a user-mode trained prediction being incorrectly tagged and inserted into the supervisor-mode predictor.
  • Widespread Impact: The attack affects all Intel processors supporting EIBRS, enabling cross-privilege attacks from user mode to kernel, and from virtual machines to hypervisors, as well as compromising the IBP flushing mechanism.
  • Data Leakage via Side Channels: Attackers can leverage this injection to speculatively execute "evil gadgets" in higher privilege levels, leaking sensitive data using cache side channels.
  • Microcode Fixes Essential: Intel addressed the vulnerability with microcode updates, emphasizing the difficulty of purely software-based fixes for such deep-seated microarchitectural race conditions.

About the Speaker(s)

Sandro Rüegge is a researcher who, alongside Professor Kaveh Razavi and Dr. Daniel Wickner, co-authored the paper "Branch Privilege Injection: Compromising Spectre v2 Hardware Mitigations by Exploiting Branch Predictor Race Conditions." His presentation at USENIX Security highlights his expertise in microarchitectural security and speculative execution vulnerabilities. The work presented is a testament to his diligent research in uncovering subtle flaws in modern processor designs and their implications for system security.

Reviews

Dr. Zero (Offensive Security Researcher) — MUST SEE

Rüegge and co-authors don't just find another Spectre gadget — they break a hardware mitigation that Intel shipped as the definitive fix and that the entire industry trusted for six-plus years. Discovering that EIBRS's privilege tagging is raceable through a system call boundary, and that the BTB update pipeline is asynchronous in a security-relevant way nobody had modeled, is exactly the kind of foundational microarchitectural insight that resets assumptions. This is USENIX-tier work that earned a CVE, forced an Intel microcode response after nine months, and reopens VM-to-hypervisor Spectre v2 as a live threat vector.

Heather Calloway (CISO) — WEAK

Technically rigorous work that belongs in the conversation — invalidating a hardware mitigation that Intel and the industry treated as settled is a genuine finding. But the talk as described delivers almost nothing to the people who need to act on it: the CISO who has to prioritize patching windows, the cloud security team assessing hypervisor exposure, or the board asking whether prior attestations about Spectre remediation were accurate.

→ Top-rated talks at 34th USENIX Security Symposium (USENIX Security '25)

All talks from 34th USENIX Security Symposium (USENIX Security '25)