fix(bpf): disable preemption during hook processing - #1569
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Enterprise Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (4)
Included review availability: Your plan provides up to 12 included reviews per hour; 11 remain after this review. 📝 WalkthroughWalkthroughThe PR pins ChangesAYA and LSM compatibility
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to The reviewed compatibility updates and generated hook migration do not leave an identified merge-blocking risk. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1569 +/- ##
=======================================
Coverage 33.40% 33.40%
=======================================
Files 22 22
Lines 3628 3628
Branches 3628 3628
=======================================
Hits 1212 1212
Misses 2407 2407
Partials 9 9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Can you be more specific about what shared per-CPU maps could be affected? |
|
This prevents the hooks from being preempted and replaced by another hook that might overwrite the contents of the shared per-CPU maps before sending the event to the ringbuffer. A similar issue was found to be corrupting events in Falco and is addressed in this PR of our fork, see the discussion there for more details: stackrox/falcosecurity-libs#98 In order to call `bpf_preempt_enable/disable` aya needs to support ksyms, which is currently only supported on main, therefore we pin the dependency to a commit known to work. We will unpin this once a new aya release is created.
These kfuncs where added in kernel version 6.12 and causes verifier issues on RHCOS 4.16 and 4.18 on our CI.
61cebd7 to
2371024
Compare
There was a problem hiding this comment.
It sounds reasonable to disable preemption as a quick workaround for now, but I
think we need to re-evaluate this in some time, as in long term we may not even
need this (at least not for all progs):
-
The helper map is used for reading in the custom d_path implementation, which
as far as I recall is needed only for old kernels without sufficientbpf_d_pathsupport. -
Regarding cgroups, I still think they way we do this currently is hacky (exactly for the
reasons like preemption and such), and using cgroup id is somewhat better. -
The bound_path concept is something I'm still not clear about, may be worth
adding some documentation what is it and why it exists. But in any case it seems
to be used only insb_umountprog, limiting the need for disabled preemption. -
From what I see metrics are cumulative, and even though the update may be
preempted, it still will be atomic, right? If yes, then it shouldn't be a
problem.
In the end we shouldn't consider disabling preemption lightly, as it has
performance impact (non-preemptible bpf programs are less flexible in this
regard).
Other than that, few commentaries that are not related to this PR specifically,
but I've stumbled upon this:
-
It seems like the helper map is being used differently in different places?
Some call sites useget_helperfunction, others get the map directly --
maybe worth unifying? -
Do I see correctly, that helper map in
__submit_eventand
process_fill_lineage(in arguments) is not used?
Description
This prevents the hooks from being preempted and replaced by another hook that might overwrite the contents of the shared per-CPU maps before sending the event to the ringbuffer. A similar issue was found to be corrupting events in Falco and is addressed in this PR of our fork, see the discussion there for more details: stackrox/falcosecurity-libs#98
In order to call
bpf_preempt_enable/disableaya needs to support ksyms, which is currently only supported on main, therefore we pin the dependency to a commit known to work. We will unpin this once a new aya release is created.As a final simplification, to prevent new hooks and branches in existing one from having to remember to re-enable preemption before exiting some macro magic is used. We can potentially leverage these macros to define some other common patterns in the future.
Checklist
Automated testing
If any of these don't apply, please comment below.
Testing Performed
CI should be enough.
Summary by CodeRabbit
Bug Fixes
Refactor