Introduction
While Rust is celebrated for its memory safety, it provides an "unsafe" escape hatch for low-level systems programming. Code within unsafe blocks can bypass compiler checks, reintroducing classic vulnerabilities like buffer overflows and Use-After-Free (UAF) bugs. LiteRSan is a high-performance memory sanitizer designed specifically for Rust that leverages the language’s unique ownership and borrowing rules to identify "risky" pointers. By replacing the heavyweight shadow memory and red zones of traditional AddressSanitizer (ASan) with compact, per-pointer metadata, LiteRSan achieves a staggering reduction in overhead—dropping runtime costs from ~150% to just 18.8%—while detecting Rust-specific bugs that traditional tools miss.
The Problem with Generic Sanitizers
To catch memory errors in unsafe code, developers typically reach for AddressSanitizer (ASan). However, ASan was built for C/C++ and treats all memory accesses as potentially dangerous. This leads to two major issues in the Rust ecosystem:
- Extreme Overhead: ASan-based tools for Rust (like ERASan and RustSan) often incur 2–3x runtime slowdowns and massive memory footprints (up to 800%+ overhead) because they rely on generic C-style alias analysis that doesn't understand Rust's strict ownership model.
- Detection Gaps: ASan relies on physical memory states (e.g., is this memory currently "quarantined"?). It can miss "logical" memory errors unique to Rust, such as when a programmer uses
mem::forgetto bypass a destructor, leaving a raw pointer dangling even though the memory hasn't been physically freed yet.
The LiteRSan Approach
LiteRSan moves away from the "one-size-fits-all" approach of ASan through a three-stage pipeline designed to minimize instrumentation while maximizing detection accuracy.
Stage 1: Rust-specific Static Analysis
Instead of analyzing every pointer, LiteRSan uses reachability analysis to ignore dead code and lifetime-aware taint analysis to pinpoint "risky pointers." These are raw pointers exposed in unsafe code and any pointers derived from them. Because LiteRSan understands Rust's ownership, it can prune out pointers that the compiler already guarantees are safe, drastically reducing the number of checks needed.
Stage 2: Metadata Inference
Traditional sanitizers use "shadow memory" to track the state of every byte of RAM. LiteRSan replaces this with compact metadata stored in separate maps. For spatial safety, it tracks Capacity, Initialized Length, and Offset. For temporal safety, it tracks Ownership and May-alias relationships.
Stage 3: Selective Instrumentation
LiteRSan only inserts runtime checks (instrumentation) for the specific risks identified in Stage 1. If a pointer is only at risk for spatial errors (like an out-of-bounds access), it doesn't get temporal checks, and vice versa.
Key Insights: Spatial vs. Temporal Risks
A key insight of the LiteRSan architecture is that spatial risks (like offsets) don't propagate the same way temporal risks (like ownership) do. If you perform arithmetic on a raw pointer, only that derivation is spatially risky. However, if an object is freed, all pointers aliasing it become temporally risky. LiteRSan's taint analysis handles these two classes differently to stay efficient.
Furthermore, LiteRSan tracks the "logical" validity of a pointer based on Rust's Drop implementation. This allows it to catch UAF bugs where an object is "forgotten" or moved—a scenario where ASan often fails because the underlying memory remains physically allocated.
Evaluation and Results
The authors evaluated LiteRSan using 28 benchmarks, including popular crates like regex and tokio, as well as large-scale applications like the Servo web engine and ripgrep. The performance gains are the highlight of the paper:
- Runtime Overhead: LiteRSan averages 18.84% overhead, compared to 152.05% for ERASan and 183.50% for RustSan.
- Memory Overhead: LiteRSan uses almost no extra memory (0.81%), whereas existing tools balloon memory usage by 739% to 861%.
- Compilation Speed: LiteRSan is roughly 15x faster to compile than previous state-of-the-art sanitizers.
- Bug Detection: LiteRSan detected 100% (20/20) of the most recent RustSec bugs tested, including 4 specific cases (2 OOB, 1 UAF, 1 use-before-initialization) where ASan failed completely.
Limitations and Future Work
LiteRSan currently only analyzes Rust source code and does not harden external C/C++ libraries linked via Foreign Function Interface (FFI). Bugs originating deep within a C library could still go undetected. Additionally, the tool does not specifically target "type confusion" bugs from mem::transmute, though it can catch them if they lead to spatial or temporal errors. Future work involves extending checks to FFI boundaries and integrating with sandboxing for holistic cross-language defense.
Summary updated