Unsafe Rust code is necessary for interoperability with C/C++ libraries and implementing low-level data structures, but it can cause memory safety violations in otherwise memory-safe Rust programs. Sanitizers can catch such memory errors at runtime, but introduce many unnecessary checks even for memory accesses guaranteed safe by the Rust type system. We introduce SafeFFI, a system for optimizing memory safety instrumentation in Rust binaries such that checks occur at the boundary between unsafe and safe code, handing over the enforcement of memory safety from the sanitizer to the Rust type system. Unlike previous approaches, our design avoids expensive whole-program analysis and adds much less compile-time overhead (2.64x compared to over 8.83x). On a collection of popular Rust crates and known vulnerable Rust code, SafeFFI achieves superior performance compared to state-of-the-art systems, reducing sanitizer checks by up to 98%, while maintaining correctness and flagging all spatial and temporal memory safety violations.
翻译:非安全Rust代码在与C/C++库互操作及实现底层数据结构时不可或缺,但它可能导致原本内存安全的Rust程序出现内存安全违规。净化器虽能在运行时捕获此类内存错误,但会对Rust类型系统已保证安全的内存访问引入大量不必要的检查。本文提出SafeFFI系统,通过优化Rust二进制文件中的内存安全检测机制,使检查仅发生在非安全代码与安全代码的边界处,从而将内存安全的保障职责从净化器移交至Rust类型系统。与既有方案不同,本设计避免了昂贵的全程序分析,并大幅降低编译时开销(仅2.64倍,而现有方案超过8.83倍)。在主流Rust代码库与已知漏洞代码集上的实验表明,SafeFFI在保持正确性并捕获所有时空内存安全违规的同时,较前沿系统实现了更优性能,将净化器检查减少高达98%。