Severity by source
AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:H
Remote, unauthenticated, single-packet trigger (AV:N/AC:L/PR:N/UI:N); bounded 7-byte overflow into one adjacent static var gives limited integrity impact (I:L) but reliable crash/DoS (A:H), no data disclosure (C:N).
Primary rating from Vendor (TuranSec).
CVSS VectorVendor: TuranSec
Lifecycle Timeline
2DescriptionCVE.org
The LINUXTCP port of FreeModbus contains an off-by-one bounds check in xMBPortTCPPool() (demo/LINUXTCP/port/porttcp.c). The check if (usTCPFrameBytesLeft > MB_TCP_BUF_SIZE) uses a strict greater-than comparison instead of greater-than-or-equal against the 263-byte MB_TCP_BUF_SIZE limit. An MBAP frame with a Length field of 264 makes usTCPFrameBytesLeft equal to 263, which passes the flawed check, and the subsequent recv() call writes up to 263 bytes starting at buffer offset 7 into the 263-byte static buffer aucTCPBuf, overflowing it by 7 bytes into the adjacent static variable usTCPBufPos. A single crafted, unauthenticated Modbus TCP packet triggers the overflow, since Modbus has no built-in authentication.
AnalysisAI
Out-of-bounds write in the LINUXTCP demo port of FreeModbus (cwalter-at fork) lets a remote, unauthenticated attacker overflow the static aucTCPBuf receive buffer by sending a single crafted Modbus TCP (MBAP) frame. Because the xMBPortTCPPool() length validation uses a strict '>' instead of '>=' against the 263-byte MB_TCP_BUF_SIZE, a frame declaring Length 264 passes the check and recv() writes 7 bytes past the buffer into the adjacent usTCPBufPos variable, corrupting parser state. CVSS is 9.1 (I:H/A:H); there is no public exploit identified at time of analysis and it is not on CISA KEV.
Technical ContextAI
FreeModbus is an open-source implementation of the Modbus RTU/ASCII/TCP protocol stack widely embedded in industrial and IoT device firmware. The flaw lives in the reference LINUXTCP transport port (demo/LINUXTCP/port/porttcp.c), which buffers incoming Modbus Application Protocol (MBAP) frames into a fixed 263-byte static buffer aucTCPBuf. Modbus TCP frames carry a 7-byte MBAP header (transaction ID, protocol ID, length, unit ID) followed by the PDU; the code reads the header-declared Length field to size the remaining recv(). The root cause is CWE-787 (out-of-bounds write) caused by a classic off-by-one boundary error: 'if (usTCPFrameBytesLeft > MB_TCP_BUF_SIZE)' should be '>=', so the maximum-plus-one case where usTCPFrameBytesLeft equals 263 slips through and recv() writes starting at offset 7, exceeding the 263-byte capacity by 7 bytes into the adjacent static usTCPBufPos.
RemediationAI
No vendor-released patch identified at time of analysis. The correct fix is to change the bounds check in xMBPortTCPPool() from 'if (usTCPFrameBytesLeft > MB_TCP_BUF_SIZE)' to '>=', or equivalently to reject any MBAP frame whose declared Length would make usTCPFrameBytesLeft reach or exceed MB_TCP_BUF_SIZE (263) before the recv() call; rebuild affected firmware from the corrected source at https://github.com/cwalter-at/freemodbus/blob/master/demo/LINUXTCP/port/porttcp.c. Where patching is not immediately possible, restrict network exposure of the Modbus TCP service (default port 502) with firewall rules so only trusted control-network hosts can connect, and place the device behind a Modbus-aware gateway or IDS that drops MBAP frames with a Length field larger than the protocol maximum (253 for the PDU / 260 total) - the trade-off is that any legitimate over-length client traffic is dropped, but well-formed Modbus never needs Length 264. Network segmentation of OT/ICS assets away from general IT and the internet is the primary compensating control given Modbus lacks authentication.
More in Freemodbus
View allSame weakness CWE-787 – Out-of-bounds Write
View allSame technique Buffer Overflow
View allShare
External POC / Exploit Code
Leaving vuln.today
EUVD-2026-53348
GHSA-cjvm-2pqq-6v6h