Manuscript Offprint
arXiv:2610.39374DualGuard: Comprehensive and Efficient Memory Safety across Sequential and Speculative Execution
Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.
Artifact Evaluated NDSS Available Functional Reproduced
DUALGUARD: Comprehensive and Efficient Memory Safety across Sequential and Speculative Execution
Sixuan Dang Duke University sixuan.dang@duke.edu
Quan Zhou Google quanzhour@google.com
Kaiming Huang Penn State University kzh529@psu.edu
Jianan Zhu UC Riverside jzhu218@ucr.edu
Anitha Gollamudi University of Massachusetts Lowell anitha_gollamudi@uml.edu
Trent Jaeger UC Riverside trentj@ucr.edu
Danfeng Zhang Duke University danfeng.zhang@duke.edu
Abstract—Although decades of research have yielded sophisticated mechanisms for enforcing memory safety, speculative execution can subvert these protections through transient memory operations. Conversely, defenses designed specifically for speculative safety, such as Speculative Load Hardening (SLH), cannot enforce memory safety during non-speculative execution. A naive combination of defenses from both domains raises two fundamental challenges: (1) which combination of otherwise fragmented defenses can ensure dual memory safety under speculative and non-speculative executions? (2) whether such combinations introduce redundant protections that incur unnecessary performance overhead?
We present DUALGUARD, a unified framework for dual memory protection under non-speculative and speculative executions. DUALGUARD systematically analyzes memory behaviors, classifying them into four categories, and further identifies the minimal composition requirements for dual memory safety, which allow us to strategically combine existing mitigations and design new ones to avoid redundant or excessive protections. We implement DUALGUARD through a combination of static analysis and runtime enforcement within the LLVM infrastructure. Our evaluation demonstrates that DUALGUARD reduces overhead by 3%–72% compared to naive compositions of fragmented defenses. In some cases, it even incurs lower overhead than approaches that guarantee memory safety solely under either non-speculative or speculative execution.
of exhaustive checks associated with those schemes, several defense schemes utilize static program analysis to identify and remove redundant checks [15], [16], [17]: they place checks only at operations whose memory-safety cannot be proven. To further reduce overhead, QuickSafe [18] isolates memory objects associated with a known exploit from the rest of the program. These schemes ensure that programs under sequential execution (i.e., architecturally committed or non-speculative) adhere to memory safety constraints.
However, such memory-safety assurance is undermined by advances in modern processors, namely, speculative execution. Originally introduced to improve hardware performance through branch prediction and out-of-order execution, speculation has been proven to be an insidious source of transient execution vulnerabilities. Attacks like Spectre [19] and Melt-down [20] exploit instructions that are speculatively executed to induce new memory errors that are absent in sequential execution. Consider the following code snippet (known as an instance of Spectre attack variant 1):
The code snippet has no memory error during sequential execution, as is always bounded by . But a speculative memory error which reads beyond 's bound can occur when the CPU mispredicts the branch outcome and executes speculatively. Although these speculative reads never affect architectural state (like registers and RAM), they can change microarchitectural state such as caches (e.g., which element of is fetched into cache), which can reveal the value accessed speculatively. In light of Spectre attacks, more recent works have revisited memory safety in the context of speculative execution and revealed more attack surfaces due to speculative memory errors [21], [22], [23], [24].
Despite a substantial body of work on memory safety in the context of sequential execution, and growing interest in its treatment under speculative execution, prior work often implicitly assumes that memory safety mechanisms designed for sequential execution can be directly composed with spec-
Network and Distributed System Security (NDSS) Symposium 2027 22–26 March 2027, Seoul, Republic of Korea ISBN 978-1-970672-09-1 https://dx.doi.org/10.14722/ndss.2027.232195 www.ndss-symposium.org ulative defenses. However, as we argue in this paper, this “mitigation-upon-mitigation” approach result in a fragmented protection landscape characterized by two primary limitations:
-
A naive composition of defenses from these two domains does not necessarily yield both sequential and speculative memory safety, which we term dual memory safety in the paper. For example, applying branch-based memory-safety mechanisms like Baggy [2] either before or after SLH-based defenses remains insecure under speculative execution, as they introduce additional memory safety issues during speculative execution (Section II-D).
-
A naive combination of defenses from each category can also incur unnecessary overhead. Consider the code below, where a mask-based defense for sequential execution is applied to safeguard accesses to arrays A and B:
where arrays A and B have size of 8. The code is already safe under speculative execution. However, speculative defenses (including those that selectively mitigate speculative memory errors [25], [26], [27]) still adds redundant protections that incur unnecessary performance overhead.
This paper presents the first systematic study of the interaction between sequential and speculative spatial memory errors: it develops both the theoretical foundations for reasoning about dual memory safety, and practical safety mechanisms that are efficient and dual memory safe. In particular, we tackle the following two critical research questions:
-
Q1: Which combinations of otherwise fragmented defenses for sequential and speculative memory safety can ensure dual memory safety?
-
Q2: How do we achieve dual memory safety without introducing redundant protections that incur unnecessary performance overhead?
Our work builds on a rigorous formal framework (Section IV) that associates each program location with a violation region, defined as the set of out-of-bounds memory accesses that may originate from that location. We further refine this notion by classifying vulnerable accesses within each violation region as sequential-only, speculative-only, or both. This classification isolates the minimal conditions required to prevent each class of memory error.
To address Q1, we model spatial memory-safety mechanisms as rewriting systems whose goal is to eliminate the violation regions associated with each command. We then identify a key property necessary to achieve dual safety, which we term safety preservation. Informally, a sequential (resp. speculative) memory-safety mechanism is safety-preserving if it does not introduce new speculative (resp. sequential) violations. We formally prove that, given two sound memory-safety mechanisms drawn from each domain, applying a safety-preserving mechanism after the other always yields dual memory safety. This constitutes the first theoretical contribution of the paper.
To address Q2, we further establish that when both the sequential and speculative mechanisms are sound and safety-preserving, a selective composition strategy becomes feasible.
Specifically, the sequential (respectively, speculative) memory-safety mechanism can be safely omitted at program locations that are initially free of sequential (respectively, speculative) memory violations when the corresponding mechanism is applied subsequently. This result enables more efficient compositions while preserving dual memory safety, and constitutes the second theoretical contribution of this work.
Building on these theoretical insights, we analyze the safety properties of a wide variety of mechanisms from the sequential and speculative domains, including Baggy bounds [2], Delta Pointers [5], SafeStack [6], SLH [28], SpecASan [29], and CHERI [30]. We show that while SafeStack and SLH are safety-preserving, Baggy and Delta Pointers are not (either due to additional branches introduced by code rewriting or underlying hardware enforcement that is unsafe under speculative execution). As a consequence, it is unsafe to apply Baggy and Delta Pointers after speculative defenses. To the best of our knowledge, this is the first systematic study of existing mechanisms for dual memory safety. Moreover, we develop novel variants of Baggy and Delta Pointers, termed DUALBAGGY and DUALDELTAPointers, respectively, which we prove to be dual memory safe by themselves.
Finally, we implement a dual memory safety tool DUALGUARD (Section VI). DUALGUARD employs a static program analysis to systematically identify sources of sequential and speculative spatial memory violations at compile time and then applies dual-memory-safe mechanisms, including the novel DUALBAGGY and DUALDELTAPointers mechanisms, selectively to each class of violation regions, thereby eliminating redundant checks. We evaluate DUALGUARD on standard security and performance benchmarks, as well as real-world cryptographic libraries (Section VII). The results demonstrate that DUALGUARD reduces overhead by 3%–72% compared to naive compositions of fragmented defenses. In some cases, it even incurs lower overhead than approaches that guarantee memory safety solely under either sequential or speculative execution.
In summary, this work makes the following contributions:
-
We develop a rigorous formal framework (Section IV) that reasons about the interaction between sequential and speculative spatial memory errors, as well as key properties that enable safe composition (Section V-A).
-
We present the first systematic analysis of dual memory safety across existing sequential and speculative defenses (Section V-B) and develop novel dual-memory-safe variants of Baggy Bounds and Delta Pointers (Section V-D).
-
We implement DUALGUARD (Section VI) that automatically hardens source code to enforce dual memory safety. We evaluate DUALGUARD using an extensive benchmark suite of programs (Section VII).
II. BACKGROUND AND THREAT MODEL
A. Memory Safety
Violations of memory safety are commonly divided into two categories: spatial and temporal errors.
Spatial memory errors occur when a memory access reads or writes to an address outside of the object's allocated memory bounds. Spatial memory errors remain one of the most prevalent and reliably exploitable classes of software vulnerabilities, which can lead to threats such as buffer overflows and Heartbleed [13], [14].
Temporal memory errors occur when a memory access reads or writes to an address at a wrong time (e.g., when the address has been deallocated and repurposed). Temporal memory errors can lead to use-after-free bugs, using uninitialized values, and so on.
In this paper, we focus on spatial memory safety, both due to its importance for security, and the fact that it is an important component that enables Spectre-like attacks. Many widely adopted memory safety mechanisms are designed for spatial memory safety as well. For example, mechanisms like bounds checking [2], [3], [4], [5], software fault isolation (SFI) [6], [7], and hardware-assisted enforcement [31], [32], detect and prevent illegal pointer dereference during non-speculative execution [33].
B. Memory Errors under Spectre v1
Among various Spectre and Meltdown attack variants [34], a notable class targets the branch prediction unit to circumvent branch-based bounds checking. These attacks, known as "Spectre v1" attacks, typically utilize full gadgets that speculatively access out-of-bounds memory and subsequently leak it through microarchitectural side channels. For instance, the well-known Spectre attack [19] employs gadgets such as if (x < A_size) { y = B[A[x] * 4096]; } to speculatively load memory beyond the bounds of array A. The resulting access to array B modifies a specific cache line that encodes the out-of-bounds value into the cache state. Since the processor does not rollback changes into cache state, an attacker can subsequently infer the secret data via a cache side channel.
While a full gadget combines an out-of-bound memory access and a cache side channel to reveal secret data, other speculative attacks also exploits half gadgets, which only consist of out-of-bound memory accesses. For example, half gadgets can be coupled with other microarchitectural attacks like Rowhammer [35] to reveal the out-of-bounds value [36], where half gadgets are used to monitor physical memory activity and guide fault injection. In addition, prior works [37], [21] utilize out-of-bounds memory writes to launch speculative return-oriented programming (ROP) attacks.
C. Threat Model
DUALGUARD aims to provide spatial dual memory safety across sequential and speculative execution. We adopt a threat model that is consistent with prior research on both memory safety under sequential execution [2], [38], and security countermeasures against Spectre v1 attacks [39], [25], [40].
More specifically, we consider traditional spatial memory safety violations, such as out-of-bound pointer dereferences or invalid memory accesses that occur during sequential execution. Spatial memory safety violations are also the root cause
of Spectre v1 vulnerabilities. On the other hand, following prior studies of memory safety [38], [41], we leave temporal memory errors (e.g., use-after-free) for future work, as they are orthogonal to Spectre attacks.
For speculative execution, we assume an adversary who is capable of fully exploiting speculative program execution, including controlling branch prediction unit to step into an arbitrary branch at a branching instruction, and provide untrusted inputs that affects which memory address is being accessed speculatively. While most prior works [27], [40] also assume that only a cache-based side channel that can reveal out-of-bounds values (i.e., they only consider full-gadgets), we consider a stronger threat model where all transient memory accesses might be exploited (e.g., via Rowhammer attacks [36] or ROP attacks [37], [21]), including those where no immediate cache-based side channels exist after the speculative memory access. In other words, our threat model considers both full and half Spectre gadgets (Section II-B).
Finally, our threat model covers Spectre v1 (bounds check bypass) attacks. Other variants, including Spectre v2 (BTB poisoning) [42], Spectre-RSB [43], Spectre v4 (speculative store bypass) [39], as well as Meltdown attacks [20], are out of the scope in this paper. We discuss possible future directions beyond the scope of this paper in Section VIII.
D. Motivation
Next, we demonstrate why a naive composition of fragmented defenses for memory safety does not achieve sound and efficient dual memory safety. We take Baggy bounds checking [2] as an example of sequential memory-safety mechanism, and SLH [28] as a speculative-safety mechanism.
Consider the following code snippet.
if (x < 9) { y = A[x]; }
Assume the size of array A is 8. Since the code may access A [8] due to the incorrect bounds check, the code is memory unsafe during sequential execution. Moreover, with speculative execution, an attacker can also perform out-of-bounds access by manipulating the branch predictor.
When both Baggy and SLH are available, one can compose them in either order, with SLH applied before Baggy or vice versa. However, we show that both composition orders are unsafe, and a naive composition results in redundant layers of protection and hence, unnecessary performance overhead.
a) SLH first, then Baggy: SLH thwarts Spectre-like attacks by (1) introducing data dependency between the branch condition and the access to the array A, and (2) masking the index to the array A. With SLH, the code is hardened as:
if (x < 9) { mis = x < 9 ? 0 : -1; addr = &A[x]; hardened_addr = addr | mis; y = load(hardened_addr); }
Here, mis is a dedicated register tracking the mis-speculation status: it stores all-one bits under misprediction, and all-zero bits otherwise. The address of A[x] is hardened by operation
OR between the computed addresses and mis. Therefore, if the prediction is correct, addr | 0 preserves addr; otherwise, every bit is set to 1, resulting in an invalid address reserved by SLH.
Then, Baggy introduces new branches to protect against sequential memory errors: it rewrites the memory access to:
1 addr = &A[x]; 2 log_size = size_table[A >> log_slot_size]; 3 if ((addr XOR A) >> log_size != 0) 4 addr = slow_path(A, addr); 5 y = load(addr);
Here, Baggy introduces a new array access at Line 2, which never goes out of bounds. The reason is that the size table it indexes into has a size of memory_size/slot_size, where slot_size is a fixed constant. Due to the right shifting operation, the introduced array access is always spatially safe.
The branch introduced by Baggy at Line 3, however, is not speculatively safe: it may be mispredicted, allowing an attacker to speculatively reach Line 5 despite Baggy's check at Line 3. Moreover, slow_path itself contains conditional branches to determine whether an error is repairable, which are also speculatively unsafe, and further enlarge the attack surface.
b) Baggy first, then SLH: When reversing the composition order, the combination may initially appear dual safe, as the branching instructions introduced by Baggy are mitigated by SLH, thereby removing the attack surface discussed above.
However, this composition is still not dual memory safe due to a more subtle vulnerability. Specifically, Baggy relies on canonical address checks, a hardware-level safety mechanism in modern CPUs, to reject accesses to invalid addresses. Recent work has demonstrated that such checks can be bypassed under speculative execution (e.g., CVE-2020-12965) [44]. Consequently, the composition of “Baggy then SLH” remains unsafe under speculative execution, as SLH does not enforce protections for canonical address checks.
c) Performance overhead: Beyond the security concerns above, a naive composition of fragmented memory safety defenses may introduce redundant or excessive protections, particularly given that these mechanisms already incur nontrivial performance overheads when deployed independently. For instance, on a cryptographic library benchmark, we observe that composing off-the-shelf Baggy with SLH results in up to 10X slowdown (Section VII-C).
In summary, naive composition of existing defense mechanisms for sequential and speculative memory safety does not necessarily provide the desired safety guarantees. Moreover, the resulting performance overhead is often prohibitive, limiting the practicality of such approaches for real world software.
III. RELATED WORK
A. Memory Safety in Spectre Era
In light of Spectre attacks, several works have revisited memory safety in the context of speculative execution: they analyze how speculative behaviors can invalidate existing memory safety mitigations [21], [22], [23], [24], [29]. For example, PACMAN [23] and TikTag [24] show that speculative execution could break ARM pointer authentication (PA) and memory tagging extension (MTE), leading to control flow hijacking. BlindSide [22] uses memory errors to break Address Space Layout Randomization (ASLR) mechanisms via speculatively probing randomized memory layout without crashing the system. SPEAR [21] aims to bypass stack canary, CFI and bounds check in GO [45]. These works focus primarily on how speculation undermines prior memory-safety defenses. However, they ignore the fact that speculation itself could introduce extra memory errors that are not exposed during sequential execution. As a consequence, they often suggest layering speculative safety mechanisms (Section III-B) on top of traditional ones, creating potentially unsafe and redundant protection stacks [46], [29] that DUALGUARD aims to identify and remove.
DUALGUARD re-examines the interaction between memory safety and speculative execution from a unified perspective. Rather than treating speculative safety as a retrofit to existing memory safety systems, it integrates both domains into a systematic view of when and where protection is truly necessary.
B. Defenses against Spectre VI Attacks
Since the seminal work of Spectre [19], both academia and industry have proposed a broad spectrum of defenses [34]. Most related to this paper are software-based defenses, which fall into three categories.
Architectural primitives such as LFENCE [47], IBRS [48], or ARM's CSDB [49] initialize instructions to disable speculation completely. While effective when carefully placed, pervasive use of these primitives incurs prohibitive overhead.
Observing the prohibitive overhead of disabling speculation completely, defense mechanisms like ones based on LAHF instruction [50] and Speculative Load Hardening (SLH) [28] introduce artificial data dependencies between branch conditions and subsequent memory operations to ensure that speculative accesses cannot touch sensitive data before branch resolve. Notably, SLH [28] was implemented in LLVM since version 8. To reduce the overhead of SLH, several optimized variants have been proposed, limiting instrumentation to necessary control flows only [26], [27], [25]. While these selective and lightweight variants share the same objective of removing unnecessary protection as DUALGUARD, they do not protect against sequential memory errors.
IV. FORMALIZING MEMORY ERRORS
Our goal is to provide dual memory safety. A central challenge in achieving this goal is the need to precisely reason about both sequential and speculative memory behaviors, as well as their interactions. To address this challenge, we first define a small imperative language together with a formal semantics that captures both sequential and speculative memory errors. We then introduce a classification of memory behaviors into four categories, presenting each both informally and formally. This categorization provides a theoretical foundation for reasoning about dual memory safety (Section V).
Expressions
Boolean Expressions
Command
Fig. 1: Language syntax. and represent binary arithmetic and comparison operations respectively.
A. Language Syntax
Following prior work [51], we consider a simple imperative language whose syntax is defined in Figure 1. An expression can be a constant , a variable , a pointer arithmetic (where is an address computed with a base address and an offset ), or a binary arithmetic operation on two expressions. The language captures assignment, branching, sequential composition, and memory operations in the form of and . Since by definition may contain a memory access operation , both memory loads and stores are modeled in the language syntax, and it supports nested array access like . We select a source-level language for formalization because of its readability and simplicity. Our code analysis is conducted on lower-level intermediate representation code, as detailed in Section VII.
B. Semantics
Memory model. We model the memory state as a mapping from memory addresses to the values stored at those addresses. Additionally, we define a global range as a mapping from memory objects to the allocated memory regions , which are sets of continuous memory addresses that are considered safe for to access. For instance, a fine-grained object-level memory safety mechanism, such as Baggy [2], defines the range of an object as , where represents the base address of the object and denotes its allocated size. A coarse-grained memory safety mechanism, like SFI [6], specifies the range of an object as , where is the sandbox that the object resides within, and and represent the base address and size of the sandbox , respectively.
Program state. Following [51], [52], the speculative-aware language semantics is parameterized on a global prediction oracle, , a partial function that takes the location of a branch command and returns a queue of predicted branch outcomes (i.e., a queue of truth values). Moreover, it assumes a fixed transaction window size , modeling the size of the reordering buffer in processor. Speculatively executed instructions are executed under a speculative transaction [52], which is ultimately either committed (when the prediction is correct) or rolled back (when the prediction is incorrect).
Each transaction tracks information like the memory state and command to resume in case of a rollback. Since the rest of the paper does not depend on its precise definition, we leave the full definition in the Appendix.
We define program state as a tuple that consists of a memory state , a sequence of (potentially nested) speculative transactions as well as , the remaining program to be executed. A single-step evaluation rule has the form of:
where event consists of (1) begin, rollback, and commit, which denote the start, rollback, and commit of the th transaction respectively, and (2) load (a[n]) and store (a[n]) indicate the loading and storing of memory address at program location . Given a global prediction oracle and a fixed window size, the semantics is deterministic and yields a single execution trace that captures both the sequential and speculative behaviors of the program. Since the semantics mostly follows prior work [51], we omit the evaluation rules here and formalize them in the Appendix.
Speculative traces and trace projection. An execution of the entire program generates a trace of events, which consist of both memory operations and speculative transaction labels (i.e., begin, rollback, and commit) around those operations. Let represent a program and represent an oracle that describes the behavior of a branch predictor. We write to represent that a trace is generated from an initial state given an oracle .
For instance, consider a code snippet:
1 if (x < 8)
2 y = A[x];
3 else
4 y = A[0];
Assume we have size and in the initial program state . With an oracle that always mispredicts a branch [52], the speculative trace of this program is
From the trace, it is evident that causes a memory error, but only under speculative execution.
To analyze the sequential and speculative behaviors of a program's execution, as well as their interactions, we extract two projections from : sequential and speculative projections.
Definition 1 (Sequential Projection). The sequential projection of a trace , written as , is the longest subsequence of trace , excluding all rolled-back speculative transactions, i.e., all operations enclosed by a matching pair of begin and rollback.
In the example above, the sequential projection is computed by removing the speculative transaction between begin and rollback, resulting in . The sequential projection corresponds exactly to the trace that is produced by executing the program under sequential semantics.
Definition 2 (Speculative Projection). A speculative projection of a trace , written as , is the complement of sequential projection , i.e., the longest subsequence of trace with operations enclosed by a matching pair of begin and rollback.
In the example above, we have , indicating that the memory error due to out-of-bound access is only executed under a mis-prediction.
Note that the trace projections above only classify each memory access to be either sequential or speculative. However, for developing memory safety mechanisms, we are more interested in whether each program location can produce sequential memory errors, speculative memory errors, or both. We develop such categorizations on memory locations next.
C. Categorization
To reason about the memory-related behavior of each program location, we write to denote all possible sequential executions of (i.e., ), and to denote its complement (i.e., executions of under speculation). Note that by definition, both and consist of a set of memory accesses in the form of or , where is the program location that issues the memory access to .
For each program location , we define its Access Set in trace as the set of all memory loads and stores issued by :
Definition 3 (Access Set). Given a program location l, its access set (A) in a program execution trace is:
Note that access set is defined on any execution trace , which consists of both sequential and speculative memory accesses, as well as their combinations. Moreover, if a program location l can legally index into multiple objects (e.g., via pointer aliasing), the definition includes all memory accesses to those objects.
Next, we define memory access that might violate memory safety at each program location.
Definition 4 (Sequential Violation Region). A sequential violation region of a program location , , is the set of memory addresses that can access out-of-bounds during sequential execution.
Definition 5 (Speculative Violation Region). A speculative violation region of a program location , , is the set of memory addresses that can access out-of-bounds during speculative execution.
Next, we formally categorize each program location into one of the four categories based on whether its violation regions are empty. Although the categorization appears straightforward, it serves as a formal foundation for identifying the minimal requirements on each program location to achieve dual memory safety, which we elaborate in Section V.

