DO_SETRESUID(9)

πŸ“¦ version 11.0, in nixpkgs unstable

πŸ’… do_setresuid, do_setresgid πŸ’…

okay so bestie, this is the DO_SETRESUID(9) page from the Kernel Developer's Manual β€” section 9, kernel-dev land. It's all about setting a process's uid and gid, and yes, it's giving very specific kernel-internals main character energy. Let's get into it. 🫢


✨ NAME ✨

do_setresuid, do_setresgid β€” set process uid and gid

🌸 SYNOPSIS 🌸

#include <sys/ucred.h>

int
do_setresuid(struct lwp *lwp, uid_t ruid, uid_t euid, uid_t svuid,
    u_int flags);

int
do_setresgid(struct lwp *lwp, uid_t ruid, uid_t euid, uid_t svuid,
    u_int flags);

πŸ¦‹ DESCRIPTION πŸ¦‹

The do_setresuid and do_setresgid functions are used to implement the various system calls that allow a process to change its real, effective, and saved uid and gid values. Yes, the whole trio: real, effective, saved. We love a complete set. πŸ’–

The do_setresuid function sets the specified process's real user ID to ruid, its effective user ID to euid, and its saved user ID to svuid. If any of the uid arguments are -1 then that assignment is skipped. Iconic "nope, not touching that one" behavior. πŸ™ˆ

If suser() is true, then any values may be assigned, otherwise the new uid values must match one of the existing values and the caller must have set the relevant bit in flags. So privileged folks get the full menu, and everyone else gets the matching-values combo meal. πŸ”₯

The flags argument specifies which of the existing uid values the new value must match. It should be set to a logical OR of ID_{R,E,S}_EQ_{R,E,S}, where ID_E_EQ_R means that it is valid to set the effective ID to the current value of the real ID. That naming is very "iykyk" β€” the page literally gives you the example with ID_E_EQ_R. πŸŽ€

Lowkey important: flags is the whole vibe check for which existing uid value the new value is allowed to match, so it should be that logical OR of ID_{R,E,S}_EQ_{R,E,S}, periodt. Don't just freestyle it and hope for the best. πŸ’…

The do_setresgid function sets the group IDs but otherwise behaves in the same manner as do_setresuid. The process's group list is neither examined nor effected. That's the exact word from the original page β€” we keep the lore, okay? 😭

πŸ” CODE REFERENCES πŸ”

These functions are implemented in: sys/kern/kern_prot.c.

πŸ‘€ SEE ALSO πŸ‘€

πŸ“œ HISTORY πŸ“œ

Implemented for NetBSD 2.0 to replace ad-hoc code in each system call routine and in the various compat modules. Honestly? A cleanup era. We stan replacing scattered copy-pasted chaos with one shared implementation. πŸ‘‘


okay that's the whole page, bestie β€” no cap, every arg, flag, path, and SEE ALSO made it in. πŸ’–

this cutie came from the Debian version of the page, dated September 28, 2003. yes, 2003. vintage. πŸŽ€

πŸ“¦ where this page comes from