setuid bit ignored ?

For Linux specific issues

setuid bit ignored ?

Postby X-Ryl669 » Sat May 08, 2010 2:07 pm

Hi,

I'm trying to run a Juce based software under a specific user-id so I've set the standard setuid bit on the executable.
This fails since Juce::Thread and juce::Process change back the user ID to the effective user (who's launching the process).
I wouldn't expect a library to deal with user ID at all (or if it does, I would expect it restore the previous state correctly, so it's transparent to the user).

Also, this seems wrong currently:
Code: Select all
void* threadEntryProc (void* value)
{
    // New threads start off as root when running suid
    Process::lowerPrivilege();

    juce_threadEntryPoint (value);
    return 0;
}

Here's an example code to show this:
Code: Select all
#include <unistd.h>
#include <sys/types.h>
#include <pthread.h>

void * threadEntryProc(void * value)
{
    printf("T e:%d, r:%d\n", geteuid(), getuid());
    while (1);
}

int main(int a, char ** b)
{
    printf("e:%d, r:%d\n", geteuid(), getuid());
        setreuid (geteuid(), getuid());
    printf("e:%d, r:%d\n", geteuid(), getuid());
    pthread_t t;
    pthread_create(&t, NULL, threadEntryProc, 0);
    while(1);
    return 0;
}

Gives (on setuid executable):
Code: Select all
e:0, r:1000
e:1000, r:0
T e:1000, r:0


So clearly the thread uid and euid is the same as the process itself.
Said differently, changing the uid and euid in a thread changes for the whole process, thus losing the setuid permission given to the executable.
X-Ryl669
X-Ryl669
JUCE UberWeenie
 
Posts: 1124
Joined: Sun Apr 24, 2005 5:30 pm

Re: setuid bit ignored ?

Postby jules » Sat May 08, 2010 2:26 pm

Well, I have to admit that I have no idea at all what that code was intended to do! I don't remember writing it, so think it must be left over from the original linux port, years ago, which was done by someone else, and which contained a few dodgy hacks... I thought I'd cleaned it all up by now, but I've clearly missed a couple of places, so thanks for pointing it out! There's a similar lowerPrivilege call in the startup code that I'll also remove.
User avatar
jules
Fearless Leader
 
Posts: 17216
Joined: Mon Sep 06, 2004 9:03 am
Location: London, UK

Re: setuid bit ignored ?

Postby X-Ryl669 » Sat May 08, 2010 2:28 pm

Great, thanks!
X-Ryl669
X-Ryl669
JUCE UberWeenie
 
Posts: 1124
Joined: Sun Apr 24, 2005 5:30 pm


Return to Linux

Who is online

Users browsing this forum: No registered users and 1 guest