zlacker

[parent] [thread] 28 comments
1. pornel+(OP)[view] [source] 2022-10-02 15:49:45
Lack of a non-hacky no-panic guarantee is a pain. That would be like a no-segfault guarantee in C.

But Rust's situation is still safer, because Rust can typically prevent more errors from ever becoming a run-time issue, e.g. you may not even need to use array indexing at all if you use iterators. You have a guarantee that references are never NULL, so you don't risk nullptr crash, etc.

Rust panics are safer, because they reliably happen instead of an actually unsafe operation. Mitigations in C are usually best-effort and you may be lucky/unlucky to silently corrupt memory.

Panics are a problem for uptime, but not for safety (in the sense they're not exploitable for more than DoS).

In the long term crashing loud and clear may be better for reliability. You shake out all the bugs instead of having latent issues that corrupt your data.

replies(2): >>layer8+t5 >>hegels+z6
2. layer8+t5[view] [source] 2022-10-02 16:20:52
>>pornel+(OP)
One has to be careful about words. When Rust (or Linux) is used in (say) a vehicle or in a nuclear power plant, panicking certainly has immediate safety implications.
replies(2): >>pornel+56 >>avgcor+s8
◧◩
3. pornel+56[view] [source] [discussion] 2022-10-02 16:23:39
>>layer8+t5
But it can still be safer - e.g. a panic can trigger an emergency stop instead of silently overwriting the "go full throttle" variable.
replies(1): >>mike_h+Eb
4. hegels+z6[view] [source] 2022-10-02 16:25:53
>>pornel+(OP)
I think you're missing the point Linus made. Panicking is safer from a memory safety perspective, but it's not from a kernel perspective. You'll lose all the file changes that are not saved, you'll risk having disk written in a bad state which can be catastrophic, etc.
replies(3): >>pornel+R8 >>lifthr+H9 >>zozbot+of
◧◩
5. avgcor+s8[view] [source] [discussion] 2022-10-02 16:34:30
>>layer8+t5
And a perfect, bug-free ballistic rocket program is unsafe in the sense that it is efficient at causing damage.

Rust’s “safety” has always meant what the Rust team meant by that term. There’s no gotcha to be found here except if you can find some way that Rust violates its own definition of the S-word.

This submission is not really about safety. It’s a perfectly legitimate concern that Rust likes to panic and that panicking is inappropriate for Linux. That isn’t about safety per se.

“Safety“ is a very technical term in the PL context and you just end up endlessly bickering if you try to torture the term into certain applications. Is it safer to crash immediately or to continue the program in a corrupted state? That entirely depends on the application and the domain, so it isn’t a useful distinction to make in this context.

EDIT: The best argument one could make from this continue-can-be-safer perspective is that given two PLs, the one that lets you abstract over this decision (to panic or to continue in a corrupted state, preferably with some out of band error reporting) is safer. And maybe C is safer than Rust in that regard (I wouldn’t know).

replies(2): >>layer8+U9 >>goto11+MP1
◧◩
6. pornel+R8[view] [source] [discussion] 2022-10-02 16:36:37
>>hegels+z6
I understand his point. I just disagree, and prefer a different tradeoff.

Yes, a kernel panic will cause disruption when it happens. But that will also give a precise error location, which makes reporting and fixing of the root cause easier. It could be harder to pinpoint of the code rolled forward in broken state.

It will cause loss of unsaved data when it happens, but OTOH it will prevent corrupted data from being persisted.

replies(2): >>wtalli+Pc >>stjohn+Fy
◧◩
7. lifthr+H9[view] [source] [discussion] 2022-10-02 16:40:58
>>hegels+z6
Panic corresponds to a potential logic bug. If you have a logic bug, you already risk its consequences even if the panic didn't happen. As long as panic can be caught (and in Rust, it's indeed the case) it is safer than the alternative.
replies(1): >>hegels+Go1
◧◩◪
8. layer8+U9[view] [source] [discussion] 2022-10-02 16:41:42
>>avgcor+s8
That’s exactly my point. Rust’s definition of safety is a very specific one, and one has to be careful about what it actually implies in the context where Rust is employed. “Safety” isn’t a well-defined term for PL in general. “Soundness” is.
replies(2): >>avgcor+Qh >>UncleM+Gv
◧◩◪
9. mike_h+Eb[view] [source] [discussion] 2022-10-02 16:51:18
>>pornel+56
Yes, or jumping to the "emergency stop" routine can instead trigger "go full throttle" because the jump address has been corrupted.

Or in an actual vehicle, the "emergency stop" (if that means just stomping on the brakes) can flip the car and kill its passengers.

replies(1): >>stjohn+Az
◧◩◪
10. wtalli+Pc[view] [source] [discussion] 2022-10-02 16:58:29
>>pornel+R8
> But that will also give a precise error location, which makes reporting and fixing of the root cause easier. It could be harder to pinpoint of the code rolled forward in broken state.

I think you must have missed out on how Linux currently handles these situations. It does not silently move on past the error; it prints a stack trace and CPU state to the kernel log before moving on. So you have all of the information you'd get from a full kernel panic, plus the benefit of a system that may be able to keep running long enough to save that kernel log to disk.

◧◩
11. zozbot+of[view] [source] [discussion] 2022-10-02 17:12:08
>>hegels+z6
Panic in Rust need not equate to a literal kernel panic. It can call an oops handler, which might manage to keep the system operational depending on where the failure occurred.
replies(1): >>hegels+up1
◧◩◪◨
12. avgcor+Qh[view] [source] [discussion] 2022-10-02 17:26:18
>>layer8+U9
Memory safety is a well-defined term.
replies(1): >>layer8+Vi
◧◩◪◨⬒
13. layer8+Vi[view] [source] [discussion] 2022-10-02 17:30:54
>>avgcor+Qh
I agree, but that isn’t the term that was used here, and Rust proponents usually mean more than memory safety by “safe” (like e.g. absence of UB).
replies(2): >>avgcor+Gm >>veber-+M22
◧◩◪◨⬒⬓
14. avgcor+Gm[view] [source] [discussion] 2022-10-02 17:50:53
>>layer8+Vi
Going through that thread (a few posts back) it seems that “Rust is safe” (as seen in this submission title) was stated first by Torvalds. It wasn’t mentioned first by a “Rust aficianado”. So you would really have to ask Torvalds what he meant. But his mentioning of it (and this submission) obviously alludes to “safe” claims by the Rust project. Which has always been memory safety.
replies(1): >>layer8+mp
◧◩◪◨⬒⬓⬔
15. layer8+mp[view] [source] [discussion] 2022-10-02 18:05:58
>>avgcor+Gm
I disagree that “safe” as used by the Rust community is always restricted to memory safety, see my parent comment.
◧◩◪◨
16. UncleM+Gv[view] [source] [discussion] 2022-10-02 18:46:00
>>layer8+U9
> “Safety” isn’t a well-defined term for PL in general. “Soundness” is.

