Fix out_frame buffer overflow in companion radio response handlers #1659
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: High
Summary
The
onContactResponsehandler in the companion radio firmware copies peer response data intoout_framewithout checking whether the data fits. Theout_framebuffer isMAX_FRAME_SIZE + 1(173 bytes), but peer responses can be up toMAX_PACKET_PAYLOAD(184 bytes).Three code paths are affected — status response, telemetry response, and binary response. Each writes a small header (6-8 bytes) then copies
len - 4bytes of response data. Whenlenis close to 184, the total write reaches 188 bytes, overflowing the buffer by 15 bytes.How this can be exploited
A malicious peer that you've logged into (repeater, room server) can send an oversized status or telemetry response. The companion radio node receives and decrypts it successfully (the peer has a valid shared secret), then copies the response into the undersized
out_framebuffer on the stack.This corrupts adjacent stack variables and the return address. On ESP32, this causes a crash/reboot at minimum, and could potentially be leveraged for code execution. An attacker could use this to:
Users would see their device crash or reboot every time it connects to a specific repeater or room server.
Fix
Cap the memcpy length to the remaining space in
out_framebefore copying, in all three affected code paths. Oversized responses are truncated rather than overflowing.Test plan
Heltec_v3_companion_radio_ble