A Formal Approach to Secure Speculation

Kevin Cheang, Cameron Rasmussen, Sanjit A. Seshia, Pramod Subramanyan

Abstract

Transient execution attacks like Spectre, Meltdown and Foreshadow have shown that combinations of microarchitectural side-channels can be synergistically exploited to create side-channel leaks that are greater than the sum of their parts. While both hardware and software mitigations have been proposed against these attacks, provable security has remained elusive. This paper introduces a formal methodology for enabling secure speculative execution on modern processors. We propose a new class of information flow security properties called trace property-dependent observational determinism (TPOD). We use this class to formulate a secure speculation property. Our formulation precisely characterises all transient execution vulnerabilities. We demonstrate its applicability by verifying secure speculation for several illustrative programs.

What Problem Does This Paper Address?

Modern processors rely on speculative execution to maintain high performance. By guessing the outcome of conditional branches and executing instructions ahead of time, CPUs avoid idling while waiting for slow memory operations. If the guess is correct, the processor gains a significant speed boost. If the guess is wrong—a "misspeculation"—the processor discards the results, reverting the architectural state (registers and memory) to a known good point.

However, transient execution attacks like Spectre exploit a critical flaw: while the architectural state is reverted, the microarchitectural state—specifically the CPU cache—is not. An attacker can trick the processor into speculatively executing a "wrong-path" instruction sequence that accesses sensitive data. Even though the results are never committed to registers, the access leaves a footprint in the cache that the attacker can later measure via timing side-channels.

The four stages of a typical transient execution attack.

The fundamental challenge in securing these systems is that traditional security models, such as non-interference, are overly restrictive. They demand zero information leakage, which is practically impossible for modern software running on shared hardware. Disabling speculation entirely to achieve this goal would result in performance penalties of up to 50%. Consequently, researchers need a formal way to prove that speculation does not introduce new vulnerabilities beyond those already present in a program's normal execution.

Methods: Formalizing Secure Speculation

To address this, the authors introduce a formal framework centered on a new security property: Trace Property-Dependent Observational Determinism (TPOD).

The TPOD Hyperproperty

TPOD is a hyperproperty that reasons about four different execution traces simultaneously. It formalizes the concept of "relative security." Instead of asking if a program is perfectly secure, TPOD asks: "If two standard (non-speculative) runs of a program are indistinguishable to an observer, are their speculative counterparts also indistinguishable?" If speculation causes two runs that should look the same to look different, a new vulnerability has been introduced.

Speculative Operational Semantics (AIR)

To model these attacks, the authors developed AIR (Assembly Intermediate Representation). Unlike standard instruction set models, AIR explicitly tracks "speculation levels" and models the behavior of branch predictors. This allows the framework to capture how an adversary can "mistrain" the hardware to trigger specific misspeculation events.

A detailed trace of a Spectre-style attack, illustrating how misspeculation leaves a measurable footprint in the cache.

Automated Verification Toolchain

The methodology is implemented in a toolchain that automates the security proof process:

  1. Lifting: C code is compiled to x86 and then lifted into a formal intermediate representation using the BAP (Binary Analysis Platform).
  2. Modeling: The lifted code is translated into UCLID5, a formal verification modeling language.
  3. Solving: The tool uses SMT (Satisfiability Modulo Theories) solvers to either find a concrete exploit (a counterexample) or provide a mathematical proof that the code is secure, often after the insertion of mitigations like lfence instructions.

Key Results and Insights

The authors evaluated their tool against Paul Kocher’s Spectre benchmarks—a standard suite of 15 victim functions. The results demonstrated both high precision and efficiency:

  • Precision: The tool identified vulnerabilities in benchmarks that other state-of-the-art tools missed. It also correctly identified "conditionally vulnerable" code, where an exploit only exists under specific semantic conditions (e.g., when a variable N is zero).
  • Performance: Verification is remarkably fast. For the tested benchmarks, the tool could either find an exploit or verify a fix in under 13 seconds on a standard laptop.
  • Semantic Awareness: The tool proved that some common "fixes," such as moving a fence instruction to a different line, remained insecure, highlighting the danger of relying on human intuition for complex microarchitectural security.

Limitations and Future Work

While a significant step forward, the current model has limitations. It primarily focuses on in-order execution and direct conditional branches (Spectre v1). It does not yet fully account for the complexities of out-of-order execution or indirect jumps (Spectre v2). Furthermore, while the tool is effective for small "gadgets," scaling formal verification to massive codebases like the Linux kernel remains an open challenge. Future work aims to extend the AIR semantics to include more complex features like memory address disambiguation and return address stacks.

Summary updated

BibTeX
@inproceedings{cheang2019formal,
  author = {Kevin Cheang and Cameron Rasmussen and Sanjit A. Seshia and Pramod Subramanyan},
  title = {{A Formal Approach to Secure Speculation}},
  booktitle = {CSF},
  year = {2019},
  doi = {10.1109/csf.2019.00027},
}
Figure