Skip to content

Add minimum payload_len check for TRACE packet parsing#1663

Open
weebl2000 wants to merge 1 commit into
meshcore-dev:devfrom
weebl2000:fix/trace-min-payload-len
Open

Add minimum payload_len check for TRACE packet parsing#1663
weebl2000 wants to merge 1 commit into
meshcore-dev:devfrom
weebl2000:fix/trace-min-payload-len

Conversation

@weebl2000

@weebl2000 weebl2000 commented Feb 11, 2026

Copy link
Copy Markdown
Contributor

Severity: Medium

Summary

The TRACE packet handler reads 9 bytes from the payload — trace_tag (4), auth_code (4), and flags (1) — before any length validation. The Dispatcher layer does not enforce a minimum payload_len for any packet type, so a TRACE packet with payload_len = 0 reaches this code and reads stale data from the payload buffer.

Additionally, uint8_t len = pkt->payload_len - i (where i = 9) underflows when payload_len < 9, wrapping to ~247. This can cause the subsequent offset >= len check to pass or fail incorrectly, leading to unintended trace forwarding or hash matching against garbage data.

Who can exploit this: any node on the mesh — TRACE packets are unauthenticated and direct-routed.

What it takes: a single crafted short TRACE packet.

What users might see

Incorrect trace routing, spurious trace forwarding, or (less likely) nodes processing traces they shouldn't. No crash — reads stay within the 184-byte payload buffer.

Fix

Add pkt->payload_len >= 9 to the existing guard condition so undersized TRACE packets are silently dropped before any field parsing.

Test plan

  • Normal path traces still work
  • Short/corrupt TRACE packets are silently dropped
  • Build tested on Heltec_v3_companion_radio_ble

Build firmware: Build from this branch

@weebl2000
weebl2000 force-pushed the fix/trace-min-payload-len branch 2 times, most recently from 9ab59b8 to 5f2fc48 Compare February 26, 2026 22:16
@weebl2000
weebl2000 force-pushed the fix/trace-min-payload-len branch 2 times, most recently from 07b3d23 to d13b147 Compare March 3, 2026 14:41
@weebl2000
weebl2000 force-pushed the fix/trace-min-payload-len branch from d13b147 to 0b13373 Compare March 23, 2026 13:28
@weebl2000
weebl2000 force-pushed the fix/trace-min-payload-len branch from 0b13373 to 0bb3a0e Compare April 4, 2026 11:18
@weebl2000
weebl2000 force-pushed the fix/trace-min-payload-len branch from 0bb3a0e to 4bfecae Compare May 26, 2026 09:52
@weebl2000
weebl2000 force-pushed the fix/trace-min-payload-len branch 2 times, most recently from bf03ea9 to 4abc325 Compare June 6, 2026 19:57
@weebl2000
weebl2000 force-pushed the fix/trace-min-payload-len branch 2 times, most recently from a03fd8c to 3f72127 Compare June 17, 2026 10:06
@weebl2000
weebl2000 force-pushed the fix/trace-min-payload-len branch from 3f72127 to 7139919 Compare July 14, 2026 13:26
The TRACE handler reads 9 bytes (trace_tag, auth_code, flags) from the
payload before any length validation. A short TRACE packet causes reads
of stale buffer data and an underflow in the remaining-length
calculation (uint8_t len = payload_len - 9 wraps to ~247).

Add payload_len >= 9 to the existing guard condition so undersized
TRACE packets are silently dropped.
@weebl2000
weebl2000 force-pushed the fix/trace-min-payload-len branch from 7139919 to a4c911c Compare July 22, 2026 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant