Skip to content

Fix MAVLink message bounds validation vulnerabilities#14067

Merged
DonLakeFlyer merged 1 commit intomasterfrom
fix/mavlink-message-bounds-validation
Mar 6, 2026
Merged

Fix MAVLink message bounds validation vulnerabilities#14067
DonLakeFlyer merged 1 commit intomasterfrom
fix/mavlink-message-bounds-validation

Conversation

@DonLakeFlyer
Copy link
Collaborator

Harden MAVLink message handlers against malicious or malformed payloads that could trigger out-of-bounds memory access.

Fixes https://github.com/mavlink/qgroundcontrol/security/advisories/GHSA-v5rc-wh3c-c4cw

ImageProtocolManager (GHSA-v5rc-wh3c-c4cw)

  • Validate DATA_TRANSMISSION_HANDSHAKE fields (size, payload, packets) before allocating the image buffer
  • Enforce 1 MB upper bound on image size
  • Reject payload values exceeding ENCAPSULATED_DATA data[253] array size
  • Pre-allocate image buffer to declared size instead of growing via unchecked indexed writes
  • Replace byte-by-byte copy loop with bounds-clamped memcpy
  • Cast seqnr to uint32_t before multiplication to prevent overflow

Vehicle (LOG_DATA)

  • Add bounds check on log.count against sizeof(log.data) before emitting the signal, preventing downstream consumers from reading past the 90-byte data array

FTPManager (FILE_TRANSFER_PROTOCOL)

  • Validate hdr.size against sizeof(request->data) at the single message entry point, protecting all downstream handlers (burst read, list directory, fill missing blocks) from reading past the 239-byte data array

@github-actions
Copy link
Contributor

github-actions bot commented Mar 5, 2026

Build Results

Platform Status

Platform Status Details
Linux Passed View
Windows Passed View
MacOS Passed View
Android Passed View

All builds passed.

Pre-commit

Check Status Details
pre-commit Failed (non-blocking) View

Pre-commit hooks: 32 passed, 78 failed, 10 skipped.

Test Results

linux-sanitizers: 52 passed, 0 skipped

linux_gcc_64: 52 passed, 0 skipped

Total: 104 passed, 0 skipped

Code Coverage

Coverage: N/A

No baseline available for comparison

Artifact Sizes

Artifact Size
QGroundControl 328.34 MB
QGroundControl 318.73 MB
QGroundControl-aarch64 195.93 MB
QGroundControl-installer-AMD64 164.99 MB
QGroundControl-installer-AMD64-ARM64 76.94 MB
QGroundControl-installer-ARM64 77.88 MB
QGroundControl-mac 183.45 MB
QGroundControl-windows 183.46 MB
QGroundControl-x86_64 187.58 MB

No baseline available for comparison


Updated: 2026-03-06 04:23:26 UTC • Triggered by: MacOS

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

_imageHandshake = {};
break;
}
if (_imageHandshake.payload > sizeof(mavlink_encapsulated_data_t::data)) {
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sizeof(mavlink_encapsulated_data_t::data) is not valid C++ for a non-static member; this will fail to compile. Use sizeof(encapsulatedData.data) (or an equivalent sizeof(((mavlink_encapsulated_data_t*)nullptr)->data)) to compare against the ENCAPSULATED_DATA data array size.

Suggested change
if (_imageHandshake.payload > sizeof(mavlink_encapsulated_data_t::data)) {
if (_imageHandshake.payload > sizeof(((mavlink_encapsulated_data_t*)nullptr)->data)) {

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong

break;
}

_imageBytes.resize(_imageHandshake.size, '\0');
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QByteArray::resize only takes a single size argument; resize(_imageHandshake.size, '\0') will not compile. If you want the buffer zero-initialized, use fill('\0', _imageHandshake.size) or assign a QByteArray(_imageHandshake.size, '\0') after the validation checks.

Suggested change
_imageBytes.resize(_imageHandshake.size, '\0');
_imageBytes.fill('\0', _imageHandshake.size);

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong

Harden MAVLink message handlers against malicious or malformed payloads
that could trigger out-of-bounds memory access.

ImageProtocolManager (GHSA-v5rc-wh3c-c4cw):
- Validate DATA_TRANSMISSION_HANDSHAKE fields (size, payload, packets)
  before allocating the image buffer
- Enforce 1 MB upper bound on image size
- Reject payload values exceeding ENCAPSULATED_DATA data[253] array size
- Pre-allocate image buffer to declared size instead of growing via
  unchecked indexed writes
- Replace byte-by-byte copy loop with bounds-clamped memcpy
- Cast seqnr to uint32_t before multiplication to prevent overflow

Vehicle (LOG_DATA):
- Add bounds check on log.count against sizeof(log.data) before emitting
  the signal, preventing downstream consumers from reading past the
  90-byte data array

FTPManager (FILE_TRANSFER_PROTOCOL):
- Validate hdr.size against sizeof(request->data) at the single message
  entry point, protecting all downstream handlers (burst read, list
  directory, fill missing blocks) from reading past the 239-byte data
  array

Fixes: GHSA-v5rc-wh3c-c4cw
@DonLakeFlyer DonLakeFlyer force-pushed the fix/mavlink-message-bounds-validation branch from bae5113 to d478b64 Compare March 6, 2026 03:25
@DonLakeFlyer DonLakeFlyer merged commit 0f30c72 into master Mar 6, 2026
28 of 30 checks passed
@DonLakeFlyer DonLakeFlyer deleted the fix/mavlink-message-bounds-validation branch March 6, 2026 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants