CVE-2026-29972
Received Received - Intake
Stack-Based Buffer Overflow in nanoMODBUS Library

Publication date: 2026-05-08

Last updated on: 2026-05-08

Assigner: MITRE

Description
nanoMODBUS through v1.22.0 has a stack-based buffer overflow in recv_read_registers_res() in nanomodbus.c. When a client calls nmbs_read_holding_registers() or nmbs_read_input_registers(), the library writes register data from the server response to the caller-provided buffer based on the response's byte_count field before validating that byte_count matches the requested quantity. A malicious Modbus TCP server can send a response with byte_count=250 (125 registers) regardless of the requested quantity, causing up to 248 bytes of attacker-controlled data to overflow the buffer, potentially allowing remote code execution.
CVSS Scores
EPSS Scores
Probability:
Percentile:
Meta Information
Published
2026-05-08
Last Modified
2026-05-08
Generated
2026-06-19
AI Q&A
2026-05-08
EPSS Evaluated
2026-06-18
NVD
EUVD
Affected Vendors & Products
Showing 1 associated CPE
Vendor Product Version / Range
debevv nanomodbus to 1.22.0 (inc)
Helpful Resources
Exploitability
CWE
CWE Icon
KEV
KEV Icon
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 Quick Actions
Instant insights powered by AI
Executive Summary

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.

Impact Analysis

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.

Compliance Impact

The provided information does not specify any direct impact of this vulnerability on compliance with common standards and regulations such as GDPR or HIPAA.

Detection Guidance

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.
Mitigation Strategies

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.

Chat Assistant
Ask questions about this CVE
Hi! I’m here to help you understand CVE-2026-29972. Ask me anything about the vulnerability, its impact, or mitigation strategies.
0/70
EPSS Chart