Using setuid to relinquish root rights
Hello,
I'm running a Xenomai (3.1) app, that comprises both realtime xenomai thread and plain linux threads. The app starts as root so as to be able to bind <1024 tcp sockets.
After initialisation of the sockets and RT IPCs, I would like to reliquinsh root rights, by calling setuid.
After that call, I get lots of syscall <56> denied to "One of my RT thread" and syscall <61> denied to "One of my RT thread".
I figured out I had to set the CAP_SYS_NICE capability to the app before, so I added caps = cap_get_proc();cap_set_flag(caps, CAP_EFFECTIVE, 1, cap_list, CAP_SET); cap_set_proc(caps);prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0);
Without success. Morevover, the user that I set the uid to has group xenomai as primary group plus I do echo 1000 > /sys/module/xenomai/parameters/allowed_group before running the app, but still.
Anybody can point me in the right direction.
Thanks in advance
François
Quoted 14 lines · François Legal
Hello,
I'm running a Xenomai (3.1) app, that comprises both realtime xenomai thread and plain linux threads. The app starts as root so as to be able to bind <1024 tcp sockets.
After initialisation of the sockets and RT IPCs, I would like to reliquinsh root rights, by calling setuid.
After that call, I get lots of syscall <56> denied to "One of my RT thread" and syscall <61> denied to "One of my RT thread".
I figured out I had to set the
CAP_SYS_NICEcapability to the app before, so I added caps =cap_get_proc();cap_set_flag(caps, CAP_EFFECTIVE, 1, cap_list, CAP_SET);cap_set_proc(caps);prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0);
Quoted 4 lines
Without success. Morevover, the user that I set the uid to has group xenomai as primary group plus I do echo 1000 >
/sys/module/xenomai/parameters/allowed_groupbefore running the app, but still.Anybody can point me in the right direction.
We may have regressions here as this configuration is not systematically tested. From your description and me read-up of our current logic, this is supposed to work fine.
Can you debug the kernel logic in more details, check, if the cap is raised properly during the xenomai bind syscall and if we are later on checking it correctly? Maybe some other condition that the cap if failing, though I don't see yet which one.
Jan
Signature · 2 lines
Siemens AG, Technology Competence Center Embedded Linux
Quoted 20 lines · Jan Kiszka
Quoted 14 lines · François Legal
Hello,
I'm running a Xenomai (3.1) app, that comprises both realtime xenomai thread and plain linux threads. The app starts as root so as to be able to bind <1024 tcp sockets.
After initialisation of the sockets and RT IPCs, I would like to reliquinsh root rights, by calling setuid.
After that call, I get lots of syscall <56> denied to "One of my RT thread" and syscall <61> denied to "One of my RT thread".
I figured out I had to set the
CAP_SYS_NICEcapability to the app before, so I added caps =cap_get_proc();cap_set_flag(caps, CAP_EFFECTIVE, 1, cap_list, CAP_SET);cap_set_proc(caps);prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0);Quoted 4 lines
Without success. Morevover, the user that I set the uid to has group xenomai as primary group plus I do echo 1000 >
/sys/module/xenomai/parameters/allowed_groupbefore running the app, but still.Anybody can point me in the right direction.
Quoted 9 lines
We may have regressions here as this configuration is not systematically tested. From your description and me read-up of our current logic, this is supposed to work fine.
Can you debug the kernel logic in more details, check, if the cap is raised properly during the xenomai bind syscall and if we are later on checking it correctly? Maybe some other condition that the cap if failing, though I don't see yet which one.
Hello,
I won't be able to this before begining of next month, however, I would need some pointers on what to look for and where. I have to tell that I've never used capabilities before.
François
Quoted 5 lines
Jan
--
Siemens AG, Technology
Competence Center Embedded Linux
Quoted 24 lines · Jan Kiszka
Quoted 14 lines · François Legal
Hello,
I'm running a Xenomai (3.1) app, that comprises both realtime xenomai thread and plain linux threads. The app starts as root so as to be able to bind <1024 tcp sockets.
After initialisation of the sockets and RT IPCs, I would like to reliquinsh root rights, by calling setuid.
After that call, I get lots of syscall <56> denied to "One of my RT thread" and syscall <61> denied to "One of my RT thread".
I figured out I had to set the
CAP_SYS_NICEcapability to the app before, so I added caps =cap_get_proc();cap_set_flag(caps, CAP_EFFECTIVE, 1, cap_list, CAP_SET);cap_set_proc(caps);prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0);Quoted 4 lines
Without success. Morevover, the user that I set the uid to has group xenomai as primary group plus I do echo 1000 >
/sys/module/xenomai/parameters/allowed_groupbefore running the app, but still.Anybody can point me in the right direction.
We may have regressions here as this configuration is not systematically tested. From your description and me read-up of our current logic, this is supposed to work fine.
Quoted 7 lines
Can you debug the kernel logic in more details, check, if the cap is raised properly during the xenomai bind syscall and if we are later on checking it correctly? Maybe some other condition that the cap if failing, though I don't see yet which one.
Jan
I could take some time to see what happens. I probably had a problem in my capability setting code. For reference, this is my understanding of what has to be done :
Set the KEEPCAPS security bit
Relinquish root rights
Set the CAP_SYS_NICE capability
After this sequence, the CAP_SYS_NICE is correctly set in the process (you can tell by checking CapEff in /proc/[pid]/status)
However, I seem to have a chicken and egg problem here.
Reliquinshing of root rights is done after IPCs and thread creation, so my thread are running. The problem is that as soon as setuid is called, then every thread using IPCs start running round as the call to IPC functions return error, and it seem the main thread never get to be scheduled to set the CAP_SYS_NICE bit.
If I try to relinquish root rights after my IPCs are created but before the threads are created, I get an error while creating the threads. If I try to raise the main thread priority before doing the sequence, it does not work (pthread_setschedparam_ex returns 20)
Does all this means I have to do the root rights relinquish sequence in the thread with the highest priority ?
Thanks
François
Quoted 3 lines
--
Siemens AG, Technology
Competence Center Embedded Linux
Quoted 43 lines · François Legal
Quoted 24 lines · Jan Kiszka
Quoted 14 lines · François Legal
Hello,
I'm running a Xenomai (3.1) app, that comprises both realtime xenomai thread and plain linux threads. The app starts as root so as to be able to bind <1024 tcp sockets.
After initialisation of the sockets and RT IPCs, I would like to reliquinsh root rights, by calling setuid.
After that call, I get lots of syscall <56> denied to "One of my RT thread" and syscall <61> denied to "One of my RT thread".
I figured out I had to set the
CAP_SYS_NICEcapability to the app before, so I added caps =cap_get_proc();cap_set_flag(caps, CAP_EFFECTIVE, 1, cap_list, CAP_SET);cap_set_proc(caps);prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0);Quoted 4 lines
Without success. Morevover, the user that I set the uid to has group xenomai as primary group plus I do echo 1000 >
/sys/module/xenomai/parameters/allowed_groupbefore running the app, but still.Anybody can point me in the right direction.
We may have regressions here as this configuration is not systematically tested. From your description and me read-up of our current logic, this is supposed to work fine.
Quoted 7 lines
Can you debug the kernel logic in more details, check, if the cap is raised properly during the xenomai bind syscall and if we are later on checking it correctly? Maybe some other condition that the cap if failing, though I don't see yet which one.
Jan
I could take some time to see what happens. I probably had a problem in my capability setting code. For reference, this is my understanding of what has to be done :
Set the KEEPCAPS security bit
Relinquish root rights
Set theCAP_SYS_NICEcapabilityAfter this sequence, the
CAP_SYS_NICEis correctly set in the process (you can tell by checking CapEff in /proc/[pid]/status)
Quoted 9 lines
However, I seem to have a chicken and egg problem here.
Reliquinshing of root rights is done after IPCs and thread creation, so my thread are running. The problem is that as soon as setuid is called, then every thread using IPCs start running round as the call to IPC functions return error, and it seem the main thread never get to be scheduled to set the
CAP_SYS_NICEbit.If I try to relinquish root rights after my IPCs are created but before the threads are created, I get an error while creating the threads. If I try to raise the main thread priority before doing the sequence, it does not work (
pthread_setschedparam_exreturns 20)Does all this means I have to do the root rights relinquish sequence in the thread with the highest priority ?
I just tried that too, and it does not work either. The other thread seem to be running round on failing IPC (semaphore in my test case) calls.
Quoted 9 lines
Thanks
François
Quoted 3 lines
--
Siemens AG, Technology
Competence Center Embedded Linux
Quoted 49 lines · François Legal
Quoted 47 lines · François Legal
Quoted 24 lines · Jan Kiszka
Quoted 14 lines · François Legal
Hello,
I'm running a Xenomai (3.1) app, that comprises both realtime xenomai thread and plain linux threads. The app starts as root so as to be able to bind <1024 tcp sockets.
After initialisation of the sockets and RT IPCs, I would like to reliquinsh root rights, by calling setuid.
After that call, I get lots of syscall <56> denied to "One of my RT thread" and syscall <61> denied to "One of my RT thread".
I figured out I had to set the
CAP_SYS_NICEcapability to the app before, so I added caps =cap_get_proc();cap_set_flag(caps, CAP_EFFECTIVE, 1, cap_list, CAP_SET);cap_set_proc(caps);prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0);Quoted 4 lines
Without success. Morevover, the user that I set the uid to has group xenomai as primary group plus I do echo 1000 >
/sys/module/xenomai/parameters/allowed_groupbefore running the app, but still.Anybody can point me in the right direction.
We may have regressions here as this configuration is not systematically tested. From your description and me read-up of our current logic, this is supposed to work fine.
Quoted 7 lines
Can you debug the kernel logic in more details, check, if the cap is raised properly during the xenomai bind syscall and if we are later on checking it correctly? Maybe some other condition that the cap if failing, though I don't see yet which one.
Jan
I could take some time to see what happens. I probably had a problem in my capability setting code. For reference, this is my understanding of what has to be done :
Set the KEEPCAPS security bit
Relinquish root rights
Set theCAP_SYS_NICEcapabilityAfter this sequence, the
CAP_SYS_NICEis correctly set in the process (you can tell by checking CapEff in /proc/[pid]/status)However, I seem to have a chicken and egg problem here.
Reliquinshing of root rights is done after IPCs and thread creation, so my thread are running. The problem is that as soon as setuid is called, then every thread using IPCs start running round as the call to IPC functions return error, and it seem the main thread never get to be scheduled to set the
CAP_SYS_NICEbit.
Quoted 8 lines
Quoted 5 lines
If I try to relinquish root rights after my IPCs are created but before the threads are created, I get an error while creating the threads. If I try to raise the main thread priority before doing the sequence, it does not work (
pthread_setschedparam_exreturns 20)Does all this means I have to do the root rights relinquish sequence in the thread with the highest priority ?
I just tried that too, and it does not work either. The other thread seem to be running round on failing IPC (semaphore in my test case) calls.
Can anybody help on this ?
I'm attaching my test case
Quoted 11 lines
Quoted 9 lines
Thanks
François
Quoted 3 lines
--
Siemens AG, Technology
Competence Center Embedded Linux