CVE-2022-21658
Race condition in std::fs::remove_dir_all in rustlang
Mitigation
- Upgrade rust to 1.58.1 or later.
Who should check
- Anyone running rust-lang rust < 1.58.1
Vulnerability facts
- Affected
- rust-lang rust < 1.58.1
- Fixed in
- rust-lang rust 1.58.1
- Exploited in the wild
- Not in CISA KEV
- Public exploit / PoC
- Yes: see the exploit references below
- Remote exploitation
- Not remotely exploitable (local or adjacent access needed)
- CVSS
- 7.3 (v3.1, CNA)CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:C/C:N/I:L/A:HOpen in CVSS calculator
Show all 8 CVSS metrics
- Attack vector: Local
- Attack complexity: Low
- Privileges required: Low
- User interaction: None
- Scope: Changed (impact reaches other components)
- Confidentiality impact: None
- Integrity impact: Low
- Availability impact: High
- EPSS
- 1.12% chance of exploitation in 30 days (percentile 66, 2026-11-26)
- CWE
- CWE-363, CWE-367
- Modified
Description
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.
Affected and fixed versions
| Package / product | Affected | Fixed | Source |
|---|---|---|---|
| rust-lang rust | < 1.58.1 | — | cvelist |
Check your systems with an agent
Paste this into Claude Code, Cursor or another coding agent. It only reads; it changes nothing.
Check whether anything I run is affected by CVE-2022-21658. Work read-only: do not install, upgrade, delete or change anything. Details: https://flawdb.com/CVE-2022-21658.md Affected: rust-lang rust < 1.58.1 Fixed in: rust-lang rust 1.58.1 Steps: 1. Search this machine and project for rust-lang rust: dependency manifests and lockfiles, installed packages, container images and running services. 2. For each match, note the installed version and whether it is inside the affected range. 3. Report a table: location, installed version, affected (yes / no / unsure), evidence. If affected, say which fixed version or mitigation from the details link applies, but don't apply it.
References
Vendor advisories
- https://github.com/rust-lang/rust/security/advisories/GHSA-r9cc-f5pr-p3j2
- https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/BK32QZLHDC2OVLPKTUHNT2G3VHWHD4LX/
- https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/C63NH72Q7UHJM5V3IVYRI7LVBGGFQMSQ/
- https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/CKGTACKMKAPRDPWPTU26GYWBELIRFF5N/
- https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/7JKZDTBMGAWIFJSNWKBMPO5EAKRR4BEW/
- https://security.gentoo.org/glsa/202210-09
Patches
- https://github.com/rust-lang/rust/pull/93110
- https://github.com/rust-lang/rust/pull/93110/commits/32ed6e599bb4722efefd78bbc9cd7ec4613cb946
- https://github.com/rust-lang/rust/pull/93110/commits/406cc071d6cfdfdb678bf3d83d766851de95abaf
- https://github.com/rust-lang/rust/pull/93110/commits/4f0ad1c92ca08da6e8dc17838070975762f59714
Exploits and PoCs
FAQ
Is CVE-2022-21658 being exploited?
There is no confirmed exploitation: CVE-2022-21658 is not in the CISA Known Exploited Vulnerabilities catalog. Public exploit code or a proof of concept is available. EPSS estimates a 1.12% chance of exploitation in the next 30 days (as of 2026-11-26).
How serious is CVE-2022-21658?
High: CVSS 7.3 (v3.1, scored by CNA). Not remotely exploitable (local or adjacent access needed).
Which versions are affected by CVE-2022-21658?
rust-lang rust < 1.58.1.
Is there a fix for CVE-2022-21658?
Yes. Fixed in rust-lang rust 1.58.1. Upgrade rust to 1.58.1 or later.
How do I check if I'm affected by CVE-2022-21658?
Find where you use the affected software (dependency lockfiles, installed packages, container images, servers) and compare the installed version with the affected range above. The agent prompt on this page does this read-only.