Fig. 2: Categorization of memory behaviors
1 y = A[3]; 2 if (i < 8) 3 y = A[3];
(a) Always safe
1 i = 10; 2 if (i < 8) 3 y = A[i];
(c) Safe, Unsafe
1 y = A[i]; 2 if (i >= 8) 3 y = A[i]
(b) Unsafe, Safe
1 i = 0; 2 while (i < 10) 3 y = A[i]; 4 i = i + 1;
(d) Both unsafe
Fig. 3: Motivating examples, where the size of array A is 8.
Definition 6 (Categorization). Given a program location l, categorization (C) is a mapping that classifies l into one of the four categories, , , and , where S stands for safe, and U stands for unsafe.
Intuitively, the categorization classifies each memory-accessing location l into one of four regions shown in Figure 2.
• : dual memory safe.
• : sequentially unsafe but speculatively safe.
• : sequentially safe but speculatively unsafe.
• : sequentially unsafe and speculatively unsafe.
We use the examples in Figure 3 to elaborate on each category. For all examples, assume array A has a size of 8.
Case . Figure 3a shows an array access using a constant index that is smaller than the array size. Both memory reads at Line 1 and 3, which are under a branch, are always memory safe as the index is set to 3. The intuition can be confirmed with Definition 6, as violation regions , , and are all empty. Since the code is always safe, no memory-safety defense is required.
Case . One instance of is an out-of-bound access that occurs only under sequential execution, such as when the execution is not under any branches. Figure 3b presents a contrived yet more interesting and counterintuitive example where the access is guarded by a branch.
When non-negative is smaller than 8, both the sequential and speculative executions read which is memory safe. However, when , say 10, the sequential execution reads twice, which is out-of-bound, while the speculative execution does nothing after the first access at Line 1. We can see this more clearly with its execution trace under the always-mispredict oracle:
For this trace, , which are both out of bound, and . Hence, for or 3, we have and . So both Line 1 and 3 are categorized as . As for defense, such program locations require sequential memory safety defenses at minimum, given that the defensive instrumentation itself does not introduce additional memory-safety violations (Section III-A).
Case . This category includes classic Spectre v1 attacks, where out-of-bound memory access only occurs under a misprediction. Figure 3c shows a code snippet where the array access A[i] is guarded by a bounds check at Line 2. Under sequential semantics, the access at Line 3 is never reached and thus free from memory errors. But with speculative execution, Line 3 can be speculatively executed and access A[10], which is out-of-bounds. We can see this more clearly with its execution trace:
For this trace, we have and , which is out of bound. Hence, but . As the memory error only occurs during speculative execution, defenses against Spectre V1 attacks, such as adding LFENCE or applying SLH, suffice to remove the speculative memory error, given that they do not introduce additional memory-safety violations (Section III-A).
Case . Figure 3d shows an example that is both sequentially unsafe and speculatively unsafe. Under sequential execution, the memory access at Line 3 will access A[8] and A[9] out-of-bounds in the last two loop iterations because of the incorrect bounds check at Line 2. Moreover, under misprediction, iterations after that might access A[i] where under misprediction, which leads to speculative memory error as well. We can see this more clearly with the following execution trace where only the last prediction when has a misprediction:
Hence, and . So and .
V. DUAL MEMORY SAFETY
One important impact of the categorization of program locations is to enable formal and precise reasoning about dual memory safety, which is formalized as follows.
Definition 7 (Dual Memory Safety). A program satisfies dual memory safety if it is free of all memory violation regions:
A. Composition Theorem
To ensure dual memory safety, one challenging question is how to combine, or modify existing memory-safe mechanisms with partial protection. As discussed in Section II-D, a naive composition of existing defense mechanisms does not necessarily provide dual safety. Moreover, the resulting performance overhead can be prohibitive.
To address the challenge, we first model each memory safety mechanism as a program rewriting process, and use and to denote defense mechanisms for sequential and speculative memory errors respectively. A sound memory-safe mechanism should possess the following property:
Definition 8 (Sound Memory-Safety Mechanism). A sequential memory-safe mechanism is sound if it removes all sequential violation locations: . .
Likewise, a speculative memory-safety mechanism is sound if it removes all speculative violation locations: . .
To systematically reason about the composition of memory-safe mechanisms, we identify an essential condition that makes the composition of two memory-safety mechanisms dual memory safe. We term this essential property safety preservation.
Definition 9 (Safety Preservation). A sequential memory-safety mechanism preserves memory safety if it does not introduce new speculative violations: . .
Similarly, a speculative memory-safe mechanism preserves memory safety if it does not introduce new sequential violations: . .
Note that Definition 9 quantifies over each program location in , the program prior to rewriting. Since a given mechanism might instrument multiple instructions at a single location , the rewritten code, e.g., , is a set of instructions. For notational convenience, we overload to denote the union of violation sets associated with all commands in .
Next, we prove the composition theorem.
Theorem 1 (Composition). For any program c and two sound memory-safe mechanisms and :
• is safety preserving is dual memory safe.
• is safety preserving is dual memory safe.
Proof. We prove the first bullet as the other case is symmetric.
• For speculative memory safety, we consider an arbitrary location . Then since is sound.
• For sequential memory safety, we consider an arbitrary location . Then represents the commands after applying to .
Since is safety preserving, . . Moreover, since is sound, we have
for each . Hence, , or equivalently, . Since this holds for any , is sequentially memory safe.
B. Systematic Analysis of Memory Safety Mechanisms
To demonstrate the practical relevance of Theorem 1, we first investigate the safety properties of existing mechanisms, summarized in Table I. We select a variety of representative memory safety mechanisms, ranging from object-based bounds checking (Baggy [2]), pointer-based bound checking (Delta Pointers [5]), sandboxing (SafeStack [6]), Spectre defense (SLH [28]), to hardware-aided (SpecASan [29] and CHERI [30], [53]) mechanisms. We subsequently show that our newly developed composition theory significantly streamlines the analysis of dual safety.
Baggy is not safety-preserving. Baggy introduces branches in the transformed code, which may expand the speculative violation region. Recall the example in Section II-D, where Line 1 is transformed to a branch-based bounds check. Before applying Baggy, as Line 1 is not guarded by any branch. However, with Baggy, it is sequentially sound as . However, due to the branch-based bounds check added by Baggy. Hence, Baggy is not safety-preserving, as .
Delta Pointers is not safety-preserving. Delta Pointers [5] is a pointer-based defense that divides a 64-bit virtual address into three parts, the most significant bit (MSB), a 31-bit delta tag, and a 32-bit address.

