Live data from Hacker News

Rust in Android: move fast and fix things

security.googleblog.com

41–50 of 430 posts

Re: Rust in Android: move fast and fix things

#41
post #15

Earlier quoted context omitted.

The first chart does in fact a compelling reason to believe the effect is not that at all. If the "easy" code was predominantly being rewritten you would expect to % new memory unsafe code and % memory safety vulnerabilities to scale at different rates as the difficult to work on areas remained in C and kept causing new memory vulnerabilities. Personal experience also provides a compelling reason, my experience is ab…

I would expect memory safety vulns to be dropping in most C/C++ projects due to better practices

You would be severely disappointed.

Re: Rust in Android: move fast and fix things

#42
post #7

At this point I feel like it's no longer an uphill climb to get Rust into foundational, mission-critical code adoption. The benefits are so obvious. Maybe it's just a lingering religious war? In any case, I'm glad we're seeing more and more evidence and case-studies of why "rewrite it in Rust" isn't just a meme.

But the approach here is "write new code in rust", not rewrite.

Google rewrote Android's Bluetooth stack in Rust.

Re: Rust in Android: move fast and fix things

#43

I don't understand the graphs presented here. On the first graph showing "New Memory Unsafe Code" and "Memory safety Vulns" we don't have any steady state. The amount of both "unsafe code" and "memory safety vulns" had apparently already been dropping before 2019. None the matter though, we see a great big drop at 2022 in both. Then in the next graph, showing "Rust" and "C++", we see that the amount of C++ code writt…

> How can one possibly square those two pieces of data to point at rust somehow fixing the "memory safety vulns"?

The code base contains Kotlin and Java as well

Re: Rust in Android: move fast and fix things

#44
post #15

Earlier quoted context omitted.

The first chart does in fact a compelling reason to believe the effect is not that at all. If the "easy" code was predominantly being rewritten you would expect to % new memory unsafe code and % memory safety vulnerabilities to scale at different rates as the difficult to work on areas remained in C and kept causing new memory vulnerabilities. Personal experience also provides a compelling reason, my experience is ab…

I would expect memory safety vulns to be dropping in most C/C++ projects due to better practices

This contradicts what Google has reported about their own code, which is that most vulnerabilities are in new code

Re: Rust in Android: move fast and fix things

#45
post #2

This is the bomb that sank C++ in 2026. Have fun justifying that Rust is "also" unsafe, with the right tools you can achieve the same in C++, if you're a great dev you can do even better, etc.

I mean we know for sure Rust is unsafe there is whole bug tracker dedicated to all the ways it's unsafe. My favorite is that you can cast any lifetime to static no matter how short it actually is in 100% safe Rust. (doesn't mean it's not an improvement on C++)

This doesn't 'cast' anything. The compiler prevents this because it would allow references that outlive their owners. Freely 'casting' only works for data that is static in nature anyways, at which point a coercion is taking place. Any other way involves `std::mem::transmute` or `Box::leak` and the like.

Re: Rust in Android: move fast and fix things

#46

Earlier quoted context omitted.

I mean we know for sure Rust is unsafe there is whole bug tracker dedicated to all the ways it's unsafe. My favorite is that you can cast any lifetime to static no matter how short it actually is in 100% safe Rust. (doesn't mean it's not an improvement on C++)

This doesn't 'cast' anything. The compiler prevents this because it would allow references that outlive their owners. Freely 'casting' only works for data that is static in nature anyways, at which point a coercion is taking place. Any other way involves `std::mem::transmute` or `Box::leak` and the like.

Here is a nice segfault in perfectly legal safe Rust https://play.rust-lang.org/?version=stable&mode=debug&editio...

I'd call it casting thought technically maybe it's not you might want to call it something else? You don't need transmute or leak. The issue is only 10 years old now https://github.com/rust-lang/rust/issues/25860

Re: Rust in Android: move fast and fix things

#47

Earlier quoted context omitted.

> That gnarly horrid mess that only a few greybeards grok and has massive test coverage, a long tail of requirements enforced by tests and experience, and a culture of extreme rigor? Longer reviews, more rollbacks, and less likely to be rewritten. I'd say that this is likely the most likely to be rewritten actually, because high test coverage is a massive enabler in such a rewrite, and because having a project that “…

> It's more of one additional anecdotal evidence that Rust is good. But that means it's likely to be the worst kind of science: - Group of people agree that Rust is good. This is a belief they hold. - Same group of people feel the need to search for argument that their belief is good. - The group does "science" like this. And then the rest of us have a data point that we think we can trust, when in reality, it's just…

> And then the rest of us have a data point that we think we can trust, when in reality, it's just cherry picked data being used to convey an opinion.

Calling what Google did here "science" and cherry picked is quite a disservice. It's observational data, but do you have any objection to the methodology they used? Or just (assumed?) bad vibes?

Re: Rust in Android: move fast and fix things

#48

Earlier quoted context omitted.

But the approach here is "write new code in rust", not rewrite.

Google rewrote Android's Bluetooth stack in Rust.

Also mentioned:

  Chromium: Parsers for PNG, JSON, and web fonts have been replaced with memory-safe implementations in Rust

Re: Rust in Android: move fast and fix things

#49
post #5

Note that Google still doesn't have official support for using Rust in Android userspace, though. Despite all pluses on the blog, NDK only supports C and C++ tooling, same on Android Studio, and it is up to the community to do the needful work, if anyone feels like using Rust instead.

Nobody's stopping you from using the NDK to compile Rust though. Android's ABI is just an ABI like any other. The system doesn't care if you built an .so using Rust or anything else so long as it plays by the rules.

Some people rather reach out for first party support, instead of filling in the gaps for the big boys.

Re: Rust in Android: move fast and fix things

#50
post #17
post #13

Earlier quoted context omitted.

rust has other advantages. I think cargo is better than cmake. I think the syntax is better, I think the way dependencies and modules are handled is better. It can be annoying to write "safe" code, but once it meets a certain standard I can be confident in multithreaded applications I write. I would like to use rust to write android apps. I don't really like the whole android studio java thing.

> I think cargo is better than cmake I expect that Google is using neither of these for most of their own code, but rather their own build system (which I think is the same between the languages). I absolutely agree if you aren't Google though.

Yeah my understanding is that google has some sort of God program they use that can compile anything and has 10,000 command line options.
Post reply on HN