A program, pwrstat as an example, can be run by ordinary user IDs if the setuid (chmod 4xxx) is set and, the file is owned by root. When the setuid permission is set, the entity is run as if by the owner of the file. If that is root, it implies root's privileges. It should follow that if a shell has setuid and, is owned by root, it should run with root's privileges. An example would be
#!/bin/bash
cp $1 /var/aa.aa
Yet someone other than root running the example shell (with permission -rwsr-xr-x) gets permission denied on the copy.
OK, a program works, a shell doesn't. I tried creating a simple C program that uses
system ()
Same result.
The main question here is why setuid is not allowing a shell to be run as root. A sub-question is why a C program cannot issue the commands that would be in that shell?
Some of the high reputation users are voting to close this question as it is similar to previous questions EXCEPT, Those previous questions and answers are complex. Please don't forget many users here would probably get lost in the uids, setuid, seteuids and what-not which make sense to those who are probably ready to sit a linux adminstration certification exam.
The bit you are referring to allows whoever runs that item to run it as if they were the same id that owns the file. That does not mean any child process inherits the UID of original process.
In Ubuntu, things run as processes. Even what seem like system commands such as cp are really programs that run as processes. You may have noticed a large copy to the slow thumbdrive will show up in
top
orps -ef
as a process. So, while it is true the process with permissions 4755 might run as root, sub-processes will not. bash shell scripts initiate sub-processes to perform functions, such as move (mv) and copy (cp). Likewise a C program calling system() is really causing a sub-process and that sub-process, like the sub-processes in the bash script of the original question do not have root authority.Checkout some of the more basic commands of Ubuntu systems. cp is really running the program /usr/bin/cp.