r/rust • u/CenturionGamer • Oct 01 '24
Google’s Shift to Rust Programming Cuts Android Memory Vulnerabilities by 68%
https://thehackernews.com/2024/09/googles-shift-to-rust-programming-cuts.html?m=1[removed] — view removed post
41
u/AssistingJarl Oct 01 '24
...sorry, can we talk about that domain name for a moment? It's definitely not what I was expecting. Is this a legit source?
6
u/CenturionGamer Oct 01 '24
12
u/ninja_tokumei Oct 01 '24
MSN is largely just a mirror of other news websites. The original source for that one is TechRadar
21
u/syklemil Oct 01 '24 edited Oct 01 '24
Reminds me of http://hackerne.ws, which is a redirect to https://news.ycombinator.com
17
8
u/steveklabnik1 rust Oct 01 '24
Is this a legit source?
The story is legit. The source feels a bit spammy to me.
1
Oct 01 '24
It's like a resume. Chief fluffer 2022-present: Decreased flaccidity by 68%. They're not aiming at programmers. They're aiming at corporate.
1
u/ren01r Oct 02 '24
I have met the founders of this website. I don't know if they're in control anymore but it is legit.
162
Oct 01 '24
It is more impressive if you take into account how many vulnerable points are getting address quickly.
Nice job!
101
3
u/mrdevlar Oct 01 '24
I am curious is it possible now to write a full Android application in Rust?
6
u/UtherII Oct 02 '24 edited Oct 08 '24
It's possible, but if your application has a GUI, using a JVM Language like Java or Kotlin is recommended since the Android API was designed for those languages. Your program can still call Rust crates through JNI.
Firefox on Android used to be fully native, but it switched to a GUI in Java calling a webengine in C++ and Rust to be more responsive.
-1
u/C_Madison Oct 02 '24
No one deflects as hard as (some) C/C++ programmers. They should go into professional fighting sports, at least their defense will be perfect.
3
u/jeffmetal Oct 02 '24
Would love to know how many memory safety issues have been found in the rust code. A previous blog post said they had written 1.5 million lines of rust and found none, but that was a few years ago.
3
u/PiedDansLePlat Oct 01 '24
In the end, google will be the last vulnerability, the one gathering, packaging and selling your infos everywhere.
1
u/Tweenk Oct 02 '24
Google doesn't sell user data, it sells ad space on its websites and an ad placement service that matches advertisers with potentially interested users. They determine which users might be interested based on their interactions with Google's services.
1
u/syklemil Oct 01 '24
Trailing off a discussion someone else were having on the previous reddit discussion about memory safety vs null safety and how they're different: Memory safety involves not reading arbitrary memory locations, which is more likely to become a security issue. See e.g. the earlier google blog about memory safe languages under What about non-memory-safety vulnerabilities?
-59
Oct 01 '24
Is that a flex? I don’t think that’s a flex
66
u/the-code-father Oct 01 '24
It's not a flex. It's important industry data that is available for citation when people complain that vulnerabilities exist in C++ codebases due to a skill issue. There is no "git gud" approach to avoiding memory issues, the proven way to do so is to switch to a memory safe language.
-33
u/CyberWank2077 Oct 01 '24
or patch the language to be memory safe.
40
u/the-code-father Oct 01 '24
Congratulations you just invented a new memory safe language!
You can't just patch memory safety into C++, if you look at the current proposal for doing so it's basically a new language with the C++ name tacked onto the existing language. That makes it very much inline with C++ design philosophy
12
Oct 01 '24 edited Oct 01 '24
For anyone that wants to give the "Safe C++" proposal a read, here is a link. I do warn you, the syntax in the examples gets... Interesting
7
u/ThunderChaser Oct 01 '24
The proposal literally just reads like "make C++ into Rust lmao".
5
u/the-code-father Oct 01 '24
I had the same initial reaction to it, but even if this document is the only thing that ever comes of this initiative I still think it's quite valuable. At least now when someone asks "Why can't we just make C++ safe?" You can point at this document to demonstrate the amount of work required to do that
2
u/C_Madison Oct 02 '24
C++ started as "C with classes" after all. Maybe that's the way they like their language design: "C++ with Rust!" ... Wonder what it will be called. R++?
2
1
u/CyberWank2077 Oct 02 '24
while it would be better (IMO) if we could just move all the existing projects, tools, frameworks and proffesional knowledge to Rust, its not that easy. You have more cpp experts or intermediate developers than Rust, and too many exisiting projects. If you can extend cpp to have what you need, this is often a better solution than just jumping ship and trying to deprecate the older language.
The real question is, how do you do it? and multiple paths seem to take place at once. There are attempts at creating sort of a CPP2, there is google's Carbon, there is rust being compiled to the LLVM, and there are these suggestions of adding implicit safety features to cpp26. If the final result of cpp26 will be good, it might no longer be worth it to try and move to Rust for many projects.
3
6
Oct 01 '24
Why ? Explain?
-13
u/PurepointDog Oct 01 '24 edited Oct 01 '24
It means they had a lot of memory vulerabilities, and many of them were likely low-hanging fruit when using a proper tool for the job (ie rust)
29
u/the-code-father Oct 01 '24
If you actually read the post you would understand that they were literally doing everything you could possibly do to avoid these kinds of issues. Extensive code reviews, every sanitizer that's out there, lots and lots of testing were all being used. Using a memory safe language is by far the most effective way to avoid memory related vulnerabilities.
-1
18
u/gotMUSE Oct 01 '24
How are people still arguing 'skill issue' in 2k24?
13
u/Dasher38 Oct 01 '24
Most people I've seen arguing that IRL don't know anything else than C, and when something else comes under their hands, they pretend it's C and say they don't like it as they just turn it into a bad C. So it's a skill issue, but not a C/C++ skill issue, more like a learning issue.
7
u/TDplay Oct 01 '24
many of them were likely low-hanging fruit when using a proper tool for the job
Android 1.0 released 7 years before Rust 1.0.
You can say many things about Google, but you can't fault them for not using tools that simply didn't exist yet.
1
12
Oct 01 '24
[removed] — view removed comment
60
u/BiedermannS Oct 01 '24
Android itself could be written in any language that’s capable of running on that hardware. Historically that has been c/c++ which does the low level stuff like drivers, which it exposes to a Java virtual machine. That c/c++ code can be replaced by other languages tho, which is where rust comes in.
-4
Oct 01 '24 edited Mar 04 '25
[removed] — view removed comment
53
u/hgwxx7_ Oct 01 '24
No, you'd still prefer Kotlin/Java.
This is more for Google. For example the Android Bluetooth stack is a part of the OS and it is written in Rust.
14
u/nicholsz Oct 01 '24
No, but you can make calls to Rust from Java or Kotlin if you're trying to optimize parts of your code. Also the libraries you're calling will be using more and more Rust behind the scenes as time marches on.
20
u/tajetaje Oct 01 '24
UI code is almost always a JVM language like Java or Kotlin, but system functionality and daemons are in lower level languages
7
u/killersquirel11 Oct 01 '24
I think Tauri now supports Android, so technically yes. But that's entirely unrelated to above post.
6
u/BiedermannS Oct 01 '24
You could have used rust for parts of your android app for a long time already. Even before that. It just means that parts of the system your app is running in is now written in rust instead of C++.
19
u/nicholsz Oct 01 '24 edited Oct 01 '24
Android uses a virtual machine called "dalvik" (oops, that's deprecated. it's called the "Android Runtime" now) that works like the jvm. Like the JVM, it runs bytecode which can be compiled from a number of languages like Java or Kotlin.
Also like the JVM, it has a JNI that allows it to make calls to native code compiled with the expected call stack conventions (which includes C/C++). Google has done some work to make it easy to make these calls to Rust instead of C/C++, and by leveraging Rust they've reduced memory vulnerabilities.
8
u/Theemuts jlrs Oct 01 '24 edited Oct 01 '24
The kernel is based on Linux.Edit because I was stating the obvious: There's an ongoing effort to make Rust a supported language for Linux kernel development. Google is experimenting with a re-implementation of the Android Binder, which is an inter-process communication (IPC) mechanism. This mechanism uses a kernel driver, and this kernel driver is the part that's being re-implemented in Rust.
2
u/GenTelGuy Oct 02 '24
Android apps can be written only in Java, right?
Kotlin is also an option, and it's a more modern language than Java that makes for more secure and bug-resistant apps
And the Android OS uses whatever language Linux uses, and runs Java. Where Rust?
This "whatever language Linux uses" was usually C, but now they're using Rust instead for parts of it
2
u/small_kimono Oct 01 '24
The Rust bits are in the Binder driver. See: https://rust-for-linux.com/android-binder-driver
1
u/Tweenk Oct 02 '24
This blog post is not about Rust in the kernel, it's about Rust in Android OS userspace components.
1
u/Tweenk Oct 02 '24
This is about the Android OS, not Android apps.
Android OS contains many more components than the Linux kernel - it also includes IPC, a virtual machine environment that supports both AOT and JIT (ART), a display server, an audio server, a networking stack, a Bluetooth stack, a cryptography framework, media codecs, userspace device drivers, HAL implementations, etc.
The Rust code mentioned in the blog is mainly in those userspace OS components. For example, a significant portion of Android's Bluetooth stack is now in Rust.
17
u/CenturionGamer Oct 01 '24
Good follow up article…https://security.googleblog.com/2024/09/eliminating-memory-safety-vulnerabilities-Android.html?m=1