CVE-2022-21658
Race condition in std::fs::remove_dir_all in rustlang
Reported by github_m · Published January 20, 2022
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.
Fixed versions
Upgrade to a fixed version or later. Language registries are listed first, then Linux distributions, then vendor products.
| Package | Ecosystem | Fixed in |
|---|---|---|
| cargo-doc | Amazon Linux | 1.61.0-2.amzn2.0.1 |
| rustfmt | Amazon Linux | 1.61.0-2.amzn2.0.1 |
| rust | Amazon Linux | 1.61.0-2.amzn2.0.1 |
| rust-src | Amazon Linux | 1.61.0-2.amzn2.0.1 |
| rust | dhi.docker.com | 1.58.1 |
| cargo | Amazon Linux | 1.61.0-2.amzn2.0.1 |
| rust-analysis | Amazon Linux | 1.61.0-2.amzn2.0.1 |
| rust-std-static | Amazon Linux | 1.61.0-2.amzn2.0.1 |
| rust-debugger-common | Amazon Linux | 1.61.0-2.amzn2.0.1 |
| rls | Amazon Linux | 1.61.0-2.amzn2.0.1 |
| clippy | Amazon Linux | 1.61.0-2.amzn2.0.1 |
| iphone_os | apple | 15.4 |
7 more packages have a fixed version. See every fix in Lookup.
Risk scores
Affected products
| Vendor | Product | Versions |
|---|---|---|
| rust-lang | rust | < 1.58.1 |
| amazon:2 | cargo-doc | 0 |
| amazon:2 | rustfmt | 0 |
| amazon:2 | rust | 0 |
| amazon:2 | rust-src | 0 |
| amazon:2 | cargo | 0 |
| amazon:2 | rust-analysis | 0 |
| amazon:2 | rust-std-static | 0 |
| amazon:2 | rust-debugger-common | 0 |
| amazon:2 | rls | 0 |
| amazon:2 | clippy | 0 |
| rust-lang | rust | 0 |
| amazon:2 | rust-gdb | 0 |
| amazon:2 | rust-doc | 0 |
Timeline
- Jan 20, 2022 CVE Published
- Feb 8, 2022 EPSS Score (30 in total, the first dated here)
- Mar 24, 2022 PoC Published
- Mar 10, 2026 Security Advisory (8 in total, the first dated here)
- Jul 7, 2026 Coalition ESS Score
Query this with the API
The same record, from the CLI:
vulnetix vdb vuln CVE-2022-21658
vulnetix vdb fixes CVE-2022-21658
Or with curl, using the org id and key from your account page:
curl -s -H "Authorization: ApiKey ${VULNETIX_ORG_ID}:${VULNETIX_API_KEY}" \
"https://api.vdb.vulnetix.com/v2/vuln/CVE-2022-21658/fixes/registry"
The Community plan is free and allows 50 queries a day. Get a free API key · API quickstart
References
- FEDORA-2022-1bafa3fc91 vendor-advisory
- FEDORA-2022-2c73789458 vendor-advisory
- FEDORA-2022-1b76e3a192 vendor-advisory
- FEDORA-2022-06569a0a60 vendor-advisory
- GLSA-202210-09 vendor-advisory