FlexBuffers: reject cyclic buffers in the C++ Verifier (fixes stack-exhaustion DoS on access)#9187
Open
asroyxCySec wants to merge 1 commit into
Open
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
The FlexBuffers verifier accepted cyclic buffers when a reuse_tracker was supplied. Because offsets point backwards, a vector/map element can reference an ancestor node that is still being verified; the reuse tracker's de-duplication treated that re-visit as "already verified" and returned true, so verification passed. Recursive accessors (Reference::ToString() and any user traversal) then followed the cycle with no depth/cycle guard, recursing until the stack was exhausted (DoS). Without a reuse_tracker the depth limit already rejected these buffers; the tracker's early return is what bypassed it. Make the reuse tracking cycle-aware in VerifyVector: mark a node in-progress while its children are verified and mark it verified on completion. A re-visit of an in-progress node is a cycle (reject); a re-visit of a completed node with the same type is a legitimate shared/DAG reference (skip, as before). This preserves DAG de-duplication of shared keys/strings and keeps verification linear. Also add a regression test (FlexBuffersCyclicBufferTest) and extend flexbuffers_verifier_fuzzer to access the buffer after a successful verify, so the "verified => safe to access" property is fuzzed going forward.
asroyxCySec
force-pushed
the
fix/flexbuffers-verifier-cycle
branch
from
July 26, 2026 01:33
c236f8f to
3f34c39
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.
Problem
flexbuffers::VerifyBuffer(buf, len, &reuse_tracker)accepts cyclic buffers. Because FlexBuffers offsets point backwards, a value inside a vector/map can reference an ancestor node that is still being verified. The reuse tracker's de-duplication treats that re-visit as "already verified" and returnstrue, so verification succeeds. The recursive accessors (Reference::ToString(), and any user code that walks the structure) then follow the cycle with no depth/cycle guard and recurse until the stack is exhausted → crash.This breaks the guarantee that a buffer passing
VerifyBufferis safe to access.Minimal reproducers (both pass verification with a reuse tracker before this change, then crash on access; both are correctly rejected after it):
01 00 28 01(4 bytes) — a vector whose element is the vector itself (self-loop).02 24 01 02 28 01(6 bytes) — a vector element that points back to the parent vector.Note: without a reuse tracker the depth limit already rejects these buffers; the tracker's early "already verified" return is what bypasses that limit.
Fix
Make the reuse tracking cycle-aware in
Verifier::VerifyVector: mark a node in progress while its children are verified and mark it verified on completion. A re-visit of an in-progress node is a cycle (reject); a re-visit of a completed node with the same type is a legitimate shared/DAG reference (skip, as before). This preserves the tracker's DAG de-duplication (shared keys/strings/key-vectors) and keeps verification linear.Testing
flattests, built with-fsanitize=address):ALL TESTS PASSED, includingFlexBuffersTest,FlexBuffersReuseBugTest, and the newFlexBuffersCyclicBufferTest. No regressions.FlexBuffersCyclicBufferTestasserting both cyclic reproducers are rejected.tests/fuzzer/flexbuffers_verifier_fuzzer.ccto callGetRoot(...).ToString(...)after a successful verify, so the "verified ⇒ safe to access" property is fuzzed (it previously only verified, never accessed).