Skip to content

docs(bpf/net): document why the socket-hook deny tails are intentionally not de-duped#210

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

docs(bpf/net): document why the socket-hook deny tails are intentionally not de-duped#210
ErenAri merged 1 commit into
mainfrom
feat/net-hook-dedup-v2

Conversation

@ErenAri

@ErenAri ErenAri commented Jun 2, 2026

Copy link
Copy Markdown
Owner

Summary

Re-attempted the network-hook tail de-dup (the reverted #207) the right way this time: diagnosed the -22 root cause on real 6.8/6.12 kernels via the cross-kernel bpfcompat matrix before touching main. The evidence is a clean negative result — the de-dup cannot be landed without regressing BPF-LSM load on two LTS kernels, for zero behavioral benefit. This PR records that finding in-code so it isn't attempted a fourth time.

What was proven (on real 6.8 + 6.12 kernels)

All 6 socket_* hooks fail to load (0/6) under every viable de-dup form, vs 6/6 for the hand-written tails:

Variant 6.8/6.12 socket hooks loaded
#207 __always_inline helper 0/6 ❌
Function-like macro (no helper boundary) 0/6 ❌
Macro minus the ipv6 maybe-NULL branch 0/6 ❌
Good hand-written per-hook tails 6/6 ✅ (all 5 target kernels)

Ruled out: complexity/instruction limit (the de-dup is smaller — 6937 vs 8685 insns), helper-function BTF metadata (no emit_net_block_event FUNC even in the broken object — clang inlined it), outlined BPF-to-BPF subprogram (22 FUNCs in all variants), the ipv6 maybe-NULL pointer.

Cause: load-time -EINVAL with no verifier output even at log_level=1 → the kernel's func_info/line_info BTF validation rejecting the unified tail's instruction layout on 6.8/6.12, which 5.15/6.1/6.17 accept. Verifier acceptance is non-monotonic across versions. A real __noinline subprogram is structurally impossible (emit needs 14 args > BPF's 5-register call limit).

Change

A 22-line INTENTIONAL DUPLICATION comment at the net hooks. No code/behavior change. This PR also exercises the bpfcompat matrix gate (#209) — which should pass 5/5, proving the hooks still load everywhere.

🤖 Generated with Claude Code

…uped

Re-attempting the net-hook tail de-dup (the reverted PR #207) regresses
BPF-LSM load of all 6 socket_* hooks on kernels 6.8 and 6.12 -- reproduced
on the cross-kernel bpfcompat matrix across three independent implementations
(__always_inline helper, function-like macro, macro minus the ipv6 branch).
The unified-tail instruction layout is rejected by the 6.8/6.12 verifiers at
bpf_prog_load (-EINVAL, func_info/line_info BTF validation, no verifier-log
output) while 5.15/6.1/6.17 accept it -- verifier acceptance is non-monotonic
across versions, and the hand-written per-hook tails are the layout that loads
everywhere. A real __noinline subprogram is impossible (emit needs 14 args >
BPF's 5-register call limit). The de-dup buys only line count, zero behavior
change. Document the constraint in-code so it is not re-attempted; the matrix
gate (PR #209) catches any load regression pre-merge.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@ErenAri ErenAri merged commit beb2aa4 into main Jun 2, 2026
41 of 42 checks passed
@ErenAri ErenAri deleted the feat/net-hook-dedup-v2 branch June 2, 2026 22:45
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