Skip to content

Flowbit ordering cyclic/v4#13756

Closed
inashivb wants to merge 4 commits into
OISF:masterfrom
inashivb:flowbit-ordering-cyclic/v4
Closed

Flowbit ordering cyclic/v4#13756
inashivb wants to merge 4 commits into
OISF:masterfrom
inashivb:flowbit-ordering-cyclic/v4

Conversation

@inashivb

Copy link
Copy Markdown
Member

Previous PR: #13747

Changes since v3:

  • fixed bugs
  • final leg of the solution added
  • tests added

Known TODOs:

  • a problem discovered with the current algorithm by the s-v test firewall-01-tcp-pkt-state-flowbits
    For a given READ command (isset, isnotset) and a given WRITE command (set, unset, toggle)
    current algorithm marks a combination of following signatures as cyclic -- which shall be rejected in the final rev of this work
flowbit:READ,A; flowbit:WRITE,B; sid:1;
flowbit:WRITE,A; flowbit:READ, B, sid:2;

However, there may exist such flowbit combinations that are not cyclic. From the test firewall-01-tcp-pkt-state-flowbits,

pass tcp any 443 -> any any (flags:SA; flow:not_established; flowbits:isset,syn; flowbits:set,synack; sid:2;)
pass tcp any any -> any 443 (flags:A; flow:not_established; flowbits:isset,synack; flowbits:unset,syn; flowbits:unset,synack; sid:3;)
  • fn docs
  • code + commit segregation cleanups

Link to tickets:

SV_BRANCH=OISF/suricata-verify#2627

Question: What shall be done with signatures which contain a cyclic dependency? Current PR's behavior is to restore the original signature ordering in such a case.

This should make it possible to catch invalid combinations in the same
signature early. This patch covers checking the following invalid cmd
combinations:
- set + isset
- unset + isnotset
- set + toggle
- set + unset
- isset + isnotset

the same flowbit in the same signature which is basically an unnecessary
operation.
This helps bring down the difficulty of handling of actual complex flowbit chains.

Bug 7772
Bug 7773
Bug 7774
Bug 7817
Bug 7818
This solution makes use of the petgraph crate to create a graph of
flowbits and signatures. Following steps are involved.
1. Nodes are created for flowbits as well as signatures
2. A directed edge is added:
   from flowbit to signature iff the flowbit use TODO cmd in that sig
   from signature to flowbit iff the flowbit used TODO cmd in that sig
3. The graph is then normalized i.e. the flowbit nodes are removed and a
   clean directed edge is created connecting a dependency graph among
   the signatures. This is done because flowbits are inconsequential in
   the final required solution.
4. The graph is checked for any cycles. In a case like that, the ruleset
   must be rejected as it cannot be satisfied during runtime anyway.
5. Finally, a BFS (Breadth First Search) is performed on the graph
   giving the exact order in which signatures should be such that no
   dependee comes before a dependant.

Bug 7771
Bug 7638
before adding them to the Detection Context's signature list. The
de_ctx->sig_list serves as a sorted signature list that is later passed
on to the grouping fns. If no property of high value changes the order
of the signatures, the order coming from de_ctx->sig_list is final.

Add the appropriate calls to resolve flowbit dependencies before adding
them to the sig_list. This is especially important for flowbits with
complex ordering involved.

Bug 7771
Bug 7638
@inashivb

Copy link
Copy Markdown
Member Author

This is very close to completion from my end and passes the basic tests so I'd like to see if it holds up in the QA lab..

@suricata-qa

Copy link
Copy Markdown

WARNING:
ERROR: buid failure for build_asan QA build

field baseline test %
build_asan

Pipeline = 27251

@inashivb inashivb closed this Aug 28, 2025
@inashivb inashivb deleted the flowbit-ordering-cyclic/v4 branch August 28, 2025 02:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants