I am relatively new to the concepts mentioned in the question and reading about them from different sources only makes them more confusing. So this is what I understood so far:
When we are given permissions for a file, they look like this:
-rwsr-xr-- 1 user1 users 190 Oct 12 14:23 file.bin
We assume that a user user2
who is in the group users
tries to execute file.bin
. If the setuid bit were not set, this would mean that both the RUID and EUID of file.bin
were equal to the UID of user2
. But since the setuid bit is set, this means that the RUID is now equal to the UID of user2
, while EUID is the UID of the owner of the file, user1
.
My questions are:
- What is the difference between the owner of the file and
root
? Doesroot
have the same permissions as the owner? Or would we need a separate entry in the permissions list forroot
? - Difference between RUID and EUID?
- As I understand it the RUID and EUID are applied only to processes. If that is the case, why do they have the value of user id's?
- If RUID is the user who creates the process, and EUID is the user who is currently running the process, then the first sentence of the first answer in this question does not make any sense to me.
- Did I understand correctly what the setuid bit does?
setuid
bit set. – jcbermu Mar 23 '15 at 14:23root
) can set EUID and RUID to arbitrary values (for example, thelogin
,su
, andsudo
programs do that). Generally, once a privileged process changes its UIDs to non-zero values, it is no longer privileged and cannot becomeroot
again. See the man pages setuid(2), seteuid(2), and setreuid(2). – Scott - Слава Україні Mar 23 '15 at 19:55fork
. This creates a new process, that is a clone of the original, but different PID, and the child returns 0 from fork (parent returns child's pid). Then there isexec
this reads a program from disk and executes it. This is the sys-call that allows to gain a UID (or capability), as you describe.exec
does not create a new process, it replaces the code of the existing process. – ctrl-alt-delor Sep 06 '18 at 18:38euid = ruid
assignment allows you to copy real to effective, while leaving real alone. The saved UID lets a process copy the real UID to the effective UID (i.e., restore the effective UID to the ID of the user who is running the command) *and then* set the effective UID to the UID of the executable file again. (3) That other UID that you mention is properly called file system user ID (fsuid); … (Cont’d) – Scott - Слава Україні Sep 06 '18 at 20:08setfsuid()
is nowadays unneeded and should be avoided in new applications.” – Scott - Слава Україні Sep 06 '18 at 20:09