Skip to content
OpenAdvisories
High · 7.3 Public exploit CVE-2022-21658 EUVD-2022-26876

Race condition in std::fs::remove_dir_all in rustlang

Published Jan 20, 2022 · Updated Apr 22, 2025 · Assigned by GitHub_M

Description

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.

Affected products

VendorProductAffectedFixed
rust-lang rust < 1.58.1 —

Fixed in Linux distributions

Distributions backport fixes, so the version that fixes this vulnerability differs per release — upgrade to at least the version shown. From the distributions' security trackers and advisories.

ReleasePackageFixed inAdvisory
Debian 14 rustc 1.57.0+dfsg1-1 —
Debian 13 rustc 1.57.0+dfsg1-1 —
Debian 12 rustc 1.57.0+dfsg1-1 —
ReleasePackageFixed inAdvisory
Ubuntu 20.04 LTS rustc 1.59.0+dfsg1~ubuntu1~llvm-1~ubuntu1~20.04.2 —
Show 2 more (older releases, extended support, other products)
ReleasePackageFixed inAdvisory
Ubuntu Pro 16.04 LTS rustc No fix yet —
Ubuntu Pro 14.04 LTS rustc No fix yet —
ReleasePackageFixed inAdvisory
RHEL 8 rls +15 1.58.1-1.module+el8.6.0+14021+586eff1a RHSA-2022:1894

AlmaLinux

Errata ↗
ReleasePackageFixed inAdvisory
AlmaLinux 8 rls +15 1.58.1-1.module_el8.6.0+2748+176088b3 ALSA-2022:1894

Rocky Linux

Errata ↗
ReleasePackageFixed inAdvisory
Rocky Linux 8 rust +1 1.58.1-1.module+el8.6.0+826+60f85975 RLSA-2022:1894
ReleasePackageFixed inAdvisory
SLES 15 SP3 rust 1.59.0-150300.21.20.1 SUSE-SU-2022:0843-1
SLES 15 SP3 rust1.55 1.55.0-150300.7.6.1 SUSE-SU-2022:0171-1
SLES 15 SP3 rust1.56 1.56.1-150300.7.6.1 SUSE-SU-2022:0149-1
SLES 15 SP3 rust1.57 1.57.0-150300.7.7.1 SUSE-SU-2022:0175-1
SLES 15 SP3 rust1.58 1.58.0-150300.7.3.1 SUSE-SU-2022:0843-1
SLES 15 SP3 rust1.59 1.59.0-150300.7.4.2 SUSE-SU-2022:0843-1
SLES 15 SP2 rust 1.53.0-22.1 SUSE-SU-2022:0491-1
SLES 15 SP1 rust 1.53.0-22.1 SUSE-SU-2022:0491-1
SLES 15 rust 1.53.0-3.40.1 SUSE-SU-2022:0200-1
Show 13 more (older releases, extended support, other products)
ReleasePackageFixed inAdvisory
SLES for SAP 15 SP2 rust 1.53.0-22.1 SUSE-SU-2022:0491-1
SLES for SAP 15 SP1 rust 1.53.0-22.1 SUSE-SU-2022:0491-1
SLES for SAP 15 rust 1.53.0-3.40.1 SUSE-SU-2022:0200-1
SLE Real Time 15 SP2 rust 1.53.0-22.1 SUSE-SU-2022:0491-1
SLE HPC 15 SP2 rust 1.53.0-22.1 SUSE-SU-2022:0491-1
SLE HPC 15 SP1 rust 1.53.0-22.1 SUSE-SU-2022:0491-1
SLE HPC 15 rust 1.53.0-3.40.1 SUSE-SU-2022:0200-1
SUSE Package Hub 15 SP3 libredwg 0.12.5-bp153.2.3.1 openSUSE-SU-2022:0149-1
SUSE Manager Server 4.1 rust 1.53.0-22.1 SUSE-SU-2022:0491-1
SUSE Manager Retail Branch Server 4.1 rust 1.53.0-22.1 SUSE-SU-2022:0491-1
SUSE Manager Proxy 4.1 rust 1.53.0-22.1 SUSE-SU-2022:0491-1
SUSE Enterprise Storage 7 rust 1.53.0-22.1 SUSE-SU-2022:0491-1
SUSE Enterprise Storage 6 rust 1.53.0-22.1 SUSE-SU-2022:0491-1
ReleasePackageFixed inAdvisory
openSUSE Tumbleweed rust1.56 1.56.1-4.1 openSUSE-SU-2024:11767-1
openSUSE Tumbleweed rust1.57 1.57.0-3.1 openSUSE-SU-2024:11768-1
openSUSE Tumbleweed rust1.58 1.58.0-2.1 openSUSE-SU-2024:11769-1
openSUSE Leap 15.3 libredwg 0.12.5-bp153.2.3.1 openSUSE-SU-2022:0149-1
openSUSE Leap 15.3 rust 1.53.0-22.1 openSUSE-SU-2022:0843-1, openSUSE-SU-2022:0491-1
openSUSE Leap 15.3 rust1.55 1.55.0-150300.7.6.1 openSUSE-SU-2022:0171-1
openSUSE Leap 15.3 rust1.56 1.56.1-150300.7.6.1 openSUSE-SU-2022:0149-1
openSUSE Leap 15.3 rust1.57 1.57.0-150300.7.7.1 openSUSE-SU-2022:0175-1
openSUSE Leap 15.3 rust1.58 1.58.0-150300.7.3.1 openSUSE-SU-2022:0843-1
openSUSE Leap 15.3 rust1.59 1.59.0-150300.7.4.2 openSUSE-SU-2022:0843-1

Amazon Linux

ReleasePackageFixed inAdvisory
Amazon Linux 2 rls +11 1.61.0-2.amzn2.0.1 ALAS2-2022-1817

Azure Linux

ReleasePackageFixed inAdvisory
Azure Linux 2 (CBL-Mariner) rust 1.59.0-1 —

Oracle Linux

ReleasePackageFixed inAdvisory
Oracle Linux 8 rls +15 1.58.1-1.module+el8.6.0+20563+1eb4e043 ELSA-2022-1894

Public exploits

Exploit or proof-of-concept code for this vulnerability is publicly available, which lowers the bar for attackers. Treat it as a reason to patch sooner.

Third-party code, not reviewed by us. Public PoCs are sometimes fake or contain malware. Read the code first and run it only in an isolated lab, against systems you are authorised to test.

GitHub 1 repository

Sources: PoC-in-GitHub, Metasploit Framework, Exploit-DB — updated daily. Only links are listed; no exploit code is hosted here.

Advisories 23

References