Page 1 of 1

Which UIDs should setuid attribute set?

Posted: Sat Apr 04, 2015 4:19 pm
by mariuszp
I tried googling this and all i'm getting is that the setuid attribute shall set the user to the owner. But which UIDs should I actually set? Just the effective UID? Or also the real UID and saved-set-UID?

I'm guessing that it should be just effective, because otherwise programs like "sudo" wouldn't be able to tell who started them. But then again, the real UID must be set for things like "kill" to work.

So how am I supposed to do this? Also please give me a source if possible, because I actually cannot find what POSIX says about this (looking at some sudo code, it seems to assume that the real UID is of the user who actually started the process).

Re: Which UIDs should setuid attribute set?

Posted: Mon Apr 06, 2015 5:10 am
by jnc100
It sets all 3. seteuid() was designed to just set the effective uid. See the notes here for more info on how to handle the case of kill().

Regards,
John.

Re: Which UIDs should setuid attribute set?

Posted: Tue Apr 07, 2015 5:40 am
by mariuszp
I know that setuid() function sets all 3, i was asking about the setuid attribute (mask 04000). Thats the one that executables like sudo need to get root permissions.

Re: Which UIDs should setuid attribute set?

Posted: Tue Apr 07, 2015 8:51 am
by jnc100
Apologies, I should read more carefully. The same reference holds however (see the discussion of System V in the rationale) however it acts like the 2nd case, i.e. being called by an unprivileged user and only sets the effective uid (also see here).

kill requires that the real or effective uid of the sending process is equal to the real or saved setuid of the receiving process (or that kill is run as root), thus just setting the effective uid should also work.

Regards,
John.