CVEfocus › CVE database › CVE-2022-21658

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

CVSS 7.3 HighEPSS 1.1% (higher than 66% of CVEs)Published 2022-01-20Updated 2025-04-22Assigner: GitHub_M

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.

CWE-363CWE-367

What to do

Fixed builds are available from AlmaLinux, Debian, Red Hat, Rocky Linux, Ubuntu: see the table below for the fixed version per release.

Ubuntu has not shipped a fix for every release yet.

Is your server affected? One read-only command checks every installed package against this CVE and all others, using each vendor's fixed versions. Get started or get a free API key.

curl -sS "https://api.cvefocus.com/v1/check?format=text" -H "Authorization: Bearer $CVEFOCUS_KEY" \
  -H "Content-Type: text/plain" --data-binary @inventory.txt

Vendor status at a glance

38Fixed
2Fix pending
5Will not fix
18Not affected

Status by vendor and release

From each vendor's own security data and VEX statements. "Fixed" means a fixed build is published for that release.

ReleasePackageStatusFixed versionAdvisory
Ubuntu 24.04rustcNot affected
vulnerable_code_not_present
Ubuntu 22.04rustcNot affected
vulnerable_code_not_present
Ubuntu 20.04rustcFixed1.59.0+dfsg1~ubuntu1~llvm-1~ubuntu1~20.04.2UBUNTU-CVE-2022-21658
Ubuntu 16.04rustcFix pendingUBUNTU-CVE-2022-21658
Ubuntu 14.04rustcFix pendingUBUNTU-CVE-2022-21658
Debian 14rustcFixed1.57.0+dfsg1-1DEBIAN-CVE-2022-21658
Debian 13rustcFixed1.57.0+dfsg1-1DEBIAN-CVE-2022-21658
Debian 12rustcFixed1.57.0+dfsg1-1DEBIAN-CVE-2022-21658
Red Hat Enterprise Linux 9cargoNot affected
Red Hat Enterprise Linux 9clippyNot affected
Red Hat Enterprise Linux 9rustNot affected
Red Hat Enterprise Linux 9rust-analysisNot affected
Red Hat Enterprise Linux 9rust-analyzerNot affected
Red Hat Enterprise Linux 9rust-debugger-commonNot affected
Red Hat Enterprise Linux 9rust-docNot affected
Red Hat Enterprise Linux 9rust-gdbNot affected
Red Hat Enterprise Linux 9rust-lldbNot affected
Red Hat Enterprise Linux 9rust-srcNot affected
Red Hat Enterprise Linux 9rust-std-staticNot affected
Red Hat Enterprise Linux 9rust-std-static-wasm32-unknown-unknownNot affected
Red Hat Enterprise Linux 9rust-std-static-wasm32-wasiNot affected
Red Hat Enterprise Linux 9rust-std-static-wasm32-wasip1Not affected
Red Hat Enterprise Linux 9rust-toolsetNot affected
Red Hat Enterprise Linux 9rustfmtNot affected
Red Hat Enterprise Linux 9stratisdWill not fix
Will not fix
Red Hat Enterprise Linux 9stratisd-dracutWill not fix
Will not fix
Red Hat Enterprise Linux 9stratisd-toolsWill not fix
Will not fix
Red Hat Enterprise Linux 8cargoFixed0:1.58.1-1.module+el8.6.0+14021+586eff1aRHSA-2022:1894
Red Hat Enterprise Linux 8cargo-docFixed0:1.58.1-1.module+el8.6.0+14021+586eff1aRHSA-2022:1894
Red Hat Enterprise Linux 8clippyFixed0:1.58.1-1.module+el8.6.0+14021+586eff1aRHSA-2022:1894
Red Hat Enterprise Linux 8rlsFixed0:1.58.1-1.module+el8.6.0+14021+586eff1aRHSA-2022:1894
Red Hat Enterprise Linux 8rustFixed0:1.58.1-1.module+el8.6.0+14021+586eff1aRHSA-2022:1894
Red Hat Enterprise Linux 8rust-analysisFixed0:1.58.1-1.module+el8.6.0+14021+586eff1aRHSA-2022:1894
Red Hat Enterprise Linux 8rust-debugger-commonFixed0:1.58.1-1.module+el8.6.0+14021+586eff1aRHSA-2022:1894
Red Hat Enterprise Linux 8rust-docFixed0:1.58.1-1.module+el8.6.0+14021+586eff1aRHSA-2022:1894
Red Hat Enterprise Linux 8rust-gdbFixed0:1.58.1-1.module+el8.6.0+14021+586eff1aRHSA-2022:1894
Red Hat Enterprise Linux 8rust-lldbFixed0:1.58.1-1.module+el8.6.0+14021+586eff1aRHSA-2022:1894
Red Hat Enterprise Linux 8rust-srcFixed0:1.58.1-1.module+el8.6.0+14021+586eff1aRHSA-2022:1894
Red Hat Enterprise Linux 8rust-std-staticFixed0:1.58.1-1.module+el8.6.0+14021+586eff1aRHSA-2022:1894
Red Hat Enterprise Linux 8rust-std-static-wasm32-unknown-unknownFixed0:1.58.1-1.module+el8.6.0+14021+586eff1aRHSA-2022:1894
Red Hat Enterprise Linux 8rust-std-static-wasm32-wasiFixed0:1.58.1-1.module+el8.6.0+14021+586eff1aRHSA-2022:1894
Red Hat Enterprise Linux 8rust-toolsetFixed0:1.58.1-1.module+el8.6.0+14021+586eff1aRHSA-2022:1894
Red Hat Enterprise Linux 8rustfmtFixed0:1.58.1-1.module+el8.6.0+14021+586eff1aRHSA-2022:1894
Red Hat Enterprise Linux 8stratisdWill not fix
Will not fix
Red Hat Enterprise Linux 8stratisd-dracutWill not fix
Will not fix
AlmaLinux 8cargoFixed1.58.1-1.module_el8.6.0+2748+176088b3ALSA-2022:1894
AlmaLinux 8cargo-docFixed1.58.1-1.module_el8.6.0+2748+176088b3ALSA-2022:1894
AlmaLinux 8clippyFixed1.58.1-1.module_el8.6.0+2748+176088b3ALSA-2022:1894
AlmaLinux 8rlsFixed1.58.1-1.module_el8.6.0+2748+176088b3ALSA-2022:1894
AlmaLinux 8rustFixed1.58.1-1.module_el8.6.0+2748+176088b3ALSA-2022:1894
AlmaLinux 8rust-analysisFixed1.58.1-1.module_el8.6.0+2748+176088b3ALSA-2022:1894
AlmaLinux 8rust-debugger-commonFixed1.58.1-1.module_el8.6.0+2748+176088b3ALSA-2022:1894
AlmaLinux 8rust-docFixed1.58.1-1.module_el8.6.0+2748+176088b3ALSA-2022:1894
AlmaLinux 8rust-gdbFixed1.58.1-1.module_el8.6.0+2748+176088b3ALSA-2022:1894
AlmaLinux 8rust-lldbFixed1.58.1-1.module_el8.6.0+2748+176088b3ALSA-2022:1894
AlmaLinux 8rust-srcFixed1.58.1-1.module_el8.6.0+2748+176088b3ALSA-2022:1894
AlmaLinux 8rust-std-staticFixed1.58.1-1.module_el8.6.0+2748+176088b3ALSA-2022:1894
AlmaLinux 8rust-std-static-wasm32-unknown-unknownFixed1.58.1-1.module_el8.6.0+2748+176088b3ALSA-2022:1894
AlmaLinux 8rust-std-static-wasm32-wasiFixed1.58.1-1.module_el8.6.0+2748+176088b3ALSA-2022:1894
AlmaLinux 8rust-toolsetFixed1.58.1-1.module_el8.6.0+2748+176088b3ALSA-2022:1894
AlmaLinux 8rustfmtFixed1.58.1-1.module_el8.6.0+2748+176088b3ALSA-2022:1894
Rocky Linux 8rustFixed0:1.58.1-1.module+el8.6.0+826+60f85975RLSA-2022:1894
Rocky Linux 8rust-toolsetFixed0:1.58.1-1.module+el8.6.0+826+60f85975RLSA-2022:1894

What the vendor says

As published in the CVE record by GitHub_M, the CVE's assigner (usually the vendor). Check the vendor's advisory before acting.

Vendor advisories:

References

About this page

Compiled by CVEfocus from the CVE List, the security data and VEX statements of Ubuntu, Debian, Red Hat, AlmaLinux, Rocky Linux and Microsoft, CISA's Known Exploited Vulnerabilities catalog and FIRST EPSS, refreshed several times a day (data status). Information only; see the disclaimer. Official record: cve.org · NVD.