A Closer Look at the Security Risks in the Rust Ecosystem

Xiaoye Zheng, Zhiyuan Wan, Yun Zhang, Rui Chang, David Lo

TL;DR

While Rust is celebrated for its memory safety, its ecosystem is not immune to critical vulnerabilities. This paper presents the first large-scale empirical study of 433 Rust vulnerabilities, revealing that memory safety and concurrency issues still account for two-thirds of security risks, largely driven by the use of the unsafe keyword.

What Problem Does This Paper Address?

Rust’s primary selling point is its "fearless concurrency" and memory safety, enforced by a strict compiler. However, to perform low-level tasks, developers use the unsafe keyword to bypass these checks. As the Rust ecosystem (crates.io) explodes in popularity, a critical question emerges: Does Rust’s safety model actually translate to a more secure ecosystem in practice?

Prior research focused on specific bug types or the general usage of unsafe. This paper fills a major gap by providing a systematic, end-to-end investigation into the characteristics, life spans, and fix patterns of vulnerabilities across the entire Rust ecosystem.

Methods

The researchers employed a mixed-methods empirical approach:

  1. Data Collection & Mapping: They aggregated 433 unique vulnerabilities from sources like RustSec, NVD, and GitHub Advisories. They used Software Fault Patterns (SFP) to map disparate classification schemes (CWE vs. RustSec) into 17 consistent vulnerability types.
  2. Life Span Analysis: They calculated the time from a vulnerability's introduction (using git blame) to its public disclosure and eventual fix.
  3. Compiler-Assisted Inspection: The team developed a custom Rust compiler plugin to automatically identify whether vulnerable code resided in "safe" or "unsafe" functions and blocks.
  4. Manual Fix Pattern Mining: They manually inspected 218 fix commits to categorize how developers actually resolve these issues.

Datasets

The study utilized several key data sources:

  • The Vulnerability Dataset: 433 unique vulnerabilities, 300 code repositories, and 218 fix commits spanning seven years.
  • Crates.io Metadata: Metadata for 84,105 packages to calculate vulnerability density and popularity metrics.
  • Replication Package: The authors have made their dataset and tools publicly available on GitHub and Zenodo.

Key Insights and Ideas

  • The "Unsafe" Magnet: Vulnerable code contains statistically significantly more unsafe functions and blocks than the rest of the codebase. While unsafe is necessary for systems programming, it remains the "achilles heel" of Rust security.
  • The Long Shadow of Bugs: It takes an average of 770 days (2.1 years) for a vulnerability to be disclosed after it is introduced. This creates a massive "window of opportunity" for attackers.
  • Disclosure Without Defense: Alarmingly, one-third of vulnerabilities have no fix committed at the time they are publicly disclosed.
  • The Popularity Paradox: Popular packages have more reported vulnerabilities (likely due to more "eyes" on the code), but less popular packages suffer from vulnerabilities for a higher number of versions, likely due to slower maintenance cycles.
  • Localization is Key: Most vulnerabilities are highly localized, often affecting just a single file or a few lines of code. This suggests that targeted audits of unsafe blocks could yield high security ROI.

Key Results

  • Dominant Risks: Memory management (40%) and Memory access (39.17%) are the most frequent vulnerability types, followed by Synchronization (20.56%).
  • Vulnerability Density: There is a continuous upward trend in security risks at the package level, but a decreasing trend at the code level since August 2020, suggesting that while more packages are being flagged, the quality of new code is improving.
  • Fix Complexity: Fixes are generally small—the median fix adds 14 lines and deletes 4.
  • Three Primary Fix Patterns:
    1. Safe Functions: Developers usually add more safe code/checks to validate preconditions.
  • Unsafe Blocks: Developers often remove the unsafe block entirely and refactor into safe Rust.
  • Unsafe Functions: Fixes often involve modifying unsafe trait implementations (e.g., adding Send or Sync bounds to prevent data races).

Limitations and Future Work

The authors acknowledge that their study is limited to disclosed vulnerabilities; many "silent" fixes or undiscovered bugs are not captured. Furthermore, the manual inspection of commits, while rigorous, is subject to human interpretation.

Future Work: The researchers suggest developing automated tools for continuous vulnerability monitoring in the Rust ecosystem and creating more sophisticated static analysis tools specifically designed to audit the boundaries between safe and unsafe Rust code.

Summary updated

BibTeX
@article{zheng2024closer,
  author = {Xiaoye Zheng and Zhiyuan Wan and Yun Zhang and Rui Chang and David Lo},
  title = {{A Closer Look at the Security Risks in the Rust Ecosystem}},
  journal = {ACM Trans. Softw. Eng. Methodol.},
  year = {2024},
  url = {https://openreview.net/forum?id=tMeUcxCi6T},
}
Figure