If it indicates a violation of kernel assumptions, a panic is fine, that's what BUG() exists for as well after all. If it's possible due to external input it should of course use something like the .get() apis instead.
Just cause its a kernel doesn't mean you want to ignore oit of bounds, that's how you get security bugs.
You don't want to ignore it, but if you're linking code that panics wnen it detects of oob access, that is a security hole allowing vectors for denial of service. If that's Rust's method for dealing with oob access, then Rust code shouldn't go in the kernel. It should be changed to do something less drastic.
Hm. I don't even agree that out of bounds access, unsafe casts from int to float (ie quake fast inverse square root), should automatically cause a panic.
Let the panics come from the hardware, not from your language. One is truly fatal, the other is we-don't-like-undefined-behavior-so-lets-just-panic-and-say-we-dont-have-undefined-behavior-in-our-language
Let the panics come from the hardware, not from your language. One is truly fatal, the other is we-don't-like-undefined-behavior-so-lets-just-panic-and-say-we-dont-have-undefined-behavior-in-our-language
I’m with Linus that Rust should be “fixed” with a mode where we ban any sort of runtime “panic” from being compiled in (outside of very explicitly controlled exceptional circumstances), but there is no reason achieving this needs to entail the massive reliability/stability cost of undefined behavior.
There is no good reason to want undefined behavior (of which hardware-sensitive ”panic” conditions is one), since it not only makes writing reliable bug-free software needlessly difficult in general, but opens the door to endless bugs and severe security vulnerabilities.
So, the only remaining question is whyand when we would ever need any undefined behavior to write high performance software, whether high or low level.
Rust answers this. It proves we no longer need (nor should ever desire, obviously) undefined behavior and memory unsafety as the default state of our programming language in order to write highly readable, efficient software (both system level and user level).
And the benefits of safe-by-default are massive, and should be the obviously correct choice in an industry where extremely dangerous and harmful security vulnerabilities are shamefully pervasive — a sad state which is arguably a direct consequence of stubbornly holding to incorrect ideas that we somehow need undefined behavior to prevent sacrificing performance or other nebulous unsubstantiated concerns.
I'm not so sure you want to fail fast in a kernel, however. In face, if I'm not mistaken, that's been Linus's long-standing policy - "whatever you do, don't crash user space".
If it indicates a violation of kernel assumptions, a panic is fine,
Not in release, it is not. You log it and move on. I'd prefer my OS to produce an out of bounds warning, letting me save my work before rebooting than unconditionally deciding for me that my work is less important than the OS.
I'd prefer my OS to produce an out of bounds warning, letting me save my work before rebooting than unconditionally deciding for me that my work is less important than the OS.
But logging is not the alternative.
The alternative, in C, is that the OS just read from or wrote to outside the memory area it was supposed to access.
If your developer is conscientious enough to check and log in C, then they're conscientious enough to check and log in Rust -- the panic is an alternative to "UB", not an alternative to smooth handling of edge cases.
Rust allows specifying the panic handler, however it cannot return (and resume execution) because there's no code at the call site to handle the error.
A panic is a bug, and that's not something a flag can fix.
115
u/Nicksaurus Apr 14 '21
I assume he would prefer an error code at runtime on an out-of-bounds access