The tag bits encode the distance between the current pointer value and the upper bound of the associated object. During pointer arithmetic, the tag is updated relative to the address change. When the pointer moves out of bounds, by design, the arithmetic causes the tag to overflow into the MSB, which triggers a hardware exception as modern hardware enforces canonical address checks. For an memory access such as (where the size of is 8), the instrumented code is
1 addr = 6A[x];
2 new_addr = addr + (x << 32);
3 masked_addr = new_addr & ADDR_MASK;
4 y = load(masked_addr);
where ADDR_MASK is the mask removing the tag bits. When , the addition at Line 2 overflows the tag to MSB, resulting a hardware exception at Line 4 since MSB is set.
Unlike Baggy, Delta Pointers does not introduce branch-based software checks. However, it relies on hardware canonical address checks to prevent dereferencing of invalid pointers, which can be bypassed under speculative execution on AMD CPUs [44], [54], [55]. Recent research [56] also found that Intel CPUs can be affected, but by Spectre v2 attacks, which is out-of-scope for this paper. Consider the original access , say at line , without Delta Pointers instrumentation,
| Mechanism | Range | Safety | Preservation |
|---|---|---|---|
| Baggy | Object | → | No |
| Delta Pointers | Object | → | No |
| SafeStack | Safe: ObjectUnsafe: Unsafe Stack* | →Dual | YesYes |
| SLH | Object | ⌒† | Yes |
| SpecASan | Object | Dual | Yes |
| CHERI | Object | Dual | Yes |
| Baggy+SLH | Object | → | No |
| SLH+Baggy | Object | → | No |
| DeltaPointers+SLH | Object | → | No |
| SLH+DeltaPointers | Object | → | No |
| SafeStack+SLH | Safe: ObjectUnsafe: Unsafe Stack* | DualDual | YesYes |
| DUALBAGGY | Object | Dual | Yes |
| DUALDELTAPOINTERS | Object | Dual | Yes |
TABLE I: Properties of Memory Safety Mechanisms.
*: SafeStack enforces a coarse-grained software-fault isolation policy on unsafe objects: accesses to unsafe objects are constrained within the unsafe stack.
†: SLH is speculative safe if the out-of-bound accesses stem from branch misprediction.
we have as no mis-prediction occurs. However, since speculative execution may bypass the canonical address check at Line 4. Therefore, delta pointers is not safety-preserving, as .
SafeStack is safety-preserving. SafeStack [6] splits the program stack into two separate regions, where a safe stack stores safe objects whose accesses are all provably safe (i.e., for all that may access the object), and an unsafe stack stores everything else. By design, it provides sequential (but not speculative) memory safety to those objects on the safe stack, and the protection is at the object granularity.
For objects on the unsafe stack, however, SafeStack enforces a coarse-grained software fault isolation (SFI) policy, ensuring that all accesses to unsafe objects remain within the bounds of the unsafe stack through the use of segment registers (e.g., gs and fs). The defense is dual safe for unsafe objects, but only at the granularity of the whole unsafe stack.
Moreover, because safe stack relies solely on base-and-offset arithmetic, it is safety-preserving as it does not introduce additional memory accesses under speculative execution.
SLH is safety-preserving. Recall the example in Section II-D. SLH masks memory addresses that may become out-of-bounds under speculative execution using a dedicated register mis, which tracks the mis-speculation status. Accordingly, SLH is conditionally sound when mis accurately reflects the status of the branch-prediction unit. However, bypassing hardware-enforced canonical address checks under speculative execution does not stem from branch misprediction. Consequently, applying SLH to such instructions does not yield sound speculative protection for these checks, instrumented by mechanisms like Baggy and Delta Pointers.
On the other hand, the masking operation does not change program semantics under sequential semantics, nor introducing new memory accesses. Hence, it ensures that . Therefore, SLH is safety-preserving.
SpecASan is safety-preserving. SpecASan [29] extends the protection of ARM's hardware based defense, MTE, which enforces memory tag checks only under sequential execution, to also cover speculative execution. Hence, it is dual safe.
SpecASan does not introduce new memory accesses during enforcement. So, SpecASan is safety-preserving.
CHERI is safety-preserving. CHERI [30] replaces traditional integer pointers with capabilities that include addresses, bounds, and permissions. Upon each memory access, bounds are directly extracted from the capability and compared against the address during both sequential and speculative executions. Hence, CHERI is dual safe. Moreover, CHERI does not add any new memory accesses. Thus, CHERI is safety-preserving.
C. Dual safety properties.
With Theorem 1, it becomes straightforward to determine whether the composition of two mechanisms ensures dual safety. For example, applying Baggy or Delta Pointers, which are not safety preserving, on top of other mechanisms yields only sequential memory safety. One subtlety arises in compositions where SLH is applied on top of a sound sequential defense, since SLH is only conditionally sound. In particular, both Baggy and Delta Pointers rely on hardware enforcement through canonical address checks, for which SLH does not provide speculative protection. Consequently, applying SLH on top of Baggy or Delta Pointers does not guarantee dual memory safety. In contrast, SafeStack does not rely on Spectre-vulnerable hardware check, making “SafeStack +SLH” a dual safe composition.
D. Software-Based Dual Safe Mechanisms
Based on the insights from dual safety analysis, we next present two novel mechanisms that are dual memory safe.
DUALBAGGY. Baggy allocates memory objects in fixed size slots, ensuring that each allocation size is a power of two. This design reduces out-of-bounds checks on pointer arithmetic to examining the high order bits of the pointer, which can be implemented via a bitwise XOR followed by a right shift.
Consider a 64 bit system with a 128 byte object. The lowest 5 bits encode the offset within a slot, while the highest 57 bits represent the object's base address, uniquely identifying the allocation. The remaining 2 bits distinguish among the four slots allocated to this object.

