116 points · by mfrw · 4y ago · 34 comments
+ spin_lock(&unix_gc_lock);
+ spin_unlock(&unix_gc_lock);
So they acquire+release a lock without doing anything in between, sort of as a way to introduce a barrier.I have a vague feeling that if something like this is necessary, there is something odd about the locking model of that code in general. It most likely shows that locking is used in a process centric way, as opposed to data centric.
The patch in question https://patchwork.ozlabs.org/project/netdev/patch/CAOssrKcfn... is not an RFC, was written by a redhat eng., had a proper commit message, was signed off, and had plenty of feedback.
Edited and re-edited: I was too quick to presume commenter was just spouting the common “rust is a panacea” theme. Kernels are all about “unsafe” concurrent access and reentrant code, so rust is not a panacea. For this case of multi-threaded/multi-process access (presumably from ring-0 kernel code accessing shared kernel memory), using rust primitives to help prevent race conditions could make sense (smart pointers), because the code is unlikely to be performance sensitive and the feature is there to protect against a fairly extreme corner case (crazy ad hoc GC for cyclic graph of processes sending each other file descriptors). Reliable discussion on rust for kernel drivers here: https://security.googleblog.com/2021/04/rust-in-linux-kernel... Disclaimer: not a kernel nor rust dev. In past dabbled with embedded kernel debugging. I keep tweaking this edit, because it is complicated!
This is in fact an example of a class of bug that Rust's compiler is uniquely able to protect from - other memory safe languages don't make guarantees about concurrent accesses at all - at least not Java, C#, Go, Python, Haskell, OCaml etc. Perhaps Ada does have something?
This CVE appears to be due to a race condition despite using atomics, so likely this could've happened in Rust code. Really to implement this sort of GC I'd wager that unsafe rust would also be required unless an entirely different algorithm was used.
Possibly. But the first question is whether the person writing this in Rust would have used unsafe. Without knowing more details here, it's hard for me to guess.
> other memory safe languages don't make guarantees about concurrent accesses at all - at least not Java
Well, Java does have synchronized methods. Those lock the entire class. You can imagine writing a "manager" class that encapsulates all the GC data structures here, and that would have made this perfectly safe in Java using existing language features.
Of course, that would have been slower - so, again, it is tempting to use unsafe approaches, even in a memory-safe language like Java, but then you do risk bugs like this.
But of course I do agree that Rust, even with some amount of unsafe, would be a far safer language than C!
A Haskell-like language for kernel development would lean heavily on linear typing. Some prototypes have been made and used.
However, it still has issues of its own; no language is perfect and the best-suited for all use cases.
The more you believe and trust Rust, the more limitless your possibilities become for your family, your career and your life!.
Insane.
People there were thinking about this as a possible fix for a hypothetical crash, not a security issue, and no one was able to prove that there was a crash, nor that the patch fixed it.
No one bothered reviewing it, and the original person who raised the patch didn't advocate further.
None of this seems even close to "insane", this seems like exactly what you expect in most software projects. "Hey, can you explain the bug this patch fixes more?" -> contributor vanishes into the aether -> nothing happens.