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

Support ELF with empty PT_DYNAMIC reference #193

Merged
merged 1 commit into from
Dec 3, 2019

Conversation

jan-auer
Copy link
Contributor

Some ELF files may contain PT_DYNAMIC program headers that have a zero p_filesz pointing to invalid memory if the corresponding section has been stripped. This currently causes an error when parsing the dynamic headers.

Copy link
Owner

@m4b m4b left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry I missed this somehow

@m4b
Copy link
Owner

m4b commented Dec 3, 2019

I'm just curious, why would this be empty?

@jan-auer
Copy link
Contributor Author

jan-auer commented Dec 3, 2019

Unfortunately, I don’t know the full chain that created such a file. Probably, the data pointed to by the header has been stripped, and to keep things easier the header was only rewritten instead of removed. At least, I’ve seen this behavior with sections.

@m4b
Copy link
Owner

m4b commented Dec 3, 2019

I can’t remember isn’t the filessz effectively the dynamic loader filename ?

Which means the binary is just malformed if it’s 0.

Also afaik you cant meaningfully strip the PT_DYNAMIC, since it’s a program header and not a section header.

@m4b m4b merged commit e5ff551 into m4b:master Dec 3, 2019
@romainthomas
Copy link

I would be curious to understand how a valid ELF file can have a PT_DYNAMIC segment with a filesize set to 0 ?
(I agree that it is possible for section)

@jan-auer can you share the sample ?

@m4b
Copy link
Owner

m4b commented Dec 3, 2019

Yea I’m pretty sure it can’t. Iiuc it would have an empty dynamic loader and the kernel wouldn’t exec. At least last I checked these things.

Curious to see sample as well :)

@jan-auer
Copy link
Contributor Author

jan-auer commented Dec 3, 2019

Will try to do that - iirc this happened on a file we pulled from the Debian debug server, so it should be possible to share it.

@m4b
Copy link
Owner

m4b commented Dec 3, 2019

Oh interesting. That might be it. If I recall correctly the stripped debug symbols (usually from objcopy) are a dynamic library that gdb knows to load if its build id matches another binary you run gdb on.

@philipc
Copy link
Collaborator

philipc commented Dec 3, 2019

Yeah objcopy --only-keep-debug appears to set the PT_DYNAMIC filesz to 0.

@jan-auer jan-auer deleted the fix/empty-dyn branch May 6, 2020 07:16
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.

5 participants