r/linux • • Oct 19 '25

Kernel Oops! It's a kernel stack use-after-free: Exploiting NVIDIA's GPU Linux drivers

https://blog.quarkslab.com/nvidia_gpu_kernel_vmalloc_exploit.html
260 Upvotes

43 comments sorted by

View all comments

48

u/[deleted] Oct 19 '25

And this is why we need memory safe languages.

52

u/LeeHide Oct 19 '25

we need a lot of things, like incentives that aren't completely crazy, laws that make companies care about quality, etc.

we cannot blame this on one technology

1

u/[deleted] Oct 20 '25

Try laws basic on empirical facts and empirical reasoning, every legal system I’m aware of functions more like the code of hamurabi than like a well reasoned protocol

-2

u/[deleted] Oct 19 '25

I don't disagree with the incentives, but this class of issue does not exist in memory safe languages (unless you explicitly opt-in), so it can most certainly be attributed to the programming language used.

25

u/RamBamTyfus Oct 19 '25

I don't think it's possible to create drivers without unsafe code blocks. As drivers talk to hardware and hardware can change values in memory at any time, for instance using interrupts or dma. It's certainly possible to make human errors even if you program your driver in Rust.

8

u/RoyAwesome Oct 19 '25

with rust, the amount of code that requires unsafe is minimized to just the aspects that require it. that limits the scope of a code review and points reviewer effort into the places where it's very obvious that they need to pay attention to. If that code is sound, then the rest of the code outside of the unsafe block is similarly sound, reducing the problem space.

If someone decides to just unsafe huge swaths of code, a maintainer will reject that patch long before it gets close to integration with the entire kernel.

20

u/turdas Oct 19 '25

The bug in question here looks to happen in a code block that would have required unsafe Rust to implement anyway.

-1

u/RoyAwesome Oct 20 '25 edited Oct 20 '25

allowing code reviewers to focus in on that specific code knowing it's unsafe.

7

u/not_from_this_world Oct 20 '25

Rust people points at C code:

See, this one is in C so NO ONE WILL EVER CAREFULLY REVIEW THIS EVEN IF IT IS IN A CRITICAL PART THAT WOULD REQUIRED unsafe IN RUST ANYWAY. NO ONE. EVER. BECAUSE IT'S IN C.

And then pat themselves in the back. "If this was in Rust the difference is that we would have review it."

2

u/RoyAwesome Oct 20 '25

C code "Review this whole thing. It's all potentially dangerous and could have memory issues"

Rust code: "Carefully review this one section for memory or soundness issues. Once we're sure its good, the rest of the code can just be reviewed for logic or code style"

→ More replies (2)

4

u/turdas Oct 20 '25

Odds are they still wouldn't have caught it given how the bug wasn't in Nvidia's code per se but rather in how it interacts with the kernel.

Rust is no magic bullet for this class of bug for low-level programming. With well written C/C++ code human reviewers can already spot the dodgy segments that require extra attention, which has much the same effect as marking code as unsafe.

→ More replies (1)

11

u/LeeHide Oct 19 '25

I'm saying sadly I reckon the incentives move people to just go "I have a deadline, I need to get this done, who cares, unsafe { std::pre::... }" and we'll be back to square one

5

u/MyraidChickenSlayer Oct 20 '25

unsafe { std::pre::... }" and we'll be back to square one

And, it still won't be square one. Which oke do you think is harder? Finding bug in 100% of code or just 1% part of the code?

8

u/[deleted] Oct 19 '25

At least it would be clearly auditable where such unsafe code could reside and again an opt-in. A lot of unsafe code exists not because it cannot be written in a safe manner, but because unsafe is the default in such languags, even when you don't need it.

Having a language that is safe by default is an incentive to write safe code, it slaps you in the wrist when you do. These two concepts are interlinked.

9

u/RoyAwesome Oct 19 '25 edited Oct 19 '25

that doesn't fly with the way that linux kernel gets work done though. nvidia's deadlines are not the concern for anyone else in the maintainer hierarchy.

There are enough checks that something like that will just get rejected long before it reaches Linus. If it somehow did, Linus would probably berate every single person in the chain that let it get that far.

This is in the open source driver, and doing something like that is very obvious and easy to catch in code reviews.

17

u/gmes78 Oct 19 '25

This is in the open source driver, and doing something like that is very obvious and easy to catch in code reviews.

It's Nvidia's out-of-tree driver. The Linux kernel development process does not affect it.

→ More replies (2)

1

u/LeeHide Oct 19 '25

fair, my bad

5

u/gjahsfog Oct 19 '25

Unsafe is both opt-in and harder to use than safe, so nobody is going to use unsafe to meet a deadline lol

1

u/ben0x539 Oct 20 '25

Eh, could totally see someone using unsafe to cheat lifetimes to 'static or to get at private fields or something if they're in a rush.

→ More replies (2)
→ More replies (2)

5

u/macromorgan Oct 20 '25

As someone who has written a fair amount of kernel code, I fail to see how a memory safe language like Rust is going to outperform C. I get it if you’re willing to trade performance for safety, but just understand that’s a trade off you’re going to making. The safety isn’t free.

6

u/aloha2436 Oct 20 '25

Most of Rust's safety is compile-time checks; there's no inherent runtime cost to the Rust language. If the compiler gets in the way, you can use unsafe to make the performance-for-safety tradeoff piecemeal rather than wholesale.

16

u/small_kimono Oct 20 '25 edited Oct 20 '25

I fail to see how a memory safe language like Rust is going to outperform C.

There are a few ways.

I am sure you know that FORTRAN regularly outperforms C in benchmarks, because it assumes aliased variables aren't mutated, which one can do in Rust, but can't do, at scale, in C.

See: https://dl.acm.org/doi/pdf/10.1145/3371109

Rust is also more composable, so one can perhaps more easily use more complex data structures, where they might be a burden to get correct in C.

See: https://bcantrill.dtrace.org/2018/09/28/the-relative-performance-of-c-and-rust/

I get it if you’re willing to trade performance for safety, but just understand that’s a trade off you’re going to making.

I think -- 1) what's the performance difference?, 2) and where would one see that difference?, are better questions.

Linux kernel devs have done their research and from what I've see the performance penalty is negligible, while things like concurrency are made easier.

See: https://x.com/josh_triplett/status/1569363148985233414

Re: the NVME sample driver, we see in the common case, no difference for 4K read/writes, at higher queue depths Rust is faster, and the worst case seems to be a 6% difference for 512B read/writes on low queue depths (which BTW no one is using anymore?).

See: https://rust-for-linux.com/nvme-driver

Let's imagine Rust is on average a 2% hit. A 2% hit in a Bluetooth or wireless phone modem driver which is now infinitely more secure is a hit I would take? A 2% single-threaded hit, so that my filesystem is now more concurrent, and now much faster and responsive under load, is a hit I would take?

And -- performance isn't the only question, one has to ask which language helps one make the software more correct, more quickly? Rust seems to succeed there as well. It doesn't matter how fast the software is if it returns the wrong data, or if it crashes under load?

The safety isn’t free.

Seems like a bargain though?

5

u/klorophane Oct 20 '25

Rust's borrow-checker is purely compile-time. It does not have a runtime cost per se.

6

u/Indolent_Bard Oct 20 '25

It doesn't need to outperform it, it just needs to perform as well.

→ More replies (5)