Bounds-check reply_path in anonymous request handlers #1664
+18
−12
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
handleAnonRegionsReq,handleAnonOwnerReq, andhandleAnonClockReqfunctions in the repeater firmware read areply_path_lenbyte (masked to 0–63) from the decrypted payload and immediatelymemcpythat many bytes intoreply_path. The caller passes a bare pointer (&data[5]) without any remaining-length information, so the handlers have no way to validate whether the data buffer actually containsreply_path_lenbytes.With a minimal-length anonymous request (16 bytes decrypted from one AES block), only 11 bytes remain after offset 5. A
reply_path_lenof 63 causes a read of 52 bytes of uninitialized stack memory intoreply_path, which is then used to route the response.Who can exploit this: any node — anonymous requests use ECDH with the receiver's public key, so any sender can produce a valid MAC.
What it takes: a single crafted ANON_REQ packet.
What users might see
The node sends a response with a garbage routing path, wasting airtime. The response is unlikely to be delivered. No crash — reads stay within the 184-byte
data[]stack buffer.Fix
data_lenparameter to all threehandleAnon*Reqfunctions1 + reply_path_len <= data_lenbefore the memcpyonAnonDataRecvto ensurelen > 5before passing&data[5]Test plan
Heltec_v3_repeater