Sample Header Ad - 728x90

effective vs real user ID : why doesn't it return root as effective ID in my example?

3 votes
1 answer
792 views
I did some reading about the difference between real and effective user ID. I thought I understood, but I have a doubt : according to my comprehension, in the example below the command $ id -un should return root as effective user, not jack :
$ sudo cp /usr/bin/bash /usr/bin/bashroot
$ sudo chmod u+s /usr/bin/bashroot
$ ls -l /usr/bin/bashroot 
-rwsr-xr-x 1 root root 1234376 oct.  25 15:42 /usr/bin/bashroot

$ bashroot

$ id -un
jack

$ id -unr
jack
bashroot has setuid and belongs to root, so according to my comprehension I expected $ id -un to return root, not jack. What do I miss ? [EDIT] More specifically, why doesn't /usr/bin/bashroot behave like /usr/bin/passwd, given that both have setuid ?
$ ls -l /usr/bin/passwd 
-rwsr-xr-x 1 root root 63960 févr.  7  2020 /usr/bin/passwd

$ ls -l /usr/bin/bashroot 
-rwsr-xr-x 1 root root 1234376 oct.  25 15:42 /usr/bin/bashroot

$ passwd
Changing password for jack.
Current password:
Then, in another terminal :
$ bashroot

$ ps -a | grep passwd
1682362 pts/3    00:00:00 passwd
$ ps -eo pid,ruid,euid | grep 1682362
1682362  1000     0

$ ps -a | grep bashroot
1682405 pts/4    00:00:00 bashroot
$ ps -eo pid,ruid,euid | grep 1682405
1682405  1000  1000
The effective UID of passwd is root (0), which is expected. Why is the effective UID of bashroot 1000 (jack) and not root ? [EDIT2 : OS]
$ cat /etc/debian_version 
11.6
$ uname -a
Linux d11work 5.10.0-20-amd64 #1 SMP Debian 5.10.158-2 (2022-12-13) x86_64 GNU/Linux
$ bash --version
GNU bash, version 5.1.4(1)-release (x86_64-pc-linux-gnu)
[EDIT3] See Stephen Kitt's answer :
$ bashroot -p

# id -un
root

# id -unr
jack
Asked by ChennyStar (1969 rep)
Oct 25, 2023, 02:55 PM
Last activity: Oct 26, 2023, 09:55 AM