Especially in the Linux/POSIX world, daemons that need some root capabilities for temporary initialization purposes only (e.g., to read a root-owned private key file, or to open a port<1024, or to increase resource limits), often seem to follow a design pattern where they change their credentials with function calls such as setuid()
/setresuid()
and setgid()
/setresgid()
, and then call fork()
to run the actual program as its child. Supposedly the fork()
-ing is done "just in case", but what is or was the actual security consideration for doing so?
And to follow up on that, is that reason still relevant when (in addition to setgroups(0, NULL)
, setresgid(GID_NOBODY, GID_NOBODY, GID_NOBODY)
and setresuid(UID_NOBODY, UID_NOBODY, UID_NOBODY)
), the program is also proactively limiting Linux capabilities, by dropping every capability as soon as it is no longer needed, by calling cap_set_proc()
?