What is Spectre?

A class of vulnerabilities that induces mispredicted speculative execution to read secret data and infers its value from traces left in the cache.

Field: Hardware Security

Japanese name: Spectre

How a Spectre attack works

The classic bounds-check-bypass form targets code like: if (x < size) y = table[data[x] * 4096]. The attacker first calls it many times with valid x, training the branch predictor to expect the check to pass. Then the attacker supplies an out-of-range x while size is not in the cache. Waiting for size, the CPU speculatively reads data[x], which is really a secret byte elsewhere in memory, and loads the table line chosen by that byte. When the check resolves, the work is discarded, but the line remains cached; timing accesses to each table line reveals which one is fast, and therefore the secret.

Architectural vs. microarchitectural state

The instruction set architecture (ISA) promises that a mispredicted path leaves no trace in program-visible, or architectural, state: registers and memory are rolled back exactly. Microarchitectural state, such as cache contents, branch predictor tables and translation buffers, exists only for performance and is not restored. Spectre turns that hidden state into a covert channel by measuring timing differences, typically with flush-and-reload techniques. No ISA rule is broken, which is why the problem spans processors from many vendors and why it is described as a class of vulnerabilities rather than a single bug.

Spectre vs. Meltdown

Meltdown, disclosed at the same time, abused out-of-order execution in certain designs that let a user-mode load forward kernel data to dependent instructions before the permission fault was raised. It was largely fixed by separating kernel and user page tables in operating systems and then by hardware changes. Spectre instead tricks a victim into speculatively accessing memory that the victim itself is allowed to address, steering it with branch predictors. Because it relies on speculation in general, not on one implementation shortcut, it affects nearly all high-performance CPUs and has no single complete fix.

Mitigations and their cost

Software defenses insert a speculation barrier such as x86 lfence after sensitive bounds checks, or clamp indices with a mask so even speculative accesses stay in range. The branch-target-injection variant, which poisons indirect branch predictions, is countered by retpoline code sequences and by microcode and hardware controls that restrict or flush predictor state across privilege or process boundaries. Browsers reduced timer precision and isolated websites in separate processes. Each measure costs some performance, so they are applied at vulnerable points rather than by disabling speculation altogether.

Try it: questions about Spectre

What is the principle behind the speculative execution vulnerability known as Spectre?

  1. AA CPU arithmetic error changes the results of additions
  2. BInstructions executed speculatively along a predicted branch are rolled back, but their traces in the cache remain and can be read by timing measurements
  3. CSpeculative execution overheats the CPU
Show answer and explanation

Answer: B. Instructions executed speculatively along a predicted branch are rolled back, but their traces in the cache remain and can be read by timing measurements

CPUs execute instructions on the predicted side of a branch before its outcome is known and discard the results if the prediction was wrong. In Spectre, an attacker trains the predictor to mispredict, so a path that should never execute reads secret data and loads a cache location that depends on its value. The results are discarded but the cache state is not restored, so the value can be inferred through a cache side channel.

Why does information still leak in attacks like Spectre even though speculatively executed instructions are rolled back?

  1. AThe rollback fails and secret values remain in registers
  2. BSpeculative results are saved to disk
  3. COnly architectural state such as registers is rolled back; microarchitectural state such as caches is not restored
Show answer and explanation

Answer: C. Only architectural state such as registers is rolled back; microarchitectural state such as caches is not restored

CPUs are designed to fully restore program-visible state (registers and memory contents) on a misprediction. But microarchitectural state, such as cache contents and branch predictor state, is internal performance state and is not restored. The ISA contract is honored, yet internal state becomes visible from outside as timing differences; that is the essence of this class of vulnerability.

FAQ

Has Spectre been fixed?

Specific variants are mitigated by microcode, compiler and operating system changes and by hardware updates, but the underlying class cannot be eliminated without giving up speculation. Many new variants have been found since its disclosure.

What is the difference between Spectre and Meltdown?

Meltdown let user code read kernel memory by exploiting a delayed permission check in some processors, and was fixed fairly directly. Spectre misleads branch prediction so a program speculatively leaks data it can address, which makes it far broader and harder to mitigate.

Why does Spectre need a cache timing measurement?

Speculative results are discarded, so the secret never appears in a register the attacker can read. Encoding it in which cache line was loaded, and then timing loads, is how the value is recovered.

Questions that mention Spectre (3)

Spectre appears in 5 practice questions across 3 topics, including Hardware Security, Hardware Security: Advanced Topics and Trends, CPUs and architecture.

  1. Which is NOT used as a countermeasure to speculative-execution vulnerabilities such as Spectre?
  2. Which correctly pairs the descriptions of retpoline and IBRS, countermeasures against the Spectre variant that abuses indirect branch prediction (branch target injection)?
  3. Which is an example of vulnerabilities revealing attacks that exploit traces of speculative execution left in the cache to infer data that should not be accessible?

Books on Hardware Security Ad

As an Amazon Associate I earn from qualifying purchases.

This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.

Back to the glossary