CVE-2024-25391
Executive Summary
CVE-2024-25391 identifies a stack buffer overflow vulnerability in the libc/posix/ipc/mqueue.c file of RT-Thread, an open-source real-time operating system (RTOS). The flaw exists in versions through 5.0.2 and can be triggered when processing POSIX message queue operations. An attacker who can send crafted IPC messages to a vulnerable RT-Thread device may cause a stack buffer overflow, leading to denial of service (DoS) or potentially arbitrary code execution. No public exploit code or patch is currently available, and the CVSS score is listed as 0.0 due to incomplete NVD data. The EPSS score is 0.0%, indicating low exploitation activity at this time.
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
RT-Thread is a widely used RTOS in IoT and embedded systems. The vulnerability resides in the core POSIX IPC library, which is a standard component of the RT-Thread distribution. Since RT-Thread is often integrated into larger firmware builds, the supply chain risk is moderate. Developers using RT-Thread versions 5.0.2 or earlier should assess their exposure, especially if the device exposes message queue interfaces to untrusted inputs.
CVSS Breakdown & Threat Level
The NVD has not assigned a CVSS vector or score for this CVE. Based on the vulnerability type (stack buffer overflow in an IPC mechanism), a reasonable assessment would be:
- Attack Vector (AV): Local (L) – requires local access to the system or ability to send IPC messages.
- Attack Complexity (AC): Low (L) – the overflow is triggered by standard message queue operations.
- Privileges Required (PR): Low (L) – an attacker needs user-level access to send IPC messages.
- User Interaction (UI): None (N) – no user action required beyond sending the message.
- Scope (S): Unchanged (U) – the overflow affects the same security context.
- Confidentiality (C): High (H) – potential for arbitrary code execution.
- Integrity (I): High (H) – potential for code execution.
- Availability (A): High (H) – overflow can cause a crash.
Estimated CVSS:3.1 Score: 7.8 (High)
Threat Level: High – due to the potential for code execution in an RTOS environment where reliability is critical.
Deep Dive & Mechanics
The vulnerability is a classic stack buffer overflow in the mqueue.c file of RT-Thread's POSIX IPC implementation. The mq_send and mq_receive functions likely use fixed-size stack buffers without proper bounds checking when copying message data. An attacker can send a message larger than the expected buffer size, causing the overflow.
Root Cause: The mqueue.c implementation does not validate the length of the message against the allocated stack buffer before copying. This allows an attacker to overwrite the return address and other stack variables.
Attack Vector: An attacker with local access to the RT-Thread system (e.g., via a serial console, network service, or another compromised component) can send a crafted message to a POSIX message queue. The overflow occurs during the copy operation in mq_send or mq_receive.
Impact: Successful exploitation can lead to:
- Denial of service (system crash).
- Arbitrary code execution in the context of the RT-Thread kernel (if the overflow is in kernel space) or the user process (if in user space). Given RT-Thread's architecture, this is likely a kernel-level vulnerability.
Vulnerable vs. Patched Code
Since no patch is available, a direct comparison is not possible. However, the vulnerable code pattern is:
// Vulnerable pattern (hypothetical)
void mq_send(mqd_t mqdes, const char *msg_ptr, size_t msg_len, unsigned int msg_prio) {
char stack_buffer[256]; // Fixed-size buffer
// No bounds check on msg_len
memcpy(stack_buffer, msg_ptr, msg_len); // Overflow if msg_len > 256
// ... rest of function
}
A patched version would include a length check:
// Patched pattern (hypothetical)
void mq_send(mqd_t mqdes, const char *msg_ptr, size_t msg_len, unsigned int msg_prio) {
char stack_buffer[256];
if (msg_len > sizeof(stack_buffer)) {
// Return error or handle gracefully
return -1;
}
memcpy(stack_buffer, msg_ptr, msg_len);
// ... rest of function
}
Exploitation & Lab Setup
Red Team
Objective: Trigger a stack buffer overflow to cause a crash or achieve code execution.
Prerequisites:
- Access to an RT-Thread device (version <= 5.0.2) with POSIX message queue support enabled.
- Ability to send IPC messages (e.g., via a serial console or network service).
Exploit Steps:
- Identify a message queue file descriptor (e.g.,
/dev/mqueueor a named queue). - Send a message with a payload larger than the expected buffer size (e.g., 300 bytes when the buffer is 256 bytes).
- Observe the system crash or attempt to control the overflow to redirect execution.
Example Payload (Python):
import socket
# Assume a network service that forwards to mqueue
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(("target_ip", 1234))
# Craft overflow payload
payload = b"A" * 256 + b"BBBB" # Overflow return address
sock.send(payload)
sock.close()
Blue Team
Detection:
- Monitor for unusually large IPC messages.
- Enable stack canaries if supported by the compiler.
- Use memory protection (e.g., MPU) to prevent stack execution.
Mitigation:
- Apply input validation on message sizes before passing to
mq_send. - Use dynamic memory allocation instead of fixed stack buffers.
- Disable POSIX message queues if not needed.
Indicators of Compromise (IOCs)
- Network: Unusually large packets on IPC-related ports (e.g., custom RT-Thread services).
- System: Kernel panic logs or crash dumps showing stack corruption in
mqueue.c. - Memory: Stack memory containing patterns of repeated characters (e.g., 0x41 for 'A').
- Logs: Error messages like "mq_send: invalid message length" (if patched) or missing validation.
Detection Engineering
YARA Rule
rule CVE_2024_25391_RTThread_Mqueue_Overflow {
meta:
description = "Detects stack buffer overflow in RT-Thread mqueue.c"
author = "Valters IT"
date = "2025-04-10"
reference = "CVE-2024-25391"
strings:
$s1 = "mq_send" ascii wide
$s2 = "mq_receive" ascii wide
$s3 = "stack_buffer" ascii wide
$s4 = "memcpy" ascii wide
condition:
all of ($s1, $s2, $s3, $s4) and filesize < 1MB
}
Sigma Rule
title: CVE-2024-25391 RT-Thread mqueue Stack Overflow
id: 8a9b7c6d-5e4f-3a2b-1c0d-9e8f7a6b5c4d
status: experimental
description: Detects attempts to exploit stack buffer overflow in RT-Thread mqueue
author: Valters IT
date: 2025-04-10
logsource:
product: linux
service: syslog
detection:
selection:
- "mq_send: message too long"
- "stack overflow in mqueue"
- "kernel BUG at mqueue.c"
condition: selection
falsepositives:
- Legitimate large messages (unlikely)
level: high
Suricata Rule
alert tcp any any -> any any (msg:"CVE-2024-25391 RT-Thread mqueue Overflow Attempt"; flow:to_server; content:"|41 41 41 41|"; depth:256; threshold:type limit, track by_src, count 1, seconds 60; sid:1000001; rev:1;)
Remediation & Mitigation
Immediate Actions:
- Disable POSIX message queues if not required for operation.
- Apply input validation on message sizes in custom code that uses
mq_send/mq_receive. - Monitor for updates from RT-Thread regarding a patch.
Long-term Fix:
- The RT-Thread development team should patch
mqueue.cto include bounds checking on message lengths before copying to stack buffers. - Use dynamic memory allocation or increase buffer sizes with proper validation.
Workaround:
- If source code is available, manually add a length check in
mqueue.c:
if (msg_len > MAX_MSG_SIZE) {
return -1; // or handle error
}
Valters IT Signature: This report was generated by Valters IT DevSecOps AI. For questions, contact security@valters-it.com.