]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
fix data seg handling to not queue packets from remote that is in closed state
authordavis mcpherson <davis.mcpherson@gmail.com>
Thu, 7 Apr 2016 14:10:12 +0000 (10:10 -0400)
committerdavis mcpherson <davis.mcpherson@gmail.com>
Thu, 7 Apr 2016 14:10:12 +0000 (10:10 -0400)
src/stream/tcp/tcp_session.cc
src/stream/tcp/tcp_state_established.cc

index 3e2de5453223894d3ccf99b43402ddda0953c622..534d9e5be5482da524539b575c616c34172f5fe4 100644 (file)
@@ -814,43 +814,46 @@ void TcpSession::handle_data_segment(TcpSegmentDescriptor& tsd)
         flush_policy_names[talker->flush_policy],
         flush_policy_names[listener->flush_policy]);
 
-    // FIXIT - move this to normalizer base class, handle OS_PROXY in derived class
-    if (config->policy != StreamPolicy::OS_PROXY)
+    if ( TcpStreamTracker::TCP_CLOSED != talker->get_tcp_state() )
     {
-        /* check for valid seqeuence/retrans */
-        if (!listener->is_segment_seq_valid(tsd) )
-            return;
-
-        // these normalizations can't be done if we missed setup. and
-        // window is zero in one direction until we've seen both sides.
-        if (!(flow->get_session_flags() & SSNFLAG_MIDSTREAM) && flow->two_way_traffic())
+        // FIXIT - move this to normalizer base class, handle OS_PROXY in derived class
+        if (config->policy != StreamPolicy::OS_PROXY)
         {
-            // sender of syn w/mss limits payloads from peer since we store mss on
-            // sender side, use listener mss same reasoning for window size
-            TcpStreamTracker* st = listener;
+            /* check for valid seqeuence/retrans */
+            if (!listener->is_segment_seq_valid(tsd) )
+                return;
+
+            // these normalizations can't be done if we missed setup. and
+            // window is zero in one direction until we've seen both sides.
+            if (!(flow->get_session_flags() & SSNFLAG_MIDSTREAM) && flow->two_way_traffic())
+            {
+                // sender of syn w/mss limits payloads from peer since we store mss on
+                // sender side, use listener mss same reasoning for window size
+                TcpStreamTracker* st = listener;
 
-            // trim to fit in window and mss as needed
-            st->normalizer->trim_win_payload(tsd, (st->r_win_base + st->get_snd_wnd() -
-                st->r_nxt_ack));
+                // trim to fit in window and mss as needed
+                st->normalizer->trim_win_payload(tsd, (st->r_win_base + st->get_snd_wnd() -
+                        st->r_nxt_ack));
 
-            if (st->get_mss())
-                st->normalizer->trim_mss_payload(tsd, st->get_mss());
+                if (st->get_mss())
+                    st->normalizer->trim_mss_payload(tsd, st->get_mss());
 
-            st->normalizer->ecn_stripper(tsd.get_pkt());
+                st->normalizer->ecn_stripper(tsd.get_pkt());
+            }
         }
-    }
 
-    // dunno if this is RFC but fragroute testing expects it  for the record,
-    // I've seen FTP data sessions that send data packets with no tcp flags set
-    if ((tsd.get_tcph()->th_flags != 0)or (config->policy == StreamPolicy::OS_LINUX)
-        or (config->policy == StreamPolicy::OS_PROXY))
-    {
-        process_tcp_data(tsd);
-    }
-    else
-    {
-        tel.set_tcp_event(EVENT_DATA_WITHOUT_FLAGS);
-        listener->normalizer->packet_dropper(tsd, NORM_TCP_BLOCK);
+        // dunno if this is RFC but fragroute testing expects it  for the record,
+        // I've seen FTP data sessions that send data packets with no tcp flags set
+        if ((tsd.get_tcph()->th_flags != 0) or (config->policy == StreamPolicy::OS_LINUX)
+                or (config->policy == StreamPolicy::OS_PROXY))
+        {
+            process_tcp_data(tsd);
+        }
+        else
+        {
+            tel.set_tcp_event(EVENT_DATA_WITHOUT_FLAGS);
+            listener->normalizer->packet_dropper(tsd, NORM_TCP_BLOCK);
+        }
     }
 
     listener->reassembler->flush_on_data_policy(tsd.get_pkt());
index 378c27c2e26ea0527b0f6aedf44dceddb8b7ffdd..2d41bae4c1a4fabc29eca2cad1b78f3fb62210f5 100644 (file)
@@ -108,7 +108,6 @@ bool TcpStateEstablished::data_seg_recv(TcpSegmentDescriptor& tsd, TcpStreamTrac
     auto& trk = static_cast< TcpStreamTracker& >( tracker );
 
     trk.update_tracker_ack_recv(tsd);
-
     session.handle_data_segment(tsd);
 
     return default_state_action(tsd, trk);