Fix out-of-bounds read in TRACE packet hash matching#1655
Open
weebl2000 wants to merge 1 commit into
Open
Conversation
00e9749 to
8a461cf
Compare
3 tasks
1c05fbc to
bf17df3
Compare
bf17df3 to
558f8d9
Compare
The TRACE handler uses isHashMatch() to compare this node's hash against an entry in the payload, but did not verify that enough bytes remain in the payload for the full hash comparison. The hash size is variable (1, 2, 4, or 8 bytes depending on path_sz), so when offset is close to the end of the payload, isHashMatch reads past the buffer boundary. Add a bounds check ensuring offset + hash_sz <= len before calling isHashMatch, preventing the over-read.
558f8d9 to
0c27534
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.
Severity: Medium
Summary
The TRACE packet handler compares this node's identity hash against an entry in the payload to decide whether to forward the packet. The hash size is variable — 1, 2, 4, or 8 bytes depending on the
path_szfield in the packet flags. The existing bounds check (offset >= len) only verifies that the start of the hash is within the payload, but doesn't account for the full hash length. Whenoffsetis close to the end of the payload,isHashMatchreads past the valid payload bytes.Impact
The over-read stays within the
payload[184]array in thePacketstruct — it reads stale data from previous packets in the pool, not unmapped memory. This means it won't crash or hard-fault any node.The practical effect is incorrect routing decisions for TRACE packets:
Any node on the mesh can trigger this since TRACE packets are unauthenticated and direct-routed. A crafted packet with
path_sz = 3(8-byte hashes) and a payload length that leaves fewer than 8 bytes after the offset will hit this path.Fix
Add a bounds check ensuring
offset + hash_sz <= lenbefore callingisHashMatch. Packets that don't have enough payload bytes for a full hash comparison are now silently dropped.Test plan
offset >= lenbranch)Heltec_v3_companion_radio_bleBuild firmware: Build from this branch