I find that the existing answers to not actually answer the question in a straightforward way:
LD_RUN_PATH
is used by the linker (see ld
) at the time you link your software. It is used only if you have no -rpath ...
on the command line (-Wl,rpath ...
on the gcc command line). The path(s) defined in that variable are added to the RPATH
entry in your ELF binary file. (You can see that RPATH
using objdump -x binary-filename
—in most cases it is not there though! It appears in my development binaries, but once the final version gets installed RPATH
gets removed.)
LD_LIBRARY_PATH
is used at runtime, when you want to specify a directory that the dynamic linker (see ldd
) needs to search for libraries. Specifying the wrong path could lead to loading the wrong libraries. This is used in addition to the RPATH
value defined in your binary (as in 1.)
LD_RUN_PATH
really causes no security threat unless you are a programmer and don't know how to use it. As I am using CMake to build my software, the -rpath
is used all the time. That way I do not have to install everything to run my software. ldd
can find all the .so files automatically. (the automake environment was supposed to do that too, but it was not very good at it, in comparison.)
LD_LIBRARY_PATH
is a runtime variable and thus you have to be careful with it. That being said, many shared object would be really difficult to deal with if we did not have that special feature. Whether it is a security threat, probably not. If a hacker takes a hold of your computer, LD_LIBRARY_PATH
is accessible to that hacker anyway. What could happen is that you use the wrong path(s) in that variable, your binary may not load, but if it loads you may end up with a crashing binary or at least a binary that does not work quite right. One concern is that over time you get new versions of the library and you are likely to forget to remove the LD_LIBRARY_PATH
which means you may be using an unsecure version of the library.
The one other possibility for security is if the hacker installs a fake library of the same name as what the binary is searching, library that includes all the same functions, but that has some of those functions replaced with sneaky code. He can get that library loaded by changing the LD_LIBRARY_PATH
variable. Then it will eventually get executed by the hacker. Again, if the hacker can add such a library to your system, he's already in and probably does not need to do anything like that in the first place (since he's in he has full control of your system anyway.) Because in reality, if the hacker can only place the library in his account he won't do anything much (unless your Unix box is not safe overall...) If the hacker can replace one of your /usr/lib/...
libraries, he already has full access to your system. So LD_LIBRARY_PATH
is not needed.