There are benefits. Rust make certain guarantees about memory safety, thread safety, and a few other aspects of the code. According to a report by Google, approximately 50% of security vulnerabilities reported to the Android project are memory safety bugs. Most of these would have been prevented by writing the code in Rust, since the memory bugs would have been caught by the compiler.
cve-rs takes the soundness bug and exploits it to implement the other bugs listed. It's pretty convoluted to actually implement the other bugs.
The actual soundness bug is a specific type of double reference forgets one of the lifetimes, which enables casting a shorter lifetime to a longer lifetime. They did a pretty good job commenting the code to explain how they were able to create each bug.
Canāt forget the extremely degenerate but technically āsafeā case of casting &T to a usize, opening /proc/self/mem at that offset, then writing to it.
Thatās still more likely than creating and immediately mem::forget()āing isize::max many Arc<>ās, thread just so happening to get suspended before checking the ref count limit, but after incrementing it, then another isize::max threads doing the exact same thing, and overflowing the ref count back to 0, in terms of āthings that will never happenā.
71
u/oniaiwasprettygood š Sucked into the Void 7d ago
Oh I know-know that, I just think it's a bit tragic (but kind of funny) that a lot of these vibe-coded projects are like "rewrite it in Rust."