Group privileges are dropped after the user id, when the process may no longer change them
What it finds
setuid(user); setgid(group);: once the user id is no longer root, the process may not change its group ids any more, so the second call fails and the process keeps the group of root. Groups are dropped first, then the user.
In one function, a call of setgid, setregid, setresgid, setgroups or initgroups must come after a call of setuid, setreuid or setresuid whose argument is not the literal 0, which would take root back rather than drop it, nor -1, which leaves that id as it is. A group call whose own statement goes on to drop the user, as setgroups(...) || setresgid(...) || setresuid(...), is in the right order and is not reported, whatever ran before it on another path.
From the rule's source, group_dropped_after_user.rs.
#include <unistd.h> void drop(uid_t uid, gid_t gid){ setuid(uid); setgid(gid);tx0 reports: setgid comes after setuid} void right(uid_t uid, gid_t gid){ setgid(gid); setuid(uid);} void regain(gid_t gid){ setuid(0); setgid(gid);} int revoke(int ouid, uid_t uid, gid_t gid){ if (ouid && (setgid(gid) || setuid(uid))) return 1; if (ouid == 0 && (setgid(gid) || setuid(uid))) return 1; return 0;} void restore(uid_t saved_uid, gid_t saved_gid){ setreuid(saved_uid, -1); setregid(saved_gid, -1);} Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/c:group-dropped-after-user" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/c:group-dropped-after-user] reason="..."tx0 explain tx0/c:group-dropped-after-user shows the same in the terminal. Found a false positive? Report it.