You are not logged in.

#1 2018-03-18 11:45:51

andrzej1_1
Member
Registered: 2017-09-07
Posts: 50

[SOLVED] Incorrect effective UID

Hello! I am experiencing issues with ids, which are not correct. Consider simple program:

#include <stdio.h>
#include <unistd.h>

int main(void) {
    printf(
        "         UID           GID  \n"
        "Real      %d  Real      %d  \n"
        "Effective %d  Effective %d  \n",
             getuid (),     getgid (),
             geteuid(),     getegid()
    );

seteuid(600);
    printf(
        "         UID           GID  \n"
        "Real      %d  Real      %d  \n"
        "Effective %d  Effective %d  \n",
             getuid (),     getgid (),
             geteuid(),     getegid()
    );

setuid(1000);

    printf(
        "         UID           GID  \n"
        "Real      %d  Real      %d  \n"
        "Effective %d  Effective %d  \n",
             getuid (),     getgid (),
             geteuid(),     getegid()
    );

setuid(0);
    printf(
        "         UID           GID  \n"
        "Real      %d  Real      %d  \n"
        "Effective %d  Effective %d  \n",
             getuid (),     getgid (),
             geteuid(),     getegid()
    );

    return 0 ;       
}

Usage:

andew@archPC$ cd /tmp
andew@archPC$ gcc test.c -o test
andew@archPC$ sudo chown root:root test
andew@archPC$ sudo chmod u+s test
andew@archPC$ ls -al
-rwxr-xr-x  1   4755 root  9984 Mar 18 12:27  test
andew@archPC$ ./test
         UID           GID  
Real      1000  Real      100  
Effective 1000  Effective 100  
         UID           GID  
Real      1000  Real      100  
Effective 1000  Effective 100  
         UID           GID  
Real      1000  Real      100  
Effective 1000  Effective 100  
         UID           GID  
Real      1000  Real      100  
Effective 1000  Effective 100

As you can see effective ids are not changed, even though s-bit is set and setuid is executed.

I am wondering is it kernel bug or my system configuration is mixed. Could you check result on your machines?

Solved:
This behaviour is casued by nosuid mount option in /tmp. More info: https://unix.stackexchange.com/question … -directory

Last edited by andrzej1_1 (2018-03-18 12:57:37)

Offline

Board footer

Powered by FluxBB