Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

@lukashino
Copy link
Contributor

Follow-up of #14512

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

Describe changes:
v4.1:

  • clangformat fix
  • ai review - localtime changed to SCLocattime, the time check is present in the code few lines above the subtraction, redundant negative check removed.

v4.0:

  • bumped current cache version to "_v2.hs"
  • addressed review comments, fixed Phillipe's note on double-spaces
  • non-current cache versions are deleted
  • Touch function majorly simplified, dropped support for Windows and utimensat
  • wordings

v3.3:

  • rebased

v3:

  • cache stats added as an independent component for MPM cache stats
  • sensor name removed from the cache file name
  • humantime Rust crate
  • warning added about one cache folder for simultaneously running multiple instances

v2:

  • Hyperscan cache files are now hashed using SHA256 and stored in the hex of a full length (256 bits -> 64 characters)
  • Sensor name is now part of the cache file names, individual instances can now be distinguished with the sensor name
  • The time parsing C function was replaced with a Rust crate
  • In HS: Prune stale cache files from disk v1.1 #13850, Jason asked about the immediate pruning - that is possible, just set the max age to (e.g. 2) seconds.
  • In HS: Prune stale cache files from disk v1.1 #13850, Jason pointed out a synchronization problem of multiple instances sharing one cache folder, e.g., over NFS. This is not addressed here and is currently easily solved by, e.g., sensor name or per-instance folder.

v1:

  • time parsing function from config,
  • "touch" files to signal actively used files,
  • pruning function to remove the HS MPM cache files older than the age specified in the config.

The logic to determine a stale file is currently based on the modification timestamp in the file systems. The accessed time stamp was not used as it may be switched off. Alternatively, we could use a local DB/notekeeping file of the last used files/caches but this approach seemed simpler.

I can also add GitHub CI tests, I thought of some scenarios.

Lukas Sismis added 11 commits December 19, 2025 09:40
To have a system-level overview of when was the last time the file was
used, update the file modification timestamp to to the current time.

This is needed to remove stale cache files of the system.

Access time is not used as it may be, on the system level, disabled.

Ticket: 7830
Hyperscan MPM can cache the compiled contexts to files.
This however grows as rulesets change and leads to bloating
the system. This addition prunes the stale cache files based
on their modified file timestamp.

Part of this work incorporates new model for MPM cache stats
to split it out from the cache save function and aggregate
cache-related stats in one place (newly added pruning).

Ticket: 7830
This is especially relevant for multi-instance simultaneous setups
as we might risk read/write races.
Copilot AI review requested due to automatic review settings December 19, 2025 08:57
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@codecov
Copy link

codecov bot commented Dec 19, 2025

Codecov Report

❌ Patch coverage is 62.71930% with 85 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.10%. Comparing base (8247ec6) to head (89e0719).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14516      +/-   ##
==========================================
- Coverage   82.11%   82.10%   -0.01%     
==========================================
  Files        1013     1013              
  Lines      262297   262495     +198     
==========================================
+ Hits       215380   215532     +152     
- Misses      46917    46963      +46     
Flag Coverage Δ
fuzzcorpus 59.31% <6.34%> (+<0.01%) ⬆️
livemode 18.83% <6.34%> (+0.07%) ⬆️
pcap 44.59% <6.34%> (-0.03%) ⬇️
suricata-verify 64.95% <6.34%> (-0.03%) ⬇️
unittests 59.26% <62.71%> (-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.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 18 out of 41 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +355 to +359
PatternDatabaseCache *pd_cache_stats = mpm_conf->cache_stats;
pd_cache_stats->hs_dbs_cache_pruned_cnt = removed;
pd_cache_stats->hs_dbs_cache_pruned_considered_cnt = considered;
pd_cache_stats->hs_dbs_cache_pruned_cutoff = cutoff;
pd_cache_stats->cache_max_age_seconds = mpm_conf->cache_max_age_seconds;
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

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

In SCHSCachePrune, mpm_conf->cache_stats is dereferenced without checking if it's NULL. If CacheStatsInit is not implemented or returns NULL for some reason but CachePrune is implemented, this will cause a null pointer dereference. Add a null check before accessing cache_stats.

Copilot uses AI. Check for mistakes.
{
uint32_t hash[2] = { 0 };
hashword2(&pd->pattern_cnt, 1, &hash[0], &hash[1]);
SCSha256 *hasher = SCSha256New();
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

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

SCSha256New() is called without checking if it returns NULL. While Box::new in Rust will panic on allocation failure rather than returning NULL, it's good practice to check the return value when crossing FFI boundaries to make the code more defensive.

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

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

Agree here

@suricata-qa
Copy link

Information: QA ran without warnings.

Pipeline = 28848

}

if (!SCSha256FinalizeToHex(hasher, hash, hash_len)) {
hasher = NULL;
Copy link
Member

Choose a reason for hiding this comment

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

why is this set to NULL here and not in the success case?

@victorjulien
Copy link
Member

For a bigger and more complex PR like this, please don't include doc space cleanup commits. Those can go into their own PR to ease review.

@victorjulien
Copy link
Member

victorjulien commented Dec 23, 2025

In my MT setup, the old files are removed as expected, but I do get lots of warnings

Dec 23 07:49:54 c2758 suricata[372808]: Info: threshold-config: tenant id 2: Threshold config parsed: 24 rule(s) found [SCThresholdConfParseFile:util-threshold-config.c:1013]                                 
Dec 23 07:49:55 c2758 suricata[372808]: Info: detect: tenant id 2: 149984 signatures processed. 17241 are IP-only rules, 13264 are inspecting packet payload, 118915 inspect application layer, 110 are decoder eve
nt only [SigPrepareStage1:detect-engine-build.c:1813]                                                                                                                                                              
Dec 23 07:50:04 c2758 suricata[372808]: Info: detect: tenant id 3:  2 rule files processed. 149975 rules successfully loaded, 0 rules failed, 0 rules skipped [SigLoadSignatures:detect-engine-loader.c:467]       
Dec 23 07:50:06 c2758 suricata[372808]: Info: threshold-config: tenant id 3: Threshold config parsed: 24 rule(s) found [SCThresholdConfParseFile:util-threshold-config.c:1013]                                 
Dec 23 07:50:06 c2758 suricata[372808]: Info: detect: tenant id 3: 149984 signatures processed. 17241 are IP-only rules, 13264 are inspecting packet payload, 118915 inspect application layer, 110 are decoder eve
nt only [SigPrepareStage1:detect-engine-build.c:1813]                                                                                                                                                              
Dec 23 07:54:55 c2758 suricata[372808]: Warning: mpm-hs-cache: Failed to prune "/var/lib/suricata/cache/sgh/ids/11742246800208668391_v1.hs": No such file or directory [SCHSCachePrune:util-mpm-hs-cache.c:350]
Dec 23 07:54:55 c2758 suricata[372808]: Warning: mpm-hs-cache: Failed to prune "/var/lib/suricata/cache/sgh/ids/02562962361114740350_v1.hs": No such file or directory [SCHSCachePrune:util-mpm-hs-cache.c:350]
Dec 23 07:54:55 c2758 suricata[372808]: Warning: mpm-hs-cache: Failed to prune "/var/lib/suricata/cache/sgh/ids/15437361307607464697_v1.hs": No such file or directory [SCHSCachePrune:util-mpm-hs-cache.c:350]
Dec 23 07:54:55 c2758 suricata[372808]: Warning: mpm-hs-cache: Failed to prune "/var/lib/suricata/cache/sgh/ids/05136570439696308227_v1.hs": No such file or directory [SCHSCachePrune:util-mpm-hs-cache.c:350]
Dec 23 07:54:55 c2758 suricata[372808]: Warning: mpm-hs-cache: Failed to prune "/var/lib/suricata/cache/sgh/ids/06890636526248207111_v1.hs": No such file or directory [SCHSCachePrune:util-mpm-hs-cache.c:350]
...
Dec 23 07:54:55 c2758 suricata[372808]: Notice: mpm-hs-cache: Rule group caching - loaded: 132 newly cached: 0 total cacheable: 132 [SCHSCacheStatsPrint:util-mpm-hs-cache.c:391]
Dec 23 07:54:55 c2758 suricata[372808]: Notice: mpm-hs-cache: Rule group caching - loaded: 0 newly cached: 132 total cacheable: 132 [SCHSCacheStatsPrint:util-mpm-hs-cache.c:391]
Dec 23 07:54:55 c2758 suricata[372808]: Info: mpm-hs-cache: Cache pruning removed 4264/5119 of HS caches due to version-incompatibility (v2) or age (<2025-12-16 07:54:55) [SCHSCacheStatsPrint:util-mpm-hs-cache.c:394]
Dec 23 07:54:55 c2758 suricata[372808]: Info: mpm-hs-cache: Cache pruning removed 4359/5168 of HS caches due to version-incompatibility (v2) or age (<2025-12-16 07:54:55) [SCHSCacheStatsPrint:util-mpm-hs-cache.c:394]

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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.