Analyzing Unsafe Rust Usage Across Domains

Abdulaziz Alotaibi

Project Overview

Problem: Rust’s unsafe mode allows developers to bypass its memory safety guarantees to achieve fine-grained control over hardware and performance optimizations. However, this introduces significant risks such as memory safety bugs (e.g., use-after-free errors, null pointer dereferences, and data races) that can compromise system reliability and security. Understanding how unsafe Rust is used across different domains and improving tools to detect vulnerabilities are essential for enabling developers to write safer and more efficient systems.

Approach: I analyzed unsafe Rust usage in 20 open-source projects across five domains: embedded systems, databases, distributed systems, general-purpose libraries, and Byzantine Fault Tolerance (BFT). I categorized unsafe Rust code into four key patterns: Memory Management, Foreign Function Interfaces (FFI), Unchecked Assumptions, and Performance Optimization. Using a custom Python tool, I detected and isolated unsafe Rust blocks, then tested a subset of 60 blocks with Rudra, a static analysis tool, to identify memory safety vulnerabilities.

Results: The analysis revealed that unsafe Rust is used primarily for Memory Management and Interfacing with Non-Rust Code (FFI), particularly in performance-critical domains like embedded systems and databases. Rudra did not identify any memory safety bugs in the analyzed blocks, suggesting cautious developer practices but also exposing limitations in Rudra's ability to detect nuanced vulnerabilities. Future work could focus on expanding the analysis to more unsafe patterns, automating the isolation process for scalability, and improving detection tools to address complex real-world scenarios.

Project Materials

References/Research

The analysis in this study builds on previous work and tools that address memory safety and unsafe Rust usage:

This project extends the application of Rudra to real-world developer projects and highlights limitations in existing tools, setting the stage for future improvements in static analysis and unsafe Rust detection.