Skip to content

Fix shared library corruption when rerunning patchelf - #202

Merged
domenkozar merged 1 commit into
NixOS:masterfrom
rpurdie:master
Jun 3, 2020
Merged

domenkozar merged 1 commit into
NixOS:masterfrom
rpurdie:master

Conversation

@rpurdie

@rpurdie rpurdie commented Jun 3, 2020

Copy link
Copy Markdown
Contributor

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

domenkozar commented Jun 3, 2020 •

Copy link
Copy Markdown
Member

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

@rpurdie

rpurdie commented Jun 3, 2020

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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

sjackman commented Jun 3, 2020

Copy link
Copy Markdown

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

@sjackman

sjackman commented Jun 3, 2020

Copy link
Copy Markdown

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

@domenkozar

Copy link
Copy Markdown
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