fix(libsinsp): add FTR_STORAGE for plugin fields in unary check expressions#2935
Conversation
|
Welcome @max-frank! It looks like this is your first PR to falcosecurity/libs 🎉 |
…ssions The unary_check_expr visitor installs an extract cache but does not add the FTR_STORAGE transformer for plugin fields with unstable pointers (EPF_NO_PTR_STABILITY). This causes the shared extract cache to store shallow pointer copies that become stale when a subsequent extraction from the same plugin overwrites the internal buffer. The binary_check_expr visitor already handles this correctly by checking is_ptr_unstable() and adding FTR_STORAGE when a cache is present. This commit mirrors that logic in the unary check path. The bug manifests when a filter combines a unary check (e.g. 'exists') on a plugin field with a binary check on the same field, with an intervening extraction from a different field of the same plugin: plugin_field_A exists AND plugin_field_B = "x" AND plugin_field_A = "y" Without FTR_STORAGE, step 3 reads garbage from the cache and produces incorrect filter results. Introduced in f319ef8 ("polish and enable filter caching", Jun 2024). Affects libs >= 0.18.0, Falco >= 0.39.0. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Maximilian Frank <mfrank@mercari.com>
6d3c663 to
e84345f
Compare
Perf diff from master - unit testsHeap diff from master - unit testsHeap diff from master - scap fileBenchmarks diff from master |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2935 +/- ##
==========================================
+ Coverage 74.96% 74.98% +0.01%
==========================================
Files 296 296
Lines 31472 31490 +18
Branches 4977 4978 +1
==========================================
+ Hits 23594 23612 +18
Misses 7878 7878
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
LGTM label has been added. DetailsGit tree hash: 423c921d12b4afbb33a527fee3615810bdebd142 |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ekoops, leogr, max-frank The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
@ekoops @leogr Thanks for the quick review and merge 🙇 I am wondering is it worth to back patch previous falco/libs releases to include the fix. The bug is actually pretty substantially impacting rule evaluation for anything involving plugins. In our case we immediately saw impact when we moved to a release that use the container plugin for |
Good point. We are evaluating that right now. We will keep you posted 👍 |
|
We agreed on releaseing a patch version for the |
|
Thank you very much, for the quick decision and release on the patched version for 0.23.0 as well! 🙇 |
What type of PR is this?
/kind bug
/area libsinsp
Any specific area of the project related to this PR?
libsinsp — filter compiler
What this PR does / why we need it:
The
unary_check_exprvisitor in the filter compiler installs an extract cache for plugin fields but does not add theFTR_STORAGEtransformer to stabilize pointers. Plugin fields haveEPF_NO_PTR_STABILITY, meaning their extracted value pointers point into the plugin's internal buffer and become invalid when the same plugin extracts another field.The
binary_check_exprvisitor already correctly handles this by checkingis_ptr_unstable()and addingFTR_STORAGEwhen a cache is present (filter.cpp:548-553). This PR mirrors that logic in the unary check path.Without this fix, the following filter pattern produces incorrect results:
plugin_field_A exists(unary) — caches a shallow pointer (no FTR_STORAGE)plugin_field_B = "x"(binary) — overwrites the plugin's internal bufferplugin_field_A = "y"(binary) — cache hit returns stale pointer → wrong resultThis commonly manifests in Falco when rules use
existson container/k8s plugin fields in conditions and also reference the same plugin fields in exceptions.Which issue(s) this PR fixes:
Fixes #2934
Special notes for your reviewer:
sample.proc_nameandsample.tick) that share the same internal storage in the test plugin — extracting one overwrites the other's cached pointerf319ef8b4(Jun 2024), affects libs >= 0.18.0, Falco >= 0.39.0Does this PR introduce a user-facing change?:
Yes, previously incorrectly evaluated conditions will evaluate correctly now