Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can I not PRELOAD my own libc.so.6 to run a dynamic executable

I am trying to run a dynamic executable (xxx) but I am getting the following error:

$ ./xxx
./xxx: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by ./xxx)
./xxx: /lib64/libc.so.6: version `GLIBC_2.17' not found (required by ./xxx)

As the libc in the system in version 2.12 and is too old for my binary.

I have copied version 2.27 of libc which would work with this particular binary. If I try to run it using LD_PRELOAD:

$ LD_PRELOAD="./libc.so.6" ./xxx
ERROR: ld.so: object './libc.so.6' from LD_PRELOAD cannot be preloaded: ignored.
./xxx: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by ./xxx)
./xxx: /lib64/libc.so.6: version `GLIBC_2.17' not found (required by ./xxx)

The system is a RedHat 6 server:

$ uname -a
Linux platinum 2.6.32-754.3.5.el6.x86_64 #1 SMP Thu Aug 9 11:56:22 EDT 2018 x86_64 GNU/Linux

The same steps work instead on my Ubuntu 18.10 machine. Why am I prevented from proloading my own libc? Also, why couldn't ld.so provide a more comprehensive explanation as of why my libc cannot be preloaded?

I might add that the following fails:

$ /lib64/ld-linux-x86-64.so.2 ./libc.so.6 
Segmentation fault (core dumped)

So I am guessing the binary I am using is likely incompatible with the RedHat kernel somehow.

like image 504
freeseek Avatar asked Oct 29 '25 12:10

freeseek


1 Answers

The problem is that dynamic loader (/lib/ld-linux.so.2) is linked with the old libc and it already pre-loaded. To load the new libc, you also need to take the new ld-linux.so linked with this libc. This program can be launched from command line:

$ LD_LIBRARY_PATH="." ./ld-linux.so.2 ./xxx

Some applications may incorrectly work this way and need to set dynamnic loader in its binary (elf) file:

$ patchelf --set-interpreter ./ld-linux.so.2 --set-rpath '$ORIGIN' ./xxx
$ ./xxx

The path to ld-linux.so may be absolute or relative the current directory but not with $ORIGIN as runpath.

like image 138
sercxjo Avatar answered Oct 31 '25 13:10

sercxjo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!