Join the Cyber Forum: Threat Intel on May 12, 2026 to learn how AI is reshaping threat defense.Join the Virtual Cyber Forum: Threat IntelRegister Now
Experiencing a Breach?Blog
Get StartedContact Us
SentinelOne
  • Platform
    Platform Overview
    • Singularity Platform
      Welcome to Integrated Enterprise Security
    • AI for Security
      Leading the Way in AI-Powered Security Solutions
    • Securing AI
      Accelerate AI Adoption with Secure AI Tools, Apps, and Agents.
    • How It Works
      The Singularity XDR Difference
    • Singularity Marketplace
      One-Click Integrations to Unlock the Power of XDR
    • Pricing & Packaging
      Comparisons and Guidance at a Glance
    Data & AI
    • Purple AI
      Accelerate SecOps with Generative AI
    • Singularity Hyperautomation
      Easily Automate Security Processes
    • AI-SIEM
      The AI SIEM for the Autonomous SOC
    • AI Data Pipelines
      Security Data Pipeline for AI SIEM and Data Optimization
    • Singularity Data Lake
      AI-Powered, Unified Data Lake
    • Singularity Data Lake for Log Analytics
      Seamlessly Ingest Data from On-Prem, Cloud or Hybrid Environments
    Endpoint Security
    • Singularity Endpoint
      Autonomous Prevention, Detection, and Response
    • Singularity XDR
      Native & Open Protection, Detection, and Response
    • Singularity RemoteOps Forensics
      Orchestrate Forensics at Scale
    • Singularity Threat Intelligence
      Comprehensive Adversary Intelligence
    • Singularity Vulnerability Management
      Application & OS Vulnerability Management
    • Singularity Identity
      Identity Threat Detection and Response
    Cloud Security
    • Singularity Cloud Security
      Block Attacks with an AI-Powered CNAPP
    • Singularity Cloud Native Security
      Secure Cloud and Development Resources
    • Singularity Cloud Workload Security
      Real-Time Cloud Workload Protection Platform
    • Singularity Cloud Data Security
      AI-Powered Threat Detection for Cloud Storage
    • Singularity Cloud Security Posture Management
      Detect and Remediate Cloud Misconfigurations
    Securing AI
    • Prompt Security
      Secure AI Tools Across Your Enterprise
  • Why SentinelOne?
    Why SentinelOne?
    • Why SentinelOne?
      Cybersecurity Built for What’s Next
    • Our Customers
      Trusted by the World’s Leading Enterprises
    • Industry Recognition
      Tested and Proven by the Experts
    • About Us
      The Industry Leader in Autonomous Cybersecurity
    Compare SentinelOne
    • Arctic Wolf
    • Broadcom
    • CrowdStrike
    • Cybereason
    • Microsoft
    • Palo Alto Networks
    • Sophos
    • Splunk
    • Trellix
    • Trend Micro
    • Wiz
    Verticals
    • Energy
    • Federal Government
    • Finance
    • Healthcare
    • Higher Education
    • K-12 Education
    • Manufacturing
    • Retail
    • State and Local Government
  • Services
    Managed Services
    • Managed Services Overview
      Wayfinder Threat Detection & Response
    • Threat Hunting
      World-Class Expertise and Threat Intelligence
    • Managed Detection & Response
      24/7/365 Expert MDR Across Your Entire Environment
    • Incident Readiness & Response
      DFIR, Breach Readiness, & Compromise Assessments
    Support, Deployment, & Health
    • Technical Account Management
      Customer Success with Personalized Service
    • SentinelOne GO
      Guided Onboarding & Deployment Advisory
    • SentinelOne University
      Live and On-Demand Training
    • Services Overview
      Comprehensive Solutions for Seamless Security Operations
    • SentinelOne Community
      Community Login
  • Partners
    Our Network
    • MSSP Partners
      Succeed Faster with SentinelOne
    • Singularity Marketplace
      Extend the Power of S1 Technology
    • Cyber Risk Partners
      Enlist Pro Response and Advisory Teams
    • Technology Alliances
      Integrated, Enterprise-Scale Solutions
    • SentinelOne for AWS
      Hosted in AWS Regions Around the World
    • Channel Partners
      Deliver the Right Solutions, Together
    • SentinelOne for Google Cloud
      Unified, Autonomous Security Giving Defenders the Advantage at Global Scale
    • Partner Locator
      Your Go-to Source for Our Top Partners in Your Region
    Partner Portal→
  • Resources
    Resource Center
    • Case Studies
    • Data Sheets
    • eBooks
    • Reports
    • Videos
    • Webinars
    • Whitepapers
    • Events
    View All Resources→
    Blog
    • Feature Spotlight
    • For CISO/CIO
    • From the Front Lines
    • Identity
    • Cloud
    • macOS
    • SentinelOne Blog
    Blog→
    Tech Resources
    • SentinelLABS
    • Ransomware Anthology
    • Cybersecurity 101
  • About
    About SentinelOne
    • About SentinelOne
      The Industry Leader in Cybersecurity
    • Investor Relations
      Financial Information & Events
    • SentinelLABS
      Threat Research for the Modern Threat Hunter
    • Careers
      The Latest Job Opportunities
    • Press & News
      Company Announcements
    • Cybersecurity Blog
      The Latest Cybersecurity Threats, News, & More
    • FAQ
      Get Answers to Our Most Frequently Asked Questions
    • DataSet
      The Live Data Platform
    • S Foundation
      Securing a Safer Future for All
    • S Ventures
      Investing in the Next Generation of Security, Data and AI
  • Pricing
