-
-
Notifications
You must be signed in to change notification settings - Fork 486
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
patchelf --set-rpath outputs a binary with broken .dynsym/.dynstr #244
Comments
What seems to be happening is that patchelf is finding some unused space which isn't covered by any PT_LOAD segment. It's placing .dynstr/.dynsym in there, but it's not making sure that these are mapped even though it seems to be required. A simple workaround should be to just ensure there's a segment covering these, and if not create a PT_LOAD segment. This could be optimized further to instead try and extend an existing segment... but I don't think there is much point to that except creating a "nicer" ELF file. |
cc @rpurdie |
Looking at this a bit more, I was wondering what indicates that Whatever fix patchelf ends up implementing should likely be using |
I've hit the same problem when expanding |
Have you solved this problem? |
@dreamc-2016 I must have fixed it in #264. I have a few patches on my fork that do stuff but I haven't tested them on Linux targets so I haven't been keen on merging them. |
@ehmry this issue still persists :( can the PR be revived? To reproduce: (1) build On Ubuntu GCC is configured with Example: $ cd $(mktemp -d)
$ curl -Lfs https://github.com/NixOS/patchelf/releases/download/0.15.0/patchelf-0.15.0.tar.gz | tar -zx --strip-components=1 -f -
$ ./configure
$ make "LDFLAGS=-Wl,-rpath,/example -no-pie" "CXXFLAGS=-O2 -g -fno-pic" install prefix=$PWD/install -j
$ cd install/bin
$ cp patchelf patchelf.copy
$ ./patchelf --set-rpath /longer/path patchelf.copy
$ gdb -ex r --args ./patchelf.copy
Reading symbols from ./patchelf.copy...
warning: Loadable section ".dynstr" outside of ELF segments
Starting program: /tmp/tmp.3gvU6yERyd/install/bin/patchelf.copy This is Ubuntu 20.04, GCC 9.4.0, binutils 2.34. Would a better solution be to add a new pt_load program header covering the moved/new section? Edit, it's actually a different issue. Patchelf grows the dynstr section, reshuffles the sections, ends up with two contiguous pt_load program headers, and the dynstr section goes out of bounds of the first pt_load. |
I will not reopen my PR because I don't have the time to give patchelf patches the attention and care that they need :| . |
This is not a robust fix, the first PT_LOAD segment is expanded forward to cover .dynstr or .dynsym. This is verified to fix segmentation faults in the loader when loading programs where the .dynstr or .dynstm section gets bumped out of the LOAD segment Fixes: NixOS#244
Describe the bug
This seems to be one of the root causes behind NixOS/nixpkgs#97407
When running a certain combination of patchelf + strip + patchelf on the upstream released stage2 ghc 8.6.5 binary, the last patchelf invocation (--set-rpath with a long rpath value) ends up generating a broken ELF file which segfaults the dynamic linker.
Note that gdb seems to already point to a problem with the binary before execution:
And indeed, readelf seems to agree:
Steps To Reproduce
I attached the input binary, gzipped to make github happy: repro.gz
. To reproduce, run:
Expected behavior
A clear and concise description of what you expected to happen.
patchelf --version
outputHEAD
Additional context
For some reason the binaries in question don't crash on a 64k page size system. I suspect this is because there is another tiny LOAD segment (< 0x1000 bytes) which if rounded to 64k does end up mapping the two sections by accident (but not if rounded to 4k). That's pure luck though.
The text was updated successfully, but these errors were encountered: