Skip to content

Conversation

jlucovsky
Copy link
Contributor

Continuation of #13564

Issue: 1412

Extend the checks added for 7549 to include buffers.

Only consider sig matches with compatible ids/lists.

Link to ticket: https://redmine.openinfosecfoundation.org/issues/1412

Describe changes:

  • Extend buffer/variable checks to buffers init data
  • In strict-mode, do not load rules using variables from different buffers.
  • When not in strict mode, issue warning for rules that use variables from different buffers.

Updates:

Provide values to any of the below to override the defaults.

  • To use a Suricata-Verify or Suricata-Update pull request,
    link to the pull request in the respective _BRANCH variable.
  • Leave unused overrides blank or remove.

SV_REPO=
SV_BRANCH=OISF/suricata-verify#2576
SU_REPO=
SU_BRANCH=

jlucovsky added 2 commits July 9, 2025 09:51
Issue: 1412

When in strict mode, issue an error and refuse to load the rule if
variables produced from a different buffer are used with a separate
buffer.

When not in strict mode (default), issue a warning and load the rule.

Only consider sig matches with compatible ids/lists.
Issue 1412

Add mention of byte_{extract,math,test,jump} variable usage
and buffer scope and include how the command line option
strict-rule-keywords affects validation.
Copy link

codecov bot commented Jul 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.60%. Comparing base (116d176) to head (9405c7d).
Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #13584      +/-   ##
==========================================
+ Coverage   83.55%   83.60%   +0.04%     
==========================================
  Files        1011     1012       +1     
  Lines      275039   275072      +33     
==========================================
+ Hits       229804   229962     +158     
+ Misses      45235    45110     -125     
Flag Coverage Δ
fuzzcorpus 62.57% <95.83%> (+0.32%) ⬆️
livemode 18.97% <0.00%> (-0.19%) ⬇️
pcap 44.70% <36.11%> (+<0.01%) ⬆️
suricata-verify 65.08% <92.95%> (+<0.01%) ⬆️
unittests 59.18% <73.23%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@suricata-qa
Copy link

Information: QA ran without warnings.

Pipeline = 26847

return true;
}

SCLogWarning("Using byte variable from a different buffer may produce indeterminate "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move this check into a validate callback so that the sid is available in a warning?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that Philippe's comment here also make sense: https://github.com/OISF/suricata/pull/13564/files/664e61a2678b90d25e3f27937059a2f4817aaece#r2183567368

(apologies for the very late reply)

@catenacyber
Copy link
Contributor

Do we want this for 8.0.1 or for 9 ? This is a behavior change...


DetectByteIndexType idx;
if (!DetectByteRetrieveSMVar(name, s, -1, &idx)) {
if (!DetectByteRetrieveSMVar(name, s, false, -1, &idx, 1)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why rule line 1 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll modify this to use a sentinel value since the line number is meant to indicate the offset into the rule file(s).

SCLogDebug("Retrieved SM for \"%s\"", arg);
return sm;
}
if (DetectByteMathSMNameMatch(sm, arg)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still #13564 (comment)

This change looks suspicious

Did you test a rule with 2 buffers, each buffer doing a byte_extract+ byte_math ?

I am afraid that with this change, the second buffer will get their found_list from the first buffer when it uses to get the right sm_list == list in current code

Do you have a test for it ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rule is handled correctly -- is this what you were thinking?

alert ip any any -> any any (msg:"multi buffer"; ipv4.hdr;byte_extract:1,0,header; byte_test:1,!=,header,1;tcp.hdr; byte_extract:1,0,header2, relative;byte_test:1,=,header2,1;sid: 1;)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok... I will test it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, buffers are ok because they run only the first loop of `DetectByteExtractRetrieveSMVar``

The second loop (where you removed the check list==sm_list) is run for DETECT_SM_LIST_PMATCH and DETECT_SM_LIST_BASE64_DATA

So, this allows signature like
alert http any any -> any any (msg:"multi buffer2"; content: "toto"; byte_extract:1,0,header; http.user_agent; base64_decode; base64_data;byte_test:1,=,header,1;sid: 2;) to be accepted when it should not

Copy link
Contributor

@catenacyber catenacyber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments

@jlucovsky
Copy link
Contributor Author

Continued in #13622

@jlucovsky jlucovsky closed this Jul 19, 2025
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.

5 participants