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

patchelf doesn't update PT_NOTE segment when relocating SHT_NOTE sections #217

Closed
delroth opened this issue Jun 20, 2020 · 2 comments · Fixed by #218
Closed

patchelf doesn't update PT_NOTE segment when relocating SHT_NOTE sections #217

delroth opened this issue Jun 20, 2020 · 2 comments · Fixed by #218
Labels

Comments

@delroth
Copy link
Contributor

delroth commented Jun 20, 2020

Describe the bug

SHT_NOTE sections (e.g. .note.gnu.build-id) can sometimes be aliased by a PT_NOTE segment. When this is the case, patchelf might move the SHT_NOTE section without also updating the PT_NOTE segment. The PT_NOTE segment ends up pointing to the middle of random stuff that might have been overwritten.

This is as far as I know the root cause of NixOS/nixpkgs#91145 breaking Mesa in NixOS with patchelf 0.11.

Steps To Reproduce

$ echo 'int foo(int x) { return x; }' > test.c
$ gcc -s -shared -Wl,-build-id -o test.so test.c
$ readelf -n test.so
Displaying notes found in: .note.gnu.build-id
  Owner                 Data size	Description
  GNU                  0x00000014	NT_GNU_BUILD_ID (unique build ID bitstring)
    Build ID: 767c996573519ca3392910e472102d68d87342e7

$ patchelf --set-rpath $(perl -e 'print "A"x1000') test.so
$ readelf -n test.so
Displaying notes found in: .note.gnu.build-id
  Owner                 Data size	Description
readelf: Warning: note with invalid namesz and/or descsz found at offset 0x0
readelf: Warning:  type: 0x3, namesize: 0x00000004, descsize: 0x00000014, alignment: 8

Expected behavior

Not completely sure yet. PT_NOTE should be updated, but that means we might need to ensure we keep multiple note sections adjacent if the PT_NOTE contains multiple SHT_NOTE sections.

patchelf --version output

master

@delroth delroth added the bug label Jun 20, 2020
@domenkozar
Copy link
Member

cc @rpurdie as this is part of stripping fix.

@delroth
Copy link
Contributor Author

delroth commented Jun 20, 2020

I implemented a fix in #218. I tested it with Mesa and confirmed that now Mesa is happily finding its build-id and not segfaulting anymore. readelf is also happy, though that was actually a separate problem from the section/segment mismatch! (alignment issue, see PR)

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

Successfully merging a pull request may close this issue.

2 participants