The program cannot load after setting the setuid bit

Consider this scenario in which the A.bin executable uses libY.so and libZ.so. Ac, Yc and Zc are all written to CZc and Yc are compiled into the corresponding .so files.

This is the file directory structure

$ HOME / bin / A.bin $ Home /Library/libY.so $ Home /Library/libZ.so

When I start A.bin as a regular user, A.bin works fine as expected. Note: $ LD_LIBRARY_PATH contains $ home / lib

I changed the code in Ac by adding some features that need administrator privileges (for example, binding to a port of less than 1000). I set the setuid bit for A.bin, libY.so and libZ.so in rwsrwsrws and change the ownership of the files to root. When I try to start A.bin, I get the following error:

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

When I simply remove the setuid permission from all of these files, then the binary runs, except for those functions that are not executed, need root privileges.

How to solve this problem?

Edit: OS - Solaris 5.10

+6
c unix permissions setuid shared-objects
source share
2 answers

As AProgrammer said when running setuid programs, $ LD_LIBRARY_PATH is ignored. Therefore, the path must be hardcoded in the executable itself, using this flag when linking

gcc -R $ home / lib

The -R flag creates a list of execution paths into an executable file.

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

+10
source share

On some Unix variants, suid executables have some security features, such as ignoring LD_LIBRARY_PATH , checking ownership and access to executable and shared libraries ... I don't remember the case with Solaris, but you should probably make sure.

+3
source share

All Articles