Linux Suid Program Not Preserve the Euid After Execv

Linux Suid Program Not Preserve the Euid After Execv

Here is my c code snippet from test.c.

printf("ruid:%d, euid:%d\n",getuid(),geteuid());
char *args[] = {"/bin/bash","-c","exec id",0};
execv("/bin/bash",args);

I compile the code with sudo gcc test.c -o test; sudo chmod +s ./test, so program test has suid bit and is owned by root.

printf outputs as espected, ruid:1000, euid:0, but the program id indicates ruid and euid are both 1000.

2
Sarah Jenkins
Author

Sarah Jenkins

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.