Skip to content

Smb raw inspection/v4#15729

Open
inashivb wants to merge 2 commits into
OISF:mainfrom
inashivb:smb-raw-inspection/v4
Open

Smb raw inspection/v4#15729
inashivb wants to merge 2 commits into
OISF:mainfrom
inashivb:smb-raw-inspection/v4

Conversation

@inashivb

Copy link
Copy Markdown
Member

Previous PR: #15637

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

SV_BRANCH=OISF/suricata-verify#3164

Changes since v3:

  • bug fixes to the new additional flag for inspection
  • tests for all cases
  • rebased on top of latest main

Note: An internal test failure is evaluated and explained.

If this is acceptable, I'll clear the TODOs and submit a clean PR.

inashivb added 2 commits June 25, 2026 16:19
Suricata internally classifies the rules into certain categories based
on what it sees in a rule. Widely, any rule containing a content keyword
immediately becomes a stream type rule calling for inspection on stream
payload unless there are keywords that require matching on packet as
well. In that case, the rule becomes a pkt-stream rule. This type of
rule would cause the inspection to be triggered per stream payload and
if that didn't result in success, it'll go for the packet payload.

This category is a bit ambiguous and may result in surplus alerts in
certain cases. One example is:

rule keywords to be matched: content: "suricata"; stream_size:<,100;
1.    pkt 1 (toserver): TCP/APP_PROTO/yabadabadoooooosuricataoooooo
2.    pkt 2 (toclient): TCP/APP_PROTO/okyaba
3.    pkt 3 (toserver): TCP/APP_PROTO/ok

At (1), last ACK'd stream window is inspected, no match is found. Since
it's a pkt-stream rule, inspection is carried on on pkt 1's payload --
it's a MATCH!
After parsing pkt 1, APP_PROTO parser demands an immediate inspection
of the raw stream data. So, when pkt 3 arrives, there's stream data
ready for inspection and because a pkt-stream rule is in question, the
stream payload match must be done -- it's a MATCH!

This patch aims to separate the logic of inspection by breaking down the
wide "pkt" category into two distinct categories:
1. The keyword needs to look inside the packet data.
2. The keyword needs to look only at the packet dimensions. This is the
   new category.

Rule keywords falling in the new category would skip packet payload
inspection entirely simply because they should.
Keywords falling in this category are:
- stream_size
- flow.pkts

STODO review all keywords requiring packet.
STODO this won't work for http yet -- no raw inspection calls so it
could be quite delayed.
Internals
---------
Suricata's stream engine returns data for inspection to the detection
engine from the stream when the chunk size is reached.

Bug
---
Inspection triggered only in the specified chunk sizes may be too late
when it comes to inspection of smaller protocol specific data which
could result in delayed inspection, incorrect data logged with a transaction
and logs misindicating the pkt that triggered an alert.

Fix
---
Fix this by making an explicit call from all respective applayer parsers to
trigger raw stream inspection which shall make the data available for inspection
in the following call of the stream engine. This needs to happen per direction
on the completion of an entity like a request or a response.

Important notes
---------------
1. The above mentioned behavior with and without this patch is
affected internally by the following conditions.
- inspection depth
- stream depth
In these special cases, the inspection window will be affected and
Suricata may not consider all the data that could be expected to be
inspected.
2. This only applies to applayer protocols running over TCP.
3. The inspection window is only considered up to the ACK'd data.
4. This entire issue is about IDS mode only.

SMB parser creates a transaction per request-response pair. Appropriate calls to trigger
raw stream inspection have been added on succesful parsing of each request and
response.

Task 7863
Bug 7004
@inashivb inashivb force-pushed the smb-raw-inspection/v4 branch from 94f3676 to 57936f1 Compare June 25, 2026 11:27
@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.22581% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.96%. Comparing base (09f0851) to head (57936f1).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #15729      +/-   ##
==========================================
- Coverage   82.96%   82.96%   -0.01%     
==========================================
  Files        1003     1003              
  Lines      275031   275250     +219     
==========================================
+ Hits       228192   228349     +157     
- Misses      46839    46901      +62     
Flag Coverage Δ
fuzzcorpus 61.50% <92.90%> (+0.03%) ⬆️
livemode 18.32% <0.96%> (-0.06%) ⬇️
netns 22.68% <0.96%> (-0.08%) ⬇️
pcap 45.41% <75.48%> (+0.02%) ⬆️
suricata-verify 66.95% <80.00%> (+0.01%) ⬆️
unittests 58.41% <6.12%> (-0.05%) ⬇️

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

WARNING:

field baseline test %
SURI_TLPR1_stats_chk
.app_layer.flow.ftp_data 760 902 118.68%
.app_layer.error.ftp.parser 17 0 -

Pipeline = 32261

@inashivb inashivb marked this pull request as ready for review June 26, 2026 11:14
@inashivb inashivb requested a review from victorjulien as a code owner June 26, 2026 11:14
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