Skip to content

Resolve thread-group leader in dup_fd_from_pid for pre-6.9 kernels#59

Merged
congwang-mk merged 1 commit into
mainfrom
fix-dup-fd-pre-6.9
May 25, 2026
Merged

Resolve thread-group leader in dup_fd_from_pid for pre-6.9 kernels#59
congwang-mk merged 1 commit into
mainfrom
fix-dup-fd-pre-6.9

Conversation

@congwang-mk
Copy link
Copy Markdown
Contributor

dup_fd_from_pid duplicates a client socket into the supervisor via pidfd_open + pidfd_getfd for on-behalf bind/connect/sendmsg/getsockname. When the triggering task is a non-leader thread, it relied on pidfd_open(tid, PIDFD_THREAD), which requires Linux 6.9+; on older kernels that returns EINVAL, so the on-behalf operation fails (e.g. a multithreaded client's bind returns EINVAL).

This resolves the thread-group leader via Tgid in /proc/<tid>/status and 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 with pidfd_getfd (>= 5.6). The triggering thread is frozen on the seccomp notification, so its Tgid cannot race with pid reuse.

Verified on a 6.7.9 host (riscv64): all test_port_remap tests pass, including the multithreaded loopback / loopback_under_conflict cases that exercise this path. Architecture-independent.

🤖 Generated with Claude Code

Signed-off-by: Cong Wang <cwang@multikernel.io>
@congwang-mk congwang-mk merged commit 3e14df6 into main May 25, 2026
8 checks passed
@congwang-mk congwang-mk deleted the fix-dup-fd-pre-6.9 branch May 25, 2026 04:50
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