bpf: attach reuseport steering filter exactly once per group#371
Merged
Conversation
SO_ATTACH_REUSEPORT_CBPF is a property of the kernel reuseport group, not the individual fd: re-attaching replaces and frees the group's single prog while sibling sockets' RX softirqs may still be running it. The mvfst_hook_on_socket_create hook fired on every invocation — once per worker listener fd at bind() and again per accepted connection at runtime (site 2 wraps the worker's same listener fd) — turning that into a hot, multi-threaded use-after-free. Dedup attachment per reuseport group, keyed by the bound address:port (via getsockname). State is encapsulated in a ReuseportSteering class held in a folly::Indestructible singleton (never destructs, so a late hook call from a draining IO thread can't touch freed state on shutdown): - A mutex-guarded F14 set of already-attached SocketAddresses. The lock is held across check -> setsockopt -> insert so concurrent workers binding the same group serialize and exactly one attaches. - A per-thread folly::ThreadLocal F14 set of resolved fds as a lock-free, syscall-free fast path for the steady-state per-connection case. getsockname/setsockopt failures return without caching so a later hook retries; client sockets (where the option legitimately fails) re-run the rate-limited slow path harmlessly. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
gmarzot
approved these changes
Jun 1, 2026
Contributor
gmarzot
left a comment
There was a problem hiding this comment.
@gmarzot reviewed 1 file and all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on akash-a-n, michalhosna, mondain, Oxyd, peterchave, suhasHere, and TimEvens).
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.
SO_ATTACH_REUSEPORT_CBPF is a property of the kernel reuseport group, not the individual fd: re-attaching replaces and frees the group's single prog while sibling sockets' RX softirqs may still be running it. The mvfst_hook_on_socket_create hook fired on every invocation — once per worker listener fd at bind() and again per accepted connection at runtime (site 2 wraps the worker's same listener fd) — turning that into a hot, multi-threaded use-after-free.
Dedup attachment per reuseport group, keyed by the bound address:port (via getsockname). State is encapsulated in a ReuseportSteering class held in a folly::Indestructible singleton (never destructs, so a late hook call from a draining IO thread can't touch freed state on shutdown):
getsockname/setsockopt failures return without caching so a later hook retries; client sockets (where the option legitimately fails) re-run the rate-limited slow path harmlessly.
This change is