Skip to content
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

Fix shared library corruption when rerunning patchelf #202

Merged
merged 1 commit into from
Jun 3, 2020

Conversation

rpurdie
Copy link
Contributor

@rpurdie rpurdie commented Jun 3, 2020

When running patchelf on some existing patchelf'd binaries to change to longer
RPATHS, ldd would report the binaries as invalid. The output of objdump -x on
those libraryies should show the top of the .dynamic section is getting trashed,
something like:

0x600000001 0x0000000000429000
0x335000 0x0000000000335000
0xc740 0x000000000000c740
0x1000 0x0000000000009098
SONAME libglib-2.0.so.0

(which should be RPATH and DT_NEEDED entries)

This was tracked down to the code which injects the PT_LOAD section.

The issue is that if the program headers were previously relocated to the end
of the file which was how patchelf operated previously, the relocation code
wouldn't work properly on a second run as it now assumes they're located after
the elf header. This change forces them back to immediately follow the elf
header which is where the code has made space for them.

Should fix #170
and #192

Signed-off-by: Richard Purdie [email protected]

When running patchelf on some existing patchelf'd binaries to change to longer
RPATHS, ldd would report the binaries as invalid. The output of objdump -x on
those libraryies should show the top of the .dynamic section is getting trashed,
something like:

0x600000001 0x0000000000429000
0x335000 0x0000000000335000
0xc740 0x000000000000c740
0x1000 0x0000000000009098
SONAME libglib-2.0.so.0

(which should be RPATH and DT_NEEDED entries)

This was tracked down to the code which injects the PT_LOAD section.

The issue is that if the program headers were previously relocated to the end
of the file which was how patchelf operated previously, the relocation code
wouldn't work properly on a second run as it now assumes they're located after
the elf header. This change forces them back to immediately follow the elf
header which is where the code has made space for them.

Should fix NixOS#170
and NixOS#192

Signed-off-by: Richard Purdie <[email protected]>
@domenkozar
Copy link
Member

domenkozar commented Jun 3, 2020

@rpurdie Thank you! Any chance to add a test case in tests directory?

@rpurdie
Copy link
Contributor Author

rpurdie commented Jun 3, 2020

The easiest test case would be to check in the shared lib from the testcase in #170, run patchelf against it as described and check ldd finds the binary is still valid. Not sure if you can add that lib though and creating such a lib from sources would be a much more involved exercise.

@domenkozar
Copy link
Member

I'm going to merge this and bump patchelfUnstable in nixpkgs. Then we can build all packages and check for possible regressions.

@domenkozar domenkozar merged commit 640a35f into NixOS:master Jun 3, 2020
@sjackman
Copy link

sjackman commented Jun 3, 2020

🎉 ❤️ Thank you very much for this fix, Richard!

@sjackman
Copy link

sjackman commented Jun 3, 2020

@domenkozar Is there a stable release of patchelf planned that includes this fix?

@domenkozar
Copy link
Member

Yes, you can follow NixOS/nixpkgs#69213 as we rebuild all nix packages to verify there are no regressions this time. Once that's done we'll make a release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

patchelf 0.10 corrupts some shared libraries
3 participants