]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect: don't set conflicting packet/flow actions 13222/head
authorVictor Julien <vjulien@oisf.net>
Tue, 13 May 2025 09:26:46 +0000 (11:26 +0200)
committerVictor Julien <vjulien@oisf.net>
Tue, 13 May 2025 09:26:46 +0000 (11:26 +0200)
If for the same a packet a drop rule and a pass rule would match,
the applying of actions could be contradictionary:

- the drop would be applied to the packet
- the pass rule would also be considered, not overriding the drop,
  but still setting the flow pass flag.

This would lead to the packet being dropped, but the rest of the
flow getting passed, including retransmissions of the dropped
packet.

This patch only sets drop/pass actions if no conflicting action
has been set on the packet before. It respects the action-order.

Bug: #7653.

Fix based on:
57b17fb3b2fb ("detect: don't set conflicting packet/flow actions")

src/detect-engine-alert.c

index 466ca45703767319e0f1f6aa2c3566613556dcc1..f3e49586e0c94e864952ba1aeca7a3e6acb2f37f 100644 (file)
@@ -398,14 +398,22 @@ void PacketAlertFinalize(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx
                 }
             }
 
-            /* set actions on the flow */
-            FlowApplySignatureActions(p, pa, s, pa->flags);
+            bool skip_action_set = false;
+            if (p->action & ACTION_DROP) {
+                if (pa->action & ACTION_PASS) {
+                    skip_action_set = true;
+                }
+            }
+            if (!skip_action_set) {
+                /* set actions on the flow */
+                FlowApplySignatureActions(p, pa, s, pa->flags);
 
-            SCLogDebug("det_ctx->alert_queue[i].action %02x (DROP %s, PASS %s)", pa->action,
-                    BOOL2STR(pa->action & ACTION_DROP), BOOL2STR(pa->action & ACTION_PASS));
+                SCLogDebug("det_ctx->alert_queue[i].action %02x (DROP %s, PASS %s)", pa->action,
+                        BOOL2STR(pa->action & ACTION_DROP), BOOL2STR(pa->action & ACTION_PASS));
 
-            /* set actions on packet */
-            PacketApplySignatureActions(p, s, pa);
+                /* set actions on packet */
+                PacketApplySignatureActions(p, s, pa);
+            }
         }
 
         /* Thresholding removes this alert */