Menu ▾ ▴

#23 Out-of-bounds read in S7 response handling (_daveSetupReceivedPDU plen/dlen)

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

Summary

_daveSetupReceivedPDU in nodave.c computes p->plen/p->dlen from the S7
response header (up to 65535 each) and sets p->data = p->param + p->plen with
no check against the received length, so p->data can point far past the fixed
2048-byte msgIn buffer. The result handlers then dereference it:

p->plen = 256*p->header[6] + p->header[7];
p->data = p->param + p->plen;          // no bound vs received length
...
if ((p->data[0]==255) && (p->dlen>4))  // _daveTestResultData: OOB read

A malicious/compromised S7 PLC (or MITM) returning a crafted response to a
libnodave client triggers the OOB read.

Impact

Remote, unauthenticated out-of-bounds read: DoS and potential information
disclosure (leaked bytes can flow back via the result). Distinct from the
_daveReadISOPacket overflow (bug reported separately).

Reproduction

A response with plen=0xFFFF produces, under AddressSanitizer, a
heap-buffer-overflow READ in _daveTestResultData (nodave.c:702). Reproducer
available on request.

Suggested fix

Validate hlen+plen+dlen against the received length (dc->AnswLen) before
setting p->data/p->dlen, and bound subsequent accesses.

Reporter: Gyu-hyun Jeon, STEALIEN

Discussion


Log in to post a comment.