Search code examples
c++clinuxroot

library (.so) with root privilege


I have a C++ program that uses some C libraries. The program is executed as an "unprivileged" user but one and only one function of a library (.so) loaded by the program need root privileges (it needs to write to /dev/mem).

Do exists a way to have only that function or only that library executed as root, leaving all the rest code "unprivileged"?

Thanks to all, Cristian


Solution

  • Start the program as root and open /dev/mem as a file. Then change user id to something less intrusive. The file will keep its original permissions.