check buffer before reading branch hint data byte#4965
Open
netliomax25-code wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
*buf++that does not check whether a byte is still available.metadata.code.branch_hintsection that declares size=1 but ends right after the size field reads one byte past the section, and past the end of the module buffer when the branch hint section is the last one. Under ASAN this is a heap-buffer-overflow read at wasm_loader.c:5684.Added a CHECK_BUF before the read so the value is bounded the same way as the other fields parsed in this loop.
Validation: built with WAMR_BUILD_BRANCH_HINTS=1 under ASAN. Before the change a crafted module with a truncated branch hint reports the overflow read at handle_branch_hint_section; after the change the same module fails to load with "unexpected end of section or function", and a well-formed branch hint section still loads.