Motivated by SLH, DUALBAGGY removes the problematic branch-based and hardware-based checks in Baggy via a branchless select, which sets a computed address to -1 if the computed address goes out of bounds; otherwise, the pointer remains the same. Recall the example in Section II-D, the transformed code by DUALBAGGY is as follows.
addr = &A[x];
log_size = size_table[A >> log_slot_size];
is_oob = (addr XOR A) >> log_size != 0
final_addr = select(is_oob, -1, addr);
y = load(final_addr);
DUALDELTAPOINTERS. Delta Pointers leverage integer overflow to detect out of bounds accesses. However, as discussed in Section V-B, it relies on hardware checks that are vulnerable under speculative execution.
To fix this, we present DUALDELTAPOINTERS, a variant of Delta Pointers that explicitly inspects the most significant bit in software and sets the resulting address to -1 when this bit is set. For a memory access such as y = A[x] (where the size of A is 8), the instrumented code is as follows.
addr = &A[x];
new_addr = addr + (x << 32);
masked_addr = new_addr & ADDR_MASK;
is_oob = masked_addr < 0;
final_addr = select(is_oob, -1, masked_addr);
y = load(final_addr);
By performing a signed comparison with zero at Line 4, DUALDELTAPOINTERS detects if the MSB is set. If the pointer is OOB, the select instruction transforms the address to -1 (an inherently invalid address with all bits as 1) before the load occurs. This ensures that even during speculative execution, the address used for the memory access is safely neutralized, providing a robust protection that bridges the gap between software metadata and hardware enforcement.²
E. Selective Defense
The composition theorem enables systematic reasoning about dual memory safety. However, it conservatively assumes that memory safety mechanisms are applied to all program locations with a nonempty violation set, which can lead to excessive overhead. We next present a stronger result that enables sound and more efficient composition when both defense mechanisms are sound and safety preserving. Without loss of generality, we consider the composition in which is applied after ; by symmetry, the same reasoning applies when the order is reversed.
Our insight is that when both defense mechanisms are sound and safety-preserving, speculative safety mechanisms can be omitted at program locations that are initially free from speculative memory errors. This is intuitively safe as the safety-preserving sequential defense cannot introduce new speculative memory errors. Consider the code snippet in Figure 3b, where the out-of-bounds accesses at Lines 1 and 3 only occur under the sequential semantics. With the selective composition theorem below, we can avoid applying speculative defenses, such as SLH, to achieve dual memory safety.
²Delta Pointers focuses on overflow checks since they are deemed more common than underflow [5]. Our dual safe variant follows the same direction. Recent work has shown that strategically combining different defenses, i.e., Baggy and Delta Pointers, could achieve overall spatial safety while keeping the overhead low [57], which we leave as future work.
More precisely, given sound and safety-preserving and , we define their selective composition as follows, where mechanisms are omitted on program locations that are safe:
Theorem 2 (Selective Composition). Let be a selective speculative defense based on sound and safety-preserving mechanisms and . is dual memory safe.
Proof. The first case is trivial and the last case directly comes from Theorem 1. For the second case, we only need to show that is dual memory safe for program locations where . Since is sound, we know that . Moreover, we have , where the first subset relation holds as is safety preserving. The third case is the dual of the second case.
F. Selective Dual Memory Safe Mechanisms
To demonstrate the practical relevance of Theorem 2, we consider three selective compositions that yield dual safety. In each composition, we first apply a dual safe mechanism to fix all sequential memory errors, i.e., program locations categorized as and . Since the mechanism is dual safe, those locations are exempt from SLH protection. Then, we only apply SLH to program locations categorized as , which is safe due to Theorem 2, as for those locations. Therefore, no redundant protection is introduced in the following three compositions:
-
DUALBAGGY+SLH (SELECTIVE): DUALBAGGY is applied to program locations categorized as and ; SLH is applied to those categorized as .
-
DUALDELTAPOINTERS+SLH (SELECTIVE): in this configuration, DUALDELTAPOINTERS is applied to program locations categorized as and ; SLH is applied to those categorized as .
-
SAFESTACK+SLH (SELECTIVE): we put objects that are accessed by program locations categorized as and into the unsafe stack. Hence, SafeStack ensures dual memory safety for all accesses to the unsafe stack (Table I). Moreover, SLH is applied to all program locations categorized as .
One subtle point worth noting is that it may be tempting to place all unsafe objects (i.e., those accessed by program locations in , and ) onto the unsafe stack, and then apply SafeStack as a dual memory safety mechanism for this stack. However, this approach does not preserve the original security guarantees of SafeStack, as illustrated by the following code fragment:
1 x = A[0]; 2 y = B[8]; 3 if (i < 8) 4 z = C[i];

Fig. 4: DUALGUARD Workflow
Assume that arrays A, B, and C each have size 8. Under sequential execution, the accesses at Lines 1 and 4 are memory safe, while the access at Line 2 is unsafe. Accordingly, the original SafeStack places B on the unsafe stack, and it places A and C on the safe stack. This placement ensures object level memory safety for arrays A and C (i.e., no out-of-bounds accesses can reach them), while any erroneous access to B remains confined to the unsafe stack. Our configuration of SAFESTACK+SLH (SELECTIVE) extends the same guarantees to speculative execution.
Conservatively placing array C on the unsafe stack also ensures object level memory safety for A. However, this approach weakens the overall security guarantees, as C is no longer protected from accesses by other objects on the unsafe stack, given that they reside within the same sandbox.
VI. DUALGUARD
We present DUALGUARD, a framework that automatically enforces sound and efficient dual memory safety for target software, following the workflow shown in Figure 4. DUALGUARD begins with a two-phase analysis to identify vulnerable program locations. The first phase (DUALGUARD→) identifies locations that may exhibit sequential memory errors (i.e., those in or ), while the second phase (DUALGUARD ) identifies locations that may exhibit either sequential or speculative memory errors (i.e., those in or or ). Violations identified in both phases are then passed to a dual mitigation component, which applies dual memory safe mechanisms (Table I) accordingly.
A. Static Analysis
Each analysis phase first collects all pointer arithmetic operations in the program, where potentially unsafe spatial accesses may occur, along with the sizes of the underlying memory objects being indexed. It then performs a forward data flow analysis to compute value ranges [7], [16] for numeric program variables, which are used to determine the possible offsets involved in pointer arithmetic operations.
In particular, we use a forward-may data-flow analysis to compute the range of each variable in the program, with the data-flow equation below:
Here, is the value-range information at the entry point of basic block B, which is computed by taking the union of the range at the exit point of all its predecessors, i.e., . When the range cannot be decided at compile time, the resulting range is conservatively estimated as unbounded.
Out(B) denotes the range at the exit of basic block B. Its computation involves the sets and , which capture the variables defined in B together with their corresponding range information. By subtracting from and then taking the union with , the analysis removes outdated range information and incorporates the updated ranges introduced within B.
With all value-range information computed, the analysis determines whether an operation is safe at compile time by checking if the offset range lies within the bounds of the underlying object. Operations that violate this condition are marked as unsafe and reported accordingly.
Both DUALGUARD and DUALGUARD follow the workflow described above, but differ in two aspects: (1) DUALGUARD is path sensitive, and (2) DUALGUARD incorporates a speculative specific out-of-window analysis to exclude memory operations that are never executed speculatively.
B. Path Sensitivity
DUALGUARD identifies memory errors under sequential semantics. Consequently, path conditions can be safely leveraged to restrict the range of variable values within conditional branches, enabling a path-sensitive analysis. In contrast, DUALGUARD operates under speculative-aware semantics, in which an instruction may be executed regardless of the corresponding path condition. As a result, the analysis must conservatively evaluate memory accesses without incorporating path conditions. This conservative treatment is intended to over-approximate all possible values that a variable may assume under speculative execution semantics.
C. Out-of-Window Analysis
DUALGUARD further incorporates an out-of-window analysis to eliminate instructions that cannot be executed speculatively. In modern processors, the number of speculatively executed instructions is bounded by the size of the reorder buffer. When the reorder buffer is full, speculative execution stalls until the corresponding branch condition is resolved. Consequently, each branch induces a finite speculation window within which instructions may execute speculatively. Instructions that fall outside the speculation windows of all branches are therefore never subject to speculative execution.
To identify these out-of-window instructions, DUALGUARD performs a reachability test from every branch instruction, up to the window size. Unreachable instructions are reported by DUALGUARD as speculatively memory safe.
VII. EVALUATION
A. Implementation
We implement DUALGUARD by extending the memory safety analysis of [17], building on its LLVM-based infrastructure with approximately 1,500 additional lines of C++ code. Our extension also refines the value ranges of path conditions, improving the precision of sequential reasoning. To leverage LLVM's existing SLH infrastructure, which operates closer to the assembly level, DUALGUARD inserts dummy instructions at vulnerable program locations identified by DUALGUARD , allowing them to be mitigated in later compilation stages. The out-of-window analysis (Section VI-C) is implemented in approximately 700 lines of code. Consistent with prior work [52], we set the window size to 200 instructions, providing a conservative estimate of the reorder buffer capacity in contemporary processors. We note that the window size is fully configurable in DUALGUARD: one can easily tune it to match the re-order buffer size of their target hardware.
For both SafeStack and SLH, we modify their implementations within the LLVM infrastructure so that they are applied to the potentially unsafe objects identified by our static analysis, rather than those selected by LLVM's default heuristics. For Baggy, we build on an open source implementation from [57] and implement a dual memory safe variant, DUALBAGGY, as described in Section V-D.
For Delta Pointers, we build on its public repository [58] and introduce two additional LLVM IR instructions, icmp and select. In later compilation stages, select is lowered to cmov, which uses the EFLAGS register to determine whether to perform a mov operation. The icmp instruction is optimized away, as the relevant EFLAGS are already set by the and instruction introduced by the original Delta Pointers mechanism. Hence, at the assembly level, only a branchless cmov is added, allowing DUALDELTAPOINTERS to remain efficient while providing stronger security guarantees.
B. Evaluation Setup
We evaluate DUALGUARD on two benchmark suites. The first suite is the widely used SPEC CPU 2017 benchmark suite. Of the 16 benchmarks fully implemented in C/C++, which can be analyzed by our DUALGUARD implementation, we successfully evaluated DUALGUARD on 13: perlbench_r, mcf_r, namd_r, parest_r, povray_r, lbm_r, omnetpp_r, xalancbmk_r, x264_r, deepsjeng_r, leela_r, nab_r, and xz_r. Of the three excluded benchmarks, imagick_r crashes under both Baggy and Delta Pointers because it intentionally performs out-of-bounds memory accesses; both tools are designed to abort execution upon detecting such spatial memory violations. We exclude gcc_r and blender_r because our context-sensitive whole-program analysis either times out or exhausts available memory. We leave improving the scalability of our prototype as future work.
The second set of benchmarks is a collection of cryptographic libraries used in a prior study on SLH-based defenses [27]. The evaluation is performed on a server (Ubuntu 24.04.3 LTS) with an Intel(R) Xeon(R) 6517P CPU (3.2 GHz) and 256GB RAM.
We aim to answer the following research questions:
Q1: What is the performance overhead among DUALGUARD's dual safe mechanisms?

