简体   繁体   中英

Executable with set-user-ID-on-execution option doesn't set effective uid

Here is a program which shows euid:

$ cat main.c
#include <stdio.h>
#include <unistd.h>

int main(int argc, char** argv) {
  printf("euid: %d\n", geteuid());
  return 0;
}
$ gcc main.c -o main
$ ls -l main
-rwxr-xr-x 1 scdmb scdmb 6425 Mar 30 14:07 main

Let's set set-user-ID-on-execution option:

$ chmod u+s main
$ ls -l main
-rwsr-xr-x 1 scdmb scdmb 6425 Mar 30 14:07 main

Program executed as user scdmb shows right euid:

$ ./main
euid: 1000
$ id -u scdmb
1000

Let's execute program as other user:

$ id -u jakisuser
1001
$ su jakisuser
Password:

Now euid is the same as uid of user jakisuser:

$ ./main
euid: 1001

Why this set-user-ID-on-execution option doesn't cause that second time effective user id is not 1000 (as file owner) but 1001 (as the one who executes program)? Shouldn't it be the same as owner of file main ?

I've just tried this here and your program works perfectly.

What I suspect is happening is that you have apparmor or selinux or something else in the way which is preventing your SUID bit from taking effect. I suggest you disable those and try again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM