Abstract
Standard compiler correctness is defined by functional equivalence between source and target code. However, this definition often ignores security-critical side effects like memory persistence and execution timing. This paper explores the "correctness-security gap," where formally verified optimizations inadvertently strip away security defenses, and proposes a path toward security-aware compilation.
Introduction
In high-assurance software development, "formally verified" compilers are often seen as the gold standard for ensuring that security-critical code is translated faithfully. However, a fundamental tension exists between performance-driven optimization and security preservation. A compiler may be mathematically "correct"—meaning the output matches the source-level logic—while being practically "insecure" by removing operations that have no functional impact but are vital for security, such as memory scrubbing.
The Compiler Pipeline and the Optimization Gap
To understand where these vulnerabilities arise, one must look at the standard compiler pipeline. Modern compilers translate source code through several layers of abstraction before producing an executable.
As shown in the figure above, the "Analysis" and "Transformation" phases are where most optimizations occur. During these stages, the compiler operates on an Intermediate Representation (IR) based on an idealized "Source Abstract Machine." This model assumes that once a function returns, its local state disappears. In reality, hardware is "messy": data persists in physical RAM or registers until explicitly overwritten. Because the compiler's model doesn't account for this persistence, it may view a command to overwrite a password (a "dead store") as redundant and delete it to save cycles.
Taxonomy of Security Failures
The research categorizes the degradation of security into three primary domains:
- Information Leaks (Persistent State): Optimizations like Dead Store Elimination (DSE) remove memory scrubbing routines. Inlining can extend the lifetime of secrets on the stack, and Code Motion might move sensitive data out of protected execution environments.
- Elimination of Defenses (Undefined Behavior): Compilers often leverage "undefined behavior" (UB) as an optimization hint. For instance, if a language standard says signed integer overflow is undefined, the compiler may assume it never happens and delete developer-inserted overflow checks, creating exploitable vulnerabilities.
- Side-Channel Introduction: Optimizations such as Common Subexpression Elimination (CSE) and Strength Reduction can alter the timing profile or power consumption of cryptographic code. While the final result remains correct, the way it is calculated reveals secret keys to an observer.
Key Insights: Functional vs. Security Equivalence
The core insight of this work is that functional equivalence does not imply security equivalence. A program that produces the correct output but leaves a secret key in a CPU register is a functional success but a security failure. The "Persistence Assumption" fallacy—the idea that local variables vanish upon function exit—is a primary driver of this gap. Furthermore, compilers can inadvertently re-introduce "gadgets" or build "weird machines" by reordering code in ways the developer never intended, providing attackers with unintended execution paths.
Conclusion and Future Directions
The correctness-security gap is not a bug in compiler implementation but a limitation of the underlying formal models. Closing this gap requires moving beyond idealized abstract machines toward "Refined Machines" that account for hardware realities like timing and persistent state.
Future work should focus on:
- Developer Annotations: Introducing keywords (e.g.,
secure) to mark code regions as off-limits for specific optimizations. - Security-Aware Testing: Creating "litmus tests" for compilers to detect when an optimization violates a security property.
- Formal Refinement: Developing models that explicitly include side-channel and persistence properties in the correctness proof.
While disabling optimizations could solve the problem, the resulting 5x performance overhead makes it impractical. The path forward lies in making compilers "security-aware" rather than just "functionally correct."
Summary updated