Skip to content

bound instruction length to record end in dwarf CIE/FDE parsing - #16884

Open
isl-Ramzi wants to merge 3 commits into
firebase:mainfrom
isl-Ramzi:dwarf-record-length-bound
Open

isl-Ramzi wants to merge 3 commits into
firebase:mainfrom
isl-Ramzi:dwarf-record-length-bound

Conversation

@isl-Ramzi

Copy link
Copy Markdown
Contributor

FIRCLSDwarfParseCIERecord and FIRCLSDwarfParseFDERecord set the DWARF instruction block size with instructions.length = (uint32_t)(endAddress - ptr), but nothing checks that ptr is still at or before endAddress after the header fields are read. A record in a loaded image's __eh_frame whose declared length is shorter than the header it actually carries (or an FDE with a large augmentation length) leaves ptr past endAddress, so that subtraction goes negative and the cast wraps to a length near 4 GB. FIRCLSDwarfInstructionsEnumerate then walks the instruction cursor across that bogus range and reads well past the mapped section during crash-time unwinding.

The fix rejects the record when ptr has moved beyond endAddress, at both the CIE and FDE sites, before the length is computed. Valid records are unaffected since their headers always fit within the declared length. Added a regression test in FIRCLSDwarfTests.m that builds a CIE plus an FDE with a too-short length and checks the parse now fails cleanly instead of returning a wrapped ~4 GB instruction length.

@gemini-code-assist

Copy link
Copy Markdown
Contributor
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

@paulb777

Copy link
Copy Markdown
Member

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces bounds checks in FIRCLSDwarfParseCIERecord and FIRCLSDwarfParseFDERecord to ensure that the parsed CIE and FDE headers do not extend past their declared lengths, along with a corresponding unit test. Feedback on the changes highlights a potential integer overflow vulnerability where a very large augmentationLength could cause ptr to wrap around and bypass the new ptr > endAddress check, and suggests an improved check to prevent this.

Comment thread Crashlytics/Crashlytics/Unwind/Dwarf/FIRCLSDwarfUnwind.c
@isl-Ramzi

Copy link
Copy Markdown
Contributor Author

Pushed db6cd0c to address the review: the FDE augmentation length is now bounded against the remaining record bytes before it's added to the cursor, so a huge length can't overflow the pointer and wrap past the end check. Regression test covers the wrapping case.

@paulb777

Copy link
Copy Markdown
Member

@isl-Ramzi Would you fix the formatting?

@isl-Ramzi

Copy link
Copy Markdown
Contributor Author

Sure, fixed in bf5e402. It was the comment alignment in the new FIRCLSDwarfTests.m test, which was the only file the style check flagged.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants