Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Program can't load after setting the setuid bit on

Consider this scenario in which an executable A.bin uses libY.so and libZ.so. A.c, Y.c and Z.c are all written in C. Z.c and Y.c are compiled into respective .so files.

This is the directory structure of the files

$home/bin/A.bin $home/lib/libY.so $home/lib/libZ.so

When I run A.bin as normal user, A.bin runs normally as expected. Note: $LD_LIBRARY_PATH contains $home/lib

I changed some code in A.c adding some functionality which needs admin privileges(like binding to a port less than 1000). I set the setuid bit for A.bin, libY.so and libZ.so to rwsrwsrws, and change the ownership of the files to root. When I try to run A.bin, I get the following error

ld.so.1: A.bin: fatal: libY.so: open failed: No such file or directory Killed

When I just remove the setuid permission from all those files, then the binary runs except for the functionality fails where it needs root privileges.

How to overcome this problem ?

Edit: The OS is Solaris 5.10

like image 565
Saradhi Avatar asked Aug 21 '09 07:08

Saradhi


People also ask

What happens when a program runs with the setuid bit on?

The setuid bit simply indicates that when running the executable, it will set its permissions to that of the owner, instead of setting it to the user who launched it.

How do I run a program as setuid root?

use setuid to run an executable as root If we run ls -l ./main again we'll see an s where an x used to be in the user column. When this binary is run by any user the executable will actually be run as the owner of the file! Since root owns the file the executable will run as root.

How do I enable setuid bit?

Setting the setuid bit We can use chmod to set the setuid bit. Like with other permissions, it can be done symbolically or using octal values (numbers 0-7). To set the setuid bit symbolically, we can use chmod u+s </path/to/the/file>.

What security problems a setuid root program may cause?

setuid and setgid files are dangerous because they might give an unauthorized user root access, or at least access to run a program in another user's name.


1 Answers

As AProgrammer said, while executing setuid programs, $LD_LIBRARY_PATH is ignored. Hence the path has to be hardcoded in the executable itself using this flag while linking

gcc -R $home/lib

The -R flag builds runtime search path list into executable.

Reference: http://www.justskins.com/forums/loading-shared-libraries-from-a-setuid-program-116597.html

like image 58
Saradhi Avatar answered Oct 05 '22 19:10

Saradhi