This is false. "Safety" and "Liveness" are terms used by the PL field to describe precise properties of programs and they have been used this way for like 50 years (https://en.wikipedia.org/wiki/Safety_and_liveness_properties). A "safety" property describes a guarantee that a program will never reach some form of unwanted state. A "liveness" property describes a guarantee that a program will eventually reach some form of wanted state. These terms would be described very early in a PL course.

replies(1): >>layer8+AU
◧◩◪
17. stjohn+Fy[view] [source] [discussion] 2022-10-02 19:05:56
>>pornel+R8
On one embedded projected we had a separate debug chip could safely shutdown what might be dangerous circuits in the case of controller failure. The source code for that was much much much smaller than the controller and heavily vetted by mulitiple people. The small dedicated would initiate circuit shutdown on panic from the linux kernel on the controller. My point being is it's hard to know what happens after a panic, and logging and such is nice, but that may or may not be available, but being able to do some action as simple as sending a "panic" signal to a second dedicated processor to shut down critical systems in a controlled manner is nice. "Stop the world" can be very dangerous in some situations. There were even more independent backup failsafes on the potentially dangerous circuits as well, but redundancy is even more insurance something bad won't happen.
◧◩◪◨
18. stjohn+Az[view] [source] [discussion] 2022-10-02 19:12:31
>>mike_h+Eb
It's about the odds here. Nothing is 100% safe. Independent systems almost always provide backup safety incase the OS/embedded system fails. Thing like overcurrent detector, brown out detectors, speed governors, etc in case code does something as a result of running corrupted (or something similarly awful)
◧◩◪◨⬒
19. layer8+AU[view] [source] [discussion] 2022-10-02 21:31:48
>>UncleM+Gv
What I mean is that there is no universal definition of which properties are safety properties. In principle, you can define any property you can formally reason about as a safety property. Therefore, whenever you talk about safety, you first have to define which properties you mean by that.

In the context of Rust, there are a number of safety properties that Rust guarantees (modulo unsafe, FFI UB, etc.), but that set of safety properties is specific to Rust and not universal. For example, Java has a different set of safety properties, e.g. its memory model gives stronger guarantees than Rust’s.

Therefore, the meaning of “language X is safe” is entirely dependent on the specific language, and can only be understood by explicitly specifying its safety properties.

replies(2): >>avgcor+oW >>UncleM+i31
◧◩◪◨⬒⬓
20. avgcor+oW[view] [source] [discussion] 2022-10-02 21:43:56
>>layer8+AU
> Therefore, whenever you talk about safety, you first have to define which properties you mean by that.

Like “memory safety”?

replies(1): >>layer8+L01
◧◩◪◨⬒⬓⬔
21. layer8+L01[view] [source] [discussion] 2022-10-02 22:14:36
>>avgcor+oW
For example. Rust has other safety properties beyond memory safety.
◧◩◪◨⬒⬓
22. UncleM+i31[view] [source] [discussion] 2022-10-02 22:32:22
>>layer8+AU
That's true for "soundness" too. Things aren't just "sound". They are sound with respect to something. So when you use "soundness" as a comparison against "safety", you'll have to understand how somebody could interpret your post in the way that I did.

Almost all discussion about Rust is in comparison to C and C++, by far the dominant languages for developing native applications. C and C++ are famously neither type-safe nor memory-safe and it becomes a pretty easy shorthand in discussions of Rust for "safety" to refer to these properties.

◧◩◪
23. hegels+Go1[view] [source] [discussion] 2022-10-03 01:25:44
>>lifthr+H9
1. As far as i'm aware there's no way to reliably catch all panics. catch_unwind does not catch all panics. 2. The whole point is that consequences of a panic are worse than the consequences of memory corruption. That's how the kernel was designed. There was an explicit design decision not to kernel panic in every situation where a logic error occurs.
replies(1): >>lifthr+zB1
◧◩◪
24. hegels+up1[view] [source] [discussion] 2022-10-03 01:32:36
>>zozbot+of
As far as I'm aware there's no way to reliably catch all panics. catch_unwind does not catch all panics. Handlers don't stop the program from terminating abruptly.
◧◩◪◨
25. lifthr+zB1[view] [source] [discussion] 2022-10-03 03:23:50
>>hegels+Go1
There are tons of edge cases with panics, e.g. panic can trigger a destructor that can panic itself, or unwinding may cross a language boundary which may not be well defined, but to my knowledge `catch_unwind` does catch all panics as long as unwinding reliably works. That disclaimer in the `catch_unwind` documentation only describes the `panic = abort` case.

And I thought it was clear that kernel panic is different from Rust panic, which you don't seem to distinguish. Rust panic doesn't need to cause a kernel panic because it can be caught earlier.

replies(1): >>hegels+nF1
◧◩◪◨⬒
26. hegels+nF1[view] [source] [discussion] 2022-10-03 04:11:43
>>lifthr+zB1
Obviously rust panic is not the same as a kernel panic. What you're taking for granted is that just because rust can catch a panic that it will. A simple overflow can cause a panic. When this happens, the panic might be caught before the kernel panics, but by then the program is probably already in an undefined state. It also might not be caught at all, and cause an actual kernel panic.
replies(1): >>lifthr+mI1
◧◩◪◨⬒⬓
27. lifthr+mI1[view] [source] [discussion] 2022-10-03 04:47:14
>>hegels+nF1
The program is in a defined but undesirable state, both when panic occurred in Rust and when a "simple" uncontrolled overflow happened in C (provided that the compiler is configured to not treat it as an UB, otherwise it'd be worse). And anyone doing Rust-C interop already has to be conscious about the language boundary, which happens to be a perfect place to catch Rust panics.
◧◩◪
28. goto11+MP1[view] [source] [discussion] 2022-10-03 06:16:11
>>avgcor+s8
Linus' point is that safety means something different in kernel programming than in PL theory, and that Rust have to be safe according to kernel rules before it can be used for kernel programming.
◧◩◪◨⬒⬓
29. veber-+M22[view] [source] [discussion] 2022-10-03 08:24:16
>>layer8+Vi
absence of UB is literally memory safety.

Rust proponents mean exactly "memory safety" when they say rust is safe because that is the only safety rust guarantees.

[go to top]