]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
defrag: don't use completed tracker
authorVictor Julien <vjulien@oisf.net>
Tue, 4 Jun 2024 12:43:22 +0000 (14:43 +0200)
committerVictor Julien <vjulien@oisf.net>
Tue, 25 Jun 2024 11:57:11 +0000 (13:57 +0200)
When a Tracker is set up for a IPID, frags come in for it and it's
reassembled and complete, the `DefragTracker::remove` flag is set. This
is mean to tell the hash cleanup code to recyle the tracker and to let
the lookup code skip the tracker during lookup.

A logic error lead to the following scenario:

1. there are sufficient frag trackers to make sure the hash table is
   filled with trackers
2. frags for a Packet with IPID X are processed correctly (X1)
3. frags for a new Packet that also has IPID X come in quickly after the
   first (X2).
4. during the lookup, the frag for X2 hashes to a hash row that holds
   more than one tracker
5. as the trackers in hash row are evaluated, it finds the tracker for
   X1, but since the `remove` bit is not checked, it is returned as the
   tracker for X2.
6. reassembly fails, as the tracker is already complete

The logic error is that only for the first tracker in a row the `remove`
bit was checked, leading to reuse to a closed tracker if there were more
trackers in the hash row.

Ticket: #7042.

src/defrag-hash.c

index 2f19ce28ee13de52f026ad54c748014e831e83bd..87d40f9b5109fc47e02158733a1ccd9466c07bd7 100644 (file)
@@ -591,7 +591,7 @@ DefragTracker *DefragGetTrackerFromHash (Packet *p)
                 return dt;
             }
 
-            if (DefragTrackerCompare(dt, p) != 0) {
+            if (!dt->remove && DefragTrackerCompare(dt, p) != 0) {
                 /* we found our tracker, lets put it on top of the
                  * hash list -- this rewards active trackers */
                 if (dt->hnext) {