CVE-2022-21658 | Race condition in std::fs::remove_dir_all in rustlang

Exp

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.

Published: 2022-01-20 Last update: 2024-11-21 Assigner: [email protected] Source: [email protected]

Conclusion & alert: CVE-2022-21658 is rated High Exploit Risk (70.7/100): CVSS High severity, with medium exploitation likelihood (EPSS 0.91%). Core evidence: 2 public exploit reference(s) are indexed (Exploit-DB). Mandatory action: Public exploits are available—assess exposure, apply mitigations, and prioritize patching.

Risk is dynamic; we continuously reassess and refresh what is shown on this page as upstream context changes.

Public exploit references (Exploit-DB) for CVE-2022-21658

EDB-ID Source Kind Published Link
nvd_ref exploit_tag Exploit-DB ↗
nvd_ref exploit_tag Exploit-DB ↗

Exploit prediction scoring system (EPSS) score for CVE-2022-21658

EPSS lead: Daily EPSS estimates relative likelihood of exploitation; percentile ranks this CVE among scored vulnerabilities (higher = more severe relative rank).

# Date Old EPSS score New EPSS score Delta (New - Old)
1 2026-03-04 0.76% 0.91% +0.14%
2 2026-03-01 0.89% 0.76% -0.13%
3 2026-02-04 0.89%

Full EPSS history (52 records total)

Common vulnerability scoring system (CVSS) metrics for CVE-2022-21658

CVSS metrics for this CVE.

Base score Version Severity Vector Exploitability Impact Score source
7.3 3.1 HIGH
CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:C/C:N/I:L/A:H Click to expand
Attack vector (AV:L)
They already need access on the box, or another person has to do something wrong; it’s not a remote drive-by.
Attack complexity (AC:L)
Once they can reach the bug, pulling it off is straightforward—no weird race conditions or rare setup.
Privileges required (PR:L)
A normal user session is enough; they don’t have to be admin.
User interaction (UI:N)
Nobody has to click “OK” or open a trap file; it can work without a victim helping.
Scope (S:C)
Breaking this can reach past the original component and bite other resources—bigger blast radius.
Confidentiality (C:N)
Doesn’t really leak secrets in a meaningful way.
Integrity (I:L)
Attackers could change some data, but it’s limited—not everything goes.
Availability (A:H)
Could take the service down hard or make it unusable for people who depend on it.
2.0 4.7 [email protected]
6.3 3.1 MEDIUM
CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:N/I:H/A:H Click to expand
Attack vector (AV:L)
They already need access on the box, or another person has to do something wrong; it’s not a remote drive-by.
Attack complexity (AC:H)
Even with access, the exploit needs extra luck, timing, or a fussy environment to actually work.
Privileges required (PR:L)
A normal user session is enough; they don’t have to be admin.
User interaction (UI:N)
Nobody has to click “OK” or open a trap file; it can work without a victim helping.
Scope (S:U)
Damage stays in the same “trust bubble” as the broken component—no big spill into unrelated systems.
Confidentiality (C:N)
Doesn’t really leak secrets in a meaningful way.
Integrity (I:H)
They could widely tamper with or forge data—trust in the data is badly hurt.
Availability (A:H)
Could take the service down hard or make it unusable for people who depend on it.
1.0 5.2 [email protected]
3.3 2.0 LOW
AV:L/AC:M/Au:N/C:N/I:P/A:P Click to expand
Access vector (AV:L)
Requires local access to the target system.
Access complexity (AC:M)
Exploitation needs some favorable conditions, but not exceptional ones.
Authentication (AU:N)
No authentication is required.
Confidentiality impact (C:N)
No confidentiality impact.
Integrity impact (I:P)
Partial integrity impact.
Availability impact (A:P)
Partial availability impact.
3.4 4.9 [email protected]

Weakness enumeration for CVE-2022-21658

OS Trackers for CVE-2022-21658