Get StartedContact Us
CVE Vulnerability Database
Vulnerability Database/CVE-2022-21658

CVE-2022-21658: Rust-lang Rust Race Condition Vulnerability

CVE-2022-21658 is a race condition vulnerability in Rust-lang Rust affecting the std::fs::remove_dir_all function. Attackers can exploit this to delete unauthorized files. This article covers technical details, affected versions, and mitigations.

Published: February 17, 2026

CVE-2022-21658 Overview

CVE-2022-21658 is a race condition vulnerability (CWE-363, CWE-367) affecting the std::fs::remove_dir_all function in the Rust standard library. This Time-of-Check Time-of-Use (TOCTOU) vulnerability enables symlink following during directory removal operations. An attacker could exploit this race condition to trick a privileged program into deleting files and directories that the attacker would not otherwise have permission to access or delete.

The vulnerability affects Rust versions 1.0.0 through 1.58.0, with the fix released in version 1.58.1. The Rust Security Response Working Group identified this issue and coordinated the disclosure and patch. Programs running with elevated privileges, such as system daemons and setuid binaries, are at the highest risk of exploitation.

Critical Impact

Privileged programs using std::fs::remove_dir_all can be tricked into following symlinks and deleting arbitrary files and directories, potentially leading to system compromise or data loss.

Affected Products

  • Rust-lang Rust versions 1.0.0 through 1.58.0
  • Fedoraproject Fedora 34 and 35
  • Apple iPadOS, iOS, macOS, tvOS, and watchOS (various versions)

Discovery Timeline

  • 2022-01-20 - CVE-2022-21658 published to NVD
  • 2022-01-20 - Rust-lang releases security patch in version 1.58.1
  • 2024-11-21 - Last updated in NVD database

Technical Details for CVE-2022-21658

Vulnerability Analysis

The vulnerability exists in the std::fs::remove_dir_all function, which is designed to recursively delete a directory and all its contents. The function was susceptible to a classic TOCTOU race condition where an attacker could replace a directory with a symbolic link between the time the function checks the target and when it performs the deletion operation.

When a privileged program calls remove_dir_all on a directory, there is a window of opportunity where an attacker can replace a subdirectory with a symlink pointing to a sensitive location (such as system directories or other users' files). The function would then follow the symlink and delete the contents of the linked target, effectively allowing unprivileged users to delete files they should not have access to.

This vulnerability requires local access and specific timing, but the impact is significant when exploited against privileged processes. The attack is particularly dangerous for setuid binaries and system daemons that routinely clean up temporary directories.

Root Cause

The root cause is a Time-of-Check Time-of-Use (TOCTOU) race condition in the directory traversal logic of std::fs::remove_dir_all. The function did not properly prevent symlink following during the recursive deletion process. Between checking whether an entry is a directory and actually removing its contents, an attacker could swap a directory for a symlink, causing the privileged process to follow the symlink and delete unintended targets.

The Rust standard library advisory notes that adding checks in application code before calling remove_dir_all does not mitigate the vulnerability, as such checks would be equally vulnerable to the same race condition.

Attack Vector

The attack requires local access to the system where a privileged program uses remove_dir_all. The attacker must be able to create symlinks in a location where the privileged program will traverse during its directory removal operation. The attack sequence involves:

  1. Identifying a privileged program that uses std::fs::remove_dir_all on user-controllable paths
  2. Creating a directory structure that the program will attempt to delete
  3. Racing against the deletion operation to replace a subdirectory with a symlink pointing to a target location
  4. If successful, the privileged program follows the symlink and deletes the target contents

The vulnerability requires precise timing and repeated attempts may be necessary, but exploitation is feasible particularly against programs that perform cleanup operations on predictable paths or schedules.

Detection Methods for CVE-2022-21658

Indicators of Compromise

  • Unexpected file or directory deletions in privileged or system locations
  • Presence of symlinks in directories that are targets of recursive deletion by privileged processes
  • Audit logs showing privileged processes accessing unexpected file paths via symlink redirection
  • System integrity failures or missing configuration files following privileged program execution

Detection Strategies

  • Monitor file system operations for privileged processes that perform recursive directory deletions, particularly when symlinks are involved
  • Implement file integrity monitoring (FIM) on critical system directories to detect unauthorized deletions
  • Review application logs and system audit trails for unusual deletion patterns or access to unintended paths
  • Scan Rust application binaries and dependencies to identify versions prior to 1.58.1

Monitoring Recommendations

  • Enable comprehensive audit logging for privileged processes, tracking file operations including symlink resolution
  • Deploy SentinelOne endpoint protection to detect and alert on suspicious file system activity patterns
  • Implement real-time monitoring for symlink creation in directories used by privileged cleanup processes
  • Establish baseline behaviors for privileged daemons and setuid binaries to identify anomalous file operations

How to Mitigate CVE-2022-21658

Immediate Actions Required

  • Upgrade Rust toolchain to version 1.58.1 or later immediately, prioritizing systems running privileged Rust applications
  • Rebuild all Rust applications compiled with affected toolchain versions (1.0.0 through 1.58.0)
  • Audit privileged applications and system daemons to identify those using std::fs::remove_dir_all
  • Review system permissions to minimize the attack surface for local privilege escalation attempts

Patch Information

The fix is included in Rust version 1.58.1, released on January 20, 2022. The patch implements proper symlink-safe directory removal by using platform-specific APIs where available. For detailed patch implementation, refer to the Rust Pull Request #93110 and the official Rust blog post.

Note that some platforms do not have usable APIs to properly mitigate the attack and remain vulnerable even with a patched toolchain: macOS versions before 10.10 (Yosemite) and REDOX. Users on these platforms should implement additional safeguards.

Apple has also addressed this vulnerability in their operating systems through security updates HT213182, HT213183, HT213186, and HT213193.

Workarounds

  • Avoid using std::fs::remove_dir_all on user-controllable paths in privileged contexts until the toolchain is updated
  • Run privileged cleanup processes with minimal necessary privileges using principle of least privilege
  • Implement application-level restrictions that prevent operations on directories containing symlinks where feasible
  • Consider using containerization or sandboxing to limit the blast radius of potential symlink attacks
bash
# Check current Rust version and upgrade if necessary
rustc --version

# Update Rust toolchain to latest version
rustup update stable

# Verify updated version (should be 1.58.1 or later)
rustc --version

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

  • Vulnerability Details
  • TypeRace Condition

  • Vendor/TechRust

  • SeverityMEDIUM

  • CVSS Score6.3

  • EPSS Probability0.89%

  • Known ExploitedNo
  • CVSS Vector
  • CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:N/I:H/A:H
  • Impact Assessment
  • ConfidentialityHigh
  • IntegrityNone
  • AvailabilityHigh
  • CWE References
  • CWE-363

  • CWE-367
  • Technical References
  • Fedora Package Announcement

  • Fedora Package Announcement

  • Fedora Package Announcement

  • Fedora Package Announcement

  • Gentoo GLSA 202210-09

  • Apple Security Update HT213182

  • Apple Security Update HT213183

  • Apple Security Update HT213186

  • Apple Security Update HT213193
  • Vendor Resources
  • Rust CVE-2022-21658 Blog Post

  • Rust Pull Request #93110

  • Rust Commit 32ed6e5

  • Rust Commit 406cc07

  • Rust Commit 4f0ad1c

  • GitHub Security Advisory GHSA-r9cc-f5pr-p3j2
  • Related CVEs
  • CVE-2026-25727: Rust time Library DoS Vulnerability
Default Legacy - Prefooter | Experience the World’s Most Advanced Cybersecurity Platform

Experience the World’s Most Advanced Cybersecurity Platform

See how our intelligent, autonomous cybersecurity platform can protect your organization now and into the future.

Try SentinelOne
  • Get Started
  • Get a Demo
  • Product Tour
  • Why SentinelOne
  • Pricing & Packaging
  • FAQ
  • Contact
  • Contact Us
  • Customer Support
  • SentinelOne Status
  • Language
  • Platform
  • Singularity Platform
  • Singularity Endpoint
  • Singularity Cloud
  • Singularity AI-SIEM
  • Singularity Identity
  • Singularity Marketplace
  • Purple AI
  • Services
  • Wayfinder TDR
  • SentinelOne GO
  • Technical Account Management
  • Support Services
  • Verticals
  • Energy
  • Federal Government
  • Finance
  • Healthcare
  • Higher Education
  • K-12 Education
  • Manufacturing
  • Retail
  • State and Local Government
  • Cybersecurity for SMB
  • Resources
  • Blog
  • Labs
  • Case Studies
  • Videos
  • Product Tours
  • Events
  • Cybersecurity 101
  • eBooks
  • Webinars
  • Whitepapers
  • Press
  • News
  • Ransomware Anthology
  • Company
  • About Us
  • Our Customers
  • Careers
  • Partners
  • Legal & Compliance
  • Security & Compliance
  • Investor Relations
  • S Foundation
  • S Ventures

©2026 SentinelOne, All Rights Reserved.

Privacy Notice Terms of Use

English