News for hackers. Stuff that matters.
Re:Linux Kernel Rust Code Sees Its First CVE Vulnerability by lousken on Wednesday December 17, 2025 @01:30PM (#46303493)
Why do they allow unsafe parts in linux kernel in the first place? Why rewriting C code into unsafe rust?
Re:Linux Kernel Rust Code Sees Its First CVE Vulnerability by K0nserv on Wednesday December 17, 2025 @01:42PM (#46303644)
It's important to note that the `unsafe` keyword is poorly named. What it does is unlock a few more capabilities at the cost of upholding the invariants the spec requires. It should really be called "assured" or something. The programmer is taking the wheel from the compiler and promising to drive safely.

As for why there is unsafe in the kernel? There are things, especially in a kernel, that cannot be expressed in safe Rust.

Still, having smaller sections of unsafe is a boon because you isolate these locations of elevated power, meaning they are auditable and obvious. Rust also excels at wrapping unsafe in safe abstractions that are impossible to misuse. A common comparison point is that in C your entire program is effectively unsafe, whereas in Rust it's a subset.

Re:Linux Kernel Rust Code Sees Its First CVE Vulnerability by tialaramex on Wednesday December 17, 2025 @01:40PM (#46303628)
Rust is very nice for encapsulation. C isn't great at that work, and of course it can't express the idea that whatever we've encapsulated is now safe to use this way, in C everything looks equally safe/ unsafe.
Re:Linux Kernel Rust Code Sees Its First CVE Vulnerability by informa23 on Wednesday December 17, 2025 @01:52PM (#46303808)
EDIT: Hacker News has limited my ability to respond. Please keep in mind that Rust has a large number of active fans, who may have biases for whatever reasons.

On the other hand, Rust has some rules that are more difficult to uphold than C, for instance regarding aliasing. Especially in the Linux kernel, where it was decided that strict aliasing should be turned off when compiling C. When Rust-unsafe is used, the programmer has the responsibility of not violating those rules. That can be tricky, and many Rust developers either try to avoid using unsafe, or lean heavily on Miri, even though Miri can't handle everything.

Re:Linux Kernel Rust Code Sees Its First CVE Vulnerability by MyOutfitIsVague on Wednesday December 17, 2025 @02:19PM (#46304205)
It's worth noting that "aliasing" in Rust and C typically mean completely unrelated things.

Strict aliasing in C roughly means that if you initialize memory as a particular type, you can only access it as that type or one of a list of aliasable types look like char. Rust has no such restriction, and has no concept of strict aliasing like this. In Rust, "type aliasing" is allowed, so long as you respect size, alignment, and representability rules.

Aliasing safety in Rust roughly means that you can not have an exclusive reference to an object if any other reference is active for that reference (reality is a little bit more involved than that, but not a lot). C has no such rule.

It's very unfortunate that such similar names were given to these different concepts.

Re:Linux Kernel Rust Code Sees Its First CVE Vulnerability by tialaramex on Wednesday December 17, 2025 @04:26PM (#46305729)
No. Aliasing is a single idea, an alias is another name for the same thing. The concept translates well from its usual English meaning.

The C "strict aliasing" rule is that with important exceptions the name for a thing of type T cannot also be an alias to a thing of type S, and char is an important exception. Linux deliberately switches off this rule.

Rust's rule is that there mustn't be mutable aliases. We will see why that's important in a moment.

Aliasing is an impediment to compiler optimisation. If you've been watching Matt's "Advent of Compiler Optimisation" videos (or reading the accompanying text) it's been covered a little bit in that, Matt uses C and C++ in those videos, so if you're scared of Rust you needn't fear that in the AoCO

But why mutation? Well, the optimisations concern modification. The optimiser does its job by rewriting what you asked for as something (possibly not something you could have expressed at all in your chosen language) that has the same effect but is faster or smaller. Rewrites which avoid "spilling" a register (writing its value to memory) often improve both size and speed of the software, but if there is aliasing then spilling will be essential because the other aliases are referring to the same memory. If there's no modification it doesn't matter, copies are all identical anyway.

Re:Linux Kernel Rust Code Sees Its First CVE Vulnerability by MyOutfitIsVague on Friday December 19, 2025 @03:52PM (#46330760)
Fair enough, I meant in terms of what rules and restrictions exist around aliasing, which are different between the two, but my wording was indeed off.
Re:Linux Kernel Rust Code Sees Its First CVE Vulnerability by informa23 on Wednesday December 17, 2025 @01:56PM (#46303864)
EDIT: Hacker News has limited my ability to respond. Please keep in mind that Rust has a large number of active fans, who may have biases for whatever reasons.

Multiple reasons:

1: Marketing and social media brigading, as Linus put it.

2: Pattern matching and enums, which are genuinely good.

3: Rust has some trade-offs that are closer to C++ than C, and those trade-offs have advantages and disadvantages.

4: Module system.

5: More modern macros.

6: Other advantages.

Rust also has a large heap of drawbacks.

Re:Linux Kernel Rust Code Sees Its First CVE Vulnerability by techbrovanguard on Wednesday December 17, 2025 @09:41PM (#46308371)
Posting this from a green account is just pathetic, my guy. Go outside, touch some grass.
Re:Linux Kernel Rust Code Sees Its First CVE Vulnerability by om8 on Wednesday December 17, 2025 @01:40PM (#46303622)
Re:Linux Kernel Rust Code Sees Its First CVE Vulnerability by speed_spread on Wednesday December 17, 2025 @01:46PM (#46303717)
You need unsafe Rust for FFI - interfacing with the rest of the kernel which is still C, uses raw pointers, has no generics, doesn't track ownership, etc. One day there might enough Rust in the kernel to have pure-Rust subsystems APIs which would no longer require unsafe blocks to use. This would reverse the requirements as C would be a second class citizen with these APIs (not that C would notice or care). How far Rust is to get pushed remains to be seen but it might a long time to get there.
Re:Linux Kernel Rust Code Sees Its First CVE Vulnerability by lelanthran on Thursday December 18, 2025 @12:27PM (#46315759)
> One day there might enough Rust in the kernel to have pure-Rust subsystems APIs which would no longer require unsafe blocks to use.

This is nonsense.

You'd still need unsafe blocks because a kernel requires shared mutable memory in places.

This is like saying "If it compiles, it works", which is absolute nonsense as well.

Re:Linux Kernel Rust Code Sees Its First CVE Vulnerability by speed_spread on Thursday December 18, 2025 @05:53PM (#46319956)
> This is nonsense.

I was referring to the current unsafe blocks used for Rust->C FFI. Obviously OS code in any language will need to perform low-level operations, those unsafe blocks are never going away.

Re:Linux Kernel Rust Code Sees Its First CVE Vulnerability by lelanthran on Friday December 19, 2025 @05:56AM (#46324415)
> I was referring to the current unsafe blocks used for Rust->C FFI.

You need direct shared mutable memory access with runtime locking even in the pure-Rust parts. That's kinda what OSes need, actually. Some things (Maybe DMA, possibly Page Table mutation, register saving/loading, as a few examples) can't be compile-time checked.

In fact, I would guess that if you gradually moved the Linux code over to Rust, at the end of it you'd still have maybe 50% of it in unsafe blocks.

So, no - your claim is no different than "if it compiles it works".