CVE-2022-21658Race condition in std::fs::remove_dir_all in rustlang
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.
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
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.
| Release | Package | Status | Fixed version | Advisory |
|---|---|---|---|---|
| Ubuntu 24.04 | rustc | Not affected vulnerable_code_not_present | ||
| Ubuntu 22.04 | rustc | Not affected vulnerable_code_not_present | ||
| Ubuntu 20.04 | rustc | Fixed | 1.59.0+dfsg1~ubuntu1~llvm-1~ubuntu1~20.04.2 | UBUNTU-CVE-2022-21658 |
| Ubuntu 16.04 | rustc | Fix pending | UBUNTU-CVE-2022-21658 | |
| Ubuntu 14.04 | rustc | Fix pending | UBUNTU-CVE-2022-21658 | |
| Debian 14 | rustc | Fixed | 1.57.0+dfsg1-1 | DEBIAN-CVE-2022-21658 |
| Debian 13 | rustc | Fixed | 1.57.0+dfsg1-1 | DEBIAN-CVE-2022-21658 |
| Debian 12 | rustc | Fixed | 1.57.0+dfsg1-1 | DEBIAN-CVE-2022-21658 |
| Red Hat Enterprise Linux 9 | cargo | Not affected | ||
| Red Hat Enterprise Linux 9 | clippy | Not affected | ||
| Red Hat Enterprise Linux 9 | rust | Not affected | ||
| Red Hat Enterprise Linux 9 | rust-analysis | Not affected | ||
| Red Hat Enterprise Linux 9 | rust-analyzer | Not affected | ||
| Red Hat Enterprise Linux 9 | rust-debugger-common | Not affected | ||
| Red Hat Enterprise Linux 9 | rust-doc | Not affected | ||
| Red Hat Enterprise Linux 9 | rust-gdb | Not affected | ||
| Red Hat Enterprise Linux 9 | rust-lldb | Not affected | ||
| Red Hat Enterprise Linux 9 | rust-src | Not affected | ||
| Red Hat Enterprise Linux 9 | rust-std-static | Not affected | ||
| Red Hat Enterprise Linux 9 | rust-std-static-wasm32-unknown-unknown | Not affected | ||
| Red Hat Enterprise Linux 9 | rust-std-static-wasm32-wasi | Not affected | ||
| Red Hat Enterprise Linux 9 | rust-std-static-wasm32-wasip1 | Not affected | ||
| Red Hat Enterprise Linux 9 | rust-toolset | Not affected | ||
| Red Hat Enterprise Linux 9 | rustfmt | Not affected | ||
| Red Hat Enterprise Linux 9 | stratisd | Will not fix Will not fix | ||
| Red Hat Enterprise Linux 9 | stratisd-dracut | Will not fix Will not fix | ||
| Red Hat Enterprise Linux 9 | stratisd-tools | Will not fix Will not fix | ||
| Red Hat Enterprise Linux 8 | cargo | Fixed | 0:1.58.1-1.module+el8.6.0+14021+586eff1a | RHSA-2022:1894 |
| Red Hat Enterprise Linux 8 | cargo-doc | Fixed | 0:1.58.1-1.module+el8.6.0+14021+586eff1a | RHSA-2022:1894 |
| Red Hat Enterprise Linux 8 | clippy | Fixed | 0:1.58.1-1.module+el8.6.0+14021+586eff1a | RHSA-2022:1894 |
| Red Hat Enterprise Linux 8 | rls | Fixed | 0:1.58.1-1.module+el8.6.0+14021+586eff1a | RHSA-2022:1894 |
| Red Hat Enterprise Linux 8 | rust | Fixed | 0:1.58.1-1.module+el8.6.0+14021+586eff1a | RHSA-2022:1894 |
| Red Hat Enterprise Linux 8 | rust-analysis | Fixed | 0:1.58.1-1.module+el8.6.0+14021+586eff1a | RHSA-2022:1894 |
| Red Hat Enterprise Linux 8 | rust-debugger-common | Fixed | 0:1.58.1-1.module+el8.6.0+14021+586eff1a | RHSA-2022:1894 |
| Red Hat Enterprise Linux 8 | rust-doc | Fixed | 0:1.58.1-1.module+el8.6.0+14021+586eff1a | RHSA-2022:1894 |
| Red Hat Enterprise Linux 8 | rust-gdb | Fixed | 0:1.58.1-1.module+el8.6.0+14021+586eff1a | RHSA-2022:1894 |
| Red Hat Enterprise Linux 8 | rust-lldb | Fixed | 0:1.58.1-1.module+el8.6.0+14021+586eff1a | RHSA-2022:1894 |
| Red Hat Enterprise Linux 8 | rust-src | Fixed | 0:1.58.1-1.module+el8.6.0+14021+586eff1a | RHSA-2022:1894 |
| Red Hat Enterprise Linux 8 | rust-std-static | Fixed | 0:1.58.1-1.module+el8.6.0+14021+586eff1a | RHSA-2022:1894 |
| Red Hat Enterprise Linux 8 | rust-std-static-wasm32-unknown-unknown | Fixed | 0:1.58.1-1.module+el8.6.0+14021+586eff1a | RHSA-2022:1894 |
| Red Hat Enterprise Linux 8 | rust-std-static-wasm32-wasi | Fixed | 0:1.58.1-1.module+el8.6.0+14021+586eff1a | RHSA-2022:1894 |
| Red Hat Enterprise Linux 8 | rust-toolset | Fixed | 0:1.58.1-1.module+el8.6.0+14021+586eff1a | RHSA-2022:1894 |
| Red Hat Enterprise Linux 8 | rustfmt | Fixed | 0:1.58.1-1.module+el8.6.0+14021+586eff1a | RHSA-2022:1894 |
| Red Hat Enterprise Linux 8 | stratisd | Will not fix Will not fix | ||
| Red Hat Enterprise Linux 8 | stratisd-dracut | Will not fix Will not fix | ||
| AlmaLinux 8 | cargo | Fixed | 1.58.1-1.module_el8.6.0+2748+176088b3 | ALSA-2022:1894 |
| AlmaLinux 8 | cargo-doc | Fixed | 1.58.1-1.module_el8.6.0+2748+176088b3 | ALSA-2022:1894 |
| AlmaLinux 8 | clippy | Fixed | 1.58.1-1.module_el8.6.0+2748+176088b3 | ALSA-2022:1894 |
| AlmaLinux 8 | rls | Fixed | 1.58.1-1.module_el8.6.0+2748+176088b3 | ALSA-2022:1894 |
| AlmaLinux 8 | rust | Fixed | 1.58.1-1.module_el8.6.0+2748+176088b3 | ALSA-2022:1894 |
| AlmaLinux 8 | rust-analysis | Fixed | 1.58.1-1.module_el8.6.0+2748+176088b3 | ALSA-2022:1894 |
| AlmaLinux 8 | rust-debugger-common | Fixed | 1.58.1-1.module_el8.6.0+2748+176088b3 | ALSA-2022:1894 |
| AlmaLinux 8 | rust-doc | Fixed | 1.58.1-1.module_el8.6.0+2748+176088b3 | ALSA-2022:1894 |
| AlmaLinux 8 | rust-gdb | Fixed | 1.58.1-1.module_el8.6.0+2748+176088b3 | ALSA-2022:1894 |
| AlmaLinux 8 | rust-lldb | Fixed | 1.58.1-1.module_el8.6.0+2748+176088b3 | ALSA-2022:1894 |
| AlmaLinux 8 | rust-src | Fixed | 1.58.1-1.module_el8.6.0+2748+176088b3 | ALSA-2022:1894 |
| AlmaLinux 8 | rust-std-static | Fixed | 1.58.1-1.module_el8.6.0+2748+176088b3 | ALSA-2022:1894 |
| AlmaLinux 8 | rust-std-static-wasm32-unknown-unknown | Fixed | 1.58.1-1.module_el8.6.0+2748+176088b3 | ALSA-2022:1894 |
| AlmaLinux 8 | rust-std-static-wasm32-wasi | Fixed | 1.58.1-1.module_el8.6.0+2748+176088b3 | ALSA-2022:1894 |
| AlmaLinux 8 | rust-toolset | Fixed | 1.58.1-1.module_el8.6.0+2748+176088b3 | ALSA-2022:1894 |
| AlmaLinux 8 | rustfmt | Fixed | 1.58.1-1.module_el8.6.0+2748+176088b3 | ALSA-2022:1894 |
| Rocky Linux 8 | rust | Fixed | 0:1.58.1-1.module+el8.6.0+826+60f85975 | RLSA-2022:1894 |
| Rocky Linux 8 | rust-toolset | Fixed | 0:1.58.1-1.module+el8.6.0+826+60f85975 | RLSA-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.
- rust-lang rust: affected: < 1.58.1
Vendor advisories:
- https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/… (vendor-advisory)
- https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/… (vendor-advisory)
- https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/… (vendor-advisory)
- https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/… (vendor-advisory)
- https://security.gentoo.org/glsa/202210-09 (vendor-advisory)
References
- https://github.com/rust-lang/rust/security/advisories/GHSA-r9cc-f5pr-p3j2
- https://github.com/rust-lang/rust/pull/93110
- https://github.com/rust-lang/rust/pull/93110/commits/32ed6e599bb4722efefd78bbc9cd7ec4613cb946
- https://github.com/rust-lang/rust/pull/93110/commits/406cc071d6cfdfdb678bf3d83d766851de95abaf
- https://github.com/rust-lang/rust/pull/93110/commits/4f0ad1c92ca08da6e8dc17838070975762f59714
- https://blog.rust-lang.org/2022/01/20/cve-2022-21658.html
- 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://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/7JKZDTBMGAWIFJSNWKBMPO5EAKRR4BEW/
- https://support.apple.com/kb/HT213183
- https://support.apple.com/kb/HT213182
- https://support.apple.com/kb/HT213186
- https://support.apple.com/kb/HT213193
- https://security.gentoo.org/glsa/202210-09
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.