Skip to content

Commit a6d9503

Browse files
jasonishinashivb
authored andcommitted
dnp3: bound the maximum number of objects per tx
Default to 2048, but provide a user configuration value. Ticket: #8181 (cherry picked from commit 2c95f1f)
1 parent fdd79bd commit a6d9503

File tree

5 files changed

+30
-4
lines changed

5 files changed

+30
-4
lines changed

doc/userguide/upgrade.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ Upgrading to 7.0.14
4040
Other Changes
4141
~~~~~~~~~~~~~
4242
- ``dnp3`` has reduced the maximum number of open transactions from
43-
500 down to 32, and the maximum number of points per message from
44-
unbounded to 16384. Configuration options, ``max-tx`` and
45-
``max-points`` have been added for users who may need to change
46-
these defaults.
43+
500 down to 32, the maximum number of points per message from
44+
unbounded to 16384, and the maximum number of objects per message
45+
from unbounded to 2048. Configuration options, ``max-tx``,
46+
``max-points``, and ``max-objects`` have been added for users who
47+
may need to change these defaults.
4748

4849
Upgrading to 7.0.12
4950
-------------------

rules/dnp3-events.rules

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,8 @@ alert dnp3 any any -> any any (msg:"SURICATA DNP3 Unknown object"; \
2929
alert dnp3 any any -> any any (msg:"SURICATA DNP3 Too many points in message"; \
3030
app-layer-event:dnp3.too_many_points; \
3131
classtype:protocol-command-decode; sid:2270005; rev:1;)
32+
33+
# Too many objects.
34+
alert dnp3 any any -> any any (msg:"SURICATA DNP3 Too many objects"; \
35+
app-layer-event:dnp3.too_many_objects; \
36+
classtype:protocol-command-decode; sid:2270006; rev:1;)

src/app-layer-dnp3.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ static uint64_t dnp3_max_tx = 32;
101101
/* The maximum number of points allowed per message (configurable). */
102102
static uint64_t max_points = 16384;
103103

104+
/* The maximum number of objects allowed per message (configurable). */
105+
static uint64_t dnp3_max_objects = 2048;
106+
104107
/* Decoder event map. */
105108
SCEnumCharMap dnp3_decoder_event_table[] = {
106109
{ "FLOODED", DNP3_DECODER_EVENT_FLOODED },
@@ -110,6 +113,7 @@ SCEnumCharMap dnp3_decoder_event_table[] = {
110113
{ "MALFORMED", DNP3_DECODER_EVENT_MALFORMED },
111114
{ "UNKNOWN_OBJECT", DNP3_DECODER_EVENT_UNKNOWN_OBJECT },
112115
{ "TOO_MANY_POINTS", DNP3_DECODER_EVENT_TOO_MANY_POINTS },
116+
{ "TOO_MANY_OBJECTS", DNP3_DECODER_EVENT_TOO_MANY_OBJECTS },
113117
{ NULL, -1 },
114118
};
115119

@@ -714,6 +718,7 @@ static int DNP3DecodeApplicationObjects(DNP3Transaction *tx, const uint8_t *buf,
714718
{
715719
int retval = 0;
716720
uint64_t point_count = 0;
721+
uint64_t object_count = 0;
717722

718723
if (buf == NULL || len == 0) {
719724
return 1;
@@ -728,6 +733,12 @@ static int DNP3DecodeApplicationObjects(DNP3Transaction *tx, const uint8_t *buf,
728733
DNP3ObjHeader *header = (DNP3ObjHeader *)buf;
729734
offset += sizeof(DNP3ObjHeader);
730735

736+
/* Check if we've exceeded the maximum number of objects. */
737+
if (++object_count > dnp3_max_objects) {
738+
DNP3SetEventTx(tx, DNP3_DECODER_EVENT_TOO_MANY_OBJECTS);
739+
goto done;
740+
}
741+
731742
DNP3Object *object = DNP3ObjectAlloc();
732743
if (unlikely(object == NULL)) {
733744
goto done;
@@ -1635,6 +1646,13 @@ void RegisterDNP3Parsers(void)
16351646
max_points = (uint64_t)value;
16361647
}
16371648
}
1649+
1650+
/* Parse max-objects configuration. */
1651+
if (ConfGetInt("app-layer.protocols.dnp3.max-objects", &value)) {
1652+
if (value > 0) {
1653+
dnp3_max_objects = (uint64_t)value;
1654+
}
1655+
}
16381656
} else {
16391657
SCLogConfig("Parser disabled for protocol %s. "
16401658
"Protocol detection still on.", proto_name);

src/app-layer-dnp3.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ enum {
110110
DNP3_DECODER_EVENT_MALFORMED,
111111
DNP3_DECODER_EVENT_UNKNOWN_OBJECT,
112112
DNP3_DECODER_EVENT_TOO_MANY_POINTS,
113+
DNP3_DECODER_EVENT_TOO_MANY_OBJECTS,
113114
};
114115

115116
/**

suricata.yaml.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,7 @@ app-layer:
11811181
dp: 20000
11821182
#max-tx: 32
11831183
#max-points: 16384
1184+
#max-objects: 2048
11841185

11851186
# SCADA EtherNet/IP and CIP protocol support
11861187
enip:

0 commit comments

Comments
 (0)