On GNU/Linux systems that are build using RPM packages, the rpmlint utility complains about programs that don't call setgroups before setuid.
The idea is that before dropping privileges, a process should also drop the list of supplementary group ID's with setgroups(0, NULL).
However, is this something that should always be done?
Suppose that we are running setuid root, and are carrying a list of supplementary group ID's from our original security context: the groups associated with the real user ID.
When we drop back to that real user ID, we don't necessarily want to lose those groups: code executing as the original user may depend on those supplementary memberships being in place, right?
Should we not omit setgroups(0, NULL) in setuid code before dropping privs to the original user?
(By the way, of course we don't drop privileges with setuid on Linux because that doesn't work for code running setuid non-root.)
setgroupswith a single non-zero gid (beforesetuidof course). – Polynomial May 02 '16 at 21:27rpmlintis purely about order? That is to say, it is saying that you have both setgroups and setuid in the program, but apparently in the wrong order? – Kaz May 02 '16 at 21:28setuidto the current user who ran the binary. That user isn't in the X11 group. Now that user, through that process, has access to X11 when it didn't before. Callingsetgroupswith a single group (that of the target user) removes this issue. – Polynomial May 02 '16 at 21:36root(uid 0) to provide it with administrative privileges on a particular feature on a service which doesn't give root administrative access by default. A binary which is setuid and owned by root will now have access to that group's privilege. If it doesn't drop that group, it will drop privilege to the uid of the user it callssetuidon, but still have access to that group due to the ancillary groups. By callingsetgroupsfirst it can properly drop that additional privilege. – Polynomial May 02 '16 at 21:40SeDebugPrivilege. – Polynomial May 02 '16 at 21:41setuidit doesn't do anything to the gids; you have to change that yourself. By callingsetgroupsyou can clear the stored gid and ancillary gids properly. Without doing that, your process still runs at the same effective gid as before. – Polynomial May 02 '16 at 21:45setgroupshaving any effect on the effective or saved gid, only the list. (experimentation confirms it). I'm afraid I don't follow most of what you're saying, but the references in your answer are useful. I wouldn't usesetgroupsfor the side effect of manipulating the real/stored/effectivegids; for that I havesetresgid. I wouldn't usesetresgidunless the program is running setgid. – Kaz May 02 '16 at 21:55setgroupswith a single group, versus an emptysetgroup; I can open a new question for that, though. (Maybe an emptysetgroupsdoesn't work on some Unixes?) – Kaz May 02 '16 at 22:00