14.1 How speculation is modelled and what it attacks
Every speculation side channel has the same three ingredients:
- a predictor that a less-privileged or different context can train;
- a transient window, in which the PE executes instructions it will later squash;
- a covert channel, which is microarchitectural state that the squash does not roll back and that the attacker can measure. In practice this is almost always cache residency.
The architecture describes none of the hardware involved. Predictors, reorder buffers and line-fill buffers are not in DDI0487. What the Arm ARM does define is a set of permissions and, since 2018, a short list of restrictions and barriers. This section separates the two and maps each predictor to the variant that abuses it. The hardware picture is in 6.1. Read that first if “post-commit store buffer” or “squash” are not yet concrete for you.
What the architecture says about speculation
The memory model (7.1) is defined over architecturally executed instructions, the ones that would run in a simple sequential execution of the program. Speculative execution is everything else: instructions that the PE starts and then discards. The architecture constrains speculation in a few places only.
| Rule | Status | Where it matters |
|---|---|---|
| Reads of Normal memory can be made speculatively, at any time, to any location mapped as Normal and readable in the current translation regime | Permitted | The whole cache side channel (14.2) |
| Caches can allocate a line for any Normal Cacheable location at any time, for a speculative access or a prefetch | Permitted | Covert channel, and the stale-line bugs of 8.7 |
| Translation table walks and TLB allocation can be speculative | Permitted | Speculative-AT errata (14.2), break-before-make (9.2) |
| Speculative data accesses to any Device memory type | Not permitted | MMIO safety; instruction fetch is a separate case (6.2) |
| Speculative writes becoming visible to any other observer | Not permitted | Squashed stores leave memory unchanged; they can still affect timing (v4) |
| Instruction fetch from any location that is not execute-never | Permitted, including speculatively | Device regions must be XN |
Everything else about speculation is microarchitecture. In particular, the architecture says nothing about what state a squash restores beyond architectural state. That gap is the attack surface.
After Spectre, Arm added two kinds of architectural text:
- Restrictions on the effects of speculation. These are feature-gated promises about what speculation will not do, each advertised by an ID register field. Examples are
FEAT_CSV2(branch targets trained in one hardware-described context cannot control speculation in another),FEAT_CSV3(data loaded speculatively from a location that would fault cannot be used to form a cache-timing channel, see 14.6) andFEAT_SSBS(a controllable store-bypass restriction, 14.5). The Arm ARM collects the general statements under “Restrictions on the effects of speculation” in the AArch64 application-level memory model chapter. - Speculation barriers. These are instructions with defined semantics for speculative execution:
CSDB(aHINT, so it is a NOP on older cores),SB(FEAT_SB),SSBBandPSSBB(DSB encodings),CLRBHB(FEAT_CLRBHB, aHINT, 14.4), and the prediction-restriction instructions ofFEAT_SPECRES. Ordinary barriers have no speculation semantics. ADMBorders observation and says nothing about whether a younger load executes.DSBfollowed byISBhappens to stop speculation on all known cores, and Arm documents it as the pre-SBfallback. That is guidance, not a property of DSB or ISB.
The practical rule: any mitigation must reduce to an ID-register-advertised restriction, an architectural speculation barrier, or core-specific behaviour documented by the core vendor (a TRM statement, an erratum notice or a Security Center advisory). If it is none of these, it is a guess.
Hardware-described context
The CSV2, CSV3 and SPECRES text depends on the term hardware-described context: roughly the combination of Security state, Exception level, VMID (when EL2 is enabled for that state), ASID (for regimes that use one), and, with FEAT_CSV2_2, the value of SCXTNUM_ELx. The restrictions apply between such contexts. Two consequences follow.
- The restrictions do not apply within a context. A JavaScript engine and the sandboxed script it runs share one hardware context, so CSV2 does nothing for them. That is what
SCXTNUM_ELxis for (14.7). - EL3 is its own context. On a CSV2 core, Non-secure EL1 cannot train branch targets that EL3 then uses. On a pre-CSV2 core it can, and EL3 firmware must remove the trained state on entry (14.4).
Predictor structures and the variants that abuse them
The structures below are non-architectural. Their sizes, indexing and tagging vary by core and are rarely documented in full. The mapping from structure to variant is stable across cores, though.
| Structure | What it predicts | Typical index and tag | Variant | CVE | Section |
|---|---|---|---|---|---|
| Conditional (direction) predictor | Taken or not taken for B.cond, CBZ, TBZ | PC bits, often hashed with global history | v1, bounds check bypass | CVE-2017-5753 | 14.3 |
| Branch target buffer (BTB) and indirect predictor | Target of BR, BLR, and on some cores RET | PC bits (VA), partial tag; pre-CSV2 often no context tag | v2, branch target injection | CVE-2017-5715 | 14.4 |
| Branch history buffer (BHB) | Recent taken-branch history used to select an indirect target | Global, shared across exception entry on affected cores | Spectre-BHB / BHI | CVE-2022-23960 | 14.4 |
| Return stack | Target of RET | Push on BL/BLR, pop on RET; on underflow, some cores fall back to the BTB | Return-stack attacks. Exposure is core-specific; Arm advisories treat it as part of the v2 analysis | — | 14.4 |
| Memory disambiguation (store-to-load forwarding prediction) | Whether a load may execute before an older store with an unresolved address | Load PC | v4, speculative store bypass | CVE-2018-3639 | 14.5 |
| Fault deferral in the load pipeline | Not a predictor: a permission or translation fault is raised at commit, not when data returns | — | v3 (Meltdown), v3a (rogue system register read) | CVE-2017-5754, CVE-2018-3640 | 14.6 |
| Sequential fetch past unconditional control flow | That RET, BR, ERET, SVC and so on fall through | — | Straight-line speculation (SLS) | CVE-2020-13844 | 14.2 |
Read the table as a set of questions for a code review:
- Can the attacker steer a branch direction? (v1)
- Can the attacker choose a target, either directly or through history? (v2, BHB)
- Can a load run ahead of a store that should have overwritten its source? (v4)
- Does a faulting load forward data before the fault is taken? (v3, v3a)
Different questions need different fixes, and a fix for one does nothing for another. CSDB does not touch the BTB, and CLRBHB does not stop store bypass.
The covert channel: why the cache
A transient instruction can only leave measurable traces in shared microarchitectural state. The usual channel is L1D or LLC residency:
/* the transient gadget: two dependent loads */
uint8_t secret = *(volatile uint8_t *)victim_ptr; /* transient read */
(void)probe[secret * 64]; /* transient fill of one line */
/* the attacker, afterwards, architecturally */
for (int i = 0; i < 256; i++)
t[i] = time_load(&probe[i * 64]); /* the fast one reveals 'secret' */
The first load reads the secret. The second turns it into an address, and the cache fill for that address survives the squash. The attacker then times loads to find which line is now resident:
- Flush+Reload, when the attacker and victim share memory. On AArch64, EL0 can flush by VA with
DC CIVACwhenSCTLR_EL1.UCI=1, which Linux sets. - Prime+Probe, when they do not. The attacker fills a cache set and watches for evictions.
Other channels exist: TLB state, prefetcher training, port contention and DRAM row buffers. They are slower and noisier, and the mitigations in this part do not depend on which one is used. Taking away the timer does not help either. CNTVCT_EL0 can be trapped or coarsened, but a counting thread on another core works as a timer.
So the gadget a reviewer looks for is a load whose address depends on data obtained speculatively, reachable in a transient window. One load alone leaks nothing through the cache. The data has to reach a second address-forming operation. That is why the masking patterns in 14.3 work: they break the dependency, not the load.
Security note: “Transient” includes the window after a mispredicted exception return path, after an
SVCorSMCthat the front end did not recognise as a control-flow change, and after anERET(SLS). EL3 code that doesERETand then has data-dependent loads in the following bytes, for example a literal pool or the next function, has a gadget even though those bytes are never architecturally executed. TF-A follows everyERETwith a speculation barrier for this reason (14.2).
How the variants map onto a TEE threat model
For EL3 and S-EL1/S-EL2 firmware, the attacker is normally Non-secure EL1 (a compromised kernel) or EL0 calling through it. The secrets are Secure-world keys and memory.
| Variant | Attacker trains | Victim runs | Firmware role |
|---|---|---|---|
| v1 | Branch directions, through repeated in-bounds SMC arguments | Bounds-checked table lookups in an SMC or TA handler | Mask indices in handlers (14.3) |
| v2 / BHB | BTB or BHB from NS-EL1 | EL3 or S-EL1 indirect branches (handler tables, function pointers) | Vector-entry mitigation, SMCCC_ARCH_WORKAROUND_1/3 (14.4) |
| v4 | Not a training attack: the bypass happens in the victim’s own code | Store-then-load sequences on attacker-influenced data | SSBS or chicken bits, SMCCC_ARCH_WORKAROUND_2 (14.5) |
| v3 / v3a | Nothing: the attacker reads directly | — | Firmware mostly unaffected; KPTI is an OS problem (14.6) |
| Cross-world prediction residue | Predictors shared across a world switch | The other world | FEAT_SPECRES on context switch (14.7) |
Validation note: Mitigations are validated by disabling them and checking that the attack signal appears, then enabling them and checking that it disappears. A test that passes with the mitigation enabled but never showed a signal without it proves nothing. Measure the signal on silicon or cycle-accurate RTL, because FVP and QEMU do not model predictors or cache timing. The PMU gives a lower-noise oracle than raw timing. Count
BR_MIS_PRED(0x10) andBR_PRED(0x12) to confirm that training actually happened,INST_SPEC(0x1B) againstINST_RETIRED(0x08) to confirm that a transient window opened, andL1D_CACHE_REFILL(0x03) on the probe array to see the fill without timing noise (16.5). Event availability beyond the common set is IMPLEMENTATION DEFINED; checkPMCEID0_EL0/PMCEID1_EL0.
Checkpoint
Q14.1.1 A reviewer argues: “This EL3 handler has a bounds-checked load, then DMB ISH, then a second load that uses the first value as an index. The DMB orders the loads, so there is no Spectre v1 gadget.” What is wrong with the argument?
- A. Nothing. A DMB prevents younger loads from being issued until older loads complete.
- B. The DMB needs to be a
DMB SY. An Inner Shareable barrier does not cover EL3. - C. A DMB constrains the order in which architecturally executed accesses are observed. It has no defined effect on whether younger instructions execute speculatively, so both loads can still run in the transient window.
- D. The argument is right only for Device memory, where the DMB also prevents speculative reads.
Answer
C. Ordinary barriers are defined in terms of observation order between architecturally executed accesses. They carry no speculation semantics. A core can execute the younger load speculatively and later make the outcome appear ordered, while the cache fill survives the squash. Only CSDB, SB, SSBB/PSSBB, CLRBHB and the SPECRES instructions have defined speculation effects, and DSB+ISB is a documented fallback rather than an architectural guarantee. A is the common misconception that DMB stalls issue. D confuses the Device-memory no-speculation rule, which is a property of the memory type, with a property of the barrier.
Read more: Arm ARM (DDI0487), Restrictions on the effects of speculation; Data Memory Barrier (DMB)
Q14.1.2 A core reports ID_AA64PFR0_EL1.CSV2 = 1. A browser JIT at EL0 runs untrusted script and its own trusted runtime in the same process. Is the runtime protected from branch-target injection by the script?
- A. No. CSV2 restricts branch-target training only between hardware-described contexts, and the script and runtime share EL, Security state, ASID and VMID. Separating them needs
SCXTNUM_EL0withFEAT_CSV2_2, or a software mitigation. - B. Yes. CSV2 means the BTB is tagged with the full VA, so aliasing between script and runtime is impossible.
- C. Yes, as long as the runtime is mapped with
PXN. - D. No, because CSV2 applies only to EL1 and above.
Answer
A. CSV2 is a restriction between hardware-described contexts. Within one context, branch-target training is still allowed to influence speculation. FEAT_CSV2_2 adds SCXTNUM_ELx to the context, so software can create sub-contexts (14.7). B describes a possible implementation, but the architecture promises nothing about tagging. D is wrong because CSV2 covers EL0 contexts too, distinguished by ASID.
Read more: Arm ARM (DDI0487), ID_AA64PFR0_EL1.CSV2; SCXTNUM_EL0
Q14.1.3 Which code fragment is the minimal cache-channel Spectre gadget, assuming x1 is attacker-controlled and the code runs inside a transient window?
- A.
ldr x2, [x0, x1]alone - B.
ldr x2, [x0, x1]followed bystr x2, [sp] - C.
ldr x2, [x0, x1]followed bycmp x2, #0 - D.
ldrb w2, [x0, x1]followed byldr x3, [x4, x2, lsl #6]
Answer
D. The leak needs the speculatively read value to form a second address, so that the line filled by the second load encodes the secret. A brings the secret into a register, but the only line touched is the one at an attacker-chosen address, which the attacker already knows. B’s store never leaves the core speculatively. C can leak through branch timing only if a dependent branch follows, which is a different and weaker channel.
Read more: Arm whitepaper “Cache Speculation Side-channels”; Arm ARM (DDI0487), Restrictions on the effects of speculation