Bug #4880
opendetect: hostbits and xbits rules incorrectly ordered
Description
The description of hostbits and xbits in the latest document does not match the status quo.
https://suricata.readthedocs.io/en/latest/rules/xbits.html#xbits-keyword
alert ip any any -> any any (msg:"test xbits set fakehost"; xbits:set, fakehost, track ip_dst; sid:1;)
alert ip any any -> any any (msg:"test xbits isset set fakehost and set fakerservice"; xbits:isset, fakehost, track ip_dst; xbits:set, fakeservice, track ip_dst; sid:2;)
alert ip any any -> any any (msg:"test xbits isset set fakeservice"; xbits:isset, fakeservice, track ip_dst; sid:3;)
I can't get an alert triggered by the third rule.
alert ip any any -> any any (msg:"test hostbits set fakehost"; hostbits:set, fakehost, dst; sid:1;)
alert ip any any -> any any (msg:"test hostbits isset hostbits and set fakerservice"; hostbits:isset, fakehost, dst; hostbits:set, fakeservice, dst; sid:2;)
alert ip any any -> any any (msg:"test hostbits isset fakerservice"; hostbits:isset, fakeservice, dst; sid:3;)
I can get an alert triggered by the third rule.
PM Updated by Peter Manev over 4 years ago
May be related to
https://redmine.openinfosecfoundation.org/issues/1399
PA Updated by Philippe Antoine over 2 years ago
- Related to Bug #1399: flowbits: rules not always evaluated in necessary order added
PA Updated by Philippe Antoine over 2 years ago
- Target version set to TBD
PA Updated by Philippe Antoine over 2 years ago
- Assignee set to OISF Dev
PA Updated by Philippe Antoine over 1 year ago
- Status changed from New to Feedback
- Label Needs Suricata-Verify test added
Is this still an issue in Suricata 8 ? Would you have a pcap to test the supplied rules ?
JF Updated by Juliana Fajardini Reichow 10 days ago
JF Updated by Juliana Fajardini Reichow 10 days ago
- Rule ordering: xbits setters sort after readers
Found while writing SV test for #8459. Present on `main` (checked
2026-10-21). Independent of firewall mode.
- Symptom
Two TD rules matching the same packet, one with `xbits:set,X,track ip_src`
and one with `xbits:isset,X,track ip_src`: the `isset` rule does not alert.
Rule ordering is meant to put setters before readers, so this pattern should
work.
- Cause
`SCSigGetXbitsType()` (`src/detect-engine-sigorder.c:406-460`) classifies a
rule for the hostbits / ippairbits ordering, but its two loops check different
keywords:
- MATCH list (readers: `isset` / `isnotset`): counts only `DETECT_XBITS` (`:415`).
- POSTMATCH list (writers: `set` / `unset` / `toggle`): counts only
`DETECT_HOSTBITS` (`:434`).
Result, with `NOT_USED=1 < READ=2 < SET_READ=3 < SET=4` and higher sorting
first (`SCSigLessThan`, `:539-540`):
| Rule | Classified as | Effect |
| ------------------ | -------------- | ------------------------------- |
| xbits `isset` | `READ` (2) | sorts before the setter |
| xbits `set` | `NOT_USED` (1) | writer never recognised |
| hostbits `set` | `SET` (4) | correct |
| hostbits `isset` | `NOT_USED` (1) | reader never recognised |
hostbits ends up in the right order only because both sides are misclassified
in a way that still puts the setter first. xbits with `track ip_src|ip_dst`
maps to `VAR_TYPE_HOST_BIT` (`src/detect-xbits.c:309-314`), so it goes
through the same hostbits comparison and comes out reversed.
- Possible fix
Have both loops count `DETECT_XBITS` and `DETECT_HOSTBITS`. This changes rule
ordering for any ruleset using xbits or hostbits, so it needs its own ticket
and tests (xbits and hostbits same-packet `set` -> `isset`, both `ip_src` and
`ip_pair`).
- Not checked
- Whether `ip_pair` xbits (`SCSigOrderByIPPairbitsCompare`) hit the same
reversal; the code path suggests so.
JF Updated by Juliana Fajardini Reichow 10 days ago
- Status changed from Feedback to Triaged
- Target version changed from TBD to 9.0.0-beta1
JF Updated by Juliana Fajardini Reichow 10 days ago
- Affected Versions 8.0.7, git main added
- Label Needs backport to 8.0 added
JF Updated by Juliana Fajardini Reichow 10 days ago
- Label deleted (
Needs Suricata-Verify test)
OT Updated by OISF Ticketbot 10 days ago
- Subtask #9248 added
OT Updated by OISF Ticketbot 10 days ago
- Label deleted (
Needs backport to 8.0)
SB Updated by Shivani Bhardwaj 3 days ago
- Status changed from Triaged to Assigned
- Assignee changed from OISF Dev to Shivani Bhardwaj
SB Updated by Shivani Bhardwaj 3 days ago
- Difficulty set to low
SB Updated by Shivani Bhardwaj 3 days ago
- Subject changed from hostbits/xbits: treat hostbits and xbits differently in the rule ordering stage to detect: hostbits and xbits rules incorrectly ordered
- Label Needs backport to 8.0 added
OT Updated by OISF Ticketbot 3 days ago
- Subtask #9340 added
OT Updated by OISF Ticketbot 3 days ago
- Label deleted (
Needs backport to 8.0)