Skip to content

refactor(bpf/net): centralize net_block event + enforce-signal across the 6 socket hooks#207

Merged
ErenAri merged 1 commit into
mainfrom
refactor/net-hook-dedup
Jun 2, 2026
Merged

refactor(bpf/net): centralize net_block event + enforce-signal across the 6 socket hooks#207
ErenAri merged 1 commit into
mainfrom
refactor/net-hook-dedup

Conversation

@ErenAri

@ErenAri ErenAri commented Jun 2, 2026

Copy link
Copy Markdown
Owner

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 duplicated net_block event reserve+fill+submit (13×). That per-hook duplication is exactly the class that produced past divergence bugs (the headline detect_missing_optional_lsm_hooks bug was a per-hook divergence).

Two __always_inline helpers in aegis_common.h now own that logic:

  • compute_net_enforce_signal(pid, start_time)
  • emit_net_block_event(...)the single definition of the net_block event shape

Each hook's audit/enforce branches collapse into one audit ? 0 : -EPERM tail.

aegis_net.bpf.h: 1483 → 1044 lines (-30%).

Safety

  • Every hook's address-parsing + rule-match logic is byte-identical — only the (verified) decision/emit tail changed. The deny decision (what matches) is untouched.
  • Behavior-preserving, with one deliberate exception: bind/listen rule_type is now a zero-filled char[16] (previously a 5-byte memcpy("port") that left 11 uninitialized ring-buffer bytes in the emitted event — a minor info-leak fix).

Verification

  • bpf_obj compiles clean.
  • Behavioral, on a real 6.17 BPF-LSM host: the enforcement-proof harness passes end-to-end — connect and sendmsg to 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.
  • A first cut omitted bpf_ringbuf_submit in the helper; the verifier's reference-leak check caught it immediately (now fixed) — and the behavioral harness re-confirmed enforcement.
  • CI adds cross-clang bpf-compile (15–18), veristat (15% complexity tolerance; inlined helpers keep counts flat), and kernel-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

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 ErenAri merged commit a43a88c into main Jun 2, 2026
43 checks passed
@ErenAri ErenAri deleted the refactor/net-hook-dedup branch June 2, 2026 16:02
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant