// For flags

CVE-2022-21658

Race condition in std::fs::remove_dir_all in rustlang

Severity Score

6.3
*CVSS v3.1

Exploit Likelihood

*EPSS

Affected Versions

*CPE

Public Exploits

2
*Multiple Sources

Exploited in Wild

-
*KEV

Decision

-
*SSVC
Descriptions

Rust is a multi-paradigm, general-purpose programming language designed for performance and safety, especially safe concurrency. The Rust Security Response WG was notified that the `std::fs::remove_dir_all` standard library function is vulnerable a race condition enabling symlink following (CWE-363). An attacker could use this security issue to trick a privileged program into deleting files and directories the attacker couldn't otherwise access or delete. Rust 1.0.0 through Rust 1.58.0 is affected by this vulnerability with 1.58.1 containing a patch. Note that the following build targets don't have usable APIs to properly mitigate the attack, and are thus still vulnerable even with a patched toolchain: macOS before version 10.10 (Yosemite) and REDOX. We recommend everyone to update to Rust 1.58.1 as soon as possible, especially people developing programs expected to run in privileged contexts (including system daemons and setuid binaries), as those have the highest risk of being affected by this. Note that adding checks in your codebase before calling remove_dir_all will not mitigate the vulnerability, as they would also be vulnerable to race conditions like remove_dir_all itself. The existing mitigation is working as intended outside of race conditions.

Rust es un lenguaje de programación multiparadigma de propósito general diseñado para el rendimiento y la seguridad, especialmente la concurrencia segura. El Grupo de Trabajo de Respuesta de Seguridad de Rust fue notificado de que la función de la biblioteca estándar "std::fs::remove_dir_all" es vulnerable a una condición de carrera que permite el seguimiento de enlaces simbólicos (CWE-363). Un atacante podría usar este problema de seguridad para engañar a un programa con privilegios para que elimine archivos y directorios a los que el atacante no podría acceder o eliminar de otro modo. Rust versiones 1.0.0 hasta Rust versión 1.58.0 están afectados por esta vulnerabilidad, con la versión 1.58.1 que contiene un parche. Tenga en cuenta que los siguientes objetivos de construcción no presentan APIs usables para mitigar apropiadamente el ataque, y por lo tanto siguen siendo vulnerables incluso con una cadena de herramientas parcheada: macOS versiones anteriores a 10.10 (Yosemite) y REDOX. Recomendamos a todo el mundo que actualice a Rust versión 1.58.1 tan pronto como sea posible, especialmente a las personas que desarrollan programas que esperan que sean ejecutados en contextos privilegiados (incluidos los demonios del sistema y los binarios setuid), ya que son los que presentan el mayor riesgo de estar afectados por esto. Tenga en cuenta que añadir comprobaciones en su código base antes de llamar a remove_dir_all no mitigará la vulnerabilidad, ya que también serían vulnerables a condiciones de carrera como el propio remove_dir_all. La mitigación existente funciona como es pretendido fuera de las condiciones de carrera

A race condition flaw was found in Rust's std::fs::remove_dir_all function. Rust applications that use this function may be vulnerable to a race condition where an unprivileged attacker can trick the application into deleting files and directories, causing an impact on system data integrity. If the application is privileged, an attacker can possibly delete files they would not usually have access to.

*Credits: N/A
CVSS Scores
Attack Vector
Local
Attack Complexity
High
Privileges Required
Low
User Interaction
None
Scope
Unchanged
Confidentiality
None
Integrity
High
Availability
High
Attack Vector
Local
Attack Complexity
Low
Privileges Required
Low
User Interaction
None
Scope
Changed
Confidentiality
None
Integrity
Low
Availability
High
Attack Vector
Network
Attack Complexity
High
Privileges Required
Low
User Interaction
None
Scope
Unchanged
Confidentiality
None
Integrity
High
Availability
None
Attack Vector
Local
Attack Complexity
Medium
Authentication
None
Confidentiality
None
Integrity
Partial
Availability
Partial
* Common Vulnerability Scoring System
SSVC
  • Decision:-
Exploitation
-
Automatable
-
Tech. Impact
-
* Organization's Worst-case Scenario
Timeline
  • 2021-11-16 CVE Reserved
  • 2022-01-20 CVE Published
  • 2024-04-13 EPSS Updated
  • 2024-08-03 CVE Updated
  • 2024-08-03 First Exploit
  • ---------- Exploited in Wild
  • ---------- KEV Due Date
CWE
  • CWE-363: Race Condition Enabling Link Following
  • CWE-367: Time-of-check Time-of-use (TOCTOU) Race Condition
CAPEC
References (17)
Affected Vendors, Products, and Versions
Vendor Product Version Other Status
Vendor Product Version Other Status <-- --> Vendor Product Version Other Status
Rust-lang
Search vendor "Rust-lang"
Rust
Search vendor "Rust-lang" for product "Rust"
>= 1.0.0 <= 1.58.0
Search vendor "Rust-lang" for product "Rust" and version " >= 1.0.0 <= 1.58.0"
-
Affected
Fedoraproject
Search vendor "Fedoraproject"
Fedora
Search vendor "Fedoraproject" for product "Fedora"
34
Search vendor "Fedoraproject" for product "Fedora" and version "34"
-
Affected
Fedoraproject
Search vendor "Fedoraproject"
Fedora
Search vendor "Fedoraproject" for product "Fedora"
35
Search vendor "Fedoraproject" for product "Fedora" and version "35"
-
Affected
Apple
Search vendor "Apple"
Ipados
Search vendor "Apple" for product "Ipados"
< 15.4
Search vendor "Apple" for product "Ipados" and version " < 15.4"
-
Affected
Apple
Search vendor "Apple"
Iphone Os
Search vendor "Apple" for product "Iphone Os"
< 15.4
Search vendor "Apple" for product "Iphone Os" and version " < 15.4"
-
Affected
Apple
Search vendor "Apple"
Macos
Search vendor "Apple" for product "Macos"
>= 12.0.0 < 12.3
Search vendor "Apple" for product "Macos" and version " >= 12.0.0 < 12.3"
-
Affected
Apple
Search vendor "Apple"
Tvos
Search vendor "Apple" for product "Tvos"
< 15.4
Search vendor "Apple" for product "Tvos" and version " < 15.4"
-
Affected
Apple
Search vendor "Apple"
Watchos
Search vendor "Apple" for product "Watchos"
< 8.5
Search vendor "Apple" for product "Watchos" and version " < 8.5"
-
Affected