Fig. 5: SPEC CPU 2017 overhead (Bars with the same color but different shades are directly comparable; bars with different colors represent different defense schemes and are not comparable with each other. Solid bars represent dual safe defenses, while bars with stripes are not dual safe.)
Q2: How does the overhead of DUALGUARD compare to naive stacking of sequential and speculative defenses?
Q3: Is the overhead of DUALGUARD comparable with state-of-the-art defenses that only provide either sequential or speculative safety?
Q4: How much do selective defense mechanisms (Section V-F) help to reduce overhead?
Q5: Does DUALGUARD scale to real-world programs?
C. The Overhead of DUALGUARD
DUALGUARD provides three dual-safe configurations:
-
DUALGUARD-DUALBAGGY applies dual Baggy to all potentially unsafe instructions.
-
DUALGUARD-DUALDELTAPOINTERS applies dual Delta Pointers to all potentially unsafe instructions.
-
DUALGUARD-SAFESTACKSLH is the selective composition of Safe Stack and SLH (aka. SAFESTACK+SLH (SELECTIVE) in Section V-F).
We did not include CHERI [30] and SpecASan [29] in our evaluation because both require specialized hardware support, whereas DUALBAGGY and DUALDELTAPOINTERS are software-only defenses. Specifically, CHERI depends on dedicated architectural extensions, while SpecASan relies on the ARM Memory Tagging Extension (MTE) and does not have a publicly available implementation.
For the other two selective composition variants DUALBAGGY+SLH (SELECTIVE) and DUALDELTAPOINTERS+SLH (SELECTIVE) introduced in Section V-F, we study their performance overhead under Q4 (Section VII-E).
To address Q1 and Q2, we assess the performance overhead of the three configurations of DUALGUARD and compare them against their corresponding naive compositions, which sequentially apply three mechanisms to all potentially unsafe program locations identified by our static analysis: BAGGY+SLH, DELTAPOINTERS+SLH, and SAFESTACK+SLH. It is important to note that BAGGY+SLH and DELTAPOINTERS+SLH do not satisfy dual safety (Table I); nevertheless, we include them to emphasize that, despite their lack of safety guarantees,
these naive compositions still incur substantial performance overhead.
We measure the overhead of each configuration against the original program execution time without any protection.
- SPEC CPU 2017: We summarize the results in Figure 5, where the striped bars represent ones that are not dual safe.
Baggy-based protection. The overhead of BAGGY+SLH ranges from 7% to 358.5%. In contrast, DUALGUARD-DUALBAGGY consistently incurs lower overhead. The reduction in overhead ranges from 3% for lbm_r to 95.3% for x264_r. On average,³ BAGGY+SLH incurs an overhead of 148.4%, whereas DUALGUARD-DUALBAGGY reduces it to 43.6%. Overall, DUALGUARD achieves an overhead reduction of 70.6% over the “mitigation-upon-mitigation” option based on Baggy.
Delta Pointers-based protection. The overhead of DELTA-POINTERS+SLH ranges from 11.6% to 241.9%. In contrast, DUALGUARD-DUALDELTAPOINTERS consistently incurs lower overhead except for 2 benchmarks where it incurs a slightly higher overhead. On average, DELTA-POINTERS+SLH incurs an overhead of 119.7%, whereas DUALGUARD-DUALDELTAPOINTERS reduces it to 33.6%. Overall, DUALGUARD achieves an overhead reduction of 71.9% over DELTAPOINTERS+SLH.
SafeStack-based protection. The overhead of SAFESTACK+SLH ranges from 0% to 240.1%. DUALGUARD-SAFESTACKSLH incurs lower or comparable overhead than SAFESTACK+SLH in all benchmarks. Overall, SAFESTACK+SLH incurs an overhead of 103.2% whereas DUALGUARD-SAFESTACKSLH reduces it to 99.5%, though we observe that the reduction is smaller than what we observe in the Baggy-based and Delta-Pointers-based cases.
Overall, DUALGUARD 's dual-safe configurations, particularly the novel mechanisms DUALBAGGY and DUALDELTAPOINTERS, consistently outperform their corresponding “mitigation-upon-mitigation” counterparts on the
³All averages are reported as geometric means.

Fig. 6: Cryptographic library overhead (Bars with the same color but different shades are directly comparable; bars with different colors represent different defense schemes and are not comparable with each other. Solid bars represent dual safe defenses, while bars with stripes are not dual safe.)
SPEC CPU 2017 benchmark. Among them, DUALDELTA-POINTERS incurs the lowest overhead overall.
- Cryptographic libraries: Similar to the results on SPEC CPU 2017 benchmark, DUALGUARD 's dual-safe configurations consistently outperform their corresponding “mitigation-upon-mitigation” counterparts on the cryptographic libraries as well. The results are summarized in Figure 6.
Across Baggy-, Delta Pointers-, and SafeStack-based protections, the overhead of these naive combinations ranges from 0% to 945.1%. In contrast, DUALGUARD 's configurations consistently incur lower overhead. The reduction in overhead is up to 97.6% for Baggy, 95.4% for Delta Pointers and 73.5% for SafeStack. On average, DUALGUARD-DUALBAGGY, DUALGUARD-DUALDELTAPOINTERS, and DUALGUARD-SAFESTACKSLH incur overheads of 71.9%, 28.9%, and 39.2%, respectively. Overall, we observe reduction rates ranging from 16.8% to 71.8% across all configurations. Similar to the SPEC CPU 2017 benchmark, DUALDELTAPOINTERS achieves the lowest overall overhead of 28.9%.
To better understand how DUALGUARD 's configurations achieve lower overhead than naive compositions, we also present an in-depth case study of a real-world example from the big number (bn) library of OpenSSL 3.3.0 in the Appendix. Overall, we observe that the overhead reduction mostly comes from: 1) replacing branch-based checks with more efficient branchless checks, and 2) eliminating redundant speculative instrumentation (e.g., SLH) enabled by our dual-safe defenses. We further observe that varying the reorder buffer size configuration has minimal impact on performance.
D. Dual vs. Partial Memory Safety
To address Q3, we compare DUALGUARD-DUALBAGGY and DUALGUARD-DUALDELTAPOINTERS with the SLH implementation in LLVM (LLVM SLH), LightSLH [27], Baggy, and Delta Pointers, as all of these mechanisms enforce memory safety at the granularity of objects. Among these approaches, only the DUALGUARD variants offer dual memory safety guarantees. In contrast, Baggy and Delta Pointers fail
TABLE II: Compare DUALGUARD with partial protections (*: LightSLH cannot run on SPEC benchmarks due to insufficient instruction support and scalability issues.)
| Defense | Safety | Overhead | |
|---|---|---|---|
| SPEC | Crypto | ||
| LLVM-SLH | Ω | 116% | 46% |
| LightSLH | Ω | N/A* | 31% |
| Baggy | → | 131% | 147% |
| Delta Pointers | → | 24% | 20% |
| DUALBAGGY | Dual | 44% | 72% |
| DUALDELTAPOINTERS | Dual | 34% | 29% |
to provide speculative memory safety, while LLVM SLH and LightSLH are limited to mitigating Spectre V1 attacks. Table II presents a summary of the overall performance overhead incurred by these mechanisms on the SPEC and cryptographic library benchmarks; a detailed breakdown is included in the Appendix.
We observe that the DUALGUARD defenses deliver dual memory safety guarantees while incurring only modest overhead relative to Delta Pointers and, in some cases, even lower overhead than Baggy, LLVM-SLH, and LightSLH, all while maintaining or strengthening memory safety assurances across both sequential and speculative execution contexts.
E. Selective Defense

