0

I am trying to execute a 32bit binary and use a custom libc with it. So, I used LD_PRELOAD environment variable to set the path.

export LD_PRELOAD='./libc.so.6'

After this, a simple ls shows this error -

ERROR: ld.so: object './libc.so.6' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS32): ignored.

I am currently trying this on a Ubuntu 20.04 64bit machine and I receive this error. This technique used to work fine on the same machine with Ubuntu 18.04. Why is this happening and is there a workaround for this?

Context: I am trying a CTF challenge and using LD_PRELOAD is a common technique used when the challenge also provides a custom libc. I tried running scripts that use this approach and used to work fine on Ubuntu 18.04 but they throw the same error.

Edit:
The ls command works fine but also prints the error message. Any command executed will work correctly and also show this error. Major issue is that why doesn't this work on Ubuntu 20.04 whereas it worked perfectly on 18.

Saurabh
  • 75
  • 7
  • When you set `LD_PRELOAD` with `export`, it applies to all programs you try to run, including all your regular 64-bit system programs like `ls`. So that seems like it clearly won't work. Does it work if you just set the variable on the command line when you run your specific program, e.g. `LD_PRELOAD='./libc.so.6' ./myprog`? – Nate Eldredge May 09 '20 at 11:21
  • It still crashes with a `Segmentation Fault` – Saurabh May 09 '20 at 11:28
  • Okay, maybe your program still crashes, but at least `ls` works again, right? (I assume that you have `unset LD_PRELOAD` or started a new shell?) – Nate Eldredge May 09 '20 at 12:09
  • I am sorry if the question was confusing. By `ls` shows the error I meant that any command executed after setting the variable, printed this error and worked correctly. My issue is that I have used this before and it works fine but it crashes for some reason on Ubuntu 20.04 – Saurabh May 09 '20 at 14:22
  • Does this answer your question? [Multiple glibc libraries on a single host](https://stackoverflow.com/questions/847179/multiple-glibc-libraries-on-a-single-host) Also, https://stackoverflow.com/questions/55186770/can-ld-preload-be-used-to-load-different-versions-of-glibc – Employed Russian May 10 '20 at 18:50
  • Yes. I found a fix using `patchelf` but I still want to understand why `LD_PRELOAD` fails. – Saurabh May 11 '20 at 18:22

0 Answers0