this post was submitted on 30 Apr 2024
78 points (92.4% liked)

Linux

5218 readers
5 users here now

A community for everything relating to the linux operating system

Also check out !linux_memes@programming.dev

Original icon base courtesy of lewing@isc.tamu.edu and The GIMP

founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] mikyopii@programming.dev 12 points 6 months ago (5 children)

Is there something wrong with doas? I thought doas was smaller with less of an attack surface.

[–] Kwdg@discuss.tchncs.de 8 points 6 months ago (1 children)

The only problem I found was, that it has no real alternative to sudoedit

[–] refalo@programming.dev 2 points 6 months ago (1 children)
[–] Kwdg@discuss.tchncs.de 0 points 6 months ago

Not really visudo is only to edit the sudoers file. sudoedit is a better way to edit system files.

  1. Temporary copies are made of the files to be edited with the owner. set to the invoking user.

  2. The editor specified by the policy is run to edit the temporary files. The sudoers policy uses the SUDO_EDITOR, VISUAL and EDITOR environment variables (in that order). If none of SUDO_EDITOR, VISUAL or EDITOR are set, the first program listed in the editor sudoers(5) option is used.

  3. If they have been modified, the temporary files are copied back to their original location and the temporary versions are removed.

[–] ericjmorey@programming.dev 4 points 6 months ago (1 children)

It seems Poettering is convinced doas, while decreasing attack surface, depends on SUID binary implementation which is a concern in its own right. Poettering is trying to eliminate that dependency in his `run0' implementation to reduce the attack surface even further.

The relevant excerpt from the long chain of posts from Poettering's mastodon.social account is copied below:

... led various people to revisit the problem and come up with alternatives: most prominently there's probably OpenBSD's sudo replacement called "doas". While it greatly simplifies the tool and removes much of the attack surface, it doesn't change one key thing: it's still a SUID binary.

I personally think that the biggest problem with sudo is the fact it's a SUID binary though – the big attack surface, the plugins, network access and so on that come after it it just make the key problem… … worse, but are not in themselves the main issue with sudo.

SUID processes are weird concepts: they are invoked by unprivileged code and inherit the execution context intended for and controlled by unprivileged code. By execution context I mean the myriad of properties that a process has on Linux these days, from environment variables, process scheduling properties, cgroup assignments, security contexts, file descriptors passed, and so on and so on. A few of these settings the kernel is nice…

… enough to clean up automatically when a SUID binary is invoked, but much of it has to be cleaned up by the invoked suid binary. This has to be done very very carefully, and history has shown that SUID binaries are generally pretty shit at that.

So, in my ideal world, we'd have an OS entirely without SUID. Let's throw out the concept of SUID on the dump of UNIX' bad ideas. An execution context for privileged code that is half under the control of unprivileged code and that needs careful, … … manual clean-up is just not how security engineering should be done in 2024 anymore.

With systemd v256 we are going one step towards this. There's a new tool in systemd, called "run0". Or actually, it's not a new tool, it's actually the long existing tool "systemd-run", but when invoked under the "run0" name (via a symlink) it behaves a lot like a sudo clone. But with one key difference: it's not in fact SUID. Instead it just asks the service manager to invoke a command or shell under…

… the target user's UID. It allocates a new PTY for that, and then shovels data back and forth from the originating TTY and this PTY.

Or in other words: the target command is invoked in an isolated exec context, freshly forked off PID 1, without inheriting any context from the client (well, admittedly, we do propagate $TERM, but that's an explicit exception, i.e. allowlist rather than denylist).

One could say, "run0" is closer to behaviour of "ssh" than to "sudo", in many ways. Except that…

it doesn't bother with encryption or cryptographic authentication, key management and stuff, but instead relies on the kernel's local identification mechanisms.

run0 doesn't implement a configuration language of its own btw (i.e. no equivalent of /etc/sudoers). Instead, it just uses polkit for that, i.e. how we these days usually let unpriv local clients be authorized by priv servers.

By isolating the contexts and the resources of client and target we remove some other classes of attacks…

… entirely, for example this stuff:

https://ruderich.org/simon/notes/su-sudo-from-root-tty-hijacking

But enough about all that security blabla. The tool is also a lot more fun to use than sudo.

Read the rest where he explains run0's use and functionality beyond the design logic.

[–] mikyopii@programming.dev 2 points 6 months ago

Thanks for the insight. I think I understand what he is trying to do but is a little too low-level for me to really grasp the technicalities.

[–] refalo@programming.dev 3 points 6 months ago (1 children)

it is. arguing attack surface with systemd IMO is a losing battle though.

[–] ericjmorey@programming.dev 2 points 6 months ago

Why do you say that? It seems that Poettering's reasoning for avoiding SUID binaries is sound.

[–] matcha_addict@lemy.lol 2 points 6 months ago

Some scripts or programs assume sudo by default. It's a stupid thing but also annoying.

[–] fourwd@programming.dev -2 points 6 months ago (1 children)

The main problem with sudo and doas is that they are not developed by Lennart. Seriously.

[–] refalo@programming.dev 1 points 6 months ago

I consider that a positive.