Fig. 7: The effect of selective protection
To address Q4, we compare the three selective dual memory safety mechanisms described in Section V-F against their counterparts that do not leverage Theorem 2, i.e., approaches that conservatively apply protections in sequence to all program locations classified as , or . The results are summarized in Figure 7, with a detailed per-benchmark breakdown provided in the Appendix.
We observe that, across Baggy-, Delta Pointers-, and SafeStack-based protections, selective composition reduces performance overhead by 5.4%, 4.3%, and 2.9%, respectively, on the SPEC CPU 2017 benchmark, and by 8.4%, 0%, and 17%, respectively, on cryptographic library benchmark. This reduction underscores the practical value of Theorem 2.
F. Scalability
The cryptographic library benchmarks are relatively small, with most programs comprising fewer than 1 KLoC; DUALGUARD's static analysis completes for all of them within 8 seconds. For the SPEC CPU benchmarks, the largest program is xalancbmk_r (520 KLoC), which requires 51.23 seconds for analysis, while perlbench_r requires the longest analysis time of 8254.01 seconds. These results indicate that DUALGUARD can analyze real-world codebases of moderate size within a reasonable timeframe. A detailed breakdown of analysis times for each benchmark is provided in the Appendix.
VIII. LIMITATIONS AND FUTURE WORK
Within the scope of spatial memory safety under Spectre v1 attacks, our work provides the first systematic investigation into the interaction between memory safety and speculative execution, alongside proposing concrete spatial dual memory safe defense mechanisms. Beyond that, we believe that the formal insights and methodology developed in this paper establish a foundation for exploring broader threat models. For example, our safety preservation abstraction is formulated over general program transformations rather than being inherently bound to spatial bounds checking or Spectre v1 mitigations. Consequently, it can be extended to evaluate whether other defenses (e.g., retpolines [59], IBRS [48], or reference counting [60]) preserve sequential and speculative safety guarantees.
Moreover, there are at least two future directions for extending DUALGUARD:
-
Temporal Memory Safety: Temporal defenses (e.g., reference counting [60], and garbage collection [61]) maintain object lifetime metadata rather than spatial bounds. Under speculative execution, stale or mispredicted metadata could lead to transient use-after-free conditions or premature object reclamation.
-
Other speculative attacks: Other Spectre variants, such as Specter v2 (indirect branch target poisoning) [42] and Specter-RSB (return stack buffer manipulation) [43], hijack transient control flow to arbitrary targets. Such indirect mispredictions could speculatively bypass memory-safety checks entirely or jump past instrumentation boundaries.
These attack surfaces introduce failure modes that are qualitatively distinct from the bounds-check bypass scenarios addressed in this paper. Adapting our framework and verification models to account for dynamic control-flow redirection and temporal lifecycle invariants presents a promising direction for future research.
IX. CONCLUSION
This paper introduces DUALGUARD, a unified framework to systematically address the fragmentation between non-speculative and speculative memory safety. By formalizing memory access behaviors into four distinct categories, DUALGUARD can identify the minimal requirements for achieving dual protection. Our evaluation confirms that this unified approach successfully removes redundant protections that often lead to unnecessary performance penalties. DUALGUARD achieves dual memory safety with a modest overhead, offering a robust and efficient solution for modern systems vulnerable to both sequential and speculative memory exploitations. Future work will continue to explore the scalability of the framework and generalize it to other Spectre attacks.
ETHICS CONSIDERATIONS
We have meticulously considered the ethical implications of developing DUALGUARD, a framework designed to systematically provide memory safety across sequential and speculative execution. Our goal is to mitigate existing vulnerabilities. We do not reveal any new attack surface or specific attack sequences. To ensure our work was conducted responsibly, we adhered to a rigorous ethical framework throughout the research process. We identified three primary stakeholder groups potentially impacted by our work: End-Users of the affected software systems, Software Vendors and Maintainers, and Malicious Actors.
End-Users. The individuals and organizations relying on safe software systems (e.g., cryptographic libraries) free from spatial memory errors are the ultimate beneficiaries of this research, but also the group most vulnerable to potential exploitation. To ensure no negative outcomes for end-users during the research phase, all experimental validations were conducted strictly within a private, isolated laboratory environment. Consequently, no legitimate production systems were exploited or compromised during our evaluation.
Software Vendors and Maintainers. To mitigate the risk of these vulnerabilities being exploited before defenses are in place, we adhered to standard responsible disclosure practices. As a defensive framework, we aim to ensure security by identifying and preventing potential vulnerabilities. Specifically, we identify unreported half-gadgets as potentially exploitable. However, these half-gadgets do not consist of complete exploits. Rather, they pointed out places where proactive defenses can be useful.
Malicious Actors (Attackers). A potential risk is that malicious actors might attempt to exploit program locations analyzed during our evaluation. We mitigate this risk in multiple ways:
• Defensive Focus: Our primary objective is to develop secure and efficient defenses rather than uncover new attack surfaces. In particular, our case studies and analyses focus strictly on demonstrating how DUALGUARD eliminates redundant mitigations and reduces performance overhead, without presenting end-to-end exploits or actionable attack primitives.
• Guidance for Defenders: Rather than facilitating exploitation, we provide concrete principles and mechanisms that assist defenders in evaluating their systems and deploying targeted, dual-safe protections against realistic threats.
ACKNOWLEDGMENT
This research is supported by the National Science Foundation under awards No. 2348304, No. 2401496 and No. 2401182, the Office of Naval Research under Award No. N000142512413, as well as the Air Force Research Laboratory (AFRL) under Contract No. FA8750-25-C-B041.
REFERENCES
[1] C. Cowan, F. Wagle, C. Pu, S. Beattie, and J. Walpole, "Buffer overflows: Attacks and defenses for the vulnerability of the decade," in Proceedings DARPA Information Survivability Conference and Exposition. DISCEX'00, vol. 2. IEEE, 2000, pp. 119–129.
[2] P. Akritidis, M. Costa, M. Castro, and S. Hand, “Baggy bounds checking: An efficient and backwards-compatible defense against out-of-bounds errors.” in USENIX Security Symposium, vol. 10, 2009, p. 96.
[3] R. W. Jones and P. H. Kelly, “Backwards-compatible bounds checking for arrays and pointers in c programs.” in AADEBUG, vol. 97, 1997, pp. 13–26.
[4] D. Dhurjati and V. Adve, “Backwards-compatible array bounds checking for c with very low overhead,” in Proceedings of the 28th international conference on Software engineering, 2006, pp. 162–171.
[5] T. Kroes, K. Koning, E. Van Der Kouwe, H. Bos, and C. Giuffrida, "Delta pointers: Buffer overflow checks without the checks," in Proceedings of the Thirteenth EuroSys Conference, 2018, pp. 1–14.
[6] V. Kuznetzov, L. Szekeres, M. Payer, G. Candea, R. Sekar, and D. Song, "Code-pointer integrity," in The Continuing Arms Race: Code-Reuse Attacks and Defenses, 2018, pp. 81–116.
[7] K. Huang, Y. Huang, M. Payer, Z. Qian, J. Sampson, G. Tan, and T. Jaeger, “The taming of the stack: Isolating stack data from memory errors,” 2022.
[8] T. Jim, J. G. Morrisett, D. Grossman, M. W. Hicks, J. Cheney, and Y. Wang, “Cyclone: a safe dialect of c,” in USENIX Annual Technical Conference, General Track, 2002, pp. 275–288.
[9] S. Nagarakatte, M. M. Martin, and S. Zdancewic, “Hardware-enforced comprehensive memory safety,” IEEE Micro, vol. 33, no. 3, pp. 38–47, 2013.
[10] G. C. Necula, J. Condit, M. Harren, S. McPeak, and W. Weimer, “Cured: Type-safe retrofitting of legacy software,” ACM Transactions on Programming Languages and Systems (TOPLAS), vol. 27, no. 3, pp. 477–526, 2005.
[11] S. Nagarakatte, M. M. Martin, and S. Zdancewic, “Watchdog: Hardware for safe and secure manual memory management and full memory safety,” ACM SIGARCH Computer Architecture News, vol. 40, no. 3, pp. 189–200, 2012.
[12] G. Saileshwar, R. Boivie, T. Chen, B. Segal, and A. Buyuktosunoglu, "Heapcheck: Low-cost hardware support for memory safety," ACM Transactions on Architecture and Code Optimization (TACO), vol. 19, no. 1, pp. 1–24, 2022.
[13] Z. Durumeric, F. Li, J. Kasten, J. Amann, J. Beekman, M. Payer, N. Weaver, D. Adrian, V. Paxson, M. Bailey et al., “The matter of heartbleed,” in Proceedings of the 2014 conference on internet measurement conference, 2014, pp. 475–488.
[14] H. Orman, “The morris worm: A fifteen-year perspective,” IEEE Security & Privacy, vol. 1, no. 5, pp. 35–43, 2003.
[15] M. S. Simpson and R. K. Barua, “Memsafe: ensuring the spatial and temporal memory safety of c at runtime,” Software: Practice and Experience, vol. 43, no. 1, pp. 93–128, 2013.
[16] K. Huang, M. Payer, Z. Qian, J. Sampson, G. Tan, and T. Jaeger, “Top of the heap: Efficient memory error protection of safe heap objects,” in Proceedings of the 2024 on ACM SIGSAC Conference on Computer and Communications Security, 2024, pp. 1330–1344.
[17] —, “Comprehensive memory safety validation: An alternative approach to memory safety,” IEEE Security & Privacy, vol. 22, no. 4, pp. 40–49, 2024.
[18] J. Blaser, F. Gorter, K. v. Gleissenthal, and H. Bos, “QuickSafe: Targeted Hardening Against Memory Corruption,” in 2026 IEEE Symposium on Security and Privacy (SP), 2026, pp. 1580–1598.
[19] P. Kocher, J. Horn, A. Fogh, , D. Genkin, D. Gruss, W. Haas, M. Hamburg, M. Lipp, S. Mangard, T. Prescher, M. Schwarz, and Y. Yarom, “Spectre attacks: Exploiting speculative execution,” in 40th IEEE Symposium on Security and Privacy (S&P'19), 2019.
[20] M. Lipp, M. Schwarz, D. Gruss, T. Prescher, W. Haas, A. Fogh, J. Horn, S. Mangard, P. Kocher, D. Genkin, Y. Yarom, and M. Hamburg, "Meltdown: Reading kernel memory from user space," in 27th USENIX Security Symposium (USENIX Security 18), 2018.
[21] A. Mambretti, A. Sandulescu, A. Soriotti, W. Robertson, E. Kirda, and A. Kurmus, “Bypassing memory safety mechanisms through speculative control flow hijacks,” in 2021 IEEE European Symposium on Security and Privacy (EuroS&P). IEEE, 2021, pp. 633–649.
[22] E. Göktas, K. Razavi, G. Portokalidis, H. Bos, and C. Giuffrida, “Speculative probing: Hacking blind in the spectre era,” in Proceedings of the 2020 ACM SIGSAC Conference on Computer and Communications Security, 2020, pp. 1871–1885.
[23] J. Ravichandran, W. T. Na, J. Lang, and M. Yan, “Pacman: attacking arm pointer authentication with speculative execution,” in Proceedings of the 49th Annual International Symposium on Computer Architecture, 2022, pp. 685–698.
[24] J. Kim, J. Park, S. Roh, J. Chung, Y. Lee, T. Kim, and B. Lee, “Tiktag: Breaking ARM's Memory Tagging Extension with Speculative Execution,” in 2025 IEEE Symposium on Security and Privacy (SP). Los Alamitos, CA, USA: IEEE Computer Society, May 2025, pp. 4063–4081. [Online]. Available: https://doi.ieeecomputersociety.org/10.1109/SP61157.2025.00039
[25] B. A. Shivakumar, G. Barthe, B. Grégoire, V. Laporte, T. Oliveira, S. Priya, P. Schwabe, and L. Tabary-Mauejan, “Typing high-speed cryptography against spectre v1,” in 2023 IEEE Symposium on Security and Privacy (SP). IEEE, 2023, pp. 1094–1111.
[26] J. Baumann, R. Blanco, L. Ducruet, S. Harwig, and C. Hricu, “Fslh: Flexible mechanized speculative load hardening,” in 2025 IEEE 38th Computer Security Foundations Symposium (CSF). IEEE, 2025, pp. 569–584.
[27] Y. Zhu, W. Huang, and Y. Xiong, “Place protections at the right place: targeted hardening for cryptographic code against spectre v1,” in 34th USENIX Security Symposium (USENIX Security 25), 2025, pp. 2557–2576.
[28] C. Carruth, “Speculative load hardening.” [Online]. Available: https://llvm.org/docs/SpeculativeLoadHardening.html
[29] S. Ganjisa'affar, E. M. Koruyeh, J. Zellmer, H. A. Esfeden, C. Song, and N. Abu-Ghazaleh, “Specasan: Mitigating transient execution attacks using speculative address sanitization,” in Proceedings of the 52nd Annual International Symposium on Computer Architecture, 2025, pp. 2032–2045.
[30] J. Woodruff, R. N. Watson, D. Chisnall, S. W. Moore, J. Anderson, B. Davis, B. Laurie, P. G. Neumann, R. Norton, and M. Roe, “The cheri capability model: Revisiting rise in an age of risk,” ACM SIGARCH Computer Architecture News, vol. 42, no. 3, pp. 457–468, 2014.
[31] H. Liljestrand, T. Nyman, K. Wang, C. C. Perez, J.-E. Ekberg, and N. Asokan, “{PAC} it up: Towards pointer integrity using {ARM} pointer authentication,” in 28th USENIX Security Symposium (USENIX Security 19), 2019, pp. 177–194.
[32] A. Partap and D. Boneh, “Memory tagging: A memory efficient design,” arXiv preprint arXiv:2209.00307, 2022.
[33] E. Q. Vintila, P. Zieris, and J. Horsch, “Evaluating the effectiveness of memory safety sanitizers,” in 2025 IEEE Symposium on Security and Privacy (SP). IEEE, 2025, pp. 774–792.
[34] C. Canella, J. Van Bulck, M. Schwarz, M. Lipp, B. Von Berg, P. Ortner, F. Piessens, D. Evtyushkin, and D. Gruss, “A systematic evaluation of transient execution attacks and defenses," in 28th USENIX Security Symposium (USENIX Security 19), 2019, pp. 249–266.
[35] Y. Kim, R. Daly, J. Kim, C. Fallin, J. H. Lee, D. Lee, C. Wilkerson, K. Lai, and O. Mutlu, "Flipping bits in memory without accessing them: An experimental study of dram disturbance errors," ACM SIGARCH Computer Architecture News, vol. 42, no. 3, pp. 361–372, 2014.
[36] A. Di Dio, M. Hertogh, and C. Giuffrida, “Half spectre, full exploit: Hardening rowhammer attacks with half-spectre gadgets,” in 2025 IEEE Symposium on Security and Privacy (SP). IEEE, 2025, pp. 3583–3598.
[37] A. Bhattacharyya, A. Sánchez, E. M. Koruyeh, N. Abu-Ghazaleh, C. Song, and M. Payer, “{SpecROP}: Speculative exploitation of {ROP} chains,” in 23rd International Symposium on Research in Attacks, Intrusions and Defenses (RAID 2020), 2020, pp. 1–16.
[38] F. Gorter, T. Kroes, H. Bos, and C. Giuffrida, “Sticky tags: Efficient and deterministic spatial memory error mitigation using persistent memory tags,” in 2024 IEEE Symposium on Security and Privacy (SP). IEEE, 2024, pp. 4239–4257.
[39] S. Cauligi, C. Disselkoen, D. Moghimi, G. Barthe, and D. Stefan, “Sok: Practical foundations for software spectre defenses,” in 2022 IEEE Symposium on Security and Privacy (SP). IEEE, 2022, pp. 666–680.
[40] Z. Zhang, G. Barthe, C. Chuengsatiansup, P. Schwabe, and Y. Yarom, “Ultimate {SLH}: Taking speculative load hardening to the next level,” in 32nd USENIX Security Symposium (USENIX Security 23), 2023, pp. 7125–7142.
[41] V. E. Moghadam, G. Serra, F. Aromolo, G. Buttazzo, and P. Prinetto, “Memory integrity techniques for memory-unsafe languages: A survey,” IEEE Access, vol. 12, pp. 43 201–43 221, 2024.
[42] E. Barberis, P. Frigo, M. Muench, H. Bos, and C. Giuffrida, “Branch history injection: On the effectiveness of hardware mitigations against {Cross-Privilege} spectre-v2 attacks,” in 31st USENIX Security Symposium (USENIX Security 22), 2022, pp. 971–988.
[43] E. M. Koruyeh, K. N. Khasawneh, C. Song, and N. Abu-Ghazaleh, “Spectre returns! speculation attacks using the return stack buffer,” in 12th USENIX Workshop on Offensive Technologies (WOOT 18), 2018.
[44] AMD, “Transient execution of non-canonical accesses,” 2021. [Online]. Available: https://www.amd.com/en/resources/product-security/bulletin/amd-sb-1010.html
[45] Google, “The go project,” 2025. [Online]. Available: https://go.dev/project
[46] N. Christou, A. J. Gaidis, V. Atlidakis, and V. P. Kemerlis, “Eclipse: Preventing speculative memory-error abuse with artificial data dependencies,” in Proceedings of the 2024 on ACM SIGSAC Conference on Computer and Communications Security, 2024, pp. 3913–3927.
[47] Intel Corporation, “Speculative execution side channel mitigations,” 2018. [Online]. Available: https://www.intel.com/content/dam/develop/external/us/en/documents/336996-speculative-execution-side-channel-mitigations.pdf
[48] —, “Indirect branch restricted speculation,” 2018. [Online]. Available: https://www.intel.com/content/www/us/en/developer/articles/technical/software-security-guidance/technical-documentation/indirect-branch-restricted-speculation.html
[49] ARM, “Consumption of speculative data barrier,” 2025. [Online]. Available: https://developer.arm.com/documentation/ddi0602/2022-09/Base-Instructions/CSDB--Consumption-of-Speculative-Data-Barrier-
[50] O. Oleksenko, B. Trach, T. Reiher, M. Silberstein, and C. Fetzner, “You shall not bypass: Employing data dependencies to prevent bounds check bypass,” CoRR, vol. abs/1805.08506, 2018. [Online]. Available: http://arxiv.org/abs/1805.08506
[51] R. Brotzman, D. Zhang, M. T. Kandemir, and G. Tan, “Specsafe: detecting cache side channels in a speculative world,” Proceedings of the ACM on Programming Languages, vol. 5, no. OOPSLA, pp. 1–28, 2021.
[52] M. Guarnieri, B. Köpf, J. F. Morales, J. Reineke, and A. Sánchez, “Spectator: Principled detection of speculative information flows,” in 2020 IEEE Symposium on Security and Privacy (SP). IEEE, 2020, pp. 1–19.
[53] F. A. Fuchs, J. Woodruff, P. Rugg, A. Joannou, J. Clarke, J. Baldwin, B. Davis, P. G. Neumann, R. N. Watson, and S. W. Moore, “Safe speculation for cheri,” in 2024 IEEE 42nd International Conference on Computer Design (ICCD). IEEE, 2024, pp. 364–372.
[54] NIST, “Cve-2020-12965,” 2022. [Online]. Available: https://nvd.nist.gov/vuln/detail/CVE-2020-12965
[55] S. Musaev and C. Fetzner, “Transient execution of non-canonical accesses,” arXiv preprint, 2021. [Online]. Available: https://arxiv.org/abs/2108.10771
[56] M. Hertogh, S. Wiebing, and C. Giuffrida, “Leaky address masking: Exploiting unmasked spectre gadgets with noncanonical address translation,” in 2024 IEEE Symposium on Security and Privacy (SP). IEEE, 2024, pp. 3773–3788.
[57] R. George, M. Chen, K. Huang, Z. Qian, T. La Porta, and T. Jaeger, “{OPTISAN}: Using multiple spatial error defenses to optimize stack memory protection within a budget,” in 33rd USENIX Security Symposium (USENIX Security 24), 2024, pp. 7195–7212.
[58] 2018. [Online]. Available: https://github.com/vusec/deltapointers
[59] M. F. A. Kadir, J. K. Wong, F. Ab Wahab, A. F. A. A. Bharun, M. A. Mohamed, and A. H. Zakaria, “Retpoline technique for mitigating spectre attack,” in 2019 6th International Conference on Electrical and Electronics Engineering (ICEEE). IEEE, 2019, pp. 96–101.
[60] A. Reinking, N. Xie, L. De Moura, and D. Leijen, “Perceus: Garbage free reference counting with reuse,” in Proceedings of the 42nd ACM SIGPLAN International Conference on Programming Language Design and Implementation, 2021, pp. 96–111.
[61] P. R. Wilson, “Uniprocessor garbage collection techniques,” in International Workshop on Memory Management. Springer, 1992, pp. 1–42.
[62] S. Dang, Q. Zhou, K. Huang, J. Zhu, A. Gollamudi, T. Jaeger, and D. Zhang, “Dualguard docker image,” 2026. [Online]. Available: https://hub.docker.com/r/dualguard/dualguard
[63] —, “Dualguard,” Sep. 2026. [Online]. Available: https://doi.org/10.5281/zenodo.22823571
APPENDIX
A. Formalizing Program Semantics with Speculation
Language Semantics. Recall that to model speculative execution, we introduce two parameters: a prediction oracle, , as well as the speculative transaction's length w in the language semantics. Moreover, is a partial function that takes the location of a branch command and returns a queue of predicted branch outcomes (i.e., a queue of truth values). A queue is used in the oracle so that the semantics can have different outcomes for the same branch at different execution points.
We assume that each command in the source code has a unique location l. To get the next predicted outcome of the branch command with location l, we use .
Program state. We define program state as a tuple that consists of a memory state , a sequence of (potentially nested) speculative states as well as c, the remaining program to be executed. A speculative state represents a speculative transaction [52] that models speculative execution behavior. A single-step evaluation rule has the form of
where event tracks a set of security-related events, including begin, rollback, and commit, that denote start, commit and rollback of the th speculative transaction, as well as load and store that indicate the load and store of memory address issued at program location . Since the semantics mostly follows prior work [51], we omit the evaluation rules here and formalized them in the Appendix.
We define a configuration as a tuple that consists of a memory state , a sequence of (potentially nested) speculative states as well as c, the remaining program to be executed. As standard, memory is formalized as a map from variables/array elements (addresses) to their values. A speculative state represents a speculative
Fig. 8: Speculative-Aware semantics given an oracle O and a transaction length w.
transaction [52], which consists of the predicted boolean outcome p, the memory prior to the start of the transaction, the remaining number of instructions to be executed in the transaction r, and the commands c to be resumed in case of a rollback. Moreover, we use the following helper functions to update and check the remaining number of instructions in all transactions:
-
: decrease the remaining instructions by one for each .
-
zero( ): set the remaining instructions to zero for each .
-
enabled( ): returns true if for any or when .
Given an oracle and a transaction length , each evaluation rule (summarized in Figure 8) has the form of where event tracks the memory locations being accessed and program instructions being executed; we use to denote the latter. Note that the given and , the semantics is deterministic: rules COMMIT and ROLLBACK apply when one transaction ended, while the other rules require enabled(); rule COMMIT requires and ROLLBACK requires .
Given a program , an oracle and transaction length , we use to denote the sequence of emitted events starting from the initial configuration according to the semantics given and . For example, let be the following code, where , , .
The evaluation steps is as follows according to the semantics:
Hence, generates an event trace , , , , for the concrete execution.
We note that our interpretation of and w over-approximates the ones in [52], which assumes a partial function that takes as input a program, a branching history and a branch instruction, and that returns as output the predicted branch outcome and transaction length. Our formulation considers all possible outcomes of the semantics in [52].
The following are the data flow equations we used in our value range analysis.
We use a forward-may data flow analysis to compute the range of each variable in the program. Equation (4) shows the data flow equations used by the value range analysis. is the value range information at the entry point of basic block B, which is computed by taking the union of range at the exit point of all its predecessors, i.e., . Specifically, if a variable's range information can be found in every predecessor, the analysis takes the union of all the range. If a variable's range does not exist in at least one of the predecessors, meaning the range cannot be decided at this point, so the resulting range is infinite.
Out(B) is the range at the exit point of basic block B. It is computed by deducting the kill set and then union the generation set . The kill set and the generation set contains variables that are defined in basic block B. A variable in and might be in already, which indicates this variable is updated in basic block B. By deducting and union , the analysis is able to first remove the old range in and then add the newly updated range.
The following is an example to illustrate the impact of path-sensitivity on the two phases.
int func(int i) { int A[8]; if (i < 8) { return A[i]; } return -1; }
With path-sensitivity, the path condition that has to be satisfied to reach line 4 is i < 8. Under sequential execution, the memory access at line 4 is memory safe, and it will be marked as safe by the path-sensitive analysis. Under speculative execution, however, an attacker can train the branch predictor to take true branch when , which makes the path condition no longer holds. We took the heuristic that the attacker ignoring the branch condition is equivalent to the analysis dropping path condition when constraining the value range. The path-insensitive analysis would reject the access at line 4.
B. Comparison with Partial Protections
The detailed comparison with partial protections for each benchmark is shown in Figure 9 and Figure 10 for cryptographic libraries and SPEC benchmark suite, respectively.
Sequential defense. Across the SPEC benchmarks, Baggy incurs overhead ranging from 27.9% on perlbench_r to 410% on lbm_r, with an average of 131%. In comparison, DUALGUARD-DUALBAGGY incurs an average overhead of only 44%, corresponding to a 66% reduction relative to Baggy. Delta Pointers achieves lower overhead than Baggy, ranging from 1.3% on omnetpp_r to 51% on povray_r. DUALGUARD-DUALDELTAPOINTERS demonstrates comparable or slightly higher overhead due to the extra instructions for dual-safety. Overall, DUALGUARD-DUALDELTAPOINTERS achieves overhead that is lower than
or comparable to that of Delta Pointers, while providing a stronger security guarantee.
Across the cryptographic library benchmarks, Baggy exhibits substantial runtime overhead, ranging from 1.8% for AES in OpenSSL 3.3.0 to as high as 280% for SHA-256 in Libsodium 1.0.20. Despite providing stronger security guarantees, DUALGUARD-DUALBAGGY demonstrates consistently lower overhead across most benchmarks. The primary exception is Poly1305 in NaCl, where Baggy incurs lower overhead. Overall, Baggy introduces an average overhead of 146.6%, whereas DUALGUARD-DUALBAGGY incurs an average overhead of 71.9%, representing a relative reduction of approximately 51%. Delta Pointers observe a lower overhead than Baggy, ranging from 1.3% to 56%. DUALGUARD-DUALDELTAPOINTERS demonstrates comparable or slightly higher overhead due to the extra instructions for dual-safety. On average, Delta Pointer and DUALGUARD-DUALDELTAPOINTERS incur overhead of 20.4% and 28.9%, respectively, where DUALGUARD shows a slight overhead increase.
Speculative defense. We were unable to evaluate Light-SLH on the SPEC benchmarks due to its limited instruction support and scalability limitations. LLVM's SLH incurs overhead ranging from 1% to 264%, with an average of 116%. Compared with LLVM's SLH, DUALGUARD-DUALBAGGY achieves lower overhead on all benchmarks except lbm_r and nab_r, reducing overhead by 33% on average. Similarly, DUALGUARD-DUALDELTAPOINTERS incurs slightly higher overhead only on namd_r and lbm_r, while achieving an average overhead reduction of 37.9%.
For cryptographic libraries, DUALGUARD-DUALBAGGY incur average overhead of 71.9%, whereas LLVM's SLH and LightSLH incur overheads of 45.6% and 30.6%, respectively. This higher overhead primarily stems from the fact that DUALGUARD-DUALBAGGY instrumentations consist of memory loads for the bounds table. Notably, despite its stronger safety, DUALGUARD-DUALBAGGY achieves lower overhead in 7 evaluated benchmarks compared to LLVM's SLH, and in 4 benchmark compared to LightSLH. DUALGUARD-DUALDELTAPOINTERS, on the other hand, observes an overhead of only 28.9%, which is lower than both SLH variants while providing dual-safety thanks to the in-pointer metadata storage.
C. Case Study
To better understand how DUALGUARD's configurations achieve lower overheads than naive compositions, we provide a real-world example in the big number library (bn) of OpenSSL 3.3.0. The big numbers in OpenSSL are managed in an internal stack. DUALGUARD analysis reports a potential out-of-bounds store in the stack push function below.
static int BN_STACK_push(BN_STACK st, unsigned int idx) { if (st->depth == st->size) { / Need to expand */ unsigned int newsize = } }

Fig. 9: Comparison between partial defenses and DUALGUARD for cryptographic libraries

Fig. 10: Comparison between partial defenses and DUALGUARD for SPEC benchmarks
st->size ? (st->size * 3 / 2) :
BN_CTX_START_FRAMES;
unsigned int *newitems;
if ((newitems = OPENSSL_malloc(sizeof(*
newitems) * newsize)) == NULL)
return 0;
if (st->depth)
memcpy(newitems, st->indexes, sizeof
(*newitems) * st->depth);
OPENSSL_free(st->indexes);
st->indexes = newitems;
st->size = newsize;
}
st->indexes[(st->depth)++] = idx;
return 1;
In this function, the stack is resized and reallocated if the current stack cannot hold more entries. The new size computation at Line 6 can potentially overflow the integer size and become smaller (newsize < st->depth), making the allocation size at Line 9 smaller than the actual required size. Finally, at Line 17, the access to the index st->depth could write into memory regions outside of the allocation bounds. This pattern of integer overflow followed by out-of-bounds write can be found in many high-risk vulnerabilities (e.g.,
CVE-2025-39967, CVE-2026-5121, and CVE-2026-5444).
In a naive composition of BAGGY+SLH, the store operation at Line 17 will be transformed to the following code, with the Baggy instrumentation marked as blue and SLH instrumentation marked as yellow.
depth = st->depth;
base = st->indexes;
addr = &base[depth];
log_size = size_table[base >> log_slot_size];
is_oob = (addr XOR base) >> log_size != 0
if (is_oob) {
mis = is_oob ? 0 : -1
addr = slow_path(base, addr);
} else
mis = !is_oob ? 0 : -1
hardened_addr = addr | mis;
store(idx, hardened_addr);
st->depth++;
Baggy introduces a branch to check if the index is out of the allocation bounds (i.e., newsize), which ensures the store operation stays inside bounds in sequential execution. Then, to preserve the semantics of the program before hardening, SLH inserts an else branch to keep track of the mis-speculation flag mis. Upon storing, the address is hardened by mis. With the layered instrumentation, when reaching Line 12,

