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

Bug: DOS when iterating over sections #370

Closed
pd-fkie opened this issue Aug 30, 2021 · 4 comments
Closed

Bug: DOS when iterating over sections #370

pd-fkie opened this issue Aug 30, 2021 · 4 comments

Comments

@pd-fkie
Copy link

pd-fkie commented Aug 30, 2021

Applications using pyelftools are susceptible to DOS when parsing an ELF file whose

  1. e_shentsize is zero
  2. e_shnum is larger than the actual number of entries in the section header table

The function ELFFile.iter_sections iterates over i in range(self['e_shnum']) and yields sections
at file offset self['e_shoff'] + i * self['e_shentsize'].
If e_shentsize is zero this will return the first section over and over again.
Thus a malicious ELF file can make pyelftools return the first section 9223372036854775808 times
and cause a DOS.

My question here is: Can you make pyelftools throw an exception if e_shentsize is zero because that would get rid of the DOS?
An e_shentsize of zero doesn't make sense anyway.

An exemplary ELF file that can trigger this can be found here: timeout-3561f873d79b09ce755b0981d3df30b9ac0ca0d3

@eliben
Copy link
Owner

eliben commented Aug 31, 2021

Thanks for the report. PRs to fix this are welcome.

@eliben
Copy link
Owner

eliben commented Sep 1, 2021

To be clear, pyelftools was never designed to be used in security-critical settings. For example, it's not particularly fast (being pure Python and all), and it can be trivially "DOS"-ed by passing a file with large DWARF data.

I'll gladly accept a PR that fixes this specific issue, but this isn't a high priority for me in any way.

@sevaa
Copy link
Contributor

sevaa commented Dec 13, 2023

It's not a DoS if the only computer you've sabotaged is yours.

pyelftools doesn't listen on a network - the DoS can't be triggered by a remote attacker. If the attacker already has the ability to execute arbitrary Python on your machine - you've got bigger problems.

If a third party piece accepts binaries from untrusted callers and passes them to pyelftools uncritically - that's on the said piece.

For an extended version of the same argument, see this:
https://devblogs.microsoft.com/oldnewthing/20220627-00/?p=106792

@sevaa
Copy link
Contributor

sevaa commented Apr 17, 2024

@pd-fkie Addressed in #522. Also the same for e_phentsize.

@pd-fkie pd-fkie closed this as completed Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants