Fix out-of-bounds read in objdump reloc section handling#2691
Open
sumleo wants to merge 1 commit intoWebAssembly:mainfrom
Open
Fix out-of-bounds read in objdump reloc section handling#2691sumleo wants to merge 1 commit intoWebAssembly:mainfrom
sumleo wants to merge 1 commit intoWebAssembly:mainfrom
Conversation
46086b3 to
796adde
Compare
BinaryReaderObjdump::OnRelocCount ignored the error returned by BinaryReaderObjdumpBase::OnRelocCount when the section_index was invalid. This caused the function to proceed to GetSectionName which called GetSectionStart with BinarySection::Invalid (~0), resulting in an out-of-bounds read on the stack-allocated section_starts_ array of size kBinarySectionCount (14). Propagate the error via CHECK_RESULT so that the out-of-bounds access is never reached. Add a regression test with a crafted wasm binary containing a reloc custom section that references a non-existent section index.
796adde to
ee56af2
Compare
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.
Summary
BinaryReaderObjdump::OnRelocCountignored the error returned byBinaryReaderObjdumpBase::OnRelocCountwhen thesection_indexwas invalid, causing it to proceed toGetSectionName→GetSectionStartwithBinarySection::Invalid(~0), resulting in an out-of-bounds read on the stack-allocatedsection_starts_array of sizekBinarySectionCount(14).CHECK_RESULTso the out-of-bounds access is never reached.Details
In
binary-reader-objdump.cc,BinaryReaderObjdump::OnRelocCountcalls the base class method but discards its return value:The base class returns
Result::Errorfor out-of-range indices and setsreloc_section_ = BinarySection::Invalid.GetSectionNamethen callsGetSectionStart(BinarySection::Invalid)which indexessection_starts_[~0]— far past the 14-element array.Test plan
BinaryReaderObjdump.RelocInvalidSectionIndexexercises the fix with a crafted wasm binary