zlacker

“Rust is safe” is not some kind of absolute guarantee of code safety

submitted by rvz+(OP) on 2022-10-02 14:20:21 | 276 points 514 comments
[view article] [source] [go to bottom]

NOTE: showing posts with links only show all posts
◧◩
6. mustac+G4[view] [source] [discussion] 2022-10-02 14:54:24
>>throwa+R1
As someone else in the thread notes, they seem to be talking past one and other. [0]

Linus may view his job as "Saying No" but the way he does it still leaves a little to be desired, because his reasoning is sound here, but it's less "Follow my reasoning" than "You don't want to get yelled at again do you?"

[0]: https://lore.kernel.org/lkml/CAFRnB2VPpLSMqQwFPEjZhde8+-c6LL...

12. static+W4[view] [source] 2022-10-02 14:55:53
>>rvz+(OP)
> Even "safe" rust code in user space will do things like panic when things go wrong (overflows, allocation failures, etc). If you don't realize that that is NOT some kind of true safely, I don't know what to say.

When people say "safe" there's a pretty precise meaning and it's not this.

Yes, anyone who believes rust is 100% "safe" (by any definition) is wrong. That's not something you learn in Kindergarten though, it's actually about understanding that Rice's Theorem is a generalization of the Halting Problem.

> o this is something that I really need the Rust people to understand. That whole reality of "safe" not being some absolute thing

The irony of Linus lecturing anyone on safety lol anyway "the Rust people" know this already, when they say "safe" they mean "memory safe" - https://en.wikipedia.org/wiki/Memory_safety

Anyway, dumb shit like this is why I've always been quietly dreading Rust in the kernel.

a) The kernel will never be safe software because the mainline developers don't want it to be or even know what safe means

b) It just invites more posts like this and puts Rust closer to one of the most annoying software communities

> Or, you know, if you can't deal with the rules that the kernel requires, then just don't do kernel programming.

Agreed on this point. I was very interested in kernel dev earlier in my career until I actually started to engage with it.

◧◩
16. static+95[view] [source] [discussion] 2022-10-02 14:57:15
>>Pulcin+H4
Rust's "safety" is memory safety. It's relatively well defined for a technical term: https://en.wikipedia.org/wiki/Memory_safety

edit:

> Yeah I was just trying to provide a clear definition, I didn't think you were implying it was BS.

