Menu ▾ ▴

#22 Stack buffer overflow in _daveReadISOPacket (ISO-on-TCP length field, nodave.c)

v1.0 (example)
open
nobody
None
5
2026-11-05
2026-11-05
No

Summary

_daveReadISOPacket in nodave.c reads the 4-byte TPKT header, takes the
16-bit length field directly from the wire, and reads that many bytes into the
fixed 2048-byte receive buffer msgIn (daveMaxRawLen) with no bound check:

res=read(di->fd.rfd, b, 4);
...
length=b[3]+0x100*b[2];              // from the wire, up to 65535
res+=read(di->fd.rfd, b+4, length-4); // into b = msgIn[2048], no bound

A malicious or compromised S7 PLC, or a MITM on the ISO-on-TCP link (TCP/102),
can announce a large length and send that many bytes to overflow msgIn.

Impact

Remote, unauthenticated buffer overflow (write). DoS is certain; code execution
cannot be excluded.

Reproduction

Feeding a crafted packet (TPKT length 0x2000, then 8188 bytes) to
_daveReadISOPacket with a 2048-byte buffer produces, under AddressSanitizer,
a heap-buffer-overflow WRITE of 8188 bytes 0 bytes past the 2048 buffer. A full
reproducer is available on request.

Suggested fix

Reject length > daveMaxRawLen (and length < 4) before the second read.

Reporter: Gyu-hyun Jeon, STEALIEN

Discussion


Log in to post a comment.