1
votes

I have a very simple program:

#define _GNU_SOURCE
#include<unistd.h>
#include<stdio.h>
#include<stdlib.h>

void error(char *msg) {
  printf(msg);
  exit(-1);
}

int main(int argc, char **argv) {
    uid_t ruid, euid, suid;

    if (getresuid(&ruid, &euid, &suid) < 0)
        error("Error getting process uids");

    printf("%d %d %d\n", ruid, euid, suid);
}

Compiled as follows:

gcc -o print print.c

Its owned by root, and has the setuid bit set:

-rwsrwxr-x 1 root root 8648 Oct 8 20:10 ./print*

However when I run it, I get the following permissions:

1000 1000 1000

So both the real, effective, and saved set-uid permissions are all me (1000) and not root. Has anyone ran into this? any advice?

2

2 Answers

1
votes

Ok, figured it out. The issue was that the binary was living in on an encrypted file system. (moving it to /tmp for example fixes it). Its worth noting that in mount the encrypted file system doesn't show nosuid.

-1
votes

Do you execute the code as root?

In your description, you said you ran it (not the root ran it). If so, getresuid() is expected to return "your" UID, e.g., the calling process's UID.

I ran the program on my "Ubuntu" machine (but actually the dist doesn't matter since it's a syscall) and get expected results. When I executed as root, I got "0 0 0" and when I executed as "myself", I got "1000 1000 1000"