Optimization #9432
opendnp3: drop rule on DIRECT_OPERATE bypassed after a link header with a valid CRC that breaks a link-layer rule (IPS)
Description
We'd like to report an issue in the DNP3 parser that lets a control command through an inline Suricata with a drop rule that should block it. It is related to, but separate from, our earlier report of 2026-11-07 (Modbus) and to the public PR #16442: that PR resynchronizes after a bad start, and this case has a valid start and a valid CRC, so nothing in it triggers the resynchronization.
Summary. A DNP3 link header with a valid CRC that breaks a link-layer rule, for example REQUEST_LINK_STATUS (control 0xC9) declaring a body, is accepted by the parser, which then waits for the declared body (LENGTH 60 or 255) and consumes the next frame as part of it. opendnp3 checks these rules as soon as it reads the header (ValidateHeaderParameters in LinkLayerParser.cpp, in every release since 1.1.0), rejects it, advances one octet, resynchronizes on the next 05 64 and executes the frame that follows. In IPS mode a drop rule on dnp3_func:direct_operate does not fire and the device executes the command. No dnp3 parser error is raised, so the exception policy does not apply. Every octet is well formed and every checksum valid; the header only breaks a rule of the standard.
Versions. Suricata 8.0.7, 8.0.8 and main (9.0.0-dev, 4badfd13f), exception-policy: auto (default) and ignore. Rule: drop dnp3 any any -> any any (msg:"block DNP3 DIRECT_OPERATE"; dnp3_func:direct_operate; sid:1; rev:1;)
Minimal stream (master 1 -> outstation 10, TCP 20000, one segment):
05 64 3C C9 0A 00 01 00 86 7C header: LENGTH 60, CONTROL 0xC9, valid CRC 05 64 18 C4 0A 00 01 00 3D 3A C1 C1 05 0C 01 17 01 08 03 01 64 00 00 00 64 00 76 10 00 00 00 FF FF a complete, valid DIRECT_OPERATE (CROB, index 3)
Other rules give the same result: RESET_LINK_STATES with a body (0xC0), UNCONFIRMED_USER_DATA with FCV set (0xD4), a reserved function code (0xC7).
Observed.
- suricata-verify test dnp3-ips-drop-after-link-rule-header (six flows, --simulate-ips): on 8.0.7 only the control (DIRECT_OPERATE alone) is blocked; the five flows with a rule-breaking header (0xC9 LENGTH 60 and 255, 0xC0, 0xD4, 0xC7) raise no alert.
- Inline (NFQUEUE, live opendnp3 outstation): the outstation executes the command in all 8 variants we tried (LENGTH 60 or 255; header and command in the same or separate segments; connection closed, held open, or followed by another READ), under auto and ignore, with no alert. The same DIRECT_OPERATE alone is blocked. Same result on 8.0.8 and main. Details in EVIDENCE.md.
- Passively, Suricata 8.0.7 reports the command in 0 of 192 constructed streams of this kind; opendnp3 executes it in 128 of 128 runs with LENGTH 60 or 255, and OpenPLC v3 (which embeds opendnp3 2.2.1) changes a PLC output in 128 of 128.
Cause (as far as we can tell). The parser validates the link header (start octets and header CRC) on reading it, but checks the link-layer rules (function code against PRM, FCV, and whether LENGTH is allowed for the function) only once the whole frame has arrived, so it trusts the declared LENGTH of a header the device has already discarded.
A reference fix (available on request). We have a patch against 8.0.7 that checks those rules when the header is read, under the resync-on-bad-start option, resynchronizes from the next octet when one fails (addresses stay checked at frame time, as in opendnp3), and adds an event dnp3.bad_link_rule. Inline it blocks the command in all 8 variants under both policies; the stock image with the same rules does not. On 240 s of benign traffic with 30 legitimate commands it raises no event. Offline on our 192-stream corpus it flags all 160 streams where the device behaviour depends on this choice, with no false positives, and the DIRECT_OPERATE is parsed in all 160. The patch also carries the prototype from our research (an optional recovery-policy divergence event), so it is a reference, not a proposed PR. We can send it on request, or prepare a minimal change on top of #16442 if that is more useful.
Coordination. This is one instance of a wider ambiguity in the DNP3 standard about when link-layer rules are checked. For transparency: we reported the class issue today to CISA (VINCE-NT CASE#241353), which lists OISF among the affected projects, and to INCIBE-CERT, with the same technical report. The Suricata findings appear there as part of the class issue; this message is the Suricata-specific report. We propose 2027-02-17 as the public date for all of it, and will follow your policy for the Suricata-specific part. We will not discuss this case in public threads, including #16442, until you agree.
Attached: oisf-dnp3-linkrule-reproducer.tar.gz (suricata-verify test, inline lab and evidence).
Credit, if any: Lucas Sotomayor and Diego Staino, BASE4 Security.
Files
Subtasks