refactor(bpf/net): centralize net_block event + enforce-signal across the 6 socket hooks#207
Merged
Merged
Conversation
The 6 socket_* LSM hooks (and the connect tracepoint fallback) each carried a near-identical ~95-line deny tail: a duplicated SIGKILL-escalation signal computation (6x) and a duplicated net_block event reserve+fill+submit (13x). That per-hook duplication is the exact class that produced past divergence bugs. Extract two __always_inline helpers in aegis_common.h: - compute_net_enforce_signal(pid, start_time) - emit_net_block_event(...) -- the single definition of the net_block shape and collapse each hook's audit/enforce branches into one `audit ? 0 : -EPERM` tail. Every hook's address-parsing + rule-match logic is left BYTE-IDENTICAL; only the (verified) decision/emit tail changed. Behavior-preserving, except bind/listen rule_type is now a zero-filled char[16] (was a 5-byte memcpy that left 11 uninitialized ring-buffer bytes -- a minor info-leak fix). aegis_net.bpf.h: 1483 -> 1044 lines. Verified on a 6.17 BPF-LSM host: bpf_obj compiles and the enforcement proof harness passes end-to-end (connect + sendmsg to a denied CIDR -> -EPERM, runtime_state=ENFORCE, all classes + bypasses blocked). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
ErenAri
added a commit
that referenced
this pull request
Jun 2, 2026
revert(bpf/net): restore pre-#207 net hooks — fix load regression on 6.8/6.12
This was referenced Jun 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The 6
socket_*LSM hooks (+ the connect tracepoint fallback) each carried a near-identical ~95-line deny tail: a duplicated SIGKILL-escalation signal computation (6×) and a duplicatednet_blockevent reserve+fill+submit (13×). That per-hook duplication is exactly the class that produced past divergence bugs (the headlinedetect_missing_optional_lsm_hooksbug was a per-hook divergence).Two
__always_inlinehelpers inaegis_common.hnow own that logic:compute_net_enforce_signal(pid, start_time)emit_net_block_event(...)— the single definition of thenet_blockevent shapeEach hook's audit/enforce branches collapse into one
audit ? 0 : -EPERMtail.aegis_net.bpf.h: 1483 → 1044 lines (-30%).Safety
bind/listenrule_typeis now a zero-filledchar[16](previously a 5-bytememcpy("port")that left 11 uninitialized ring-buffer bytes in the emitted event — a minor info-leak fix).Verification
bpf_objcompiles clean.connectandsendmsgto a denied CIDR (240.0.0.0/4) →-EPERM,runtime_state=ENFORCE, every class (module/file/exec/ptrace/bpf/network) + bypass (symlink/hardlink/bindmount/rename/sendmsg/overlay) BLOCKED, no silent downgrade.bpf_ringbuf_submitin the helper; the verifier's reference-leak check caught it immediately (now fixed) — and the behavioral harness re-confirmed enforcement.bpf-compile(15–18),veristat(15% complexity tolerance; inlined helpers keep counts flat), andkernel-bpf-test. I've also dispatched the bpfcompat kernel matrix on this branch to confirm the object loads on 5.15→6.17.🤖 Generated with Claude Code