Skip to content

Add minimum payload_len check for TRACE packet parsing#15

Open
weebl2000 wants to merge 3 commits intodevfrom
fix/trace-min-payload-len
Open

Add minimum payload_len check for TRACE packet parsing#15
weebl2000 wants to merge 3 commits intodevfrom
fix/trace-min-payload-len

Conversation

@weebl2000
Copy link
Owner

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


Mirror of meshcore-dev#1663

@weebl2000 weebl2000 force-pushed the fix/trace-min-payload-len branch from 5f2fc48 to 07b3d23 Compare February 28, 2026 18:09
liamcottle and others added 2 commits March 4, 2026 01:39
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 07b3d23 to d13b147 Compare March 3, 2026 14:41
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.

2 participants