VDB

CVE-2022-21658

CVE-2022-21658 PUBLISHED CVSS 7.3 HIGH

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.

PackageEcosystemFixed in
cargo-docAmazon Linux1.61.0-2.amzn2.0.1
rustfmtAmazon Linux1.61.0-2.amzn2.0.1
rustAmazon Linux1.61.0-2.amzn2.0.1
rust-srcAmazon Linux1.61.0-2.amzn2.0.1
rustdhi.docker.com1.58.1
cargoAmazon Linux1.61.0-2.amzn2.0.1
rust-analysisAmazon Linux1.61.0-2.amzn2.0.1
rust-std-staticAmazon Linux1.61.0-2.amzn2.0.1
rust-debugger-commonAmazon Linux1.61.0-2.amzn2.0.1
rlsAmazon Linux1.61.0-2.amzn2.0.1
clippyAmazon Linux1.61.0-2.amzn2.0.1
iphone_osapple15.4

7 more packages have a fixed version. See every fix in Lookup.

Risk scores

CVSS 3.1
7.3
CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:C/C:N/I:L/A:H

Affected products

VendorProductVersions
rust-langrust< 1.58.1
amazon:2cargo-doc0
amazon:2rustfmt0
amazon:2rust0
amazon:2rust-src0
amazon:2cargo0
amazon:2rust-analysis0
amazon:2rust-std-static0
amazon:2rust-debugger-common0
amazon:2rls0
amazon:2clippy0
rust-langrust0
amazon:2rust-gdb0
amazon:2rust-doc0

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

Look up in the Resolve Platform →
$ Lookup Community · 50/day Open Lookup ›