CVE-2026-29972
Stack-Based Buffer Overflow in nanoMODBUS Library
Publication date: 2026-05-08
Last updated on: 2026-05-08
Assigner: MITRE
Description
Description
CVSS Scores
EPSS Scores
| Probability: | |
| Percentile: |
Meta Information
Affected Vendors & Products
| Vendor | Product | Version / Range |
|---|---|---|
| debevv | nanomodbus | to 1.22.0 (inc) |
Helpful Resources
Exploitability
| CWE ID | Description |
|---|---|
| CWE-121 | A stack-based buffer overflow condition is a condition where the buffer being overwritten is allocated on the stack (i.e., is a local variable or, rarely, a parameter to a function). |
Attack-Flow Graph
AI Powered Q&A
Can you explain this vulnerability to me?
The vulnerability in nanoMODBUS through version 1.22.0 is a stack-based buffer overflow found in the function recv_read_registers_res() within the nanomodbus.c file.
When a client calls either nmbs_read_holding_registers() or nmbs_read_input_registers(), the library writes register data from the server's response into a buffer provided by the caller. This write operation is based on the response's byte_count field.
However, the vulnerability arises because the library does not validate that the byte_count matches the originally requested quantity before writing. A malicious Modbus TCP server can exploit this by sending a response with a byte_count of 250 (which corresponds to 125 registers), regardless of the requested amount.
This causes up to 248 bytes of attacker-controlled data to overflow the buffer, potentially leading to remote code execution.
How can this vulnerability impact me? :
This vulnerability can have serious impacts including the possibility of remote code execution on the affected system.
An attacker controlling a malicious Modbus TCP server can exploit the buffer overflow to overwrite memory on the client device, potentially allowing them to execute arbitrary code.
This could lead to unauthorized control over the device, data corruption, system crashes, or further compromise of the network where the device operates.
How does this vulnerability affect compliance with common standards and regulations (like GDPR, HIPAA)?:
The provided information does not specify any direct impact of this vulnerability on compliance with common standards and regulations such as GDPR or HIPAA.
How can this vulnerability be detected on my network or system? Can you suggest some commands?
This vulnerability can be detected by monitoring Modbus TCP traffic for anomalous or malicious responses from servers, specifically responses where the byte_count field is unusually large (e.g., 250) regardless of the requested quantity.
Since the vulnerability involves a buffer overflow triggered by a malicious Modbus TCP server response, detection can involve capturing and inspecting Modbus packets using network analysis tools like Wireshark or tcpdump.
- Use tcpdump to capture Modbus TCP traffic on the default port 502: tcpdump -i <interface> port 502 -w modbus_traffic.pcap
- Analyze the captured traffic with Wireshark, filtering for Modbus responses and inspecting the byte_count field in read register responses for suspiciously large values.
- If you have access to the nanoMODBUS client application, enable verbose or debug logging to detect unexpected large byte_count values in responses to nmbs_read_holding_registers() or nmbs_read_input_registers() calls.
What immediate steps should I take to mitigate this vulnerability?
Immediate mitigation steps include updating the nanoMODBUS library to a version later than 1.22.0 where this vulnerability is fixed.
If an update is not immediately possible, consider implementing network-level protections such as firewall rules to restrict access to Modbus TCP port 502 only to trusted servers and clients.
Additionally, monitor and block Modbus TCP responses with suspiciously large byte_count fields to prevent exploitation.
Review and apply input validation patches or workarounds in the nanomodbus.c source code, particularly validating the byte_count field before copying data to buffers.