jpmh
jpmh

Reputation: 11

Not understanding setuid

I created a VERY simple script:

//#escalate.c - a setuid utility so that we can call shutdown
//# and other things safely without needing root access.  We 
//# do need to:
//#   gcc escalate.c -o escalate.out
//#   sudo chown root:root escalate.out
//#   sudo chmod 4755 escalate.out

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>

int main()
{
    int status;
    status = setuid( 0 );   // you can set it at run time also
    system("date > /tmp/date.fil");
    return errno;
 }

On Raspian it generates the file in /tmp, owned by the root and returns 0 as expected.

On Ubuntu 22 it created the file owned by ME and the return status is 1. What am I missing about setuid(0); ?

I tried creating, modifying the permissions and ownership etc. On Raspian it works like a charm, on Ubuntu it does not.

================== OK - solved it myself. On Ubuntu I was running with an encrypted home and so it was mounted with nosuid set.

Upvotes: 0

Views: 86

Answers (1)

jpmh
jpmh

Reputation: 11

the problem was that the file system was mounted nosuid

Upvotes: 1

Related Questions