Skip to content

Fix use-after-free when non-lazily processing corrupted sections #151

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

Merged
merged 1 commit into from
Apr 12, 2025

Conversation

keddad
Copy link
Contributor

@keddad keddad commented Mar 31, 2025

Right now, return value of sec->load() is not checked on initial ELF load. However, if the stream is corrupt, it's load_data() call can fail, meaning that is_loaded flag will be left false. Despite that, problematic section will be left in the parsed data.

When reading sections after loading ELF (like in elfdump example), user might call get_data() on the section, which will in turn try to load_data() again. However, if the file was loaded non-lazily, the stream set in sec->load() will be freed by this point, thus causing a problem.

Initially I wanted to just discard corrupted sections, however, since there are test cases for corrupted elf processing, I opted to add a can_be_loaded field to section object. If load_data failed, it is set to false, thus preventing any broken reads from occuring.

Right now, return value of sec->load() is not checked on initial ELF load. However, if the stream is corrupt, it's load_data() call can fail, meaning that is_loaded flag will be left false. Despite that, problematic section will be left in the file.

When reading sections after all (like in elfdump example), user might call get_data() on the section, which will in turn try to load_data() again. However, if the file was loaded non-lazily, the stream set in sec->load() will be freed by this point, thus causing a problem.

Initially I wanted to just discard corrupted sections, however, since there are test cases for corrupted elf processing, I opted to add a can_be_loaded field to section object. If load_data failed, it is set to false, thus preventing any broken reads from occuring.
@serge1 serge1 merged commit 7a1de75 into serge1:main Apr 12, 2025
@serge1
Copy link
Owner

serge1 commented Apr 12, 2025

Accepted! Thank you!

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.

2 participants