vendor priority summary link
alpine medium CVE-2022-21658: 1 source package rows (rust); 32 state rows across 6 repos (3.19-main, 3.20-main, 3.21-main, 3.22-main, edge-community, edge-main); fixed 0, open 32. https://security.alpinelinux.org/vuln/CVE-2022-21658
debian not yet assigned CVE-2022-21658 not yet assigned priority: Debian including 1 source packages (rustc), 5 status rows across 5 suites (bookworm, bullseye, forky, sid, trixie): resolved 4, open 1. https://security-tracker.debian.org/tracker/CVE-2022-21658
gentoo normal CVE-2022-21658: 1 GLSA(s) (202210-09), 2 atom(s) (dev-lang/rust, dev-lang/rust-bin); latest impact normal. https://bugs.gentoo.org/buglist.cgi?quicksearch=CVE-2022-21658
redhat medium https://access.redhat.com/security/cve/CVE-2022-21658
suse medium CVE-2022-21658 severity moderate: SUSE including 53 source package names (1.56-2.1:cargo1.56-1.56.1-150300.7.6.1, 1.56-2.1:rust1.56-1.56.1-150300.7.6.1, …), 223 product×package rows across 31 product lines (Container bci/rust, SUSE CaaS Platform 4.0, … (31 product lines)): Fixed 223. https://www.suse.com/security/cve/CVE-2022-21658/
ubuntu medium CVE-2022-21658 medium priority: Ubuntu including 1 source packages (rustc), 15 status rows across 15 suites (bionic, focal, hirsute, impish, jammy, kinetic, lunar, mantic, noble, oracular, plucky, questing, trusty, upstream, xenial): not-affected 6, DNE 3, ignored 2, needed 2, released 2. https://ubuntu.com/security/CVE-2022-21658

Affected software / configurations for CVE-2022-21658

Vendor Product Version Raw CPE
rust-lang rust >= 1.0.0, <= 1.58.0 cpe:2.3:a:rust-lang:rust:*:*:*:*:*:*:*:*
fedoraproject fedora 34 cpe:2.3:o:fedoraproject:fedora:34:*:*:*:*:*:*:*
fedoraproject fedora 35 cpe:2.3:o:fedoraproject:fedora:35:*:*:*:*:*:*:*
apple ipados < 15.4 cpe:2.3:o:apple:ipados:*:*:*:*:*:*:*:*
apple iphone_os < 15.4 cpe:2.3:o:apple:iphone_os:*:*:*:*:*:*:*:*
apple macos >= 12.0.0, < 12.3 cpe:2.3:o:apple:macos:*:*:*:*:*:*:*:*
apple tvos < 15.4 cpe:2.3:o:apple:tvos:*:*:*:*:*:*:*:*
apple watchos < 8.5 cpe:2.3:o:apple:watchos:*:*:*:*:*:*:*:*

References for CVE-2022-21658

URL Tags
https://blog.rust-lang.org/2022/01/20/cve-2022-21658.html Exploit Mitigation Vendor Advisory
https://github.com/rust-lang/rust/pull/93110 Patch Third Party Advisory
https://github.com/rust-lang/rust/pull/93110/commits/32ed6e599bb4722efefd78bbc9cd7ec4613cb946 Patch Third Party Advisory
https://github.com/rust-lang/rust/pull/93110/commits/406cc071d6cfdfdb678bf3d83d766851de95abaf Patch Third Party Advisory
https://github.com/rust-lang/rust/pull/93110/commits/4f0ad1c92ca08da6e8dc17838070975762f59714 Patch Third Party Advisory
https://github.com/rust-lang/rust/security/advisories/GHSA-r9cc-f5pr-p3j2 Exploit Mitigation Third Party Advisory
https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/7JKZDTBMGAWIFJSNWKBMPO5EAKRR4BEW/
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://security.gentoo.org/glsa/202210-09 Third Party Advisory
https://support.apple.com/kb/HT213182 Third Party Advisory
https://support.apple.com/kb/HT213183 Third Party Advisory
https://support.apple.com/kb/HT213186 Third Party Advisory
https://support.apple.com/kb/HT213193 Third Party Advisory
cvelogic Threat Intelligence