Live data from Hacker News

The first stable release of a memory safe sudo implementation

memorysafety.org

171–180 of 260 posts

Re: The first stable release of a memory safe sudo implementation

#171

Earlier quoted context omitted.

Perhaps, but if the goal is security of a critical tool, losing some attack surface (features) if they aren’t widely used is a win. Other projects, like ntpsec[0] have taken this approach with good results. Although, I agree with another commenter in this thread[1] that this effort would have been better directed at something with an inherently small attack surface like doas. 0 - https://www.ntpsec.org/accomplishment…

The features they are leaving out were presumably added for a reason. If someone is on a system that is using sudo-rs as a drop-in replacement (not under their control) and they need to use one of those less widely-used features, how secure is the work-around they have to use instead? I'm hoping this factored in to their analysis. Sometimes reimplementing something and leaving out lesser-used features to "reduce the…

Did you know you can set up an OpenVPN tunnel with no encryption or authentication?

I'm sure for someone out there that's a make-or-break feature, but for the vast majority trying to use OpenVPN it's a massive, insecure footgun. (Hell, how many bugs have protocol negotiation led to in OpenVPN/SSL/etc?)

Compare that to Wireguard that just says... it's encrypted. Full stop. Carry on.

A lot of this tooling and technology was developed in a different era with different priorities. Security, and especially network security, was not such a huge focus 30-40 years ago. Priorities have shifted. The operating environment is a lot more homogeneous (when's the last time you dealt with a layer 2 protocol besides ethernet?), while the risk of poor security has grown immensely.

It's absolutely fair to critically evaluate these features and determine which can be removed to simplify and improve the products for the vast majority of users. If a small fraction of users stay on sudo, but the majority are able to move to a more secure option... that's a win. This is exactly what Wireguard provides versus OpenVPN.

Re: The first stable release of a memory safe sudo implementation

#172
post #129
post #28

Earlier quoted context omitted.

Do you use doas on Linux? It is not protected against tty pushback attack: https://github.com/Duncaen/OpenDoas/issues/106 That's a pretty severe unsolved security issue.

It's solved; TIOCSTI is disabled by default since Linux 6.2 https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/lin...

The thing you linked says "default y" to "Allow legacy TIOCSTI usage". So yeah, you can disable it, no, it's not the default.

There's also a related issue with TIOCLINUX and the paste functionality. (That will however be solved in an upcoming kernel version. I wrote the patch for it :-)

Re: The first stable release of a memory safe sudo implementation

#173
post #126

Earlier quoted context omitted.

And it looks like it was a buffer overflow: https://blog.qualys.com/vulnerabilities-threat-research/2021... Would Rust prevent this?

Yes it would be prevented by the borrow checker.

The borrow checker does not prevent out of bounds access of arrays (or vectors or whatever you want to call them).

The borrow checker is intended to protect against "temporal memory unsafety". It can tell you that you are using something that has already been freed, or something that could be freed while you are using it for example.

Bounds checking is a "spatial memory unsafety" problem, it has nothing to do with borrowing and exclusive references.

Bounds checking is a trivial problem, for an array that has N length, like a char[N], something tried to access a value past the end of the array (like char[11] if N=10).

Rust doesn't really do anything special here and protecting against buffer overflows does not require any novel technology.

An implementation of bounds checking is as simple as an "assert(I >= 0 && I In C this is difficult to do because arrays or are just pointers (or decay to) and pointers do not carry any information about the length. Keeping a separate variable containing the length around but this apparently is too unergonomic since virtually all C software does not check every array access in all parts of the program.

In Rust, its very rare to use raw pointers to work with "arrays". Instead there is a "slice" type that models the concept of a contiguous sequence of values in memory. The important part is that the slice type is a "fat pointer", and the fat pointer contains the length or the array. The slice type is able to check every access in all parts of program.

So all slice accesses are checked by default. and you can't "turn it off". If you really want to disable bounds checking for some reason, there is an unsafe "get_unchecked" function.

There are some sequence types other than slices, arrays for example (array is a specific type here). They are still checked but they don't have to store the length information because it's encoded into it's type.

The Vec type is another one. It is a resizable "array", and it stores 3 things, a pointer to the allocation, the capacity and the length. That's mostly not relevant here though. It checks every access like the other types.

Bounds checking is a very easily preventable error. It should not be happening in $CURRENT_YEAR.

Re: The first stable release of a memory safe sudo implementation

#174
post #60

As one of the original creators of sudo ( https://en.wikipedia.org/wiki/Sudo ) I've witnessed it getting nearly totally rewritten and then incrementally bug-fixed over the last 43 years. It must take the prize for the UNIX command most highly-scrutinized for security flaws. Flaws which have been identified and fixed. Thousands of developers and security experts have gone over it. So part of me wonders - how is it pos…

> How is it possible for a single dev team to totally reimplement it without unknowingly introducing at least a bug or two

This is possible if every bug fixed has an associated test. If they use this battery of tests to test their new implementation it should be as good as the original implementation.

Re: The first stable release of a memory safe sudo implementation

#175
post #89

Earlier quoted context omitted.

It's doable by opening the file in a privileged process (sudo) and passing the file descriptor to a non-privileged process. Maybe one could make a sudoedit that opens a file in sudo process and then spawns a non-privileged editor process which inherits the file descriptor and is given the /dev/fd/ path on the command line, so it stays none the wiser about the whole process.

Sounds like a bit of recipe for accidentally handing access to an unintended privileged fd through inheritance (ignoring the /dev/fd one) such that a compromised unprivileged SUDO_EDITOR value gives you sudo access. Maybe not likely, but I’d really be hesitant about any feature that relies on implicit fd inheritance…

Close all other fds between fork and exec then (you can look at the code of base::LaunchProcess in Chromium for an example). It’s a minuscule amount of code to audit compared to XDG portals. And it’s backwards-compatible with decades of unix programs.

For a more complicated solution: spawn a zygote process early with a unix socket which you’ll use to send the fd later. Zygote at start drops provileges. When it receives the fd, it closes the socket and execs the editor.

Re: The first stable release of a memory safe sudo implementation

#176

Earlier quoted context omitted.

[flagged]

> Like building an entirely new car company around only making side-impact collisions safer ...which still results in safer cars overall, so I don't see the problem. Especially if those cars are almost completely immune to side-impact collisions and if it's actually not a car company but a technology every manufacturer can use for future products.

You don't see the problem in starting an entirely new car manufacturer from scratch just to fix one safety issue?

> if it's actually not a car company but a technology every manufacturer can use for future products

In that case it's like every single manufacturer changing their engine design in order to have a different wiring harness with a slightly thicker shielding around a single cable. The amount of work and cost involved, and risk to every other part of the process, just to fix one tiny thing, makes no sense. It is an insane amount of work for extremely little benefit.

Re: The first stable release of a memory safe sudo implementation

#177

Earlier quoted context omitted.

I wonder how we are from a Rust UNIX userland. At least we wouldn't have to implement a C compiler!

I looked into this a few years back when I was making my own toy Linux distro, and this is the list of packages provided by a typical GNU system that meet POSIX requirements for a userspace: * `bash` * `bc` * `binutils` * `bison` * `Coreutils` * `Diffutils` * `file` * `Findutils` * `flex` * `gawk` * `glibc` * `grep` * `tar` * `gzip` * `M4` * `make` * `man-db` * `man-pages` * `procps-ng` * `psmisc` * `sed` That's a re…

> POSIX doesn't dictate an editor

ed is the standard text editor!

Re: The first stable release of a memory safe sudo implementation

#178

Earlier quoted context omitted.

Yes it would be prevented by the borrow checker.

The borrow checker does not prevent out of bounds access of arrays (or vectors or whatever you want to call them). The borrow checker is intended to protect against "temporal memory unsafety". It can tell you that you are using something that has already been freed, or something that could be freed while you are using it for example. Bounds checking is a "spatial memory unsafety" problem, it has nothing to do with bo…

Does it not provide some protection against a buffer overflow?

Re: The first stable release of a memory safe sudo implementation

#179
post #60

As one of the original creators of sudo ( https://en.wikipedia.org/wiki/Sudo ) I've witnessed it getting nearly totally rewritten and then incrementally bug-fixed over the last 43 years. It must take the prize for the UNIX command most highly-scrutinized for security flaws. Flaws which have been identified and fixed. Thousands of developers and security experts have gone over it. So part of me wonders - how is it pos…

I can only thank you for the work you've done in creating sudo, I think it's an invaluable tool in the general day to day use for so many people. As someone working on sudo-rs, our goal with creating it never was to invalidate any of the work previously done, and we are very much aware that our implementation will not be bug free, especially not at the start.

For me personally, creating this Rust version allowed me to work on something that I would normally not be able to work on, given how I would not rate my confidence in writing relatively safe C code very high. If nothing else, at least we already found a few bugs in the original sudo because of this work. Despite the 43 years of bugfixing, such a piece of software is unlikely to ever be free of bugs, even if just for the changing surroundings.

Other than that, having some alternatives can never hurt, as long as we keep cooperating and trying to learn from each others work (and from each others mistakes).

Re: The first stable release of a memory safe sudo implementation

#180
post #108

Earlier quoted context omitted.

> As annoying as it is to have to update every sudo reference -> doas, it forces you to think about everywhere you're using it, rather than waiting to see what breaks and then trying to fix it. In my scripts I never call sudo or doas. Instead, if the script needs to do something as root, I write the whole script so that it expects to itself be run as root. And then when I want to run my script, I run it as root doas…

I just constantly run as root since there is always a chance that I might need root permissions for something. /s

[deleted]
Post reply on HN