Explanation for newbies: setuid is a special permission bit that makes an executable run with the permissions of its owner rather than the user executing it. This is often used to let a user run a specific program as root without having sudo
access.
If this sounds like a security nightmare, that’s because it is.
In linux, setuid is slowly being phased out by Capabilities. An example of this is the ping
command which used to need setuid in order to create raw sockets, but now just needs the cap_net_raw
capability. More info: https://unix.stackexchange.com/questions/382771/why-does-ping-need-setuid-permission. Nevertheless, many linux distros still ship with setuid executables, for example passwd
from the shadow-utils
package.
Yes, Xorg being suid is stupid. That used to be needed due to several historical reasons, but is not any more.
But for ‘su’ or ‘sudo’ suid is still the right mechanism to use. Capabilities won’t help, when the tool is supposed to give one full privileges. Of course, in some use cases no such command is needed, then the system can run with no suid. Similar functionality could be implemented without suid too (e.g. ssh to localhost), but with its own security implications, usually bigger than those brought but a mechanism as simple as suid (the KISS rule).