# CVE-2022-21658: Race condition in std::fs::remove\_dir\_all in rustlang

> Archived entry. Full-text search covers entries since 2026-11-10; exact IDs work for all years.

- **Severity:** HIGH 7.3
- **CVSS:** 7.3 (v3.1, CNA) `CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:C/C:N/I:L/A:H`
- **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
- **Exploited in the wild:** Not in CISA KEV
- **Public exploit / PoC:** Yes (see exploit references)
- **Remote exploitation:** Not remotely exploitable (local or adjacent access needed)
- **EPSS:** 1.12% (percentile 66, 2026-11-26)
- **CWE:** CWE-363, CWE-367
- **Published:** 2022-01-20T00:00:00.000Z
- **Modified:** 2026-06-17T04:26:42.123Z

## Who should check

- Anyone running rust-lang rust \< 1.58.1

## 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

- rust-lang rust: \< 1.58.1 (cvelist)

## Mitigation

- Upgrade rust to 1.58.1 or later.

## Check your systems with an agent

Paste this into a coding agent:

```text
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.
```

## 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.

## References

- vendor: <https://github.com/rust-lang/rust/security/advisories/GHSA-r9cc-f5pr-p3j2>
- vendor: <https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/BK32QZLHDC2OVLPKTUHNT2G3VHWHD4LX/>
- vendor: <https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/C63NH72Q7UHJM5V3IVYRI7LVBGGFQMSQ/>
- vendor: <https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/CKGTACKMKAPRDPWPTU26GYWBELIRFF5N/>
- vendor: <https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/7JKZDTBMGAWIFJSNWKBMPO5EAKRR4BEW/>
- vendor: <https://security.gentoo.org/glsa/202210-09>
- patch: <https://github.com/rust-lang/rust/pull/93110>
- patch: <https://github.com/rust-lang/rust/pull/93110/commits/32ed6e599bb4722efefd78bbc9cd7ec4613cb946>
- patch: <https://github.com/rust-lang/rust/pull/93110/commits/406cc071d6cfdfdb678bf3d83d766851de95abaf>
- patch: <https://github.com/rust-lang/rust/pull/93110/commits/4f0ad1c92ca08da6e8dc17838070975762f59714>
- exploit: <https://blog.rust-lang.org/2022/01/20/cve-2022-21658.html>
- other: <https://support.apple.com/kb/HT213183>
- other: <https://support.apple.com/kb/HT213182>
- other: <https://support.apple.com/kb/HT213186>
- other: <https://support.apple.com/kb/HT213193>

## Attribution

- CVE Program: CVE® is a registered trademark of The MITRE Corporation. CVE records © 1999–2026 The MITRE Corporation. <https://www.cve.org/Legal/TermsOfUse>
- NVD: This product uses data from the NVD API but is not endorsed or certified by the NVD. <https://nvd.nist.gov/vuln/detail/CVE-2022-21658>

HTML: <https://flawdb.com/CVE-2022-21658> · JSON: <https://flawdb.com/api/v1/entries/CVE-2022-21658>
