22 ms·
“Rust is safe” is not some kind of absolute guarantee of code safety
- throwawaybutwhy 4y agoTo put things in context, Linus is being reasonable and wise and well-mannered once again. Wouldn't mind reading a few juicy expletives, to be honest.
- miohtama 4y agoI would rather believe in Rust than Santa Claus.
- mustache_kimono 4y agoAs 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+-c6LLms54QkMt+wZPjOTULESw@mail.gmail.com/ https://lore.kernel.org/lkml/CAFRnB2VPpLSMqQwFPEjZhde8+-c6LL...
- darthrupert 4y agoI wonder if he'll end up regretting opening this particular Pandora's box or will things stabilize eventually.
- thrown_22 4y agoIf everyone who wrote a blogpost about how rewriting thing x in Rust would be amazing actually rewrote x in Rust it would already be the most popular language ever.
- detaro 4y agoWhat makes you expect it might not stabilize?
- darthrupert 4y agoBecause Rust people tend to be a bit extreme. But perhaps Rust people who are also kernel programmers are less so.
- boardwaalk 4y agoContext isn't your opinion.
- staticassertion 4y agoHow is this context? Also how is it "wise" to get the definition of "safe" wrong while acting like a pedant?
- wokwokwok 4y ago>>>>> For GFP_ATOMIC, we could use preempt_count except that it isn't always enabled. Conveniently, it is already separated out into its own config. How do people feel about removing CONFIG_PREEMPT_COUNT and having the count always enabled? >>>> No (Linus) >>> As you know, we're trying to guarantee the absence of undefined behaviour for code written in Rust. And the context is _really_ important, so important that leaving it up to comments isn't enough. … >>> Do you have an opinion on the above? >> This message. Ie. No. you can’t make everyone play by your rules. (Linus, grumpily) > While I disagree with some of what you write, the point is taken. > But I won't give up on Rust guarantees just yet, I'll try to find ergonomic ways to enforce them at compile time. I mean, it doesn’t sound like he’s being petty or misunderstanding. They want special rules (which won’t work) to do runtime checking for rust code. That seems weird, right? Rust safety should be compile time. That’s the point… I dunno, maybe I don’t understand what’s being said, but I don’t think Linus is particularly wrong here, even if it’s kind of shouty.
- oconnor663 4y ago> Rust safety should be compile time. That’s the point… Array bounds checks are one of the most important safety measures Rust takes, and those have to happen at runtime (if the optimizer can't prove they'll never fire). Similarly, locking types like `Mutex` of course do all their locking and unlocking at runtime, though they also use the type system to express the fact that they will do that.
- deleted 4y ago[deleted]
- rat9988 4y agoI am the only one who would have a hard time to collaborate on a project where the "collaborators" start their message with > You need to realize that > (a) reality trumps fantasy ?
- detaro 4y ago> I am the only one [...] ? Have you missed the years and years of people criticizing Linus for his communication style?
- deleted 4y ago[deleted]
- Ecco 4y agoYou’re of course not the only one. That being said, it’s probably not that big of a deal for most people: there are countless other open source kernels, but Linux is by far the most popular, including in number of contributors.
- pfortuny 4y agoLinus is not a “collaborator”. Sometimes you need to stress the difference betwen “my opinion” (as in “Kernel development requires greater safety standards”) and “facts” (“safety does not exist in software because it does not control the hardware aspect”).
- SanjayMehta 4y agoYou need to realise that (a) that's the creator of Linux (b) see (a) above
- mynameisvlad 4y agoThat shouldn’t excuse him from being a reasonably decent person to work with. He gets a lot more leeway than being the creator of Linux should afford someone.
- 4y ago
- a_humean 4y agoI 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. The comment seemed to be making reference to rust's safety guarantees about undefined behaviour like use after free. Linus' seems to have a completely different definition of "safey" that conflates allocation failures, indexing out of bounds, and division by zero with memory safety. Rust makes no claims about those problems, and the comment clearly refers to undefined behaviour. Obviously, those other problems are real problems, but just not ones that Rust claims to solve. Edit: Reading the chain further along, it increasingly feels like Linus is aruging against a strawman.
- pfortuny 4y agoI am probably wrong but I understood that “safety meaning panic” is noeither “safe” not allowed in the Linux kernel because the kernel must not panic when an error arises.
- a_humean 4y agoWhich is why Rust has been accommodating the kernel by adding non-panic versions of the functions that Linus has been complaining about (namely that memory allocation is infallible, because that isn't an unreasonable thing to assume in applicationc code.). Still doesn't change the fact that "safe" in this context has a technical meaning, and what Linus is describing isn't that.
- Vt71fcAqt7 4y agomaybe his point is that the technical meaning should use a more acurate word in his opinion?
- a_humean 4y agoHis point seems to be the opposite, that "safety" should have a vaguer meaning in his opinion, and not the well established technical definition that the author clearly meant when he used the word.
- tcfhgj 4y ago> Not completing the operation at all, is not really any better than getting the wrong answer, it's only more debuggable. Wouldn't be that sure about that. Getting the wrong answer can be a serious security problem. Not completing the operation... well, it is not good, but that's it.
- 2OEH8eoCRo0 4y agoTrue- which is why he says to throw a warning first.
- atoav 4y agoI mean if it is a cosmetic thing sure. If it has substantial meaning I would rather have that 5 ton robotic welding arm not move than have it move through my skill. It is sometimes acceptable to get wrong output. But is nearly always better to know it is wrong.
- deleted 4y ago[deleted]
- analognoise 4y agoThis sounds like the difference between "fault tolerant" and "fail safe". Fault tolerant - you get a fault, you keep moving. Fail safe - you fail, and thus all operations are stopped.
- gmueckl 4y agoFailing may require triggering some actions actively. Going inert is not the right way in many cases. Some system absolutely require best efforts in the face of failure. A fire alarm in an otherwise secure and locked down facility may have to trigger the opening of door locks, for example.
- atoav 4y agoI mean the Rust appeal is actually that it foeces you to handle Errors. Whether you then fail or not is your decision. What Rust usually does not do is just fail. This is good for when the things you are using could error, e.g. when you use an arbitrary unicode string as a filename you might get an error because depending on the OS there might be characters that you cannot use as filenames that are valid unicode (or the other way around, possible filenames that are not valid unicode). In most programming languages this is something you need to know to catch it. In Rust this is an Error that you can or cannot handle. But you can't forget to deal with it.
- Pulcinella 4y agoNot all that familiar with the specifics of Rust, but I assume it’s “safety” is somewhat similar to Swift’s “safety,” so type safety and memory safety, which does not mean no crashes, just that you will e.g. crash on an array OOB error rather than start writing or reading to random bits of memory.
- staticassertion 4y agoRust's "safety" is memory safety. It's relatively well defined for a technical term: https://en.wikipedia.org/wiki/Memory_safety 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!)
- Pulcinella 4y agoSorry didn’t mean to imply that it was BS or anything with the scare quotes. More that there is a more specific meaning behind it than some laymen’s interpretation of the word safe. I know I was a little surprised when I was learning Swift after hearing it was called safe only to experience crashes with array OOB. Took some explanation and thinking to understand what was meant by safe.
- oconnor663 4y agoYou'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 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
- MarkSweep 4y agoWhy is panicing in the kernel on an error not an option? Like kernels can write a core dump and reboot, right?
- zetaposter 4y agoYeah ... Just reboot the machine and make me loose all my work, bro.
- charcircuit 4y agoThis is why programs automatically saving their state is important.
- elteto 4y agoNo, this is why kernels prioritizing not crashing is important. Applications saving their work is a nice extra.
- jmull 4y agoThat's not a solution to OS instability. Reliably saving state in the face of sudden total failure is both very tricky and app-specific. Just saving state changes automatically won't do it -- partial writes of complex state are likely to be inconsistent without luck or careful design and QA controls (tests, testing, on-going controls to ensure nothing new operates or relies on anything outside the safe state-saving mechanism). It makes a lot more sense to put the effort into making the OS continue as well as it can, vs requiring every app to harden itself against sudden total failures.
- dijit 4y agoif you panic and you're a kernel you very likely corrupt your filesystem, at the very least.
- layer8 4y agoWhile I don’t advocate for kernel panics, journaling filesystems are a thing.
- staticassertion 4y ago> 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 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.
- 2OEH8eoCRo0 4y agoOne of my Marine NCOs would say, "there is no such thing as safe." You aren't safe on the FOB, in your car, in your barracks, or in your house. There are only degrees of safety. Very wise almost globally applicable words.
- Ygg2 4y ago> There are only degrees of safety. Sure but people use this logic to justify no safety. Find me a marine a that goes into war totally naked.
- 2OEH8eoCRo0 4y agoThat's great for them. I dont use it to justify no safety.
- hegelstoleit 4y ago
- peoplefromibiza 4y agoYou mean for the hundreds of thousands of people that in the past 31 years willingly decided to contribute to the to the most successful and well maintained open source project ever, because the creator is such a brilliant person?
- hegelstoleit 4y agoAnyone who has to interact with him pretty much.
- peoplefromibiza 4y agoThey can very much avoid it. They chose to. Who's to blame here?
- hegelstoleit 4y agoEasy. Linus for being insufferable.
- gkbrk 4y agoWho "has to" put up with Linus? Linux is open-source software. People who feel they are putting up with Linus can just `cp linux/ betterlinux/`. If it's actually better and Linus was holding things back by being an insufferabe cunt, they can expect a huge amount of people to switch to their fork as well.
- hegelstoleit 4y agoNobody "has to" have a job either. It's interesting how words can have different standards of necessity depending on how you contextualize them. Is a basketball player tall? If you asked his friend in the NBA after a game, he might say no because he's relatively short for an NBA player. Amongst everyone else, you'd say he is definitely tall. So no, in the strict sense, you don't "have to" put up with linus, that's obviously not what I meant. Nobody "has to" put up with anyone, ever. If you want to work on the linux kernel though, you do. Otherwise, you have to do what you just said - you have to provide a better alternative which is a huge ask.
- kweingar 4y agoClassic Linus. From the closing paragraph, 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.
- aaaaaaaaaaab 4y agoIs he wrong?
- bitexploder 4y agoDoes it even matter? Rust does what it does and it was enough of a benefit to include in the kernel. It is a big accomplishment.
- kweingar 4y agoRegardless of whether he’s right or wrong, I think that this is somewhat natural and is to be expected. Like with any emerging technology, early adopters become advocates because they’re convinced of the technology’s superiority. Once they organize into a community and get to know each other personally, then at least some of the motivation shifts: you want to see your friends succeed, you want to be part of a community that is making change, you want your early adoption to be “validated” by mainstream success, etc. This can cloud technical judgment (not saying this is happening here, but if it were, it wouldn’t be surprising)
- sidlls 4y agoThey probably are, in many cases. Rust’s community, in aggregate, have developed a reputation (earned, in my opinion). It’s too bad that the community don’t follow the leaders’ example in this regard. There are some quality, level-headed Rust advocates. They appear to be the minority.
- mustache_kimono 4y agoAt least they don't go around slandering programming language communities. If we're going to be serious about who is being toxic, it's definitely Linus in this thread. Guy makes first mistake (by a very broad interpretation of "mistake". Perhaps "misunderstanding"?). Linus goes nuclear. And while his reasoning is sound, his argumentation cycles between threats, bad-faith arguments, and just plain old yelling. What some people don't understand is that the Linux kernel isn't 'led' in any meaningful sense. But I suppose some projects don't need actual leadership? I once was recommended a Metallica documentary, because "It's amusing to see what emotionally stunted 40-50 year olds who have never had anyone tell them 'No' since 18 will do." That's the Linus vibe -- somehow we've limped along to here. Seriously, read the rust/rust-lang issues/RFCs. Those people sound like grownups contrasted to this.
- say_it_as_it_is 4y agoIs this related to the use of unsafe blocks and the inventor of Linux arguing with someone out of their depth about alleged undefined behavior?
- avgcorrection 4y agoYou can browse the thread to see what it is about.
- Narishma 4y agoNo.
- fortran77 4y ago
- eric4smith 4y ago“Rust is safe” is generally the same thing as saying “I like strongly typed languages”. None of that is going to save us from bad code. Some of the biggest systems that run the world are not written with either safe code nor strongly typed languages. Yes I would say strongly typed languages and memory safe languages help make coding easier and indeed save time and some bugs. But when you get past making the kinds of errors that cause memory problems or bad types… You are still left with 95% of the bugs and logic errors anyway. Still, 5% savings in productivity is not nothing.
- PragmaticPulp 4y agoI’ve been using Rust for a while, and I’m so, so tired of hearing this argument. Yes, we know. We get it. Rust is not an absolute guarantee of safety and doesn’t protect us from all the bugs. This is obvious and well-known to anyone actually using Rust. At this point, the argument feels like some sort of ideological debate happening outside the realm of actually getting work done. It feels like any time someone says that Rust defends against certain types of safety errors, someone feels obligated to pop out of the background and remind everyone that it doesn’t protect against every code safety issue.
- TillE 4y agoIt's really common to see people say meaningless stuff like "Rust is a safe language" which is either deeply confused or deeply misleading. Rust provides certain guarantees of memory safety, which is great, but it's important to understand exactly what that means and not to oversell it.
- pornel 4y agoIt's an unproductive pedantry to expect every mention of the generalisation to be followed by a full disclaimer about exceptions and edge cases. People say "it's raining" without having to add "except under roofs".
- lifthrasiir 4y agoI think, if the wording was exactly "Rust is safe" it is indeed too vague as there are many notions of safety, and annoyingly enough people do say this. But "Rust provides memory safety" is clear enough and doesn't need further quantification.
- pornel 4y agoOfficial Rust materials are careful not to overpromise and to be clear on the extent of what is guaranteed and what isn't. The safety is always with an asterisk. Rust provides memory safety — provided that unsafe blocks, FFI, and other code running in the same process, and the OS itself, and the hardware doesn't misbehave. But if you accept that Python and Java can be called safe languages then Rust can be too. The other ones also have unsafe escape hatches and depend on their underlying implementations to be correct to uphold safety for their safe side.
- coldtea 4y ago>And the reality is that there are no absolute guarantees. Ever. The "Rust is safe" is not some kind of absolute guarantee of code safety. Never has been. Anybody who believes that should probably re-take their kindergarten year, and stop believing in the Easter bunny and Santa Claus. I thought that he had apologised and regretted being hostile in comments. Apparently not. Not that I have much of an issue with ranty colorful language, but you need to also be right and have a legitimate cause to pull it off... The point he makes is BS. "the reality is that there are no absolute guarantees. Ever" Yeah, DUH! The compiler could have bugs and soundness issues for example. The point is you don't need "absolute guarantees" just "way safer and which dozens more classes of issues discovered automatically" is already enough. The other guy didn't write about "absolute guarantees". He said "WE'RE TRYING to guarantee the absence of undefined behaviour". That's an aim, not a claim they've either achieved it, or they can achieve it 100% >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. Well, if Linus doesn't realize this is irrelevant to the argument the parent made and the intention he talked about, I don't know what to say...
- ukweld 4y agoWhy are so many people criticizing Linus? This post strikes me as relatively moderate. Other software dictators do exactly the same, but in a more underhanded and bureaucratic manner, which is worse. Yet their disciples call them "benevolent". I can deal with Linus, but not with the latter. Linus strikes me as not being really serious or vindictive. It's just a colorful way of expressing himself.
- peoplefromibiza 4y agobecause people of modern age have to destroy everything's good, to feel better about themselves, without having to actually be good.
- coldtea 4y agoSort of how Linus pisses on Rust with a not-actually-good argument?
- Tomte 4y agoI actually wondered with all the recent "Rust in the kernel" about culture clashes. I mean, most kernel developers aren't Rust programmers (and vice versa). Now we got a first glimpse at what happens. Still, I find it strange that it never seemed to come up in preparation to the first Rust merges. Were there any conflict resolution strategies in place (that I don't know about) or just "we flame it out on LKML"?
- ksec 4y agoI still believe this is only the tip of iceberg in terms of culture clashes.
- jmillikin 4y agoI think this is more "[modern] userspace vs kernel" than "Rust vs kernel". If you dig slightly below the surface in any major userspace codebase, it has abort paths everywhere. Every memory allocation might abort, every array index or dict lookup might throw an exception, which if uncaught will abort. Lock (or unlock) a mutex twice, abort. The Rust standard library inherited this philosophy in large and small ways. An easy example (already being addressed) is memory allocation, but less obvious is stuff like "integer math is allowed to panic on overflow". It's not easy to write Rust code that is guaranteed not to panic in any branch. Now the userspace-trained Rust folks are working in the kernel, and they want to be able to panic() when something goes horribly wrong, but that's not how the kernel code works. They'd have the same issue if you tried to get a bunch of GNOME contributors to write kernel drivers with GLib, even though GLib is pure C.
- mustache_kimono 4y ago> they want to be able to panic() when something goes horribly wrong I'm not sure where you are getting this from the thread? Linus is using a userspace panic as an example. That's not something that is actually happening in the kernel?
- veber-alex 4y ago> "integer math is allowed to panic on overflow" This is configurable, by default with optimizations on math overflow doesn't panic in rust, it wraps around. Obviously the kernel won't enable panics here unless in debug mode.
- Smaug123 4y agoI think a much better email from the thread to link to would be the earlier https://lkml.org/lkml/2022/9/19/840 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.
- blinkingled 4y ago> 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[sic], I don't know what to say. > Not completing the operation at all, is not really any better than getting the wrong answer, it's only more debuggable. What Linus is saying is 100% right of course - he is trying to set the expectations straight in saying that just because you replaced C code with multi thousands (or whatever huge number) of man months of efforts, corrections and refinements with Rust code it doesn't mean absolute safety is guaranteed. For him as a kernel guy just as when you double free the kernel C code detects it and warns about it Rust will panic abort on overflows/alloc fails etc. To the kernel that is not safety at all - as he points out it is only more debuggable. He is allowing Rust in the kernel so he understands the fact that Rust allows you to shoot yourself in the foot a lot less than standard C - he is merely pointing out the reality that in kernel space or even user space that does not equate to absolute total safety. And as a chief kernel maintainer he is well within his rights to set the expectation straight that tomorrow's kernel-rust programmers write code with this point in mind. (IOW as an example he doesn't want to see patches in Rust code that ignore kernel realities for Rust's magical safety guarantee - directly or indirectly allocating large chunks of memory may always fail in the kernel and would need to be accounted for even in Rust code.)
- swinglock 4y agoAt least in user space, aborting an operation is much better than incorrect results. But the kernel being incorrect makes user space incorrect as well. First of all, making a problem both obvious and easier to solve is better. Nothing "only" about it - it's better. Better both for the programmers and for the users. For the programmer the benefit is obvious, for the user problems will simply be more rare, because the benefit the programmer received will make software better faster. Second, about the behavior. When you attempt to save changes to your document, would you rather have the corruption of your document due to a bug fail with fanfare or succeed silently? How about the web page you visited with embedded malicious JavaScript from a compromised third party, would you rather the web page closed or have your bank details for sale on a foreign forum? When correctness is out the window, you must abort.
- jmillikin 4y agoAs usual HN comments react to the headline, without reading the content. A lot of modern userspace code, including Rust code in the standard library, thinks that invariant failures (AKA "programmer errors") should cause some sort of assertion failure or crash (Rust or Go `panic`, C/C++ `assert`, etc). In the kernel, claims Linus, failing loudly is worse than trying to keep going because failing would also kill the failure reporting mechanisms. He advocates for a sort of soft-failure, where the code tells you you're entering unknown territory and then goes ahead and does whatever. Maybe it crashes later, maybe it returns the wrong answer, who knows, the only thing it won't do is halt the kernel at the point the error was detected. Think of the following Rust API for an array, which needs to be able to handle the case of a user reading an index outside its bounds: struct Array<T> { ... } impl<T> Array<T> { fn len(&self) -> usize; // if idx >= len, panic fn get_or_panic(&self, idx: usize) -> T; // if idx >= len, return None fn get_or_none(&self, idx: usize) -> Option<T>; // if idx >= len, print a stack trace and return // who knows what unsafe fn get_or_undefined(&self, idx: usize) -> T; } The first two are safe by the Rust definition, because they can't cause memory-unsafe behavior. The second two are safe by the Linus/Linux definition, because they won't cause a kernel panic. If you have to choose between #1 and #3, Linus is putting his foot down and saying that the kernel's answer is #3.
- ChrisSD 4y agoThat's all very well but the Rust-in-Linux advocates are advocating for #2 and fully agree with Linus on #1. So attacking #1 is attacking straw.
- layer8 4y agoPlease correct me if I’m wrong, but Rust also has no built-in mechanism to statically determine “this code won’t ever panic”, and thus with regards to Linux kernel requirements isn’t safer in that aspect than C. To the contrary, Rust is arguably less safe in that aspect than C, due to the general Rust practice of panicking upon unexpected conditions.
- pornel 4y agoLack 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.
- bobajeff 4y agoAs a layman who hasn't done any kernel programming. Linus sounds pretty reasonable here. We can't have the kernel crashing because of a panic.
- Someone1234 4y agoA kernel crash IS a panic. They're one and the same. The discussion is a little more nuanced than just that. It is "we've entered an invalid/undefined/corrupt state, now what?" And in essence saying "We ONLY panic as a matter of last resort, we'll just spit out a bunch of loggable errors and soft fail from the kernel call until then."
- Test0129 4y ago
- selfmodruntime 4y agoBecause a gun that will disable the trigger to shoot yourself in the foot 1/10ths of the time is still worth it. Rust is also WIP. The panic problem can still be solved.
- krater23 4y agoThats the part where the gun decides that you can't kill yourself. I don't like this idea ;P
- avgcorrection 4y ago> If it “sounds like” that then you should quote one of the Rust programmers in that thread, not Torvalds.
- lkaglky3 4y ago
- pipeline_peak 4y agoSounds like the community should stop touting Rust as a “safe” language. It shouldn’t be the responsibility of every adopter to dig deep enough to find it’s actually not true.
- oconnor663 4y agohttps://doc.rust-lang.org/nomicon/what-unsafe-does.html https://doc.rust-lang.org/nomicon/what-unsafe-does.html
- stephc_int13 4y agoThis a naming/marketing issue. Because "safe" in the context of a programming language is provably wrong and thus will trigger adversary reactions. Rust is a hardened language, compared to C/C++. In the same way that Ada is hardened language, with different techniques, but the spirit is similar.
- mlindner 4y agoRust isn't really hardened in the same way as Ada at all. They're almost perpendicular to each other.
- tialaramex 4y agoI don't think I buy Linus' high level claim. It is not necessarily better to press on with the wrong answer, in some cases failure actually is an option and might be much better than oops we did it wrong. This morning I was reading about the analysis of an incident in which a London tube train drove away with open doors. Nobody was harmed, or even in immediate danger, the train had relatively few passengers and in fact they only finally alerted the driver at the next station, classic British politeness (they made videos, took photographs, but they didn't use the emergency call button until the train got to a station) Anyway, the underlying cause involves systems which were flooded with critical "I'm failing" messages and would just periodically reboot and then press on. The train had been critically faulty for minutes, maybe even days before the incident, but rather than fail, and go out of service, systems kept trying to press on. The safety systems wouldn't have allowed this failed train to drive with its doors open - but the safety critical mistake to disable safety systems and drive the train anyway wouldn't have happened if the initial failure had caused the train to immediately go out of passenger service instead of limping on for who knows how long.
- theptip 4y agoI feel like the OP is really hurting from quoting Linus out of context. This is many messages deep in a thread about automatically detecting atomic contexts in the allocator. And I don’t think he’s making a system level claim, that the whole train system should be designed to limp on through failures. He’s claiming that the kernel needs to be able to limp on so that the systems that use it can have the best chance of e.g. sending automated bug reports. (Or you can turn off the limping behavior if you want; maybe trains should do that. But maybe a train’s control system randomly rebooting might be more catastrophic than leaving its doors open? I don’t know.) From a couple messages up-thread in the OP: > … having behavior changes depending on context is a total disaster. And that's invariably why people want this disgusting thing. They want to do broken things like "I want to allocate memory, and I don't want to care where I am, so I want the memory allocator to just do the whole GFP_ATOMIC for me". And that is FUNDAMENTALLY BROKEN. 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. So don't go down this "let's have the allocator just know if you're in an atomic context automatically" path. It's wrong. It's complete garbage. It may generate kernel code that superficially "works", but one that is fundamentally broken, and will fail and becaome unreliable under memory pressure
- bumblebritches5 4y ago
- dureuill 4y agoHmmm, the linked email is not providing a lot of context, so surely I'm missing something, but there's something I definitely don't understand: is there not a third option between stopping the whole kernel on an error or allowing an incorrect result? Maybe my misunderstanding comes from my ignorance of the kernel's architecture, but surely there's a way to segregate operations in logical fallible tasks, so that a failure inside of a task aborts the task but doesn't put down the entire thing, and in particular not a sensitive part like kernel error reporting? Or are we talking about panics in this sensitive part? Bubbling up errors in fallible tasks can be implemented using panic by unwrapping up to the fallible task's boundary. To my understanding this is exactly what any modern OS does with user space processes? I always have the hardest of time in discussions with people advocating for or against that "you should stop computations on an incorrect result". Which computations should you stop? Surely, we're not advocating for bursting the entire computer into flames. There has to be a boundary. So, my take is to start defining the boundaries, and yes, to stop computations up to these boundaries.
- garaetjjte 4y ago>and in particular not a sensitive part like kernel error reporting Things like "kernel error reporting" doesn't exist as discrete element. Sure, you might decide to stop everything and only dump log onto earlycon, but running with serial cable to every system that crashed would be rather annoying. For all kernel knows, the only way to get something to the outside world might be through USB Ethernet adapter and connection that is tunneled by userspace TUN device, at which point essentialy whole kernel must continue to run.
- dureuill 4y ago> Things like "kernel error reporting" doesn't exist as discrete element. I'm not familiar with kernel development in general or Linux in particular. I would have expected there to be an error reporting subsystem, so that if a given subsystem fails the failure is reported to the error reporting subsystem (which hopefully exposes a more modern interface than serial cable), but this might be naive on my part. > For all kernel knows, the only way to get something to the outside world might be through USB Ethernet adapter and connection that is tunneled by userspace TUN device, at which point essentialy whole kernel must continue to run Again I'm missing context on this discussion. For all I know this could be an error originating with a driver, since rust support for Linux is for driver development now. It would make sense to me that an error in the GPU driver doesn't prevent the ethernet driver to report the bug
- armchairhacker 4y agowhat about a linter for Rust which highlights functions that may panic so you can avoid them? It seems like a fun project and useful feature Unless I’m mistaken, in “safe” Rust, programs can still crash but only by calling “panic”, or other trivial cases (explicitly calling “exit” with a nonzero return value, calling into ffi code, etc) Detecting functions which may “panic” and “exit” is very easy, significantly easier than detecting possible UB. Avoiding these functions (or providing a comment “no-panic guarantee” like “safety guarantee” for unsafe Rust) doesn’t seem very hard, since lots of panicking functions have a non-panicking variant.
- acjohnson55 4y agoSo much for Linus's time away to work on himself. It's disheartening to see how hard it is to change even when someone has the intention and resources to.
- oconnor663 4y agoIt's important to distinguish "better" from "perfect". That's how we get the motivation to make incremental progress every day.
- acjohnson55 4y agoI would say this demonstrates inadequate progress. As a manager, if I had a report who exhibited this level of verbal aggression, we would have a talk, and if it happened again, we'd be going through HR. It's not acceptable, regardless of technical merit.
- flumpcakes 4y agoI find the Rust community to be hostile towards any inquisitive questions about their claims of "guaranteed memory safety". I've argued before that C is probably a safer language in practise for the Linux kernel than Rust because you would have to contort and write non-idiomatic Rust, using FFI, or deal with C data structures that will hamper/remove a lot of Rust's memory safe benefits. Rust is also harder to read than C - especially if you are trying to keep a mental model of the bitmap layout in your head and just dealing with low level code. Of course I've had many negative comments from "Rustaceans", with their defence of their negativity being "we don't like it when someone comes into our community". It is a shame because Rust is a pretty cool language, but at this current rate I don't really see it being "the" systems programming language de jure. I think Zig is probably a much better fit for writing a Kernel in a safer language. Again, rust programmers pile on and tell me that "zig isn't memory safe". We can't make use of other languages that bring safety benefits without the dog pile of "you should use Rust it's safe". Apparently nothing is safe other than Rust.
- hedora 4y agoI normally enjoy Linus rants, but he needs to RTFM. In rust, safe code is code that does not have the unsafe keyword. If all the unsafe code is sound, then you (provably) get high level guarantees about memory safety, etc. The rust people are complaining that some of the unsafe RCU is unsound. They have a valid point. According to the rust manual, when you make unsound libraries sound, common courtesy dictates you create a CVE for the old implementation. This is all in the rust book; it's pretty close to "hello world". Anyway, the rust crowd is definitely right here. It would be better if the rust RCU bindings were sound.
- flumpcakes 4y agoI can't take anything you say in good faith. Are you an AI trained on the Rust subreddit? > According to the rust manual, when you make unsound libraries sound, common courtesy dictates you create a CVE for the old implementation. I cannot find the words to describe how supercilious this is.
- deleted 4y ago[deleted]
- warinukraine 4y agoHahaha I did notice there's a lot of magical thinking amongst the rust people. Prediction: in time the same will happen to "rust in the kernel" as happened to "c++ in the kernel": Linus will forbid it not because of some intrinsic problem with the language, but because the culture of the community prevented them from understanding the kernel rules.
- mlindner 4y agoThe kernel is not a magical beast. Other kernels have already been written in Rust and work fine. The ideas of Rust are not "magical thinking", they're based on fundamental mathematical principals that are irrelevant to language or tool.
- warinukraine 4y agoI didn't say that the ideas of rust are magical thinking. I said that the community falls into magical thinking a lot.
- mlindner 4y agoI'm not sure what he's trying to say here. Is he saying code that's run out of bounds of memory should continue on into la-la-land?
- awinter-py 4y agoyeah like if only they had written AI in rust instead of python AI safety wouldn't be an issue
- robalni 4y agoI feel like there is an underlying problem here that Rust tries to be a "safe" language while "safety" isn't well defined. Rust said that crashing a process is always safe so that when something unexpected happens we can always resort to crashing so that we don't risk doing anything unsafe. The problem is that this definition of safety is very arbitrary. Sometimes crashing a process can be safe (as in not causing serious problems) but sometimes not. Accessing an array out of bounds can be safe sometimes and sometimes not, and so on. Rust says that here is a list of things that are always safe and here is a list of things that are always unsafe and then people want safety everywhere so they take that definition of safety to other contexts where it doesn't make sense, like the kernel.
- mslm 4y agoThis kind of exchange was inevitable. The Rust crowd has this mentality that their code can be perfect (beyond even 'safe'), when in reality as long as your foundational system inputs and capacity aren't perfect, no downstream thing can be either. It's harder to see in user space but in the kernel you can't avoid reality. Hope the Rust crowd in general gets more moderate after this (or maybe not, but then that's only to the loss of Rust's long-term success).
- npigrounet 4y ago
- 0xbeefeed 4y agoWell, this had to happen at some point. Rust-for-Kernel isn’t just a second language. It’s another culture. A culture that is in clash with kernel community. This project should be halted right now, instead of wasting thousands of man-hours only to be stopped later. There is no way these two cultures would go along for long.
- phendrenad2 4y agoWhenever people say things like "Use Rust, it's memory safe" I know that they're clueless. Nobody has shown any evidence that for the average project, written by average developers, writing in Rust won't result in just as many exploitable bugs as writing in C. Also I had to laugh at this: > No one is talking about absolute safety guarantees. I am talking about specific ones that Rust makes: these are well-documented and formally defined As the saying goes "name three".