CVE-2025-9020
Executive Summary
CVE-2025-9020 is a high-severity Use-After-Free (UAF) vulnerability found in the PX4-Autopilot project, affecting versions up to and including 1.15.4. The flaw resides in the MavlinkReceiver::handle_message_serial_control function within src/modules/mavlink/mavlink_receiver.cpp. By manipulating the _mavlink_shell argument, an attacker with local access can trigger a use-after-free condition, potentially leading to arbitrary code execution or system instability. The attack complexity is high, and exploitation is considered difficult. A patch is available in commit 4395d4f00c49b888f030f5b43e2a779f1fa78708. This report provides a comprehensive technical analysis, detection rules, and remediation guidance.
This record — and 170,000+ others — are available via the ValtersIT API. One endpoint replaces five: NVD + GitHub CVE + CISA KEV + EPSS + Nuclei + Exploit-DB, unified.
No signup required
Supply Chain & Package Security
This vulnerability is not related to a package manager (NPM, PyPI, Go, Ruby) but is a source-code level issue in the PX4-Autopilot project. The supply chain risk is limited to organizations that build and deploy PX4-based autopilot systems from source or use pre-compiled binaries. The patch must be applied to the source code and rebuilt.
CVSS Breakdown & Threat Level
- CVSS Vector: CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:H/I:H/A:H
- Base Score: 7.0 (High)
- Attack Vector (AV): Local (L) – Requires local access to the system.
- Attack Complexity (AC): High (H) – Exploitation requires specific conditions and timing.
- Privileges Required (PR): Low (L) – Attacker needs low-level privileges.
- User Interaction (UI): None (N) – No user action required.
- Scope (S): Unchanged (U) – Vulnerability does not affect other components.
- Confidentiality (C): High (H) – Potential for data disclosure.
- Integrity (I): High (H) – Potential for data modification.
- Availability (A): High (H) – Potential for denial of service.
Threat Level: High. Although exploitation is difficult, successful exploitation could lead to full compromise of the autopilot system.
Deep Dive & Mechanics
The vulnerability is a classic Use-After-Free (UAF) in the MAVLink shell handling component. The MavlinkReceiver::handle_message_serial_control function processes MAVLink messages related to serial control. When handling the _mavlink_shell argument, the code improperly manages memory, allowing a reference to a freed object to be used.
Root Cause: The _mavlink_shell object is freed prematurely, but a pointer to it is retained and later dereferenced. This can occur when a MAVLink message triggers a sequence of operations that deallocates the shell object while a reference is still active.
Attack Vector: An attacker with local access to the system (e.g., via a compromised MAVLink connection or a malicious process) sends crafted MAVLink messages that manipulate the shell state, causing the UAF.
Impact: Successful exploitation can lead to arbitrary code execution, denial of service, or information disclosure, depending on how the freed memory is reused.
Vulnerable vs. Patched Code
Vulnerable Code (simplified):
void MavlinkReceiver::handle_message_serial_control(mavlink_message_t *msg) {
// ... parsing ...
if (_mavlink_shell) {
// Use _mavlink_shell
_mavlink_shell->doSomething();
// _mavlink_shell is freed elsewhere but pointer remains
}
}
Patched Code (commit 4395d4f00c49b888f030f5b43e2a779f1fa78708):
void MavlinkReceiver::handle_message_serial_control(mavlink_message_t *msg) {
// ... parsing ...
if (_mavlink_shell) {
// Check if _mavlink_shell is still valid
if (is_valid(_mavlink_shell)) {
_mavlink_shell->doSomething();
} else {
// Reset pointer to avoid UAF
_mavlink_shell = nullptr;
}
}
}
The patch adds a validity check before using the _mavlink_shell pointer and resets it to nullptr if it has been freed, preventing the use-after-free.
Exploitation & Lab Setup
Red Team
Prerequisites:
- Local access to a system running PX4-Autopilot <= 1.15.4.
- Ability to send MAVLink messages (e.g., via a MAVLink library or custom script).
Exploitation Steps:
- Establish a MAVLink connection to the target system.
- Send a sequence of MAVLink messages that trigger the shell closing handler and free the
_mavlink_shellobject. - Immediately send another message that dereferences the freed pointer, causing a UAF.
- Use heap spraying or other techniques to control the freed memory and achieve code execution.
Example Python script (conceptual):
import pymavlink.mavutil as mavutil
master = mavutil.mavlink_connection('udp:127.0.0.1:14550')
master.wait_heartbeat()
# Trigger shell close
master.mav.serial_control_send(
device=0,
flags=0,
timeout=0,
baudrate=0,
data=b''
)
# Send crafted message to trigger UAF
master.mav.serial_control_send(
device=0,
flags=1,
timeout=0,
baudrate=0,
data=b'\x00' * 100
)
Blue Team
Detection:
- Monitor for unusual MAVLink messages, especially
SERIAL_CONTROLmessages with unexpected flags or data. - Use memory analysis tools to detect use-after-free patterns.
- Implement logging of MAVLink message sequences and shell state changes.
Mitigation:
- Apply the patch immediately.
- Restrict local access to the system.
- Use network segmentation to limit MAVLink exposure.
Indicators of Compromise (IOCs)
- File:
src/modules/mavlink/mavlink_receiver.cpp(unpatched version) - MAVLink Messages: Unusual
SERIAL_CONTROLmessages with flags indicating shell close followed by data. - Memory Patterns: Heap corruption or crashes in the MAVLink receiver.
- Logs: Entries indicating shell state inconsistencies or unexpected terminations.
Detection Engineering
YARA Rule
rule CVE_2025_9020_UseAfterFree {
meta:
description = "Detects vulnerable code pattern in PX4-Autopilot mavlink_receiver.cpp"
author = "Valters IT"
date = "2025-04-10"
cve = "CVE-2025-9020"
strings:
$vuln_func = "handle_message_serial_control"
$vuln_ptr = "_mavlink_shell"
$vuln_use = "_mavlink_shell->"
condition:
$vuln_func and $vuln_ptr and $vuln_use
}
Sigma Rule
title: CVE-2025-9020 - Use-After-Free in PX4-Autopilot MAVLink Shell
id: 8a9b7c6d-5e4f-3a2b-1c0d-9e8f7a6b5c4d
status: experimental
description: Detects potential exploitation of CVE-2025-9020 via MAVLink serial control messages
author: Valters IT
date: 2025-04-10
logsource:
category: process_creation
product: linux
detection:
selection:
Image|endswith: '/px4'
CommandLine|contains: 'mavlink'
condition: selection
falsepositives:
- Legitimate MAVLink operations
level: high
Suricata Rule
alert udp any any -> any any (msg:"CVE-2025-9020 - PX4-Autopilot MAVLink Shell UAF"; content:"|FE|"; depth:1; content:"|01|"; distance:1; within:1; content:"|00|"; distance:2; within:1; sid:1000001; rev:1;)
Remediation & Mitigation
- Apply Patch: Update to the latest version of PX4-Autopilot that includes commit
4395d4f00c49b888f030f5b43e2a779f1fa78708. - Restrict Access: Limit local access to the autopilot system to trusted users only.
- Network Segmentation: Isolate MAVLink traffic to trusted networks.
- Monitor: Implement logging and monitoring for unusual MAVLink messages.
- Code Review: Conduct a thorough review of the MAVLink receiver code for similar issues.
Valters IT
DevSecOps & Cyber Threat Intelligence Expert