News: 1712754908

  ARM Give a man a fire and he's warm for a day, but set fire to him and he's warm for the rest of his life (Terry Pratchett, Jingo)

Rust rustles up fix for 10/10 critical command injection bug on Windows

(2024/04/10)


Programmers are being urged to update their Rust versions after the security experts working on the language addressed a critical vulnerability that could lead to malicious command injections on Windows machines.

The vulnerability, which carries a perfect 10 base severity score, is tracked as CVE-2024-24576. It affects the Rust standard library, which was found to be improperly escaping arguments when invoking batch files on Windows using the Command API.

"An attacker able to control the arguments passed to the spawned process could execute arbitrary shell commands by bypassing the escaping," said Pietro Albini of the Rust Security Response Working Group, who wrote [1]the advisory .

[2]

The main issue seems to stem from Windows' CMD.exe program, which has more complex parsing rules, and Windows can't execute batch files without it, according to the researcher at Tokyo-based Flatt Security who [3]reported the issue .

[4]

[5]

Albini said Windows' Command Prompt has its own argument-splitting logic that works differently from the usual Command::arg and Command::args APIs, which typically allow untrusted inputs to be safely passed to spawned processes.

"On Windows, the implementation of this is more complex than other platforms, because the Windows API only provides a single string containing all the arguments to the spawned process, and it's up to the spawned process to split them," said Albini. "Most programs use the standard C run-time argv, which in practice results in a mostly consistent way arguments are split.

[6]

"Unfortunately it was reported that our escaping logic was not thorough enough, and it was possible to pass malicious arguments that would result in arbitrary shell execution."

Chris Denton, a contributor to Rust's library, developed the fix that mitigated the issue, which involved making improvements to the escaping code and ensuring the Command API returned an InvalidInput error when it can't safely escape arguments.

[7]Rust developers at Google are twice as productive as C++ teams

[8]Rust can help make software secure – but it's no cure-all

[9]Google throws $1M at Rust Foundation to build C++ bridges

[10]Microsoft seeks Rust developers to rewrite core C# code

The team couldn't pinpoint a fix that would escape arguments in every case, owing to the complexity of Command Prompt, Albini said.

"If you implement the escaping yourself or only handle trusted inputs, on Windows you can also use the CommandExt::raw_arg method to bypass the standard library's escaping logic."

Rust released version 1.77.2 on Tuesday, saying that every version that came before it is vulnerable.

[11]

The language is a fan favorite, routinely topping Stack Overflow's rankings for how enjoyable developers find Rust to use in their work, and Googlers hail its [12]productivity benefits . It's also one of the newer [13]memory-safe languages national security authorities are urging developers to adopt in favor of older technologies such as C and C++.

BatBadBut

According to RyotaK, the researcher who reported the vulnerability, which they are referring to as BatBadBut due to it revolving around batch files and its severity – "bad, but not the worst" – the issue affects more technologies than Rust alone.

Erlang, Go, Python, and Ruby are also affected and have updated their respective documentation pages to raise awareness of the issue.

Node.js and PHP are both working on patches now, while Rust and Haskell both have their fixes pushed out already. Java is affected but its team has no plans to address it, according to the researcher's report.

RyotaK also made the point that users should not jump to conclusions based on the CVSS rating alone, since the severity of the issue will depend on each application individually and should be recalculated as such. ®

Get our [14]Tech Resources



[1] https://blog.rust-lang.org/2024/04/09/cve-2024-24576.html

[2] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_security/patches&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=2&c=2Zha3m@gU2Hv5oW@iE3GBFgAAAII&t=ct%3Dns%26unitnum%3D2%26raptor%3Dcondor%26pos%3Dtop%26test%3D0

[3] https://flatt.tech/research/posts/batbadbut-you-cant-securely-execute-commands-on-windows/

[4] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_security/patches&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=4&c=44Zha3m@gU2Hv5oW@iE3GBFgAAAII&t=ct%3Dns%26unitnum%3D4%26raptor%3Dfalcon%26pos%3Dmid%26test%3D0

