Skip to content

Commit 0c44f3f

Browse files
committed
stream/tcp: account for midstream sessions
Commit 497394e removed inspection of app-proto txs for packets without an established TCP connection. But this meant that the first packet seen in a session pick mid-stream could go without inspection (previous bug 5510 seemed to point towards this behavior, too). If a flow has more packets, the stream will be inspected as part of the upcoming packets and this would go unnoticed. In a single-packet flow, however, the inspection for the packed would be skipped. Although this might not affect alerts -- as they could be processed as part of the flow timeout logic, the actual traffic could be evaded in IPS, in case of a drop rule. From the above, the most visible scenario is when there is only one packet on the flow, as then the engine doesn't have "more time" to pick-up real-packets to inspect for that given flow. But certain tests show that this can also happen for more than one packet scenarios: there will be one less drop event, or traffic from a packet that should have been already dropped will be logged. This led to the possibility of a real packet not being blocked, in IPS, or matched against rules, as the corresponding portion of the stream was only inspected later, as part of the stream/flow-timeout logic. To ensure that we correctly flag the first packet seen for a given mid-stream session, we must check for the session state *after* we have dealt with TCP flags and state. Related to Bug #5510 As part of Bug #5180
1 parent 063e700 commit 0c44f3f

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/stream-tcp.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2007-2025 Open Information Security Foundation
1+
/* Copyright (C) 2007-2026 Open Information Security Foundation
22
*
33
* You can copy, redistribute or modify this Program under the terms of
44
* the GNU General Public License version 2 as published by the Free
@@ -5731,6 +5731,7 @@ int StreamTcpPacket (ThreadVars *tv, Packet *p, StreamTcpThread *stt,
57315731
if (StreamTcpPacketStateNone(tv, p, stt, ssn) == -1) {
57325732
goto error;
57335733
}
5734+
ssn = (TcpSession *)p->flow->protoctx;
57345735

57355736
if (ssn != NULL)
57365737
SCLogDebug("ssn->alproto %"PRIu16"", p->flow->alproto);
@@ -5804,17 +5805,19 @@ int StreamTcpPacket (ThreadVars *tv, Packet *p, StreamTcpThread *stt,
58045805

58055806
skip:
58065807
StreamTcpPacketCheckPostRst(ssn, p);
5807-
5808-
if (ssn->state >= TCP_ESTABLISHED) {
5809-
p->flags |= PKT_STREAM_EST;
5810-
}
58115808
}
58125809

58135810
if (ssn != NULL) {
58145811
/* recalc the csum on the packet if it was modified */
58155812
if (p->flags & PKT_STREAM_MODIFIED) {
58165813
ReCalculateChecksum(p);
58175814
}
5815+
5816+
/* if ssn was set in this run (e.g. midstream cases), reflect TCP state on the packet */
5817+
if (ssn->state >= TCP_ESTABLISHED) {
5818+
p->flags |= PKT_STREAM_EST;
5819+
}
5820+
58185821
/* check for conditions that may make us not want to log this packet */
58195822

58205823
/* streams that hit depth */

0 commit comments

Comments
 (0)