Resolve thread-group leader in dup_fd_from_pid for pre-6.9 kernels#59
Merged
Conversation
Signed-off-by: Cong Wang <cwang@multikernel.io>
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.
dup_fd_from_pidduplicates a client socket into the supervisor viapidfd_open+pidfd_getfdfor on-behalfbind/connect/sendmsg/getsockname. When the triggering task is a non-leader thread, it relied onpidfd_open(tid, PIDFD_THREAD), which requires Linux 6.9+; on older kernels that returnsEINVAL, so the on-behalf operation fails (e.g. a multithreaded client'sbindreturnsEINVAL).This resolves the thread-group leader via
Tgidin/proc/<tid>/statusand opens the leader's pidfd instead. File descriptors are shared process-wide, so the leader's pidfd can duplicate any thread's fd — on any kernel withpidfd_getfd(>= 5.6). The triggering thread is frozen on the seccomp notification, so itsTgidcannot race with pid reuse.Verified on a 6.7.9 host (riscv64): all
test_port_remaptests pass, including the multithreadedloopback/loopback_under_conflictcases that exercise this path. Architecture-independent.🤖 Generated with Claude Code