Please read this long intro to understand my concern for why we need the SUID permission for executable binary file.
- A process in Linux uses its EUID to know the effective User ID of itself.
- This user's permission is used to decide how this process interacts with other files (ex. whether this process can write to a file)
Consider the scenario with changing password via
Real life Linux
- Passwords are stored in
/etc/shadow. This file belongs to
rootwith permission (
rwx--x--x, this means only root can change the logic of passwd program.
userAruns the program, a
passwdprocess starts with RUID = EUID = userA
Result is: the program will run. A
passwd process is started but it won't be able to change the password since its EUID is userA and userA can't write to
This is when the need for SUID permission arrives. SUID allows setting EUID of a process upon execution of a binary to create that process. the EUID will be set to the owner of that binary file.
- Setting SUID permission for owner of
/usr/bin/passwdmakes EUID of any
passwdprocess started by any user takes the EUID of
rootcan write to
/etc/shadow, any user can use the
passwdprogram to start a
passwdprocess which can make changes to
There is SUID permission because in Linux, EUID of a process is not hard set to the owner of the executable binary file (which when run, will create that process)
My ideal Linux
No need for SUID permission. If executable file binA is created (and owned) by userA, any users who can execute binA will create a process with EUID = userA.
In the context of the changing password scenario, the logic of this idea is as follows:
- root is the owner of
/usr/bin/passwdand only root can change its logic.
- The logic inside
/usr/bin/passwdlets a user change its password only and not others'.
- Other users can't modify
/usr/bin/passwd, only root can.
/etc/shadowcan only be writen to by
Result is: An unprivileged user
userA can execute
$passwd. He will create a
passwd process. This process has EUID = root so it can write to the
With this theory, we can achieve: everyone can change their own password (and only their own password) without SUID permission.