Guard MSP2_SENSOR_* receivers against short payloads - #11822
Guard MSP2_SENSOR_* receivers against short payloads#11822sensei-hacker wants to merge 3 commits into
Conversation
mspProcessSensorCommand computed the incoming payload size but discarded it, letting GPS/compass/baro/airspeed/opflow/rangefinder receivers cast an unchecked pointer to a fixed-size struct. A short-but-CRC-valid frame let stale bytes from the shared MSP input buffer be read as real sensor data. Thread dataSize through to each receiver and reject any frame that isn't exactly the expected size, matching the pattern already used by MSP2_SENSOR_HEADTRACKER.
|
ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing |
PR Summary by QodoReject malformed MSP2 sensor payload sizes
AI Description
Diagram
High-Level Assessment
Files changed (13)
|
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewTip of the day💡 Did you know, you can hide the parts of a finding you never read, like the evidence or the agent prompt |
|
RAM / Flash usage vs. base branch — commit
See RAM/flash optimization guide for techniques to reduce usage. |
|
Test firmware build ready — commit Download firmware for PR #11822 247 targets built. Find your board's
|
Under the forward-compat policy (MSP payloads only gain fields at the end), a longer message from a newer sender must be accepted: apply the known leading fields and ignore the trailing bytes. Relax all seven receiver guards (GPS, compass, baro, airspeed, opflow, rangefinder, headtracker) from exact-size `dataSize != sizeof(...)` to minimum-size `dataSize < sizeof(...)`, so truncated frames are still rejected while longer frames are accepted.
|
Phase 4: lenient gates per forward-compat policy — implemented + SITL-verified. Following the 2026-08-27 forward-compat policy (MSP payloads only ever gain fields at the END; a newer sender's longer message must be accepted by older firmware — apply known fields, ignore trailing bytes), all seven
Truncated frames are still rejected outright (no partial state mutation), while longer frames are accepted — the receiver casts the buffer to the fixed struct and reads only the leading SITL verification (
Commit: |
Summary
mspProcessSensorCommandcomputed the incoming MSP payload size (dataSize) but discarded it (UNUSED(dataSize)), then dispatched to the sixMSP2_SENSOR_*receiver functions (GPS, compass, baro, airspeed, opflow, rangefinder), each of which casts the raw payload pointer directly to a fixed-size packed struct and reads every field, with no check that the actual payload was that large. A short-but-CRC-validMSP2_SENSOR_*frame (MSP v2's own CRC8 doesn't prevent a short frame, only a corrupted one) would let stale bytes from the FC's shared MSP input buffer be read as real sensor data and fed into navigation.MSP2_SENSOR_HEADTRACKER, dispatched from the same function, was already correctly guarded — it receivesdataSizeexplicitly and rejects any frame that isn't exactly the expected size. This makes the same robustness improvement to the other six sensor messages, closing the gap.Changes
dataSizefrommspProcessSensorCommand(fc_msp.c) through to each of the six sensor receiversif (dataSize != sizeof(expected_struct_t)) { return; }as the first statement in each receiver, before any field is read — matching the existingMSP2_SENSOR_HEADTRACKERpattern exactlyTesting
MSP2_SENSOR_GPSframe (10 bytes instead of the 52-byte struct) with different values encoded in the truncated bytes — confirmed FC GPS state was unaffected (stayed at the prior valid frame's values), then confirmed a subsequent correctly-sized frame was still applied normallyMSP2_SENSOR_RANGEFINDER(5-byte struct, smallest of the six) with a 2-byte short frame — same result, rejected with no state change, valid frames still acceptedCode Review
Reviewed with the
inav-code-reviewagent — approved, no critical or important issues found. One pre-existing (not introduced by this change) const-correctness inconsistency was noted ingps.hbut is out of scope for this fix.Related Issues
This was found while investigating #11672 (a different, already-resolved question about the six SET-handler bounds checks). It's a distinct code path — a general robustness fix, not a disclosed vulnerability.
Related to #11672