fix: add bounds checking before GetFieldT in reflection VerifyObject#9101
Open
Ashutosh0x wants to merge 1 commit into
Open
fix: add bounds checking before GetFieldT in reflection VerifyObject#9101Ashutosh0x wants to merge 1 commit into
Ashutosh0x wants to merge 1 commit into
Conversation
Add VerifyField<uoffset_t> checks before GetFieldT calls in VerifyObject for Obj and Union field types. Without these checks, a malformed table with out-of-bounds field offsets causes GetFieldT to compute a pointer outside the buffer, leading to heap-buffer- overflow in ReadScalar during reflection verification. Fixes google#9040
Author
|
Hi @dbaileychess — Requesting review on this security fix. It adds Verifier::VerifyField() bounds checking before GetFieldT() calls in reflection VerifyObject to prevent out-of-bounds heap reads from crafted FlatBuffer binaries. Ready for review. Thanks! |
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.
Fixes #9040
Summary
Heap buffer overflow in
flatbuffers::Verify()via the reflection verification path. TheVerifyObjectfunction callsGetFieldT()forObjandUnionfield types without first verifying that the field offset points within the buffer. A malformed table with out-of-bounds field offsets causesGetFieldT->Table::GetPointer->ReadScalar<uoffset_t>to read past the allocated buffer boundary.Root Cause
VerifyObjectinreflection.cppverifies scalar fields (Bool, Byte, Int, etc.) withtable->VerifyField<T>()before accessing them, but theObj(line 243) andUnion(line 255) cases callGetFieldT()directly, skipping the bounds check:GetFieldTdoestable.GetPointer<Table*>(field.offset()), which reads auoffset_tfrom the table buffer. If the vtable entry points past the end of the buffer, this is an out-of-bounds read.Fix
Added
VerifyField<uoffset_t>calls before eachGetFieldTcall inVerifyObject, matching the pattern already used for String fields (line 226):Impact
src/reflection.cppVerifyObjectVerify(),VerifySizePrefixed()ASAN Trace (from #9040)