Memory Safety Bugs in Rust Standard Library

(forge-blog.github.io)

192 points | by pjmlp 3 days ago ago

208 comments

  • simonask a day ago ago

    Just because emotions seem to be always boiling whenever Rust is mentioned, I want to clarify for people who only follow casually that there is nothing unusual or scandalous about these finds.

    The Rust project as a whole currently has 178 open issues with the tag I-unsound[1]. Many of these describe issues that only exist in the nightly compiler, of course, but it does happen that bugs are not caught before shipping. That's software.

    [1]: https://github.com/rust-lang/rust/issues?q=is%3Aissue+state%...

    • cowlevel 21 hours ago ago

      That there's nothing unusual about these finds, the Drop static lifetime bug, or cve-rs is proof that Rust is not, and probably never will be, memory-safe. It's still an improvement though.

      • foota 35 minutes ago ago

        Given the rate at which AI is accelerating progress, I would expect that we see a formal verification of the rust compiler in next 3 years.

      • hmry 20 hours ago ago

        Is a language only memory-safe if its implementations are completely bug-free? I guess no language can ever be memory-safe then, might as well throw out the concept.

        • 13 hours ago ago
          [deleted]
        • Sankozi 19 hours ago ago

          By that logic you can remove any trait from any language.

        • catlifeonmars 19 hours ago ago

          I think it only has to be free of memory soundness bugs.

        • cowlevel 20 hours ago ago

          Last I heard, Rust has no independent spec so the compiler is the spec.

          • pjmlp 18 hours ago ago

            Ferroce has the one shared between them and Ada Core for high integrity computing certification purposes.

          • dxdm 20 hours ago ago

            So? I don't understand how that matters here.

            • lelanthran 19 hours ago ago

              It means that the language and implementation are one and the same, so a bug in the compiler is a bug in the language.

              • dxdm 10 hours ago ago

                I understand what it means, I was wondering why it matters. Right now, it feels like we're splitting hairs to maintain an impractically absolute definition of "safety". But if there's some useful aspect to this, I'd be happy to hear it.

                • cowlevel 4 hours ago ago

                  The thing you're a complaining about is a rebuttal to hmry's insistence that the language is not an implementation, which also meets your criteria for complaining about, even though you did not do so.

              • simonask 18 hours ago ago

                What absurd nonsense. That's not how anything works.

                If it were true, every bugfix would be a breaking change. It's clearly not.

                • cowlevel 13 hours ago ago

                  Er, yes? Bugfixes can be breaking changes. Microsoft has often avoided fixing bugs in Windows because they broke apps.

        • locknitpicker 19 hours ago ago

          > Is a language only memory-safe if its implementations are completely bug-free?

          What do you call a programming language which claims to be memory-safe that has memory safety issues in it's standard library?

          • tialaramex 19 hours ago ago

            Software with bugs in it. Or shorter, Software.

            • locknitpicker 19 hours ago ago

              > Software with bugs in it. Or shorter, Software.

              Yes, that's the whole point. Rust is used to write software. Not memory-safe software. Let alone bug-free software.

              But somehow that's the extraordinary cargo cult claim that Rust proponents make. Is that claim valid?

              That's the point. Isn't it?

              • SpaceNugget 18 hours ago ago

                As pointed out above, this same logic applies to virtually every trait every language claims to have. And it's purposely obtuse and combative. You are implying the sentence "Rust is used to write buggy software" by saying "Rust is used to write ... not ... bug-free software" which is again the case for every language ever. Do you also write comments complaining about cargo culting proponents of seatbelts, fire alarms, and electrical breakers since people still die as a result car crashes, fires, and accidental electrocutions?

                And no reasonable people are claiming that rust is used to write 100% bug free software. And yet people like you imagine such people daily apparently. It's certainly not a claim made anywhere upthread of your comment so if it's your claim feel free to take full ownership of it.

              • imtringued 18 hours ago ago

                I would rather take the 0.1% lie that Rust is memory safe than the 99.9% lie that competent C and C++ developers can properly deal with the UB they sprinkle throughout their code base without causing severe security vulnerabilities.

      • Ygg2 18 hours ago ago

        By that extension. Proof that Lean having bugs must mean all Lean proofs are null and void.

    • Sytten 21 hours ago ago

      Even more, the fact that unsafe blocks are a thing allows for this kind of deep scrutiny of the STD.

    • locknitpicker 19 hours ago ago

      > Just because emotions seem to be always boiling whenever Rust is mentioned, I want to clarify for people who only follow casually that there is nothing unusual or scandalous about these finds.

      Rust unfortunately is renowned for it's toxic community (see actix-web). Within that community, some clueless but vocal members routinely attack people who have the audacity of not rewriting all their projects in Rust, and they parrot cargo cult mantras such as memory safety as their main attack points.

      Consequently, discussions on memory issues plaguing Rust often draw these types, with the expected consequences.

      Yes, Rust also suffers from memory safety issues. Yes, there are CVEs caused by Rust code. Yes, using Rust obviously does not make your code better or bug-free. But these discussions are not grounded on a technical ground.

      • ViewTrick1002 18 hours ago ago

        This is an interesting comment which mostly seems to aimed at causing outrage? For the last many years I see more people with an axe to grind whenver Rust is mentioned rather than the other way around.

        The issue with actix-web, which played out in 2018-20, was that it played very liberally with memory safety, prioritizing speed over everything else, with the author closing PRs solving memory bugs.

        Basing your definition on "techinical ground" you can dismiss anything that isn't perfect.

        Rust's solution is the human response. Memory unsafety are treated as bugs, listed and fixed. Some fast, some more slowly. Depending on impact and how deep they go. C and C++'s solution is listing them in the specification, or having it be implementation defined, and telling you to not step on the land mine.

        Given the research on this area introducing Rust in some of the most battle hardened codebases globally leads to far fewer memory issues and high impact vulnerabilities in the Rust parts. And the parts converted to Rust often are the ones which has had an history of bugs and vulnerabilities becuase they are non-trivial.

        • pjmlp 18 hours ago ago

          Here is another one, the attack on ThePD, the end result being that Rust still has no reflection support, while C has been getting several goodies caused by him moving away from Rust back into C and C++ ISO work groups.

          Thanks to that Rust community behaviour, C23 has several nice improvements, with several others to possibly land on C2y.

          • Ygg2 18 hours ago ago

            It does have reflection support on nightly (via comptime aka const only fn see https://goals.rust-lang.org/2026/reflection-and-comptime.htm...), but it's a much more complex feature than was presented in the ThePhD report.

            • pjmlp 17 hours ago ago

              Until it actually lands on stable it does not count, it may take years, if ever.

              I lost track how many features have been on nightly, there is even a website to keep track of them,

              https://doc.rust-lang.org/unstable-book/index.html

              • Ygg2 17 hours ago ago

                So by that logic we don't count C23, until all C implementers decide to follow it?

                If Jean Heyd went and implemented it, I wonder how far we'd be into actually having a decent alternative. Because his implementation did the hacky thing via trait abuse, while this actually changes compiler to allow const-only functions. The trait abuse would have exploded Rust's already long compile times.

                • locknitpicker 15 hours ago ago

                  > So by that logic we don't count C23, until all C implementers decide to follow it?

                  It seems you are confused and emotionally involved, to the point you're trying to grasp at straws to have something to shout back.

                  C is specified by an international standard, which then is used as integration target by countless implementations.

                  Languages such as Rust are different in the way they have no formal specification. Whatever went into the reference implementation is what counts as "the language", bugs and all. At best a specification can be derived from the reference implementation.

                  The key difference is that a C compiler that doesn't implement a feature and/or deviates from the implementation is considered a buggy implementation, whereas Rust is whatever is currently in rust stable. If something is not on rust stable, it is not rust.

                  • Ygg2 13 hours ago ago

                    > It seems you are confused and emotionally involved, to the point you're trying to grasp at straws to have something to shout back.

                    Not really. If you count when practically you can use a feature then it makes sense to wait till all major implementers use it. For example you can use `type_info` feature on nightly right now. Same way you can use some C23 features on some compilers but not others.

                    It's more of a light hearted jab at how I hear things work in C-land. "Wow, that feature is amazing!", "It's in C11, so it will be widely used by {current_year + 5}" (keep in mind this is an exaggeration for comedic effect).

                    Truth is the nightly features ship as fast as there is demand for them and depending on roadblocks encountered. E.g. specialization is highly sought after but effectively unsound until some nasty unsound cases are dealt with. Type_info doesn't seem to have these sort of roadblocks.

                • pjmlp 16 hours ago ago

                  ISO standards don't have a reference implementation like Rust, there is no nightly before something gets added into the standard, unfortunely some papers even follow a waterfall model.

                  Getting the PDF out is the equivalent of landing on stable.

                  We will never know now, will we?

                • yjftsjthsd-h 12 hours ago ago

                  > So by that logic we don't count C23, until all C implementers decide to follow it?

                  I mean. I'd sure be reluctant to depend on it until it had trickled out through the ecosystem

        • locknitpicker 18 hours ago ago

          > This is an interesting comment which mostly seems to aimed at causing outrage?

          No, unfortunately Rust's toxic community tends to flock to these topics to flood them with their blend cargo cult claims. Topics which happen to question and even refute their claims is like their bat signal.

          The actix-web episode is a good example of how far these types can take even the most harmless claim, at the expense of everyone.

          Meanwhile, anyone who actually works in the field for a living is hardly surprised by this. When this sort of news pops up, we check if we need to start an unplanned update and that's it.

          • ViewTrick1002 17 hours ago ago

            It is a quite interesting take that it is acceptable for the, at the time, most popular web framework, to have memory bugs in the name of speed. Especially in this day and age of vulnerabilities being discovered left and right.

            • locknitpicker 16 hours ago ago

              > It is an quite interesting take that it is acceptable for the, at the time, most popular web framework, to have memory bugs in the name of speed. Especially in this day and age of vulnerabilities being discovered left and right.

              You sound like you're trying to gaslight everyone with this story. The problem with actix-web was not "memory bugs". Not the slightest.

              The problem was that it was a high-profile project in Rust, and Rust's toxic community felt entitled to relentlessly harass it's maintainers with vacuous claims regarding the use of what they chose to frame as unidiomatic Rust to justify their campaign of personal attacks.

              To the point where they forced the maintainer to outright quit.

              We are talking about Rust's toxic community being so toxic it even leads high-profile members of the Rust community to burn out and give up.

              This was the problem. Not "bugs". It's the community.

              • ViewTrick1002 15 hours ago ago

                It is rather ironic to accuse others of toxicity and personal attacks while opening with accusations of gaslighting and calling an entire community toxic.

                The claim that the problem was "not memory bugs. Not the slightest" is demonstrably false.

                The issues were serious enough to receive a RustSec advisory and three separate CVEs covering memory corruption and potential use-after-free.

                https://rustsec.org/advisories/RUSTSEC-2018-0019.html

      • pjmlp 18 hours ago ago

        Additionally those toxic vocal evangelists keep forgetting that without C++ there is no Rust compiler.

        Their beloved language is most likely decades away from ever having a fully bootstraped reference implementation.

        Which even if it ever happens, projects like Linux would most likely never adopt, as that new reference implementation has to provide the same hardware support guarantees as LLVM and GCC.

        • imtringued 15 hours ago ago

          This is pretty funny from my perspective because I have some use cases for Rust in mind where LLVM and its entire optimization architecture is completely backwards to how an ideal Rust compiler backend would look like for the types of architectures that I intend to target.

          The mutable aliasing ecosystem is holding more advanced hardware back.

        • simonask 10 hours ago ago

          > Additionally those toxic vocal evangelists keep forgetting that without C++ there is no Rust compiler.

          You say "vocal", yet they remain eerily silent in this and every other thread about Rust on HN, as well as /r/rust over on Reddit.

          If you didn't know better, you could almost think they were imaginary.

          You seem to have a mental picture of a raging Toxic Rust Evangelist consumed by shame and rage over Rust's Dark Secret: It's using the best codegen backend on the planet (with a compatible license), LLVM, which is written in - gasp - C++!! Dun dun dunnnn!

          What a dramatic plot twist! I understand how that might feel very engaging.

          The boring truth is that everybody is pretty fine with LLVM, because no reasonable (or real) person believes that this is a problem. As long as it generates pretty decent code in a reasonable amount of time for all the important architectures, it's a great choice.

          We're trying to get work done.

        • marshray 10 hours ago ago

          What is the point of inventing some sort of existential conflict between Rust and C++?

          Why must Rust have "a fully bootstraped reference implementation"?

          This is weird, dude.

      • 8 hours ago ago
        [deleted]
    • shevy-java 20 hours ago ago

      [flagged]

      • arijun 20 hours ago ago

        I’m having a hard time understanding you here. Are you saying that since rust is a good language for AI to write code in, it says something about the (lack of) power of AI, that it wasn’t what found the bug? Because the logic there seems twisted: “F1 drivers, the biggest users of F1 cars, almost never make improvements to F1 engines”.

      • WOTERMEON 20 hours ago ago

        Are you paddling some? I’ve never seen rust described as premier language for AI

    • tescreal 15 hours ago ago

      I've been enjoying Rust somewhat, but from what I see, the "memory safety" claims aren't strong (especially if memory bugs exist within the standard library); in my humble opinion, that's akin to false advertising (or at least a bit loose).

      The main problem I have if I accept Rust as a "better C-like" with "safer memory" still ends up being the safety mechanism makes some code rather unergonomic.

      What I would most like to see is a reduction of all `unsafe` throughout. The reduction implies two things: safer, and more ergonomic.

      • marshray 10 hours ago ago

        I agree the claim of "memory safe" is not "strong" in the sense of formal verification.

        But the goal was to bring verification techniques (type systems, ownership and lifetime tracking, etc) to a practical language that also supported efficient interop with existing C libraries and APIs. Hence the 'unsafe' keyword. At this, Rust has succeeded wildly.

        I've been writing Rust for years and almost never need to use 'unsafe'.

    • fsckboy a day ago ago

      [flagged]

      • simonask a day ago ago

        Why would you think that? Bugs exist in complex software no matter how hard you try, including software written in Rust such as the Rust compiler and standard library. Did you expect the highly competent people working on these projects to just one-shot everything?

        • thesz 21 hours ago ago

          From the article: "The findings reveal three recurring patterns of misplaced trust in unsafe code: trusting code not to panic, trusting user-provided implementations to be correct, and trusting the underlying system."

          The call to "panic" is an effect and can be checked at compile time. Haskell does this with MonadError class, marking up code that may throw.

          Rust has Turing complete type system for years and still does not have effects of any kind.

          To be fair, "trusting user provided implementation" is also has something to do with effects. Proper type system would require user-provided implementation to use only certain effects and nothing else.

          So two of of found shortcomings are directly related to the type system and, specifically, to the choice of original Rust implementors to not to distinguish between pure and effectful computations.

          Do Rust implementors highly competent? Yes, of course! They work on Turing complete type system. Will they eliminate two of three recurring patterns? I strongly doubts so. It is a design decision and these are especially hard to change. Changing it will also break all Rust source code produced to that point of time.

          Is it a scandalous situation? For me, it is. The situation is so dire, actually, that "highly competent people working" has to be defended with trivially true fact that "bugs exist in complex software no matter how hard you try," instead of addressing core problem.

          • simonask 20 hours ago ago

            You're pointing out that there can exist a language other that Rust that is even safer, and prevents even more classes of bugs. That's trivially true, of course, but this language doesn't currently exist.

            • tialaramex 19 hours ago ago

              WUFFS can prevent a lot more bugs but it pays a very high price for that because it's not a General Purpose Language.

              Rust's "Hello, world!" reports an error if your stdout can't be used to actually print "Hello, world!" because e.g. it's full or has I/O errors -- that's Rust taking safety seriously

              WUFFS "Hello, world!" can't print text to stdout, that's not in its wheelhouse. It doesn't have text or printing or stdout. That's WUFFS taking safety seriously in a way that's maybe entirely too far for many people.

              WUFFS is only for Wrangling Untrusted File Formats Safely. Note that word "Format", it can't access files, has no idea what a "file" would be, it only handles the data, the file's format.

              • cowlevel 19 hours ago ago

                WUFFS is a successful limited implementation of the more general concept of formally verified code.

                We don't formally verify code because it's extremely difficult at a level that cannot be practically expressed. However difficult you think it is, square it. I wouldn't be surprised if the only two formally verified code bases that anyone actually uses are seL4 and WUFFS.

            • thesz 16 hours ago ago

                > That's trivially true, of course, but this language doesn't currently exist.
              
              This is a very bold claim.

              I already wrote above that Haskell has MonadError, an effect that explicitly tells that code can panic. Rust does not have such facility.

              Software transaction memory is implemented in Haskell as an effect, as a monad. It does not allow one to open a file unless transaction completes - the sequence of steps to open a file can be constructed in an execution of transaction, but these steps cannot be executed until transaction complete.

              This eliminates second pattern of introduction of bugs into Rust's code: assuming user code is correct. With Haskell it is not possible to open, read and close file in the middle of transaction, by construction. In Rust, one have to pay attention.

              So Haskell has ruled out at least two of three bug-introducing patterns of Rust.

              • simonask 10 hours ago ago

                Haskell has existed for a long time, yet never had a breakthrough. When I learnt it 20 years ago, it was basically the same as it is now.

                It's a great language, but it's a research language. Had it been suitable for the types of projects that get written in Rust or C++ (and it very definitely isn't), people would have adopted it a long time ago.

                I know that there is a bit of persecution complex among haskellers, and I'm sympathetic, but perhaps it's worth looking at the practicalities before drawing conclusions. As a craftsperson, I'm not extremely interested in whatever interesting monads you can come up with, when there are lazily evaluated O(n^2) bombs hiding under the carpet.

        • cowlevel 21 hours ago ago

          Actually, software that probably has no bugs does exist, starting with the seL4 microkernel. Such software is usually pretty simplistic because that goes a long way towards proving an absence of bugs.

          More practically, however, Rust has proven to have more memory safety bugs than GC languages. If you want memory safety you should go GC. If you want consistent performance or tight control over memory, and pretty good memory safety, then you should go Rust.

          • pjmlp 18 hours ago ago

            I rather take the options that offer GC, whichever kind of implementation, alongside mechanisms for value types and manual resource management when required to do so.

            D, Swift, C#, Linear Haskell, Scala (with capabilities), OCaml (with effects), Idris (with dependent types), Koka,...

          • tialaramex 19 hours ago ago

            > More practically, however, Rust has proven to have more memory safety bugs than GC languages

            Citation needed I think. Where was this proven? Who measured and on which "GC languages" ?

            • cowlevel 18 hours ago ago

              Um, this very post? The equivalent code in Go is memory-safe. As a rule of thumb, everything in a GC language is memory-safe by default and there's nothing to prove, because the GC won't deallocate anything that is pointed to, and everything has a well-defined type that's known at runtime (because the GC needs that) so you can't avoid it by bad casting. Rust's innovation was trying to achieve the same level of safety without the GC.

              Seriously, when is the last time you heard of a buffer overflow RCE in Java code? I actually want to know.

              • tialaramex 17 hours ago ago

                > The equivalent code in Go is memory-safe.

                How do you figure? Take MapWindows::clone - what does your "equivalent code in Go" look like and how is it memory safe while achieving a similar result? I say that in most cases there is no equivalence.

                > Seriously, when is the last time you heard of a buffer overflow RCE in Java code? I actually want to know.

                But why a buffer overflow? These Rust bugs aren't buffer overflows [arguably one of them is, but it's a stretch] so I can't see the relevance. There have been plenty of RCE bugs in Java, that's one reason Oracle no longer supports the "Java security model" where we trust that somehow the very complicated Java runtime won't have bugs and so we can rely on Java's safety rules to protect our system security. If you're looking to learn more about this, look for articles on "gadgets" in Java exploitation.

              • ViewTrick1002 18 hours ago ago

                Go is not memory safe by design when you introduce concurrency?

                • pjmlp 18 hours ago ago

                  Neither is Rust, outside a very specific concurrency scenario, where the data being accessed in fully contained to unprocess memory.

                  Fearless concurrency tends to overlook OS IPC mechanism, DMA, or external data like shared database connections.

                  • ViewTrick1002 17 hours ago ago

                    Isn't this moving the goalposts quite far from where we began? Like a resoundly 2026 take given that having programs work concurrently and/or in parallel has been normalized by languages like Rust, Javascript and so on.

                    It wasn't that many years ago when getting anything more than 4 cores for a gaming PC was seen as a waste because most games couldn't even use 4 threads.

                    • pjmlp 16 hours ago ago

                      Nope, the goal is still there, multiple threads accessing a specific memory location, that happens to be mapped outside the process, or a variable holding a database connection that is shared across multiple threads, and there are no Sendable trait implementations that can prevent that.

                      Threads and concurrency is not the same by the way, as Rob Pike puts it, "concurrency is not parallelism".

                      • simonask 10 hours ago ago

                        You did move the goal posts, though. Go famously has no protection against data races within the same process, leading to Undefined Behavior.

                        Why did you start talking about multiple processes? That's a much less common way to do concurrency these days.

                        Process-shared memory is an OS-specific feature with wildly diverging semantics, and it's not possible to write a memory-safe portable abstraction over that in any language. Windows comes the closest with mandatory file locking. On Linux there's nothing you can do but pray. Hence, `mmap()` is fundamentally unsafe in Rust, and that's perfectly fine.

          • saagarjha 20 hours ago ago

            Neither of these is true lmao

        • teiferer 21 hours ago ago

          You may have noticed the wave of "rewritten in rust" software in recent years, whose only (?) selling point was that this makes the software somehow automatically safe and if not bug free then at least significantly lower on bugs.

          This finding is just yet another nail in the coffin of that myth.

          • irealis 21 hours ago ago

            I have never understood this argument. Rust, by default, is safer. This is trivially true. But it also is not perfect.

            This entire argument against Rust hinges on it somehow invalidating all of the improvements it does have, all the safety it does guarantee, just because it also has a few bugs. It's neither a myth that Rust is safer, nor is it a nail in the coffin for it.

            Otherwise you must make the argument that just because unsafe exists, and is used, it is automatically as bad as let's say C - a language that has proven time and time again how trivial it is to make mistakes with. Something that just doesn't happen in Rust.

            • nopurpose 20 hours ago ago

              In addition to that, many of reported soundness issues rely on adversarial implementations for stdlib' traits by user's types, like Borrow::borrow or as_ref returning different value between back to back calls. You would do that if you try to break compiler, but not when writing regular programs.

              • teiferer 13 hours ago ago

                Well, either it is safe or it is not. Once there is a crack, creative attackers tend to find ways to exploit cracks and pry them wide open.

                That is not to say it is not an improvement. But downplaying issues does not help improving the situation. Fixing them does.

                • hmry 12 hours ago ago

                  I don't really understand the threat model here, how would one "exploit" these issues? It's not like we use Rust as a sandbox (like e.g. JavaScript). If an "attacker" wants to crash the process, they can just write std::process::abort(), or if they want to break memory safety, they can just use an unsafe block.

                  • teiferer 8 hours ago ago

                    Sophisticated exploits often are a creative chain of prying open cracks that may just have looked like innocent bugs until they were used in the right moment ans right context that made them a very useful piece in a puzzle. The naive view of a buffer overflow was also just "yeah well great they can crash the program but they could get that cheaper". Until somebody had the idea of overwriting return addresses or putting executable code there. It may be hard to say how a bug can be exploited. As long as something says "safe" but suddenly an asterisk pops up, that's the first step down worry lane.

            • teiferer 13 hours ago ago

              I don't doubt that it is indeed safer. But some people do act like all bugs are gone.

              > This entire argument against Rust

              No, it is not an argument against Rust, it is an argument against a particular sales pitch. The "nail in the coffin" is not for Rust but for that sales pitch.

              I personally like Rust and think it is a great improvement over C for many use cases and it provides a refreshing angle as an alternative to GC approaches. Just some evangelists are going too far.

              Please let's use some nuance here.

            • Galanwe 21 hours ago ago

              The annoyance comes from the fact that your kind of _reasonable_ discourse on safety is always thrown when there is a bug, but never when there is a claim that rust is 100% by construction. I.e. It's always a defensive argument, but I never see someone step up to mention it on overly optimistic claims.

              • simonask 21 hours ago ago

                I can't be defending the statements of whoever says this, but I do think that the reasonable way to understand it is that the fundamental model that the Rust compiler and standard library attempt to implement is safe and correct by construction, rather than as a statement about the concrete implementation.

                Among software developers, we shouldn't need to provide a "assuming there are no bugs" caveat with every statement about how something works, because we know that bugs are essentially unavoidable at scale. We can say that Rust makes it much easier to avoid bugs, but nobody serious has ever claimed that they are 100% eliminated.

                It's not like C or C++ compilers are bug free either, despite implementing much weaker models.

                • csande17 20 hours ago ago

                  > the fundamental model that the Rust compiler and standard library attempt to implement is safe and correct by construction

                  This comes up a lot as a defensive argument too, but it's also pretty frustrating, because Rust's "fundamental model" is not a thing that really exists. There are project proposals to create one (such as https://goals.rust-lang.org/2026/roadmap-project-zero.html#), but at the moment it's just a vague set of vibes people gesture towards to dismiss all the problems with Rust-as-actually-implemented.

                  • simonask 20 hours ago ago

                    Calling it "vibes" is just so unserious.

                    If you would like the Rust language to have a formal specification, I would suggest you look at ways to help that happen. There is already the Ferrocene[1] project.

                    The safety model of Rust is extremely well described in detail. It's not particularly hard to understand, either. Are you worried that there is some kind of fundamental flaw in the design, we're just waiting to discover it, and it will all come crumbling down? My suggestion would be to start by understanding Rust's type system and why it works the way it does, and you will very quickly build an intuition ("vibes") that it obviously works.

                    [1]: https://ferrocene.dev/

                    • csande17 19 hours ago ago

                      If your intuitive understanding of Rust is that its type system "obviously works", then you have developed an incorrect understanding! There are many documented cases where it does not work, and there is an active project to change its design so it works in more cases.

                      I don't think we should accept this kind of vibes-based reasoning from C programmers who are confident their programs don't have any memory bugs, and we shouldn't accept it from people trying to sell us programming languages either.

                      I think it's reasonable to say that Rust successfully prevents a lot of memory issues, and that it's it's a good choice for lots of projects. But it frustrates me when people try to dishonestly argue that it's perfect and then retreat to arguing that the implementation is flawed but the design is perfect, because neither statement is true but they take a lot of oxygen away from efforts to improve the situation.

                      • simonask 18 hours ago ago

                        > There are many documented cases where it does not work, and there is an active project to change its design so it works in more cases.

                        Are you referring to the implementation or the model? Because there are several bugs in the implementation, but they are very clearly bugs.

                        If you're aware of any actual holes in the type system as it is designed, I think the Rust lang team would be very interested in hearing about your paper!

                        • csande17 18 hours ago ago

                          I am referring to the one that exists in material reality, and not just the collective imagination of the people making this dishonest argument.

                          • simonask 10 hours ago ago

                            Wait, so you believe that unless the program's behavior is described by an ISO standard document, bugs cannot exist?

                            "It's a feature, not a bug!" taken to the next level. I guess I admire your dedication to obstructing reasonable discourse.

                            • csande17 5 hours ago ago

                              The problem isn't that Rust doesn't have bugs in it. The problem is when people try to say that Rust is an "implementation" of some thing that does not have bugs. This is only true because it's not possible for there to be bugs in a standard which does not exist. It creates the impression that the Rust team did design work that they have not actually done yet.

                              "But my mental model of Rust is not detailed enough to notice the bugs!" That's great, but that's also true of every bug, including the ones that are caused by major design defects, so it's not really saying much.

                        • 18 hours ago ago
                          [deleted]
                  • saagarjha 20 hours ago ago

                    I mean it would be nice to make one of those, but I also don't really see the point of doing so besides shutting up the guys who like to talk about how Rust doesn't have a spec, most of whom do not even seem involved in the language really? Nobody really has an issue with the current situation, they are all clearly bugs and they more or less get triaged appropriately.

            • pseudony 21 hours ago ago

              Funny. I would think a GCed language was safer - maybe Haskell being the safest of all (outside even more niche languages) for its ability to encode so much in the type system.

              Yet, for some curious reason, a substantial group of snake oil salesmen insist that only this one particularly cut puzzle piece (rust) fits the bill.

              • simonask 21 hours ago ago

                Who, exactly?

                It has been known for decades that GC was one way to achieve memory safety. That was one of the main selling point of Java back in the 90s - no more segfaults.

                Rust was an absolute breakthrough, because it provides a second way to gain memory safety, this time without the significant drawbacks of a garbage collector, bringing memory safety to systems programming. That's materially different.

                The only other previous attempt at this was Ada, which for a variety of reasons never quite fit the bill despite its obvious strengths.

                • dcminter 20 hours ago ago

                  > Who, exactly?

                  I'm on your side of this, but there are Rust zealots out there and they're incredibly annoying.

                  (Edit to add:)

                  As a longtime Java guy (after a decade or so as a C++ guy) what drew me to Rust wasn't actually memory safety; that was table-stakes for me and Go might have lured me in if that was all I wanted. The low-cost (cognitive complexity is a cost) of memory safety was a factor, but it was the expressive type system that sealed the deal.

                  • pjmlp 18 hours ago ago

                    Which ironically has been available since Standard ML in several descendents, including Scala on the JVM, yet Rust keeps getting the glory.

                    • dcminter 17 hours ago ago

                      Sure, but it's nice to be able to trivially distribute a binary so JVM based languages have a hindrance there. I'll set performance concerns aside as for my purposes they're usually irrelevant.

                      Otherwise Scala was nice in some respects, less nice in others (purely a matter of personal taste).

                      • pjmlp 16 hours ago ago

                        There have been AOT compilers since Excelsior JET back in the mid-2000's, among others in the enterprise and embedded commercial space, nowadays GraalVM and OpenJ9 are available as free beer, so paying for AOT is no longer an issue.

                        Scala also has a LLVM backend.

                        • dcminter 16 hours ago ago

                          Right, but there's too much reflection in JVM language libraries for this to ever seem a very appealing option (to me, YMMV).

                          I'm not saying the choice is strictly rational, just that when I came across it Rust ticked a lot of my boxes and I've since then found it a pleasant language with no more than the usual level of frustrations.

                          I like Java too though, so draw your own conclusions.

                  • simonask 20 hours ago ago

                    > I'm on your side of this, but there are Rust zealots out there and they're incredibly annoying.

                    I mean, I keep hearing about them, and they just literally never show up anywhere I am, and I'm pretty active in the Rust community.

                    • dcminter 19 hours ago ago

                      I dug out this example:

                      https://forum.qt.io/topic/142885/rewriting-qt-in-rust/10

                      They might not be that common but they're definitely out there, and memorable, and irritating. You can see why it colours people's impression of the community.

                      • simonask 18 hours ago ago

                        I skimmed the topic. This is a forum post seemingly asking an honest if ill-informed question, and it seemed to foster an interesting and informative debate about why Qt isn't a good candidate for being rewritten in Rust.

                        I didn't notice any toxicity from either side at all, though admittedly I did just skim.

                        • dcminter 17 hours ago ago

                          Ok, maybe "zealot" is the wrong word, but the guy (says himself he) doesn't really know Qt or C++ but is very sure that they should rewrite in Rust.

                          I think that's the kind of interaction people find irritating even if you don't see it.

                • pjmlp 18 hours ago ago

                  Cyclone was the breakthrough, not Rust.

              • JuniperMesos 21 hours ago ago

                Also you gotta write the garbage collector itself in some language that isn't itself garbage collected - usually C or C++, before Rust existed.

                Anyway, it's basically slander to say that people advocating Rust are snake oil salesman. Rust is a genuine improvement to systems languages over the existing options (primarily C/C++) in multiple respects, not just memory safety; it is not a panacea that solves every problem or eliminates every possible bug, and no one involved with the project ever claimed that it did.

                • pjmlp 18 hours ago ago

                  This is a common mistake to voice out, since Lisp was created it is possible to write GC implementation in such languages, history is full of examples.

                  For the record here is the Oberon GC implementation, in Oberon.

                  https://people.inf.ethz.ch/wirth/ProjectOberon/Sources/Kerne...

                  If you want a more trendy example, check D or Go.

                • pseudony 16 hours ago ago

                  " no one involved with the project ever claimed that it did" - this may be true, MAY. But the Rust community is a large tent and, unlike Zig, Odin, Go, Java or whatever unusually motivated to roll in and suggest that a rewrite in their favorite language is necessary.

                  The amount of times I've seen, even on HN, not rewriting the world's C/C++/Zig/Odin software in Rust is a moral failing is.. well.. I've never seen any other language community argue that way - and this, very naturally, breeds animosity.

                  As for systems programming, whether Rust fits the bill is a much deeper and nuanced discussion than most drive-by Rust commentators seem to have patience for. I'd point out that in spite of C++ (also a language prioritising RAII) most serious systems software is written in C. Ignoring this fact and insisting that a new, better RAII language is the panacea of systems programming seems to me just a little unserious.

                  • JuniperMesos 6 hours ago ago

                    Most serious systems software is quite bad, full of security vulnerabilities, and being written in C has a lot to do with that. C's design makes it very easy to write code with subtle bugs, often security issues, and indeed most systems software written in C is full of security vulnerabilities and has been for decades.

                    I myself think that we should rewrite most of the world's C and C++ in something else (I specifically include the Linux kernel in this, among many, many other pieces of software). Rust is obviously a strong contender here, but this is not a specifically pro-Rust viewpoint, but an anti-C/C++ one. As I said, I don't think that Rust is a panacea or that it's reasonable to conceive of Rust as a panacea. I even think it is important to research new systems languages that are not Rust and that go even further in the direction of statically-guaranteeing program correctness properties than Rust does - I explicitly do not want to treat Rust as the only good or worthwhile language to write systems software in. This doesn't mean that the C/C++-based status quo is good.

              • stymaar 20 hours ago ago

                A GCed language wouldn't be safe from the kinds of bugs exhibited in the OP, all it takes is a bug in the runtime.

          • dcminter 20 hours ago ago

            Yes, that's a myth.

            I, like many others, still think that a language that requires a bug in the compiler for a certain category of error to be exhibited is preferable to one that has no such guarantees. I like C but it's not crazy to consider rewriting a tool in Rust for memory safety reasons.

          • no-name-here 21 hours ago ago

            > automatically safe

            > bug free

            In most discussions involving Rust I hear those “counter” criticisms, but is it a common claim by Rust proponents that Rust makes software bug free, etc.? I feel like I don’t regularly encounter the original claim that others regularly argue against.

          • Certhas 21 hours ago ago

            Because?

  • hingler36 a day ago ago

    I've always felt that parts of the Rust standard library to be weirdly un-rusty. Like indexing a vector panicking instead of returning a Some(T) in case the index is out of bounds. It's easy to avoid if you put the effort in of course, but it did always feel weird that one of the first data structures you learn has this behavior right out of the gate.

    • Chai-T-Rex a day ago ago

      That's not really a memory safety bug, due to the fact that it panics rather than doing something unsafe.

      The `variable[i]` notation is intended to function like in other languages, where it returns an unwrapped value. It would be ugly, noisy, unergonomic, and annoying to have to properly handle `Some` (like in `variable[i].unwrap()`) every single time you ever used it. Imagine doing `c[i].unwrap()[j].unwrap() += a[i].unwrap()[k].unwrap() * b[k].unwrap()[j].unwrap();`.

      If you really want the result to be wrapped in `Some`, you can use `variable.get(i)`.

      • cube00 a day ago ago

        > That's not really a memory safety bug, due to the fact that it panics rather than doing something unsafe.

        The ? operator can be nicer to read then all those .unwraps() as an alternative and doesn't panic.

        I guess the concern with panics is you're not forced to think about how you want to handle them like you do when you get a `Result` or `Option` returned.

        As a result it could be used as a DDOS against your app if it's network accessible.

        • aslilac a day ago ago

          gotta remember tho that ? didn’t exist in 1.0, and now we can’t break existing code

          • cowlevel 20 hours ago ago

            Is that Rust's guarantee? I know that Go avoids breaking changes but I thought they were normal in Rust.

            • chiffaa 20 hours ago ago

              Rust does VERY limited breaking changes, the largest one probably being the `!` type inference change that was very carefully vetted, deemed a necessity and saw contributions to fix the issue in all crates in the official registry

            • arijun 20 hours ago ago

              They do break backwards compatibility at edition boundaries, but if they do that too much without a good enough reason they could end up with a python2->python3 situation, with low uptake.

            • throwawayqqq11 20 hours ago ago

              Rust editions exist for handling breaking changes. I dont get why so many people treat them as unthinkable/impossible.

        • adwn a day ago ago

          Applying the ? operator to an Option<_> doesn't work inside a function returning io::Result<_>, for example, and turning the None from an out-of-bounds vector access into some io::Result::Err usually wouldn't make sense.

          I would go so far as to say that an out-of-bounds index is always a logic error (to be handled by panicking), not an input error (to be handled with Result). And if the out-of-bounds access was caused by invalid input, then logic error consists of not checking the input before indexing.

          • ablob 20 hours ago ago

            The former issue arises from post-hoc thinking. Of course it's hard to retrofit into the language, but I see no reason why there shouldn't be facilities for the ? operator to turn a None into an appropriate error type.

            The latter is a subjective matter. There are reasons to never want a panic (hello there, Linux kernel) and reasons to do more sophisticated stuff (core dump, cleanup or notifications) before crashing. And maybe one thread shouldn't lead to process death. I think most of these decisions should be kept to the user's discretion.

      • rendaw a day ago ago

        GP didn't say it was a memory safety bug.

    • suresk a day ago ago

      I think it is a reasonable tradeoff, especially since `get(i)` is available to do what you want. An array index oob error is usually a logic issue, not some recoverable error, and in a lot of cases you're doing it where it is impossible to be wrong, so it is a lot of error-checking (and giving up things like x[0] += 1) to have the Index trait return an Option instead of a direct reference.

    • namjh 20 hours ago ago

      That's just a design decision orthogonal to memory safety:

      For "fallible" variant indexing, you have `the_slice.get(index)`: https://doc.rust-lang.org/stable/std/primitive.slice.html#me...

      Although its method signature is kind of cursed due to generics, it matches your requirement that allows graceful OOB handling.

      If the default indexing behavior were like `.get()` it would be too cumbersome to express repeated use of indexing, or multi-dimensional array indexing, etc.

      Also there is get_unchecked which is unsafe. Trivially you'll trigger OOB access when misused.

    • cowlevel 21 hours ago ago

      Wrapping everything in optional does lead to optional fatigue, and people just unwrap each optional they get since they know the index is inbounds, missing the one instance where it really is possible to get None.

      Maybe optional fatigue is Rusty but it's not a good style in any language

    • saagarjha a day ago ago

      > Like indexing a vector panicking instead of returning a Some(T) in case the index is out of bounds.

      If you are doing this then you've made a mistake in your code. Rust is consistent in catching these early.

      • uecker a day ago ago

        There is also the idea that the language is so good because such things are caught at compile time via the type system. (But this is generally not done for the same reason it is not done in C.)

        • pjmlp a day ago ago

          As shown in PL/I or NEWP, C could have done it both ways, checked and unchecked when really required, e.g. PREFIX(SUBSCRIPTRANGE), PREFIX(NOSUBSCRIPTRANGE).

          Likewise regarding the storage for the length, if one is willing to go the way C went down a few years later, declare a pointer and make the array storage be pointer based, e.g. BASED(MY_ARRAY_PTR).

          • uecker a day ago ago

            Can you explain what you mean by "make the array storage be pointer based"?

            • pjmlp 20 hours ago ago

              In PL/I you can declare arrays with a length descriptor, thus allocating storage for the length, like in mostly safe systems languages.

              Alternatively when allocating the array storage define its access to be pointer based.

              This means no length descriptor will be stored alongside the array, and the access to array elements will be done via the given pointer.

              It is up to the programmer not to mess up then.

              Unfortunately C authors never added a way to do the former, given their experience with PL/I and Multics.

              I am aware we are finally going into that direction.

              • uecker 17 hours ago ago

                In C we have already for more than a quarter of a century:

                  int n = ...;
                  int i = ...;
                  int array[n];
                  int (*p)[n] = &a; 
                  (*p)[i] = 1; // safe (with checking activated)
                  int *q = a;
                  q[i] = 1;    // unsafe (except if the compiler can derive the size somehow)
                • pjmlp 16 hours ago ago

                  Not really, because "safe (with checking activated)" isn't a thing in ISO C, some C compilers might have such possibility as language extension.

                  I am quite sure it will happily corrupt memory in most C compilers I would reach for, that are a decade old.

                  Hardly helpful to write portable code safely.

                  • uecker 16 hours ago ago

                    There is a world outside of ISO. Otherwise Rust also does not count. But yes, it would be better if it were a required part of ISO C. If somebody gave me 1 million dollar, I might be willing to finish a draft specification real quick... But since nobody did so far, it can not be terribly important.

                    • pjmlp 10 hours ago ago

                      Not in regards to portable C code, which unlike Rust, doesn't live from a single unique reference implementation.

                      If no one has done it so far, it kind of proves the point how this matters to C compiler vendors across the ecosystem.

        • saagarjha 20 hours ago ago

          The language can catch a lot of things via the type system, but there are always going to be some things that are just not in scope and must be asserted via precondition. This is one of them.

  • Panzerschrek a day ago ago

    > But many operations in Rust can panic, from out-of-bounds indexing to calls into user-provided code, and by default a panic unwinds

    That's why I think having unwinding in Rust is a mistake. It gives a false sense of safety, but it's very hard to write unwinding-correct code. So, it would be better to handle panics as immediate process termination instead.

    • Xirdus 21 hours ago ago

      But that would make Rust unsuitable for writing anything that wants to keep the program running even if something does panic - say, test harness, or a plugin system.

      • cowlevel 20 hours ago ago

        This is already the case for any other non-JVM language though, and they usually manage to deal with it by separating operating system processes. A lot of C programs have plugins (even the kernel!) and don't crash because the plugins aren't buggy (by which I don't mean they have no bugs).

        Your plugin can still crash in ways other than a panic, like a segfault inside an unsafe block.

        It's also likely possible to DoS the application from a plugin in ways other than a crash, e.g. add a billion entries to the right-click menu.

        And if you're loading a plugin, how do you know the plugin was actually written in Rust, anyway? It could be written in C and scribble over all your stack memory as soon as you load it.

        It's very hard to guarantee stability in the presence of arbitrary extensions, and you might not even want to because someone might have a real use case for an extremely large right-click menu (probably not a billion though). I don't think even language server protocol guarantees it.

        • jaen 15 hours ago ago

          Wait what? Most plugin systems do NOT use process isolation as the performance overhead is horrible.

          Usually it's either safety-via-language (Lua, JS etc.) or just YOLO (dynamically linked libraries), at best lightweight isolation like WebAssembly but that's modern projects, <1%.

          The process isolation approach is only widely used for Go (Kubernetes, Terraform), because Go doesn't support DLLs (nicely)... (and the systems themselves are very slow anyway)

          • cowlevel 4 hours ago ago

            Language Server Protocol uses a separate process and the performance is not horrible

          • marshray 10 hours ago ago

            Think about all the applications that spawn a subprocess and enable you to override the executable by configuration or just the PATH.

            Those are plugin systems too, unless your term 'plugin' requires dynamically loaded code libraries by definition.

      • masklinn 21 hours ago ago

        OTOH that panics are ok and easy to reach for and unwind is why you have to handle them and keep the program running.

        I don’t think that an unwind-less rust would have fit within the weirdness budget 10 years ago, today it would definitely be something to consider. Although it would have an unwind effect to contend with.

        • Xirdus 21 hours ago ago

          It would be entirely unsuitable for the kind of project I work on in my day job, which requires running user-provided code (trusted code, but one that may contain many bugs) in 100 different worker threads, and if one of them crashes the other 99 must keep running. Without unwinding and recovery, we'd have to completely redesign the whole application, probably to multiprocess architecture with all its downsides.

          • debugnik 16 hours ago ago

            It sucks to redesign but threads simply aren't the right tool for isolating native code, processes are.

            • Xirdus 15 hours ago ago

              I am not isolating anything. Isolation isn't this framework's job. Task management is. And it's much easier to manage tasks if a panic in one of the worker threads doesn't kill the other 99 threads as well.

              • debugnik 15 hours ago ago

                I'd call crash recovery part of isolation. You can't recover from a crash if it corrupts invariants for the other taks and the scheduler itself, and you can't entirely prevent that with your current design.

                • Xirdus 14 hours ago ago

                  I wouldn't call it partial isolation specifically to avoid people telling me "threads simply aren't the right tool for isolating". My current design can't prevent that because it's not designed to prevent that because it's not doing isolation, partial or otherwise.

          • cowlevel 20 hours ago ago

            What do you do if they segfault on raw pointers? Does Rust's runtime catch SIGSEGV and translate it to a panic?

            You can also get SIGBUS by mapping a file beyond the end of the file and then trying to read the extra bytes. If Rust's version of mmap checks this, you can still do it by truncating the file while it's mapped.

            • Xirdus 16 hours ago ago

              Crash, restart, and eventually retry all interrupted tasks when all the timeout expire server-side. Which is fine because this kind of crash is extremely rare. If every crash resulted in this, it would very much not be fine.

          • masklinn 19 hours ago ago

            > if one of them crashes

            But that's the point see? You have to catch panics because it's easy, straightforward and "common" to trigger panics.

            If it were not, you wouldn't, because the buggy user-provided code would not be triggering panics, in the same way you're not catching `std::process::abort` or segfaults or whatnot.

            • Xirdus 15 hours ago ago

              I am catching aborts and segfaults via a watchdog process. If the main process crashes, the watchdog restarts it. If in-process unwinding was impossible, then every worker thread would need to be spawned as a separate process so that a) a crash can be caught by the watchdog, and b) it doesn't interrupt the remaining worker threads for no reason. I really hope this unwind-less Rust still allows panic hooks, because otherwise I don't have an error message and a stack trace to send to the server, which would make debugging anything hell.

        • tancop 18 hours ago ago

          That would only make sense if your replaced it with a full effect system, which would also be good for different reasons (testability, bug isolation, no global state) but I don't think it's possible to fit into an existing language.

          If you don't have any way to do non local control flow you get what web developers call prop drilling. Code gets more complex because you need to check and handle every possible error condition inline.

          Maybe you could get away with it by supporting union types and changing the `?` operator to accumulate error types into a `Result<T, E1|E2|E3|...>` then short circuit on failure. That way your code can decide how to handle each one instead of choosing between immediately return error or do verbose manual handling.

          • masklinn 18 hours ago ago

            You can also type erase and shunt shit up by hand, that is what Go or Swift do (the latter with more syntactic support). It is essentially unwinding by hand, but it avoids the issue of unwitting unwinding so you don’t have a “secret” code path on the side.

      • ozgrakkurt 18 hours ago ago

        This is a downstream issue that happened because unwinding was there in the first place.

        Testing for panics is just a silly feature itself anyway.

  • nektro a day ago ago

    > Pattern 2: Trusting user-provided implementations to be correct

    reminds me of the tales from https://oxide.computer/blog/iddqd-unsafe

  • nektro a day ago ago

    > Notes from Microsoft Security's Frontier Offensive Research & Generative Exploitation Lab.

  • eptcyka 21 hours ago ago

    An effect system could gelp us reason about code by making calls to panic-capable functions marked as such. Maybe we could mark some types as panic unsafe?

    • cowlevel 20 hours ago ago

      That's literally what returning optional does.

      Effect systems usually fail because effects are very different from each other and can't be generalised.

      • eptcyka 18 hours ago ago

        Sure, but knowing if a call cannot panic can be incredibly useful. Knowing if a call can wait on I/O or not can be incredibly useful (as long as logging can be worked around).

        • cowlevel 13 hours ago ago

          Usually a call that waits on CPU or a call that waits on RAM or a call that waits on a mutex is just as bad as a call that waits on IO. The IO isn't what you actually care about.

  • codeflo 20 hours ago ago

    The community-driven quest for "panic safety" in Rust is the same curse that befell C++ in terms of "exception safety", maybe worse because at least more C++ shops are sensible enough to disable exceptions. It's an exercise put forth by language lawyers that increases program complexity beyond comprehension, often without achieving the stated goal. It's simply not practical to think through 20 convoluted edge cases for every innocent little function, which means that no realistic program will safely recover from a panic. It's best to admit this and engineer your system accordingly.

    • MindSpunk 19 hours ago ago

      To me, panic being an unwind feels like Rust's biggest sin. It's especially problematic IMO since an idiomatic Rust program would use Result and pass errors as function returns, except the panic unwind machinery sits there as a hidden return path that's very easy to forget about. It's the same problem as writing exception safe C++, every function call can turn into an early exit from the function.

      Most Rust learning material teaches panic as if it's an abort. They don't lie about it unwinding, but 99% of uses of panic use it like a fatal error with no expectation of recovery. The fact you can _recover_ from panics is even worse because you can then continue running a program after one of these "fatal" errors failed to abort the process.

      There's some powerful things panic/catch_unwind let you do. I'm yet to be convinced the complexity imposed on all code is worth the squeeze on the cases where panic = unwind is a genuine requirement.

      I wish the default was panic = abort, but as a whole I still find Rust the best tool for where I use it.

    • simonask 20 hours ago ago

      This is such a deep topic with literally decades of discourse behind it.

      I tend to agree with the general principle that panicking or throwing an exception should terminate the process in most cases. But those last microseconds of a process' lifetime matter quite a lot: Are you able to save the user's work? Are you able to log the error so the crash can be diagnosed?

      With Undefined Behavior in the picture, you cannot do anything. The whole process is toast, and its entire memory state is invalid.

      • ozgrakkurt 18 hours ago ago

        It is not really a deep topic. Pretty much anyone that undestands it agrees that unwinding is too sketchy a feature in a language like rust.

        It is just too difficult to write unwind safe code and it is not much of a benefit even if you have it.

      • ViewTrick1002 19 hours ago ago

        I would say the problem with this becomes that it’s all best effort.

        You can’t rely on it for correctness because for your software to be reliable it needs to deal with an abrupt power outage and recover.

        Best effort diagnostics make sense. And the “Rust 2.0” or successor language will with certainty close this gap.

        But I also understand why we are here. A decade ago when 1.0 came out Rust had already used up most of its complexity budget for traits, enums, borrow checker, generics, functional style programming and so on.

        Diverging even further from what was expected by the majority of programmers would very likely have left Rust as an esoteric language with a tiny following. Instead of what it became.

        And back then unsafe was thought to work more like “just do like in C”.

        There has been years of research formalizing how it actually works that’s brought us to the current understanding where it’s not trivial to write it correctly.

    • locknitpicker 19 hours ago ago

      > The community-driven quest for "panic safety" in Rust is the same curse that befell C++ in terms of "exception safety", maybe worse because at least more C++ shops are sensible enough to disable exceptions.

      You seem confused. The "exception safety" topic in C++, which clueless people often cite Google's style guide as an appeal to authority, is that it's undesirable to modify old legacy code that does not use exceptions to call libraries that do. The sole reason this is not desirable is that calling code that throws exceptions introduces code paths that the legacy code was not designed to consider and cleanups that leave it in a state it was not designed to be in (i.e., all stack unwinding and RAII cleanup in surprising points with surprising implications).

      And project managers tasked with a project that involves legacy C++ code can't simply spare time and resources to redesigns legacy project to accommodate for these changes, or the risk of having stable production code one day crash just because someone linked to a library that now throws.

      Therefore, the "exception safety" discussion in C++ is not a technical one. It is a project management one, and one which involves high reliable legacy code.

  • gspr 21 hours ago ago

    Very interesting finds for sure. But taking the "trusting user-provided code" as an example: isn't this just a case of malicious code being malicious? I understand the point that the malicious act comes through memory unsafety, and it's a big gotcha that safe Rust (i.e. Rust without `unsafe`) can trigger memory unsafe behavior. But the code doing it is still acting maliciously (by having an `AsRef` implementation that returns different slices at different times). And the code being abused (the one that does the unsafe indexing) does have `unsafe` – so this is a case of the user writing unsafe Rust that interacts with malicious safe Rust.

    I don't know if it's ever been in Rust's threat model to handle malicious code.

    • pwdisswordfishq 20 hours ago ago

      Sufficiently deniable malice is indistinguishable from incompetence. If a condition can be triggered "maliciously", then it can probably be also triggered inadvertently. There's no point in saying "that's malicious so it doesn't count".

    • mswphd 20 hours ago ago

      Rust's goal is no UB in safe Rust. That includes in (incorrect) impls of safe traits.

      Note that incorrect code can still cause

      1. incorrect outputs, or

      2. arbitrary performance degredations

      safe rust doesn't have to work magic. All it must do is prevent UB.

    • tialaramex 19 hours ago ago

      Of course this in Rust's model. The whole point of even having the distinction between safe and unsafe traits is that this is in the model.

      I thought maybe I explain this well in the README for https://github.com/tialaramex/misfortunate/ but apparently not, so that's on my FIXME list now.

      When I write such an explanation it will probably use Comte as an example. Comte implements ExactSizeIterator which is a safe trait for claiming your iterator gives accurate information about how many items are left. It's lying (but equally a safe implementer might just be mistaken), and Comte is not in fact giving accurate size information. However, if you need to rely on a promise that the iterator length is correct Rust has an unsafe trait for such promises named TrustedLen.

      Unlike Comte, mis-implementing TrustedLen could cause Memory Unsafety, but you would need to write the `unsafe` keyword and be lying or mistaken, which is what Rust promised you will happen.

      To give a concrete example, if I tell Rust I want to put the results from this iterator over Goose into an array [Goose; 6] in usual cases it will emit code to check for overflow and panic if the Iterator makes the wrong number of Goose, even if the iterator implements ExactSizeIterator and claims to have six Goose, that panic check happens. But if it implements TrustedLen and makes the same claim, the compiler will believe it and skip the check. If it was wrong about having six Goose, your program is nonsense and anything might happen.

      • theemathas 2 hours ago ago

        Some ideas to add to your crate:

        * Non-fused iterators, implementing FusedIterator

        * Iterators that, when cloned, produce an iterator with a different set of elements

        * DoubleEndedIterator which is inconsistent when iterated from each end

        * A trait such that cloning a Box<dyn Trait> produces a value with a different concrete type inside

        * A Display type that always produces an error from fmt()

        * A Display type that replaces the Formatter with a different one

        * A type that always hashes to different values.

    • dist-epoch 20 hours ago ago

      Only JavaScript partially supports this, based on the domain where the code originated from, so your website code is not infected by the Javascript run by an ad you embed.

  • ozgrakkurt 19 hours ago ago

    Do not ever use with anything other than panic = abort.

    It is just the sketchiest feature in a very realiable language.

    It doesn't make sense to me why anyone whould use rust with panic handling.

    And the of course the language trusts the operating system, how else can you program?

    This kind of thing is basically why all projects blocked AI issues, it is just slop that kind of makes sense if you don't know what you are doing.

  • petterroea 21 hours ago ago

    Is it just me or is it painful that they format their product name like that in the blog text.

  • HackerThemAll 19 hours ago ago

    Could they first focus on fixing flaws within all their products maybe? The unusable patchwork of corporate programmers motivated by promotional cycles which breaks all the time on various fronts is worth abandoning and starting over in this Rust they complain about.

  • mesm7903 a day ago ago

    [flagged]

  • jdw64 a day ago ago

    [dead]

  • senderista a day ago ago

    I sure wish they'd rewrite the Azure Linux VM Agent in Rust. That thing normally burns 10-15% of a core, and also blocks VM restart for tens of minutes, god knows why.

    • loeg a day ago ago

      I've seen certain MSFT engineers get a lock ordering warning from taking mutexes in a wrong order and "fix" it by using a spin loop + try lock instead.

      • senderista a day ago ago

        I work on a commercial database marketed as "lock-free" and I can't tell you how many CAS spin loops I've seen with no backoff or iteration bounds.

        • cowlevel 20 hours ago ago

          If it only retries because a different thread made progress, it's lock-free and total work is bounded - even though one particular thread could get very unlucky, system-wide luck is conserved.

          How much code's inside the CAS loop? If it's being held for less than (sticks finger in the wind) a few thousand of instructions then backoff or limits are actively counterproductive. That's how you're supposed to use a CAS loop.

          If it's more, you shouldn't try to invent a more clever CAS loop, you should replace it with a mutex.

          • tialaramex 19 hours ago ago

            > If it's more, you shouldn't try to invent a more clever CAS loop, you should replace it with a mutex.

            Also, if your language isn't old and crap your mutex already knows about this trick and so you should default to using a mutex, because it will do that anyway, and only write your own CAS loop if you have measured that it matters.

            Note that word measured. Since we're talking about Rust here and people doing this stuff should be used to writing SAFETY justifications in their Rust, your CAS loop should have an accompanying justification comment.

            • cowlevel 18 hours ago ago

              A CAS loop can be used to implement arbitrary atomic operations, such as "atomic square and divide by two" or "atomic logarithm". This is a proper way to use them, you don't need to use a mutex for something like that unless the computation is long (which logarithm might be - idk, haven't benchmarked it).

              Agreed that mutexes are easy and a safe default.

              • tialaramex 15 hours ago ago

                Yes that's true, if you wanted to update a count or something then you only need a CAS. I guess I was assuming their DB application is hand rolling what Be Inc. called a "Benaphore" which was a common idea 30+ years ago but is now obsolete because of Futex and Futex-like primitives such as Microsoft's WaitOnAddress

                The Benaphore wraps an OS mutual exclusion primitive (in BeOS the Semaphore) with a simple flag you can CAS, so your program makes an OS Semaphore, and when something wants mutual exclusion instead of using the OS to lock the semaphore they instead first CAS unlocked->locked and don't call the OS at all if they succeed. Only when it's contended you make the OS call and lock the OS primitive. This makes the uncontended case very fast while the contended case is little worse than before.

                With a Futex (or similar) you don't need that OS Semaphore, instead the OS just remembers a list of waiters and threads can add themselves to the list if they discover their lock was contended. In all of C, C++ and Rust the out-of-the-box mutual exclusion now does this already on popular targets, of course I think Rust does this best but I would think that because I like Rust. Even in plain C you should never assume you can do better than what's provided in the box. Either measure or accept that you don't care and use the provided mutual exclusion.

        • masklinn 21 hours ago ago

          Does the system provide ready made backoff and / or bounded CAS loop primitives? Because if you have to write the entire thing in full every time I can see why it’s get skipped.

          • senderista 10 hours ago ago

            I'm in the process of doing that lol. Most of these cases are of the form "I need to wait until X is true, it should happen within microseconds so no point to a condvar", which is fine until you're massively oversubscribed or swapping and threads start getting preempted.

          • cowlevel 20 hours ago ago

            Normally if you find yourself needing something like that, it means a CAS loop is the wrong tool for the job.

    • arccy 21 hours ago ago

      no amount of rust will fix the problems in azure that lead to https://news.ycombinator.com/item?id=47616242

  • not_a_bot_4sho a day ago ago

    A good use for AI

    • rurban a day ago ago

      No, a good use to fix their specs.

      Rust is unsafe by spec, not just by implementation. For memory and type safety. concurrency safety is impossible to get with their blocking IO approach.

      • cowlevel 20 hours ago ago

        Rust doesn't have a spec, last I heard. The compiler is the spec.

  • shevy-java 20 hours ago ago

    The best AI language has not used AI to find all bugs yet?

    I don't quite like AI, but I think from an objective point of view one can reason that AI led to the discovery of more bugs, if we deduct the non-bugs from those reports.

    • 20 hours ago ago
      [deleted]
    • saagarjha 20 hours ago ago

      "The best AI language"?

  • drnick1 a day ago ago

    [flagged]

    • Chai-T-Rex a day ago ago

      I think that the point of Rust as far as memory safety isn't perfection. The point is centralizing proper memory safety.

      With C, every single programmer has to properly account for memory safety in just about every program they write. If you fix a memory safety bug in one program, that's not necessarily going to help any other program.

      With safe Rust, that work has largely been done for you. If a memory safety bug is found and fixed in Rust's standard library, it's found and fixed for every program that uses safe Rust (with a recompile using the new standard library version).

      The point is for some experts to work together to get things as memory safe as possible in one place instead of everyone having to get things as memory safe as possible in every place.

    • adrianN a day ago ago

      You don’t need frontier models and a research project to find memory safety issues in C. Rather the opposite actually.

      • uecker a day ago ago

        There were also memory safety bugs found in Rust code without frontier models before. Note that I do not deny that Rust has an advantage with regard to memory safety (at the cost of other things, including supply chain issues), but it is massively overhyped.

        • adrianN a day ago ago

          The difference is that in rust these are considered bugs. In C these are features.

          • uecker a day ago ago

            This is the type of hyperbole and nonsense that makes Rust marketing so annoying.

            • _flux 21 hours ago ago

              On the other hand, if your safe Rust program segfaults, you should consider submitting an issue to the rust project. If your C program crashes, you should probably use a debugger.

              • cowlevel 20 hours ago ago

                What happens if you do the rust equivalent of unsafe { *cast_to_pointer(0x12345678) = 42;} ?

                Do you get a panic or a segfault?

                • uecker 20 hours ago ago

                  As someone on HN phrased it "a segfault is the protection layer stepping it", so a C program having a segfault is not worse than Rust panicking.

                  And to the GP: yes, if your safe Rust program segfaults because of a bug in the Rust standard library, then you file a bug with the Rust project. I agree this is nice!

                  But in most real-world cases, your Rust program will segfault (or panic) due to a bug in your own code or in some code in one of its many dependencies. Then you also debug it.

                  • _flux 20 hours ago ago

                    I think it's a bit worse, because when a panic happens, e.g. memory contents are still uncorrupted.

                    But indeed you are in a good place if you manage to get a segfault. The much worse case is that the program misbehaves in some unexplainable way.

                    • uecker 20 hours ago ago

                      In depends. In many cases where you have a panic in Rust, the segfault in C would also leave the memory content uncorrupted.

                      The problem is if the program misbehaves in some unexplainable way due to random corruption. And memory safety is the right path to reduce such problems. But only in the imaginary world of perfectly safe Rust code is this a reality, or with Fil-C, or verified C code, or some other memory safe language. In the actual world of most systems programming scenarious even with Rust it is only somewhat better than C.

                • _flux 20 hours ago ago

                  Segfault. Then you get to use gdb/valgrind like anyone else (although you also have Miri).

                  The strategy when integrating unsafe segments to your Rust codebase is that you provide a safe interface for them, then very carefully review the code, and also use tools such as Miri to test them. Ideally your business side would not have any unsafe code in it.

      • tomkarho a day ago ago

        True but C never went out of its way to highlight memory safety features and shut down (with a rather aggressive posture to boot) any criticism of the language with arguments revolving around this feature as if it was the Christ's second coming.

        In lieu of finding out that there are in fact multiple memory issues in std is at least amusing and some might say well deserved egg in the face of the more, shall we say, enthusiastic defenders of the language.

        • mahboi 21 hours ago ago

          You mean the Rust fans. And there are C fans who say that only n00bs do accidental UB. Nobody cares what fanatics say.

          • tomkarho 21 hours ago ago

            Indeed though only those who taut the "memory safety" line as a mantra and some kind of catchall counterargument to any and all discussion that even remotely speaks ill of their favorite tool. Fanatics as you so aptly put.

        • microtonal a day ago ago

          I have my share of criticism of Rust. But even a safe language has to deal with unsafe memory etc. at some point in the stack. The goal is to minimize such uses of unsafe and for the cases of unsafe that exist to prove that they are safe.

          These haha gotcha's are criticism leveled at language designers who never denied that there is unsafe code, that there can be bugs in unsafe code, and that such bugs can leak to safe code.

          egg in the face

          Is it an egg in the face when it requires LLM analysis to find these nowadays? It tells me that the Rust developers got really good at eliminating memory bugs that are lurking in unsafe code.

          Also, this doesn't change anything to the benefits of Rust's ownership model, which removes classes of bugs that are very common in C/C++, so the Rust advocates were still right.

          (I'll leave my rants about Rust in a thread where it's more appropriate, but they are not about memory safety.)