Project

General

Profile

Actions

Bug #7638

open
VJ SB

detect: incorrect rule ordering with more complex flowbit chains

Bug #7638: detect: incorrect rule ordering with more complex flowbit chains

Added by Victor Julien about 1 year ago. Updated 1 day ago.

Status:
In Review
Priority:
High
Target version:
Affected Versions:
Effort:
Difficulty:
high
Label:

Description

alert http any any -> any any (http.uri; content:"down"; flowbits:set,uritest; sid:11;)
alert http any any -> any any (http.user_agent; content:"Mozilla"; flowbits:isset, headtest; flowbits:set,moz; sid:10;)
alert http any any -> any any (http.method; content:"GET"; flowbits:isset,uritest; flowbits:set,headtest; sid:12;)
alert http any any -> any any (http.host; content:"ether"; flowbits:isset,moz; sid:14;)

should be ordered: 11, 12, 10, 14. Is actually ordered: 11, 10, 12, 14. This is because in the ordering there just 3 cases:
set, read, read_set. Sid 10 and 12 are both read_set, and thus correct order isn't enforced.

Subtasks 8 (2 open6 closed)

Bug #7771: flowbits: cyclic dependencies in flowbits are accepted by the engineIn ReviewShivani BhardwajActions
Bug #7772: flowbits: no-op set and isset combinations are acceptedClosedShivani BhardwajActions
Bug #7773: flowbits: no-op unset + isnotset combinations are acceptedClosedShivani BhardwajActions
Bug #7774: flowbits: invalid set + toggle combinations are acceptedClosedShivani BhardwajActions
Bug #7817: flowbits: invalid isset and isnotset combinations are acceptedClosedShivani BhardwajActions
Bug #7818: flowbits: invalid set and unset combinations are acceptedClosedShivani BhardwajActions
Bug #8083: detect: incorrect rule ordering with more complex flowbit chains (8.0.x backport)AssignedShivani BhardwajActions
Bug #8166: flowbits: invalid unset + toggle combinations are acceptedClosedShivani BhardwajActions

Related issues 1 (1 open0 closed)

Related to Suricata - Bug #1399: Flowbits rules not always evaluated in necessary orderAssignedVictor JulienActions

SB Updated by Shivani Bhardwaj 10 months ago Actions #2

  • Status changed from Assigned to In Progress
  • Difficulty set to medium

SB Updated by Shivani Bhardwaj 10 months ago Actions #3

  • Target version changed from 8.0.0-rc1 to 8.0.0

This turned out to be more than just choosing and applying a correct sorting order. Isolating this problem was not a good idea.

SB Updated by Shivani Bhardwaj 10 months ago Actions #4

  • Priority changed from Normal to High
  • Target version changed from 8.0.0 to 8.0.0-rc1
  • Difficulty changed from medium to high

I think I am more confident now that this is actually indeed a boolean satisfiability problem. These class of problems are unsolvable in polynomial time for more than 2 conditions. A demo for 2-SAT problem is given here: https://www.geeksforgeeks.org/2-satisfiability-2-sat-problem/

Note that we can always run into "unsatisfiable" data paths. For example, the engine accepts the following complex flowbit chains but there's no way to determine the correct order for these as there isn't one:

alert http any any -> any any (http.user_agent; content:"Mozilla"; flowbits:isset, headtest; flowbits:set,moz; sid:10;)
alert http any any -> any any (http.method; content:"GET"; flowbits:set,headtest; flowbits:isset,moz; sid:12;)

So, what we can do is:
1. Apply some restrictions to reduce the number of checks. e.g. cyclic dependencies like in the above mentioned example must be disallowed resulting in errors/commenting of all rules involved.
2. Create a cycle free many to many relationship internal table. i.e. b/w signatures and flowbits.

I'm currently working on listing out the possible restrictions that could/should be applied and what should the relationship table look like.

SB Updated by Shivani Bhardwaj 10 months ago Actions #5

  • Target version changed from 8.0.0-rc1 to 8.0.0

VJ Updated by Victor Julien 10 months ago ยท Edited Actions #6

  • Target version changed from 8.0.0 to 9.0.0-beta1

I think it makes sense to start with banning cyclical dependencies, as they can't be satisfied at runtime anyway. Perhaps we should create subtickets for the distinct steps.

SB Updated by Shivani Bhardwaj 10 months ago Actions #7

  • Subtask #7771 added

SB Updated by Shivani Bhardwaj 10 months ago Actions #8

  • Subtask #7772 added

SB Updated by Shivani Bhardwaj 10 months ago Actions #9

  • Subtask #7773 added

SB Updated by Shivani Bhardwaj 10 months ago Actions #10

  • Subtask #7774 added

PA Updated by Philippe Antoine 9 months ago Actions #11

  • Related to Bug #1399: Flowbits rules not always evaluated in necessary order added

PA Updated by Philippe Antoine 9 months ago Actions #12

  • Affected Versions 8.0.0 added

SB Updated by Shivani Bhardwaj 9 months ago Actions #13

  • Subtask #7817 added

SB Updated by Shivani Bhardwaj 9 months ago Actions #14

  • Subtask #7818 added

SB Updated by Shivani Bhardwaj 7 months ago Actions #15

  • Status changed from In Progress to In Review

SB Updated by Shivani Bhardwaj 5 months ago Actions #16

  • Status changed from In Review to In Progress

SB Updated by Shivani Bhardwaj 5 months ago Actions #17

  • Assignee deleted (Shivani Bhardwaj)
  • Label Needs backport to 8.0 added

SB Updated by Shivani Bhardwaj 5 months ago Actions #18

  • Subtask #8083 added

SB Updated by Shivani Bhardwaj 5 months ago Actions #19

  • Label deleted (Needs backport to 8.0)

SB Updated by Shivani Bhardwaj 5 months ago Actions #20

  • Assignee set to Shivani Bhardwaj

SB Updated by Shivani Bhardwaj 4 months ago Actions #21

  • Subtask #8166 added

SB Updated by Shivani Bhardwaj 1 day ago Actions #22

  • Status changed from In Progress to In Review

In Review PR: https://github.com/OISF/suricata/pull/15076

TBH, still in the state of "can it be solved for all possible cases?" and it's not looking bright. More info TBD on the PR.

Actions

Also available in: PDF Atom