Skip to content

backport 8845 into main-8.0.x- #16142 - #16143

Closed
jlucovsky wants to merge 3 commits into
OISF:main-8.0.xfrom
jlucovsky:8902/2
Closed

backport 8845 into main-8.0.x- #16142#16143
jlucovsky wants to merge 3 commits into
OISF:main-8.0.xfrom
jlucovsky:8902/2

Conversation

@jlucovsky

Copy link
Copy Markdown
Contributor

Continuation of #16142

Cherry-pick 8845 fixes into main-8.0.x

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

Describe changes:

  • Backport fixes for 8845 into main-8.0.x
  • Change rule rejection to warning issues unless --strict-rule-keywords is used.
    Updates:
  • Address scan-build report

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#3336
SU_REPO=
SU_BRANCH=

Zero the result when a byte_math right shift count reaches 64, the
width of the uint64_t being shifted, so the operation no longer
depends on behavior C11 6.5.7p3 leaves undefined. The left shift case
has done this since 473ca6d; the right shift case was left
unguarded.

DetectByteMathDoMatch() shifted by whatever count it was handed. On
x86_64 the hardware masks the count to its low six bits, so a count of
64 became a shift of 0 and returned the extracted value unchanged
instead of 0. That value is stored in det_ctx->byte_values[] and feeds
any byte_test, isdataat, or content offset later in the signature, so
the signature's verdict follows from an arithmetic result the standard
does not define.

The count reaches the shift from the wire. When byte_math names a
variable for rvalue, DetectEngineContentInspectionInternal() reads it
out of det_ctx->byte_values[] at
detect-engine-content-inspection.c:614, where a preceding byte_extract
stored bytes taken from the payload, so one payload byte of 0x40 sets
the count to 64.

Issue: 8845
Issue: 8902
(cherry picked from commit e5d035f)
Warn from DetectByteMathSetup() when byte_math pairs << or >> with a
literal rvalue of 64 or more, naming the signature by sid. Such a
shift gives 0 for every packet: DetectByteMathDoMatch() zeroes the
result once the count reaches 64, the width of the uint64_t being
shifted. rvalue was bounded only to the u32 range, so the rule loaded
and ran a shift whose result was 0 whatever the packet held.

The rule still loads. main rejects it in 89d09c4, the commit this
one is derived from, but a released branch should not stop loading
rules that loaded before. Passing byte_math to --strict-rule-keywords
turns the warning into a load failure, the same escalation classtype
and reference apply to values they cannot check.

A variable rvalue draws no warning. It resolves to a preceding
byte_extract or byte_math result, whose value is known only once the
rule runs, so the guard in DetectByteMathDoMatch() stays the only
check on that path.

Issue: 8845
Issue: 8902
(cherry picked from commit 89d09c4)
Record beside the existing note about division by zero that << and >>
give 0 when rvalue is 64 or more, that a rule giving such an rvalue as
a number still loads with a warning, and that --strict-rule-keywords
makes it fail to load instead. rvalue can name a byte_extract or
byte_math variable rather than a number, and then the count is not
known until the rule runs, so the rule text does not say whether it
will reach 64.

The note on main stops at the result, because 89d09c4 rejects such
a rule there instead of warning about it.

Issue: 8845
Issue: 8902
(cherry picked from commit 4a64778)
@codecov

codecov Bot commented Aug 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.25806% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.72%. Comparing base (3b04b76) to head (2b3566b).

Additional details and impacted files
@@              Coverage Diff               @@
##           main-8.0.x   #16143      +/-   ##
==============================================
- Coverage       81.73%   81.72%   -0.01%     
==============================================
  Files            1017     1017              
  Lines          277278   277339      +61     
==============================================
+ Hits           226628   226655      +27     
- Misses          50650    50684      +34     
Flag Coverage Δ
fuzzcorpus 63.87% <36.36%> (+0.01%) ⬆️
livemode 18.65% <0.00%> (-0.01%) ⬇️
netns 20.14% <0.00%> (-0.03%) ⬇️
pcap 44.45% <0.00%> (-0.05%) ⬇️
suricata-verify 65.20% <50.00%> (-0.05%) ⬇️
unittests 58.57% <72.58%> (+<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
Copy Markdown

Information: QA ran without warnings.

Pipeline = 33460

@victorjulien victorjulien added this to the 8.0 milestone Aug 31, 2026
@victorjulien

Copy link
Copy Markdown
Member

Merged in #16146, thanks!

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.

3 participants