SPIKE fuzzer gives LD_LIBRARY_PATH issue on ubuntu - linux

I am trying to configure SPIKE file fuzzer on Ubuntu machine. It gives Now you need to set your LD_LIBRARY_PATH to include the path to libdisasm.so and the path to libdlrpc.so.
I did set LD_LIBRARY_PATH using export. But it is still showing up the same error again. Seems LD_LIBRARY_PATH is not working for SPIKE. How do I solve this issue.

With your LD_LIBRARY_PATH set run ldd on the fuzzer executable (I'm assuming it's an executable). It should show you the libraries that are used and potentially missing. Keeping fixing your path until all the dependencies are met.
[user#host jobs]$ ldd `which gcc`
linux-vdso.so.1 => (0x00007fff3e193000)
libm.so.6 => /lib64/libm.so.6 (0x00007fa2c1f4c000)
libz.so.1 => /lib64/libz.so.1 (0x00007fa2c1d34000)
libc.so.6 => /lib64/libc.so.6 (0x00007fa2c197d000)
/lib64/ld-linux-x86-64.so.2 (0x00007fa2c2275000)

Related

Getting runtime error when include cthreads lib in Lazarus/free pascal

I'm trying to code a multithread application in Lazarus/free pascal, but I've noticed that when I include the "cthreads" lib (always the first line of my project.lpr file), on some Linux distros, I get a runtime error when running the application. I believe it's some broken library. However, I don't know how to identify it. Could you help me?
project1.lpr:
program project1;
uses
cthreads,
cmem;
begin
writeln('test');
end.
error:
[root#dockerinaja /]# ./project1
Runtime error 203 at $0000000000418D5C
$0000000000418D5C
$000000000040086D
ldd ./project1:
[root#dockerinaja /]# ldd /project1
linux-vdso.so.1 (0x00007ffc43fbd000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f359ff5e000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f359ff58000)
libc.so.6 => /lib64/libc.so.6 (0x00007f359fd92000)
/lib64/ld-linux-x86-64.so.2 (0x00007f359ff8b000)
I noticed that I had a very old version of Free Pascal. I just updated to version 3.2.0 and it fixed my problem. Thanks.

How can I specify the GLIBC version in cargo build for Rust?

I use rust 1.34 and 1.35. Currently it links to GLIBC_2.18.
How can I limit cargo build to link GLIBC up to version 2.14?
Unfortunately, you can't. Not really, and not consistently. This is a problem with any binary that dynamically links to GLIBC. You can try setting up multiple GLIBC versions and linking to one, or you can try patching the resulting binary, but it's inconsistent and impractical.
So what are some practical options?
Compile Statically
By using MUSL instead of GLIBC we can compile statically.
To install the MUSL target with rustup (assuming x86_64 architecture):
$ rustup component add rust-std-x86_64-unknown-linux-musl
And to use it when compiling:
$ cargo build --target x86_64-unknown-linux-musl
This is the easiest method by far, but won't always work, especially when using native libraries, unless they can also be compiled statically.
Make a VM That Has an Older Version
This is a common approach. By using an OS with an outdated, GLIBC the binary will have GLIBC symbols that are compatible with it.
Use a Docker Container
This is probably the most convenient method, in my opinion. If you have Docker, you can just compile your project with a container that contains an old GLIBC. View the Rust contianer's README for compilation instructions. The command below will compile a project using Rust 1.67 and GLIBC 2.28 (which comes with buster):
$ docker run --rm --user "$(id -u)":"$(id -g)" -v "$PWD":/usr/src/myapp -w /usr/src/myapp rust:1.67-buster cargo build --release
I compiled this on Ubuntu 22.04 and tested it on Ubuntu 20.04.
To test further, I made sure the binary relied on another dynamic library (OpenSSL) and here's the result of ldd ./mybinary after compiling with the Docker container:
$ ldd ./mybinary
linux-vdso.so.1 (0x00007ffd98fdf000)
libcrypto.so.1.1 => /lib/x86_64-linux-gnu/libcrypto.so.1.1 (0x00007fe49e248000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fe49e22d000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fe49e223000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fe49e200000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fe49e0b1000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fe49e0ab000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fe49deb7000)
/lib64/ld-linux-x86-64.so.2 (0x00007fe49ea30000)
And this is what it looks like without the container:
$ ldd ./mybinary
linux-vdso.so.1 (0x00007ffd5d7b7000)
libcrypto.so.3 => /lib/x86_64-linux-gnu/libcrypto.so.3 (0x00007fe85564c000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fe85562c000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fe855545000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fe85531d000)
/lib64/ld-linux-x86-64.so.2 (0x00007fe855f98000)

Error in libgraph installation :- missing libgraph.so.1 file in fedora 27

./a.out: error while loading shared libraries: libgraph.so.1: cannot open shared object file: No such file or directory.
ldd a.out :-inux-vdso.so.1 (0x00007ffc5bff4000) libgraph.so.1 => not found libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007fa242377000) libm.so.6 => /lib64/libm.so.6 (0x00007fa242022000) libgccs.so.1 => /lib64/libgccs.so.1 (0x00007fa241e0b000) libc.so.6 => /lib64/libc.so.6 (0x00007fa241a28000) /lib64/ld-linux-x86-64.so.2 (0x00007fa2426fe000).
here i can see that libgraph.so.1 is missing what shall i do further to get that missing file.
I had this problem even with the correct libraries installed.
Try this:
sudo cp /usr/local/lib/libgraph.* /usr/lib
and compile and run again.

Forcing ELF binary to use another libc.so [duplicate]

This question already has answers here:
Multiple glibc libraries on a single host
(11 answers)
Closed 6 years ago.
I need to make ELF binary file to use another version of libc.so for scientific purposes. I tried to do it with LD_PRELOAD and patchelf utility, but then binary does not run with an errors like:
./a.out: error while loading shared libraries: libc-2.15.so: cannot open shared object file: No such file or directory or Segmentation fault (core dumped).
I think that it is because I need another version of ld.so.
What is most efficient way to make binary use my version of libc?
EDIT: I do not have source code of binary.
EDIT: Error message edited. No SELinux, no AppArmor.
For me it looks that you did not spend the whole path to the new libc variant.
I did the following:
ldd example
linux-vdso.so.1 (0x00007ffe9c087000)
libstdc++.so.6 => /opt/linux-gnu_6.1.0/lib64/libstdc++.so.6 (0x00007f0cef872000)
libm.so.6 => /lib64/libm.so.6 (0x00007f0cef56f000)
libgcc_s.so.1 => /opt/linux-gnu_6.1.0/lib64/libgcc_s.so.1 (0x00007f0cef359000)
libc.so.6 => /lib64/libc.so.6 (0x00007f0ceef98000)
/lib64/ld-linux-x86-64.so.2 (0x000055ca3cb92000)
LD_PRELOAD=/tmp/bug_libc.so ldd example
linux-vdso.so.1 (0x00007ffc2cff8000)
/tmp/bug_libc.so (0x00007f56a1358000)
libstdc++.so.6 => /opt/linux-gnu_6.1.0/lib64/libstdc++.so.6 (0x00007f56a0f9a000)
libm.so.6 => /lib64/libm.so.6 (0x00007f56a0c98000)
libgcc_s.so.1 => /opt/linux-gnu_6.1.0/lib64/libgcc_s.so.1 (0x00007f56a0a82000)
/lib64/ld-linux-x86-64.so.2 (0x00005605c8a7a000)
If I replace with a non valid libc a got a different error message. Only if I gave the wrong path like:
LD_PRELOAD=/tmp/bug_libc.so2 ldd go
ERROR: ld.so: object '/tmp/bug_libc.so2' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/tmp/bug_libc.so2' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
linux-vdso.so.1 (0x00007ffedcde4000)
libstdc++.so.6 => /opt/linux-gnu_6.1.0/lib64/libstdc++.so.6 (0x00007f3ae2188000)
libm.so.6 => /lib64/libm.so.6 (0x00007f3ae1e85000)
libgcc_s.so.1 => /opt/linux-gnu_6.1.0/lib64/libgcc_s.so.1 (0x00007f3ae1c6f000)
libc.so.6 => /lib64/libc.so.6 (0x00007f3ae18ae000)
/lib64/ld-linux-x86-64.so.2 (0x000055df54aae000)
Maybe you have some other problem by accessing your replacement libc-file.
Check the access flags on the file and also check if SELinux or AppArmor or other protection stops loading libc in your environment. Because replacing libc opens a security hole it is a candidate for SELinux & Co!
And you should check always with ldd first. Maybe your new libc requires some more (older) variants of other libs which can not be found on your system. Normaly libc did not require other libs, but I have no idea what game you are playing. Whatever: ldd gives you a more detailed answer to the things which are going on in the library loading phase.
EDIT: segfault
If you get segfault, you typically have compiled your application with incompatible header files. You have to compile with the headers which comes with the libc version you want to use. If you compile against your system headers for system libc and run any incompatible version of precompiled libc, you get any kind of memory errors by accessing wrong data structures.
This answer explains why LD_PRELOAD can not work, and suggests solutions.
I tried to do it with LD_PRELOAD and patchelf utility
It's not clear whether your use of patchelf touched only DT_RPATH, only PT_INTERP, or both. You need to do both.

Failure to load existing library

I'm trying to explain a complex problem, so bear with me.
Say I have these files
/path/build/
/path/build/liba.so
/path/build/liba.so.3 -> liba.so
/path/build/libtest.so
I even have set PATH=/path/build:... (where ... is my normal $PATH).
At some point libtest.so will load liba.so.3 at runtime.
However, liba.so.3 doesn't seem to exist when running code that (successfully) loads libtest.so, and when I ask ldd for help, I get this:
$ ldd /path/build/libtest.so
linux-vdso.so.1 => (0x00007fff24fff000)
liba.so.3 => not found
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f8fea222000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f8fe9f9e000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f8fe9d88000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f8fe9b6a000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f8fe97c9000)
/lib64/ld-linux-x86-64.so.2 (0x00007f8fea767000)
(note the second output line)
How can I figure out what's going wrong? The library is clearly there, but the loader claims it's not.
Is /path/build on your LD_LIBRARY_PATH? The linux dynamic loader looks here for libraries on Linux, after the default locations

Resources