(would have replied but I'm rate limited on HN - thanks dang!)

◧◩◪
33. 2OEH8e+R6[view] [source] [discussion] 2022-10-02 15:06:46
>>pca006+86
kdump

https://en.wikipedia.org/wiki/Kdump_(Linux)

He also mentions that programs can report problems automatically to the distro devs. For example:

https://retrace.fedoraproject.org/faf/problems/

A kernel dump is not something you always want to upload since it can be large and contain sensitive info. I'm not a kernel dev though.

◧◩
54. arinle+u9[view] [source] [discussion] 2022-10-02 15:21:47
>>a_hume+h4
> I know next to nothing about kernel programming, but I'm not sure here what Linus' objection to the comment he is responding to here is.

You should read the email thread, as Linhas explains in clear terms.

Take for instance Linus's insightful followup post:

https://lkml.org/lkml/2022/9/19/1250

67. Smaug1+2b[view] [source] 2022-10-02 15:30:16
>>rvz+(OP)
I think a much better email from the thread to link to would be the earlier https://lkml.org/lkml/2022/9/19/840, where Linus actually talks about some of the challenges of kernel programming and how they differ from user-space programming.
◧◩
71. magica+Eb[view] [source] [discussion] 2022-10-02 15:34:02
>>kweing+O7
> I feel like he’s under the impression that Rust-advocating contributors are putting Rust’s interests (e.g. “legitimizing it” by getting it in the kernel) above the kernel itself.

I mean the post Linus initially responded to did contain[1] a patch removing a kernel define, asking if anyone had any objections over removing that define, just to make the resulting Rust code a little nicer looking.

[1]: https://lkml.org/lkml/2022/9/19/640

◧◩◪◨
90. shephe+3d[view] [source] [discussion] 2022-10-02 15:41:48
>>fritol+ya
Yes, you can define your own panic handler in Rust.

https://doc.rust-lang.org/nomicon/panic-handler.html

◧◩◪
115. jrochk+4f[view] [source] [discussion] 2022-10-02 15:52:48
>>layer8+0d
> but Rust also has no built-in mechanism to statically determine “this code won’t ever panic”,

My intuition says that's the Halting Problem, so not actually possible to implement perfectly? https://en.wikipedia.org/wiki/Halting_problem

◧◩◪
117. gerane+if[view] [source] [discussion] 2022-10-02 15:54:35
>>layer8+0d
We cannot ensure that an arbitrary program halts by statically analyzing it. And it doesn’t have anything to do with the language of choice.

https://en.m.wikipedia.org/wiki/Halting_problem

◧◩◪◨
123. ChrisS+Lf[view] [source] [discussion] 2022-10-02 15:57:30
>>Test01+2d
There's no "walking back" here. From Rust 1.0 the language was "guaranteed memory safety" https://web.archive.org/web/20150516132407/https://www.rust-...
◧◩◪◨
149. layer8+mh[view] [source] [discussion] 2022-10-02 16:06:22
>>jrochk+4f
See https://news.ycombinator.com/item?id=33057059.
◧◩
187. hedgeh+qk[view] [source] [discussion] 2022-10-02 16:22:50
>>jmilli+Fb
As I read it the issue is a little bit deeper, start with the context here and read down the thread:

https://lkml.org/lkml/2022/9/19/640

Get at least down to here:

https://lkml.org/lkml/2022/9/20/1342

What Linus seems to be getting at is that there are many varying contextual restrictions on what code can do in different parts of the kernel, that Filho etc appear to be attempting to hide that complexity using language features, and that in his opinion it is not workable to fit kernel APIs into Rust's common definition of a single kind of "safe" code. All of this makes sense, in user land you don't normally have to care about things like whether different functional units are turned on or off, how interrupts are set up, etc, but in kernel you do. I'm not sure if Rust's macros and type system will allow solving the problem as Linus frames it but it seems like a worthy target & will be interesting to watch.

◧◩◪
193. fritol+Tk[view] [source] [discussion] 2022-10-02 16:24:27
>>titzer+cf
What if the task was invoked asynchronously (and maybe it keeps happening.) What does async stack unwinding entail in Rust? Is there a parent-child relationship between invoker and invokee? async scopes (https://rust-lang.github.io/wg-async/vision/roadmap/scopes.h...) ? I've not touched Rust at all.
◧◩◪◨⬒⬓
215. layer8+hm[view] [source] [discussion] 2022-10-02 16:30:55
>>hegels+fk
Linters like Splint [0] (predating Rust) can do that for C. I’m not saying that Rust’s built-in approach isn’t better, but please be careful about what exactly you claim.

[0] http://splint.org/

◧◩◪
252. tialar+Eq[view] [source] [discussion] 2022-10-02 16:54:26
>>pwinns+Bm
> The Rust way would be to panic, train stops in between stations and must be rebooted to continue.

Which is safe. It's inconvenient, but it's safe. Failures of this sort do happen, electrical fires are probably the most extreme example. They're annoying, but nobody is at risk if you stop. Since the tube is in civilisation (even at the extreme ends of the London Underground which are outside London, like Chesham, this is hardly wilderness, you can probably see a house from where your train stopped if there aren't trees in the way) we can just walk away.

https://commons.wikimedia.org/wiki/File:Chesham_Tube_Station...

> Linus was saying no, you carry on despite the error until you get to the next station

Depending on the error the consequences of attempting to "carry on" may be fatal and it's appropriate that the decision to attempt this rests with a human, and isn't just the normal function of a machine determined to get there regardless.

◧◩◪◨
272. maxbon+et[view] [source] [discussion] 2022-10-02 17:08:00
>>3a2d29+6s
I, too, have not encountered these toxic Rust fanboys. I don't believe my head is in the sand. I do regularly see people degrading Rust and it's community, and so am convinced these toxic Rust fanboys are largely a myth based on uncharitable interpretations of otherwise reasonable statements. I think people often read "I advocate for the deprecation of all C/C++ codebases" into the statement "Rust is a 'safe' language, for a certain meaning of that term," but I don't think it's actually common to advocate for such a deprecation outside of security-critical applications.

I feel like it's a defensive reaction, that people feel like Rust is seeking to obviate arcane skills they've built over the course of their careers. Which I don't think is true, I think there will always be a need for such skills and that Rust has no mission to disrupt other language communities, but I can understand the reaction.

> You can even look in my comment history

Is this the thread you're referring to?

https://news.ycombinator.com/item?id=32878868

Because I genuinely don't see what you're talking about. No one seems to "make it their mission" and no one seems to be arguing for Rust in particular, as much as this category of languages.

◧◩◪◨⬒
286. yonixw+iw[view] [source] [discussion] 2022-10-02 17:25:43
>>layer8+Qf
"Undecidable" Is way too close to your day2day program than you think: https://en.wikipedia.org/wiki/Rice%27s_theorem

I would like to learn otherwise, but even a React JS+HTML page is undecidable... its scope is limited by chrome V8 js engine (like a vm), but within that scope I don't think you can prove anything more. otherwise we could just make static analysis to check if it will leak passwords...

◧◩◪◨⬒
288. yonixw+Ew[view] [source] [discussion] 2022-10-02 17:27:29
>>roywig+lj
"Print 1" is trivial according to this: https://en.wikipedia.org/wiki/Rice%27s_theorem.

But day to day programs are not trivial... as for your example, just switch it with this code: `print(gcd(user_input--,137))`... now it's quite more hard to "just ban some final states"

◧◩◪◨⬒⬓⬔⧯▣
319. dureui+zC[view] [source] [discussion] 2022-10-02 17:58:15
>>layer8+fp
But panics in rust are pretty much exceptions though?

The differences are they are actually meant to be used for exceptional situations ("assert violated => there's a bug in this program" or "out of memory, catastrophic runtime situation") and they are not typed (rather, the panic holds a type erased payload).

Other than that, it performs unwinding without UB, and is catchable[0]. I'm not seeing the technical difference?

[0]: https://doc.rust-lang.org/std/panic/fn.catch_unwind.html

◧◩
324. oconno+PD[view] [source] [discussion] 2022-10-02 18:05:17
>>Pulcin+H4
You've got the right idea. The Rustonomicon gives a list of approximately everything that Rust considers unsound/UB (https://doc.rust-lang.org/nomicon/what-unsafe-does.html). The most common examples are:

- use after free

- breaking the aliasing rules

- causing a "data race" (e.g. writing to the same value from multiple threads without a lock)

- producing an invalid value (like a bool that's not 0 or 1)

There's some other technical stuff like "calling a foreign function with the wrong ABI", but those four above capture most of what safe Rust wants to guarantee that you never do. I contrast, the same page provides an interesting list of things that Rust doesn't consider UB and that you can do in safe code, for example:

- deadlocks and other race conditions that aren't data races

- leak memory

- overflow an integer

- abort the whole process

◧◩
333. oconno+YE[view] [source] [discussion] 2022-10-02 18:13:31
>>pipeli+od
https://doc.rust-lang.org/nomicon/what-unsafe-does.html
◧◩◪◨
340. stjohn+AG[view] [source] [discussion] 2022-10-02 18:23:01
>>Miguel+fl
Maybe these? https://www.cyberciti.biz/tips/reboot-or-halt-linux-system-i...
◧◩◪◨⬒
341. 3a2d29+5H[view] [source] [discussion] 2022-10-02 18:27:27
>>maxbon+et
No I am not referring to that thread. I am referring to the thread further down where someone compares using a memory unsafe language to an illegal activity.

If you need an example of the rust community being toxic, I give you https://github.com/actix/actix-web

Look up the history and realize they bullied an open source project leader into leaving open source for good.

◧◩◪◨⬒⬓
344. maxbon+eJ[view] [source] [discussion] 2022-10-02 18:39:45
>>3a2d29+5H
So this thread? https://news.ycombinator.com/item?id=32879558

I still don't understand the relevance, this neither appears toxic nor to be a discussion of Rust; this looks like they put forward an out-there idea and you didn't care for it, which just seems like a discussion about consumer protection laws. I also don't see the connection from Actix drama to the idea that people are exaggerating the capabilities of Rust or causing problems for other language communities - I don't know much about it, I'm fully willing to believe toxicity was involved, but a breakdown in communication between a maintainer and their community doesn't seem like the behavior we're discussing and I don't see any evidence this was peculiar to Rust and not a phenomenon in open source at large.

I don't want to relitigate some thread I wasn't even a part of, I just don't understand.

◧◩◪◨⬒⬓⬔
349. UncleM+fK[view] [source] [discussion] 2022-10-02 18:46:00
>>layer8+to
> “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.

◧◩◪◨⬒
371. tialar+wS[view] [source] [discussion] 2022-10-02 19:43:26
>>gmueck+EA
Trains can be, and sometimes are, evacuated in a tunnel. The front (and rear, these trains are symmetrical) can be opened, converting into steps for able-bodied passengers to walk down to the tunnel floor.

There's a video of passengers doing this for real in this 2016 news article:

https://www.bbc.co.uk/news/uk-england-london-36716256

◧◩◪◨⬒⬓⬔⧯▣
381. mustac+FW[view] [source] [discussion] 2022-10-02 20:11:19
>>topspi+VV
> You put it in quotes and didn't mention any paraphrasing. Linus didn't write it.

I think it's a fair characterization of what was said. Feel free, as everyone is, to read the entire thread again. I'm not a journalist. You have the primary source at your finger tips!

> Can you point out the normative document that provides these guarantees?

You're looking at the Rust reference right? https://doc.rust-lang.org/reference/behavior-considered-unde...

◧◩◪◨⬒⬓⬔⧯▣▦
383. topspi+oX[view] [source] [discussion] 2022-10-02 20:15:18
>>mustac+FW
> You're looking at the Rust reference right?

Not normative, as stated here[1], linked from the page you cite.

[1] https://doc.rust-lang.org/nomicon/index.html

◧◩◪◨⬒⬓⬔⧯▣
403. Gauntl+N61[view] [source] [discussion] 2022-10-02 21:15:16
>>alias_+t51
My guess is they had some heuristic based on EDIDs, which are incredibly easy to spoof.

https://smile.amazon.com/EVanlak-Passthrough-Generrtion-Elim...

◧◩◪◨⬒⬓⬔
443. 3a2d29+SS1[view] [source] [discussion] 2022-10-03 03:58:48
>>maxbon+eJ
Not to mention there was this whole issue: https://news.ycombinator.com/item?id=29501893

After saying everyone was empowered to use their tool, they tried to kick someone off the team for working for Palantir.

Regardless of politics, kinda unfair to make political statements using the rust accounts, then turn around and say other people can’t be part of rust because they work for a company who is political.

◧◩◪◨⬒
453. John23+602[view] [source] [discussion] 2022-10-03 05:29:45
>>notaco+iO
Right. It's clear that many people have not heard of, or considered, Therac-25[1].

[1] https://en.wikipedia.org/wiki/Therac-25

◧◩◪◨
455. stouse+f12[view] [source] [discussion] 2022-10-03 05:45:44
>>mike_h+7k
> What about a medical procedure that WILL kill the patient if interrupted?

Allow me to introduce you to Therac-25: https://en.wikipedia.org/wiki/Therac-25

◧◩
471. scoutt+3g2[view] [source] [discussion] 2022-10-03 08:10:27
>>jmilli+Fb
I think it goes beyond "panics". Linus is saying that Rust cannot guarantee safety under certain circumstances and that safety still depends on the order of fuctions called by the kernel module developer. Because some checks on some compilations will be disabled.

"If you want to allocate memory, and you don't want to care about what context you are in, or whether you are holding spinlocks etc, then you damn well shouldn't be doing kernel programming. Not in C, and not in Rust.

It really is that simple. Contexts like this ("I am in a critical region, I must not do memory allocation or use sleeping locks") is fundamental to kernel programming. It has nothing to do with the language, and everything to do with the problem space."

https://lkml.org/lkml/2022/9/19/840

◧◩◪◨⬒⬓⬔⧯▣▦▧▨
474. ok_dad+Kk2[view] [source] [discussion] 2022-10-03 09:03:33
>>gmueck+762
The UI is one of the most important parts of a machine, look at the Therac-25! The FDA regulations require a lot of effort goes into the human factors, too, and the UI definitely had to be as reliable as the rest of the device and be as well engineered as the rest.

https://www.fda.gov/medical-devices/human-factors-and-medica...

Honestly, the FDA regulations go too far vs the EU regs. The company I worked for was based in the EU and the products there were so advanced compared to our versions. Ours were all based on an original design from Europe that was approved and then basically didn’t charge for 30 years. The European device was fucking cool and had so many features, it was also capable of being carried around rather than rolled. The manufacturing was almost all automated, too, but in the USA it was not at all automated, it was humans assembling parts then recording it in a computer terminal.

◧◩◪◨⬒⬓
495. pjmlp+lc4[view] [source] [discussion] 2022-10-03 19:08:42
>>lifthr+Tu
> Seriously, can we make at least ASAN the default?

Android helps a bit into that sense,

https://source.android.com/docs/security/test/hwasan

◧◩◪◨⬒⬓
496. pjmlp+jd4[view] [source] [discussion] 2022-10-03 19:14:43
>>paoda+qr3
UNIX was found to be less secure than Multics, thanks to the additional safety guarantees provided by PL/I type system.

https://www.acsac.org/2002/papers/classic-multics.pdf

So not even back then.

◧◩◪◨⬒
504. retard+m7a[view] [source] [discussion] 2022-10-05 13:00:11
>>Tomte+rm
SUSE was used on Mars

https://www.pcmag.com/news/linux-is-now-on-mars-thanks-to-na...

[go to top]