[5] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_security/patches&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=3&c=33Zha3m@gU2Hv5oW@iE3GBFgAAAII&t=ct%3Dns%26unitnum%3D3%26raptor%3Deagle%26pos%3Dmid%26test%3D0

[6] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_security/patches&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=4&c=44Zha3m@gU2Hv5oW@iE3GBFgAAAII&t=ct%3Dns%26unitnum%3D4%26raptor%3Dfalcon%26pos%3Dmid%26test%3D0

[7] https://www.theregister.com/2024/03/31/rust_google_c/

[8] https://www.theregister.com/2024/02/08/rust_software_memory_safety/

[9] https://www.theregister.com/2024/02/05/google_rust_donation/

[10] https://www.theregister.com/2024/01/31/microsoft_seeks_rust_developers/

[11] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_security/patches&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=3&c=33Zha3m@gU2Hv5oW@iE3GBFgAAAII&t=ct%3Dns%26unitnum%3D3%26raptor%3Deagle%26pos%3Dmid%26test%3D0

[12] https://www.theregister.com/2024/03/31/rust_google_c/

[13] https://www.theregister.com/2023/12/07/memory_correction_five_eyes/

[14] https://whitepapers.theregister.com/



Ha! Rust Is The Answer To All Our C Programming Security Issues?

Anonymous Coward

Answer: Well, No, Not Quite!!!

Re: Ha! Rust Is The Answer To All Our C Programming Security Issues?

Dan 55

No memory was harmed while arguments were improperly split, so I'm sure we should all be thankful for that.

Re: Ha! Rust Is The Answer To All Our C Programming Security Issues?

JessicaRabbit

I'm not a huge fan of Rust but come on, they're pretty clear about what security issues the language is designed to guard against and what it doesn't. They've never claimed to be a silver bullet for all security issues ever.

Re: Ha! Rust Is The Answer To All Our C Programming Security Issues?

Someone Else

They've never claimed to be a silver bullet for all security issues ever.

That's true, and good on your for pointing that out. Rust's fanbois, on the other hand...

Argh

cyberdemon

It's 2024, who the hell is still using Batch files?

On the occasions when I am forced to use Windows, the first thing I do is install a proper shell, be it Cygwin or MinGW, WSL or a VM

It's time that CMD.exe and Command.COM are retired for good, along with the rest of MS-DOS that still persists in Windows, shirley

Re: Argh

DJO

It's 2024, who the hell is still using Batch files

Everybody. They might not do so themselves but loads of programs will run a batch file in the background because it's easy and it works.

Do you sometimes see command windows popping up and disappearing just as quickly? Well that was probably a batch file.

ovation1357

But, but, but... rust is ultra-secure, and faster, with better access to the internet!

"Java is affected but its team has no plans to address it"

Blazde

That's my Java

Jim Mitchell

I'm confused (again?). This headline, advistory, etc, reads as a Rust problem, but "Erlang, Go, Python, and Ruby are also affected and have updated their respective documentation pages to raise awareness of the issue.". Do those language implementations on Windows use Rust or just made the same mistake, or ?

Dan 55

Nobody knows how to split arguments on Windows. Apart from C because it's been around the block and had the bugs knocked out of it but reimplementing all the bugs back in again in other languages appears to be the way to go.

Throatwarbler Mangrove

It sounds like the editors decided that putting Rust in the headline would garner the most attention. The article indicates that the real issue stems from the interaction between code written in the mentioned languages and the cmd.exe shell's approach to passing arguments between programs. At a guess, misinformation about how to code shell escape prevention for cmd.exe made it into some common source of truth, and the developers for all those languages used the same source, whether directly or indirectly.

sooo what your saying is

Anonymous Coward

if someone wants to use those exploits, keep using the old libraries?

sounds like a problem that won't be going away.

Alex Buell:
Or how about a Penguin logo painted in really really trippy
colours, and emblazoned with the word LSD. :o)

Geert Uytterhoeven:
We already had that one, but unfortunately Russell King fixed that nasty
palette bug in drivers/video/fbcon.c :-)
-- linux-kernel