September 7th, 2024

Google says replacing C/C++ in firmware with Rust is easy

Google has transitioned firmware for protected virtual machines to Rust, enhancing security by addressing memory safety issues. Despite challenges, the U.S. government supports Rust adoption for improved software security.

Read original articleLink Icon
Google says replacing C/C++ in firmware with Rust is easy

Google has recently transitioned the firmware for protected virtual machines in its Android Virtualization Framework from C/C++ to Rust, promoting the latter as a more secure alternative. In a detailed write-up, Android engineers Ivan Lozano and Dominik Maier highlighted the advantages of Rust, particularly its ability to mitigate memory safety issues such as buffer overflows and use-after-free vulnerabilities that are prevalent in C/C++ code. Despite Rust's benefits, the transition is complicated by the steep learning curve associated with the language and resistance from established C/C++ developers. The U.S. government and tech firms are increasingly advocating for the adoption of Rust to enhance software security, with the Cybersecurity & Infrastructure Security Agency recommending that vendors prioritize the elimination of memory safety vulnerabilities. Google has reported that its Rust developers are significantly more productive than their C++ counterparts and is committed to expanding Rust's use across its platforms, including Android and Chromium. The company aims to provide developers with the necessary resources and training to facilitate this transition, emphasizing Rust's role in building secure and reliable software.

- Google has rewritten firmware in Rust to enhance security.

- Rust is seen as a solution to memory safety issues common in C/C++.

- Transitioning to Rust faces challenges due to its learning curve and developer resistance.

- The U.S. government supports Rust adoption for improved software security.

- Google reports higher productivity from Rust developers compared to C++ engineers.

Link Icon 10 comments
By @trott - 4 months
> Google was already sold on the idea, having concluded that its Rust developers are twice as productive as its C++ engineers.

Not so. The actual study compared the cost of writing something in C++ to the cost of porting it to Rust.

By @jay-barronville - 4 months
As someone who writes, reviews, and maintains lots of C code professionally, here’s what I think a lot of Rust advocates don’t understand: We see and understand the benefits of Rust. That’s no longer something we need to be sold on. Every C programmer who’s written and reviewed any amount of nontrivial C code likely has firsthand experience dealing with memory safety bugs that would simply disappear with a memory-safe language.

The ultimate problem is that most of the muscle memory you’ve built using C over the years becomes useless when writing Rust due to so many of the semantic differences. If you were an expert and highly productive C programmer, your productivity will go out the window for what feels like a long time until you feel even just comfortable writing Rust. That makes Rust a very hard sell for C programmers who simply want to get things done. This is an area, by the way, that I think Zig does extremely well at—it provides safer semantics (despite its lack of guaranteed memory safety à la Rust) in a rather simple language and without rendering so much of your experience useless.

By @QuiEgo - 4 months
Rust is interesting but still has some pain points.

- Compile times. This, above all else.

- As an embedded dev: no_std is still rough around the edges, which the original Google blog post captured pretty well. They didn’t talk about PACs - the PAC paradigm also feels needlessly complicated - whoever wrote it really loves their zero-sized types and made it verbose to the point where the solution feels worse than the problem (at least to me) for things like using GPIO lines.

- Rust has a history of shipping serious bugs (see, floating point recently), and you basically have to constantly update your rust version. Not ideal for commercial products, which want stability.

- All of the RTOS options are also young. None of the major existing ones (e.x. FreeRTOS) support Rust natively. You’re not just asking people to learn the language, but start over on libraries and platform as well.

- The community is weird. If you don’t drink the koolaid you will be attacked.

Rust is constantly getting better, and the pain points of C impact real peoples lives in very real ways (security bugs that have led to people truly getting hurt), so Rust feels inevitable, but it’s still early days and pain.

By @zeroCalories - 4 months
I just can't bring myself to spend time learning Rust when all the demand is for C++, C, Java, Typescript, Python, etc. Feels like we're going to be stuck in this limbo forever similar to languages like Kotlin.
By @saltylicorice - 4 months
Android engineers don't really speak for the whole of Google
By @Narhem - 4 months
Not surprised, rarely is it worth rewriting an entire codebase though.

Not sure who would do that or what the implications might be for replacing all the say Python code with cpp.

By @wmf - 4 months
By @bravetraveler - 4 months
(not a judgement, just an observation) Google, the conglomerate with the resources to bless us with Go and Kubernetes; another language and a container orchestration platform created with it. Their easy isn't my easy.

You would think distributing firmware and flashing would be routine; several vendors have shown me it isn't

By @oglop - 4 months
All this talk is pointless. The DoD is what will incentivize people to finally make the switch permanent. You want the real funds, you’re gonna have to write in a memory safe language going forward. At least that’s what the US government says.