Fig. 11: The effect of selective protection on SPEC benchmarks

Fig. 12: The effect of selective protection on cryptographic libraries
the transformed code will correctly set the MSB if depth is greater than newsize. That said, the store operation still relies on the hardware check to reject an address where MSB is set, leaving the complex composition superfluous.
In contrast, DUALGUARD-DUALBAGGY instrument Line 17 as follows. By checking the bounds in a branchless manner and removing the reliance on hardware check, DUALBAGGY instrumentation is more efficient and robust against speculative attacks at the same time.
1 depth = st->depth;
2 base = st->indexes;
3 addr = &base[depth];
4 log_size = size_table[base >> log_slot_size];
5 is_oob = (addr XOR base) >> log_size != 0
6 final_addr = select(is_oob, -1, addr);
7 store(idx, hardened_addr);
8 st->depth++;
D. Selective Defense Overhead
The detailed comparison of selective defenses for each benchmark is shown in Figure 11 and Figure 12.
E. Analysis Running Time
The running time for our analysis is shown in Table III.
F. Artifact
This section details how to build and run DUALGUARD. The tool chain can be found at https://doi.org/10.5281/zenodo.22823571. The repositories include all the source code of DUALGUARD, and benchmarks except SPEC CPU 2017 benchmark suite that cannot be shared due to copyright issue. DUALGUARD can be either run by using the pre-built Docker image [62] or by building from source [63]. We recommend using the pre-built Docker image to ease the burden on setting up the tool chain.
- Using Pre-built DUALGUARD with Docker: Make sure the test machine has Docker installed. We provide the Docker image on Dockerhub [62]. Get the container running with the following commands.
1 # Pull Docker image from DockerHub
2 docker pull dualguard/dualguard:latest
3
4 # Run a container with the image
5 docker run --name dualguard -dit dualguard/
dualguard
6
7 # Get into the container's bash
8 docker exec -it dualguard bash
Inside the container, the artifact is located at /root/dualguard. DUALGUARD has been built in
TABLE III: Analysis running time
| Benchmark | Running Time (s) |
| perlbench_r | 8254.01 |
| mcf_r | 6.77 |
| namd_r | 24.55 |
| parest_r | 604.2 |
| povray_r | 1309.28 |
| lbm_r | 1.42 |
| omnetpp_r | 180.49 |
| xalancbnk_r | 51.23 |
| x264_r | 937.43 |
| deepsjeng_r | 156.22 |
| leela_r | 7.9 |
| nab_r | 149.82 |
| xz_r | 2.98 |
| OpenSSL3.3.0/AES | 0.04 |
| OpenSSL3.3.0/RSA | 6.69 |
| OpenSSL1.0.2f/RSA | 7.54 |
| OpenSSL3.3.0/ChaCha20 | 0.07 |
| OpenSSL3.3.0/Curve25519 | 0.95 |
| OpenSSL3.3.0/Poly1305 | 0.03 |
| OpenSSL3.3.0/SHA256 | 0.28 |
| Libsodium1.0.20/Salsa20 | 0.05 |
| Libsodium1.0.20/SHA256 | 0.17 |
| NaCL/Poly1305 | 0.2 |
| NaCL/Salsa20 | 0.03 |
| NaCL/SHA256 | 0.18 |
| PQClean/McEliece | 0.16 |
| PQClean/Kyber | 0.99 |
the image, but SPEC CPU 2017 benchmark suite has to be installed manually due to copyright reasons. Please install the benchmark suite according to its instructions.
After the benchmark suite is successfully installed, edit SPEC_PATH to point to the installation directory, and run the setup script.
1 # Set up benchmark harness for SPEC
2 bash ./setup.sh
- Building DUALGUARD from Source: We have tested building the system under Ubuntu 24.04, which provides the best compatibility of software used. Please have 30 GB of disk space available on your system. The instructions in this documentation assume the user is running this version of Ubuntu Linux.
First, install the dependencies.
1 sudo apt update
2 sudo apt install git build-essential python3 ninja-build wget cmake libtinfo-dev libtinfo6
Then, download the source code from the repo [63], and decompress the source code.
Before running the building script, please install SPEC CPU 2017 benchmark suite and edit SPEC_PATH to point to the installation directory. Finally, navigate into the root directory of the source code and run the building script.
1 bash ./build.sh
Run the benchmarks with the following commands accordingly.
1 # run SPEC benchmarks
2 ./run.sh spec
3
4 # run LightSLH benchmarks
5 ./run.sh lightslh
6
7 # run both
8 ./run.sh
If SPEC CPU 2017 benchmark suite is not available, run run.sh lightslh to run the LightSLH benchmarks only.
Using the following commands to visualizing the results.
1 # This will create Figure 5 and 10 in the paper
2 cd $SPEC_ROOT/scripts
3 python3 plots.py
4
5 # Produce Figure 6, 9 and 11 in the paper
6 cd LightSLH-benchmarks/bench/wrapper
7 python3 plots.py