I know that usually we don't want to have a static linking to libc for compatibility reasons, but I have an application that will run inside a Docker, and using LD_PRELOAD will gain execution to hook a libc function (for analysis purposes).
When I build this, I am getting a dynamically linked so.
# arm-linux-gnueabi-gcc -fPIC -shared -o libpreload-arm.so libpreload.c -ldl
# arm-linux-gnueabi-readelf -a libpreload-arm.so | grep Shared
Type: DYN (Shared object file)
0x00000001 (NEEDED) Shared library: [libc.so.6]
Note I am cross-compiling for ARM, as the environment in my chroot is an ARM system, and qemu-user-arm will run all of this.
I copy the required libraries into the chroot, as follows:
# cp libpreload-arm.so /usr/local/lib/libpreload.so
# cp `arm-linux-gnueabi-gcc -print-file-name=libc.so.6` /tmp/chroot/lib/
# arm-linux-gnueabi-readelf -a /tmp/chroot/lib/libc.so.6 | grep Shared
Type: DYN (Shared object file)
0x00000001 (NEEDED) Shared library: [ld-linux.so.3]
# cp `arm-linux-gnueabi-gcc -print-file-name=ld-linux.so.3` /tmp/chroot/lib/
Running this however provides this result:
# chroot /tmp/chroot /bin/sh -c "env -i HOME=/root PWD=/ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin LD_PRELOAD=/usr/local/lib/libpreload.so sh"
/bin/sh: '/lib/libc.so.6' library contains unsupported TLS
/bin/sh: '/lib/libc.so.6' library contains unsupported TLS
/bin/sh: can't load library 'libc.so.6'
It seems that something is incompatible perhaps in my running environment, but I can't figure out what. Note that I would prefer to not manually build all of my /tmp/chroot folder, as I am copying in a system that I want to emulate as much as possible into this.
As such, it seems that my options are one of the following -- neither of which I can get to work: 1) Build libpreload-arm.so with no dynamic linkings, copy it in, and run it 2) Build libpreload-arm.so with a dynamic libinking, copy it and the linked libraries in, and sort out incompatibilities
Any support would be much appreciated.
User contributions licensed under CC BY-SA 3.0