If I make a root privileged process impersonate some lesser user, and fork a child, is it safe to assume that the child has the user privileges, and nothing to do with the root? I'm using default custom made methods to imperosnate as the user and revert back to owner's creds (root). They are abstracted. But generally, these methods change the whole context of the process to that of the user's (may include uid, gid etc).
Asked
Active
Viewed 265 times
1 Answers
1
fork
doesn't change process ids, but exec
can. exec
ing will rewrite the saved-set uid with the current effective uid. The effective uid will be unchanged, unless the executable is a setuid executable, in which case it will be copied from the owner of the executable.
I think it's best to use something like:
int print_ids(void)
{
long ruid, euid, suid;
getresuid(&ruid, &euid, &suid);
return printf("%ld %ld %ld\n", ruid, euid, suid);
}
and print the uids in different contexts with different scenarios to verify in which context they change and in which they don't.

Petr Skocik
- 58,047
- 6
- 95
- 142