• Dave.@aussie.zone
        link
        fedilink
        English
        arrow-up
        33
        arrow-down
        1
        ·
        1 month ago

        Which is worse?

        • Entire driver written in a non memory safe language?
        • The interface to the rest of the kernel is marked as unsafe and then the other X percent is safe from memory corruption?

        Surely if X > 0 then this is still a net improvement?

        • sem@piefed.blahaj.zone
          link
          fedilink
          English
          arrow-up
          5
          ·
          edit-2
          1 month ago

          Rust by default will not allow you to make certain kinds of errora, which is great. But if you are doing something advanced, down at the hardware level [see below], you might need to disable those defaults in order to write the code you need. This is what people mean by “unsafe” – lacking the normal memory safeguards.

          With careful coding, “unsafe rust” or normal C, for that matter, can be free of bugs and safe. But if programmers make a mistake, vulnerabilities can creep in more easily in the unsafe sections.

          Is that basically it?

          • CandleTiger@programming.dev
            link
            fedilink
            English
            arrow-up
            4
            ·
            1 month ago

            But if you are doing something advanced, down at the hardware level

            This part is wrong. Otherwise yes correct.

            The “unsafe” code in rust is allowed to access memory locations in ways that skip the compiler’s check and guarantee that that memory location has valid data. They programmer is on their own to ensure that.

            Which as you say is just the normal state of affairs for all C code.

            This is needed not because of hardware access but just because sometimes the proof that the access is safe is beyond what the compiler is able to represent.

            • sem@piefed.blahaj.zone
              link
              fedilink
              English
              arrow-up
              1
              ·
              1 month ago

              Thank you for the correction, I’ll edit my comment.

              sometimes the proof that the access is

              safe is bevond what the compiler is able to represent

              Could you say a few more words about this? In what situations do you have to write ‘unsafe-tagged’ code blocks? Could this be changed by improvements to the compiler? Or is it necessitated by the type of task being done by the code?