Security

A flaw in Rust Programming language could allow to delete files and directories

The maintainers of the Rust programming language fixed a high-severity flaw that could allow attackers to delete files and directories from a vulnerable system.

The maintainers of the Rust programming language have released a security update for a high-severity vulnerability, tracked as CVE-2022-21658. An attacker can trigger the vulnerability to delete files and directories from a vulnerable system.

“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).” reads the advisory published by maintainers of the programming language. “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.”

The vulnerability affects Rust 1.0.0 through Rust 1.58.0, it was addressed with the release of Rust version 1.58.1 shipped last week.

An attacker with an unprivileged access to a system that wants to delete a system directory called sensitive/, for which he doesn’t’ have the permissions to do so, he could find a privileged program that removes a directory he has access to (called temp/), create a symlink from temp/foo to sensitive/, and wait for the privileged program to delete foo/. The privileged program would follow the symlink from temp/foo to sensitive/ while recursively deleting, resulting in sensitive/ being deleted.

The advisory states that std::fs::remove_dir_all already includes protection against recursively deleting symlinks, but they are not correctly implemented.

“Unfortunately that check was implemented incorrectly in the standard library, resulting in a TOCTOU (Time-of-check Time-of-use) race condition. Instead of telling the system not to follow symlinks, the standard library first checked
whether the thing it was about to delete was a symlink, and otherwise it would proceed to recursively delete the directory.” continues the advisory. “This exposed a race condition: an attacker could create a directory and replace
it with a symlink between the check and the actual deletion. While this attack likely won’t work the first time it’s attempted, in our experimentation we were able to reliably perform it within a couple of seconds.”

Follow me on Twitter: @securityaffairs and Facebook

[adrotate banner=”9″][adrotate banner=”12″]

Pierluigi Paganini

(SecurityAffairs – hacking, Rust programming language)

[adrotate banner=”5″]

[adrotate banner=”13″]

Pierluigi Paganini

Pierluigi Paganini is member of the ENISA (European Union Agency for Network and Information Security) Threat Landscape Stakeholder Group and Cyber G7 Group, he is also a Security Evangelist, Security Analyst and Freelance Writer. Editor-in-Chief at "Cyber Defense Magazine", Pierluigi is a cyber security expert with over 20 years experience in the field, he is Certified Ethical Hacker at EC Council in London. The passion for writing and a strong belief that security is founded on sharing and awareness led Pierluigi to find the security blog "Security Affairs" recently named a Top National Security Resource for US. Pierluigi is a member of the "The Hacker News" team and he is a writer for some major publications in the field such as Cyber War Zone, ICTTF, Infosec Island, Infosec Institute, The Hacker News Magazine and for many other Security magazines. Author of the Books "The Deep Dark Web" and “Digital Virtual Currency and Bitcoin”.

Recent Posts

PuTTY SSH Client flaw allows of private keys recovery

The PuTTY Secure Shell (SSH) and Telnet client are impacted by a critical vulnerability that could…

1 hour ago

A renewed espionage campaign targets South Asia with iOS spyware LightSpy

Researchers warn of a renewed cyber espionage campaign targeting users in South Asia with the…

6 hours ago

Misinformation and hacktivist campaigns targeting the Philippines skyrocket

Amidst rising tensions with China in the SCS, Resecurity observed a spike in malicious cyber…

7 hours ago

Russia is trying to sabotage European railways, Czech minister said

Czech transport minister warned that Russia conducted ‘thousands’ of attempts to sabotage railways, attempting to…

11 hours ago

Ransomware group Dark Angels claims the theft of 1TB of data from chipmaker Nexperia

The Dark Angels (Dunghill) ransomware group claims the hack of the chipmaker Nexperia and the…

13 hours ago

Cisco Duo warns telephony supplier data breach exposed MFA SMS logs

Cisco Duo warns that a data breach involving one of its telephony suppliers exposed multifactor…

23 hours ago

This website uses cookies.