Linux – Can a superuser process change the real user ID and group ID of a process, not matching those in the password file

grouplinuxusers

From APUE

The real user ID and real group ID of a process identify who we really are. These two fields are taken from our entry in the password file when we log in. Normally, these values don’t change during a login session, although there are ways for a superuser process to change them

Can a superuser process change the real user ID and real group ID of a process, so that the relation between the real user ID and real group ID doesn't match those in the password file? For example, if user Tim isn't a member of group ocean per the password file, can a superuser process change the real user ID and real group ID of a process to be Tim and ocean respectively?

Best Answer

Yes, a superuser process can change its real user ID and real group ID to any value it desires. The values in /etc/passwd and /etc/shadow are the configuration for what values should be set, but not a limitation of possible values.

Edit #1

It means programs like login will read the values from the files, so the files are configuration files or input files. They are not constraints on what a program can do. A superuser process can pass any value to the kernel, and the kernel will not check any files.

A program could call

setgid (54321);
setuid (12345);

and this would work, even if neither of the id's are mentioned in any file.

Related Question