arXiv:2609.09641cs.PLSep 2026

Manuscript Offprint

arXiv:2609.09641

UnsafeChecker: Finding Soundness Bugs in Rust Safe Abstractions

Xizhe Yin, Yaokun Zhang, Yang Feng, Baowen Xu

XIZHE YIN*, Nanjing University, China

YAOKUN ZHANG*, Nanjing University, China

YANG FENG†, Nanjing University, China

BAOWEN XU, Nanjing University, China

Rust guarantees memory safety without garbage collection through a strict ownership and borrowing system. However, for low-level systems programming, many widely used libraries rely on the unsafe keyword. These libraries encapsulate raw-pointer operations behind safe APIs to form safe abstractions. A single mistake in this internal unsafe code can break its safety contract, rendering the abstraction unsound and allowing safe clients to trigger undefined behavior. Detecting these potential soundness violations is challenging. Existing static analysis tools for C/C++ ignore Rust-specific safety contracts, while current Rust tools lack the deep semantic modeling required to track the contexts that raw pointers erase.

To address this gap, we present UnsafeChecker, a compiler-integrated static analysis framework for detecting potential soundness violations in Rust safe abstractions. UnsafeChecker analyzes Rust MIR using a flow-sensitive abstract interpretation that maintains a shared state with three components: ownership, object validity, and layout. Each warning rule consumes the subset of facts needed for the corresponding Rust safety obligation. UnsafeChecker reports both instruction-level undefined behavior and boundary-level contract violations that may escape through safe APIs. We evaluate UnsafeChecker on a benchmark of 46 Rust-Sec vulnerabilities, which contain 53 ground-truth bugs. UnsafeChecker outperforms several state-of-the-art tools, detecting 32 CVEs and covering 36 bugs (67.9% recall) with 51.6% alert-level precision. Furthermore, in a large-scale scan of real-world crates on crates.io, UnsafeChecker uncovered 114 previously unknown bugs across 83 crates, with 45 confirmed and 27 already fixed by maintainers.

Additional Key Words and Phrases: Rust, Static Analysis, Memory Safety, Unsafe Code, Abstract Interpretation

1 Introduction

Rust has become popular in systems programming, adopted by major projects such as Android and the Linux kernel [19, 21, 28]. A key reason for this popularity is that Rust guarantees memory safety without garbage collection. This makes it an ideal choice for building low-level systems that demand both high performance and strict safety. To achieve this, Rust relies on a strict ownership and borrowing system. For safe references, the compiler statically tracks their semantic context—specifically ownership relations, lifetimes, and type layouts—to enforce critical safety invariants. This ensures that every value has a unique owner, no reference outlives its data, and memory accesses are strictly bounded. As long as code remains within the safe subset of the language (Safe Rust), the compiler guarantees that these invariants hold, ensuring memory safety [24, 26].

However, the strict ownership model can be too restrictive for low-level tasks, such as direct hardware manipulation and high-performance data structures. To support this, Rust provides the unsafe keyword, which relaxes compiler checks and permits the use of raw pointers [24]. Raw pointers behave as plain addresses and do not carry the ownership, lifetime, or layout guarantees that Safe Rust relies on. As a result, the compiler cannot statically enforce these safety invariants

*Both authors contributed equally to this research.

†Yang Feng is the corresponding author.

Authors' Contact Information: Xizhe Yin, xizheyin@smail.nju.edu.cn, Nanjing University, Nanjing, Jiangsu, China; Yaokun Zhang, yaokunzhang@smail.nju.edu.cn, Nanjing University, Nanjing, Jiangsu, China; Yang Feng, Nanjing University, Nanjing, China, fengyang@nju.edu.cn; Baowen Xu, Nanjing University, Nanjing, China, bwxu@nju.edu.cn.

for them. In practice, library developers encapsulate unsafe blocks behind safe APIs, forming safe abstractions. For example, the standard library implements types such as Vec and Mutex with unsafe code, but exposes safe interfaces. This design relies on a critical contract: the internal unsafe code must manually uphold the same safety invariants mandated by Safe Rust. If this contract is broken, the abstraction is unsound, allowing safe client code to trigger undefined behavior [3, 25]. Because the compiler does not validate these conditions inside unsafe blocks, a single implementation error can compromise the safety of the entire library [28]. This gap motivates automated analyses for detecting potential soundness violations in safe abstractions.

Existing approaches fall short because they prioritize execution errors over whether unsafe code upholds the contract relied on by safe APIs. Tools designed for C and C++ operate on a flat memory model. They check for invalid memory accesses (e.g., buffer overflows) but ignore Rust's safety contracts. They also lack a language-level definition of the safety invariants that Safe Rust enforces. In Rust, these invariants are part of the soundness contract of safe abstractions [26]. For example, duplicating a raw pointer is valid in C. In Rust, however, if that pointer represents a unique resource (e.g., Box<T>), duplicating it violates ownership uniqueness. Since C/C++ tools do not model ownership semantics, they cannot detect such contract violations. Similarly, existing Rust tools often rely on syntactic pattern matching or general memory safety checks. While effective for specific bug classes, they lack the deep semantic modeling required to check that an abstraction maintains its safety invariants. They do not track the semantic context—ownership, lifecycle, and layout—that the compiler erases in unsafe blocks. Consequently, they cannot reliably check that an unsafe implementation preserves the invariants required by its safe API.

To detect potential soundness violations in safe abstractions, we design UnsafeChecker, a three-component static analysis framework for Rust. UnsafeChecker targets bugs where unsafe pointer operations violate the safety obligations that safe clients rely on. It analyzes Rust MIR by tracking three kinds of facts: ownership, object validity, and layout (Section 3). Specifically, the ownership component captures aliasing and resource uniqueness; the object-validity component tracks states such as live, moved, dropped, or uninitialized; and the layout component models pointer bounds, alignment, mutability, and offsets. These facts are maintained in one shared flow-sensitive state. Some checks are domain-local, such as layout-centered bounds checks, while others combine facts across components through shared object and pointer identities. The analysis is flow-sensitive. It propagates this composite state along the CFG until reaching a fixpoint. UnsafeChecker then checks instruction-level UB (e.g., out-of-bounds and invalid dereference) and boundary-level violations that can escape through safe APIs (e.g., returning a dangling pointer).

The contributions of this paper can be summarized as follows:

  • Framework: We propose a MIR-level static analysis that maintains ownership, object-validity, and layout facts in a shared flow-sensitive state. This design supports both domain-local checks, such as spatial layout violations, and composite checks, such as dangling pointers and double frees that require ownership and validity facts.
  • Tool: We implemented UnsafeChecker as a compiler plugin. It analyzes Rust MIR efficiently and fits into existing build pipelines.
  • Study: We evaluated UnsafeChecker on a benchmark of 46 RustSec vulnerabilities (comprising 53 ground-truth bugs). The results show that UnsafeChecker detects 32 vulnerabilities (69.6% recall) and covers 36 bugs (67.9% recall), with an alert-level precision of 51.6%, outperforming several state-of-the-art tools [4, 7, 16]. Furthermore, when applied to a large-scale scan of real-world Rust crates, UnsafeChecker uncovered 114 previously unknown bugs across 83 crates. Among these, developers have confirmed 45 as genuine vulnerabilities, and 27 have already been fixed.

References (14)