[GIT PULL 17/19 for v7.4] vfs shared net-next pidfd

From: Christian Brauner

Date: Fri Oct 16 2026 - 06:31:34 EST


Hey Linus,

/* Summary */

This adds thread specific pidfds to af_unix sockets.

SO_PASSPIDFD and SO_PEERPIDFD hand out a pidfd for the thread-group
leader. A coredump server on the coredump socket can't get a handle on
the thread that took the signal and is writing the dump, and anything
doing per-thread authentication has the same problem. The sending and
the connecting thread are recorded in addition to the thread-group
leader and sk_peer_pid becomes an array indexed by pid type.

SO_PASSPIDFD_THREAD works like SO_PASSPIDFD but delivers an
SCM_PIDFD_THREAD cmsg for the sending thread. Both options are
independent so a receiver can ask for both. On SOCK_STREAM sockets
recvmsg() only stops merging data at a thread boundary when the
receiver asked for a thread pidfd. SO_PEERPIDFD_THREAD returns a pidfd
for the thread that called connect(), listen() or socketpair(). pidfs
records the coredump on the dumping thread's struct pid too so its
pidfd reports it like the leader's does. Selftests for af_unix and the
coredump socket are included.

This is a branch shared with net-next so these changes may also reach
you through the networking pull request.

/* Testing */

No build failures or warnings were observed.

/* Conflicts */

Merge conflicts with mainline
=============================

This conflicts with the vfs-7.4-rc1.coredump tag in
tools/testing/selftests/coredump/coredump_test.h and
tools/testing/selftests/coredump/coredump_test_helpers.c between commit
eec8727ba2730 ("selftests/coredump: add a separate helper header") from
that tag and commit 1f47b275d5d5a ("selftests/coredump: check the
dumping thread's pidfd") from this tag. The coredump tag is merged
before this one. In coredump_test.h the coredump tag's version wins
since it moved every declaration into coredump_test_helpers.h. In
coredump_test_helpers.c the SO_PEERPIDFD_THREAD fallback define and the
crashing_child_thread() and get_peer_pidfd_thread() helpers from this
tag are kept on top of the coredump tag's rewrite of the file. The
first hunk is the interesting one, the rest of the combined diff is a
1200 line wall of one-sided context:

diff --cc tools/testing/selftests/coredump/coredump_test_helpers.c
index 91607e09127f,36306069f62e..000000000000
--- a/tools/testing/selftests/coredump/coredump_test_helpers.c
+++ b/tools/testing/selftests/coredump/coredump_test_helpers.c
@@@ -30,16 -21,28 +30,20 @@@
#include <unistd.h>

#include "../filesystems/wrappers.h"
-#include "../pidfd/pidfd.h"
+#include "coredump_notify_signal.h"

-/* Forward declarations to avoid including harness header */
-struct __test_metadata;
+#include "coredump_test_helpers.h"

-/* Match the fixture definition from coredump_test.h */
-struct _fixture_coredump_data {
- char original_core_pattern[256];
- pid_t pid_coredump_server;
- int fd_tmpfs_detached;
-};
-
-#ifndef PAGE_SIZE
-#define PAGE_SIZE 4096
+#if __ELF_NATIVE_CLASS == 64
+#define COREDUMP_ELFCLASS ELFCLASS64
+#else
+#define COREDUMP_ELFCLASS ELFCLASS32
#endif

-#define NUM_THREAD_SPAWN 128
-
+ #ifndef SO_PEERPIDFD_THREAD
+ #define SO_PEERPIDFD_THREAD 87
+ #endif
+
void *do_nothing(void *arg)
{
(void)arg;

With that the two declarations this tag added to coredump_test.h are
gone and coredump_socket_test.c fails to build with implicit
declarations of both helpers until they are declared in
coredump_test_helpers.h. rerere doesn't record this part, it is a
separate change on top of the merge:

diff --git a/tools/testing/selftests/coredump/coredump_test_helpers.h b/tools/testing/selftests/coredump/coredump_test_helpers.h
index 3f2f87837558..e7f0998347ca 100644
--- a/tools/testing/selftests/coredump/coredump_test_helpers.h
+++ b/tools/testing/selftests/coredump/coredump_test_helpers.h
@@ -39,6 +39,7 @@
/* Shared helper function declarations */
void *do_nothing(void *arg);
void crashing_child(void);
+void crashing_child_thread(void);
void crashing_child_sparse(size_t size);
void crashing_child_memory(__u64 task_filter, int fd_addr);
bool find_coredump_segment(int fd, __u64 vaddr, ElfW(Phdr) *segment);
@@ -59,6 +60,7 @@ int create_detached_tmpfs(void);
int create_and_listen_unix_socket(const char *path);
bool set_core_pattern(const char *pattern);
int get_peer_pidfd(int fd);
+int get_peer_pidfd_thread(int fd);
bool get_pidfd_info(int fd_peer_pidfd, struct pidfd_info *info);

/* Protocol helper function declarations */

Merge conflicts with other trees
================================

No known conflicts.

The following changes since commit 24a19b953e2a3d0ea5a8c4951a0ab8f32720c907:

Linux 7.3-rc7 (2026-10-11 20:04:55 -0700)

are available in the Git repository at:

git@xxxxxxxxxxxxxxxxxxx:pub/scm/linux/kernel/git/vfs/vfs tags/vfs-7.4-rc1.shared.net-next.pidfd

for you to fetch changes up to 96bd708bdab49bea550070d935198ad4f2028a73:

Merge patch series "net: support thread-specific pidfds for send and connect" (2026-10-12 10:58:36 +0200)

----------------------------------------------------------------
vfs-7.4-rc1.shared.net-next.pidfd

Please consider pulling these changes from the signed vfs-7.4-rc1.shared.net-next.pidfd tag.

Thanks!
Christian

----------------------------------------------------------------
Christian Brauner (11):
pid: add helpers to operate on a struct pid array
af_unix: record the pid of the sending thread
net: add SO_PASSPIDFD_THREAD to get a thread-specific SCM_PIDFD
selftests/net: SO_PASSPIDFD_THREAD
net: turn sk_peer_pid into an array indexed by pid type
af_unix: record the pid of the connecting thread
net: add SO_PEERPIDFD_THREAD to get a thread-specific pidfd
selftests/net: SO_PEERPIDFD_THREAD
pidfs: record the coredump on the dumping thread's pid too
selftests/coredump: check the dumping thread's pidfd
Merge patch series "net: support thread-specific pidfds for send and connect"

arch/alpha/include/uapi/asm/socket.h | 4 +
arch/mips/include/uapi/asm/socket.h | 4 +
arch/parisc/include/uapi/asm/socket.h | 4 +
arch/sparc/include/uapi/asm/socket.h | 4 +
fs/coredump.c | 22 +-
fs/pidfs.c | 27 +-
include/linux/coredump.h | 4 +-
include/linux/pid.h | 53 ++
include/linux/pid_types.h | 8 +
include/linux/pidfs.h | 5 +
include/linux/sched/signal.h | 18 +
include/linux/socket.h | 9 +-
include/net/scm.h | 10 +-
include/net/sock.h | 8 +-
include/trace/events/landlock.h | 2 +-
include/uapi/asm-generic/socket.h | 4 +
net/bluetooth/af_bluetooth.c | 6 +-
net/bluetooth/hci_sock.c | 8 +-
net/bluetooth/l2cap_sock.c | 2 +-
net/core/scm.c | 40 +-
net/core/sock.c | 108 ++--
net/unix/af_unix.c | 66 +--
net/unix/af_unix.h | 3 +-
tools/lib/python/kdoc/xforms_lists.py | 1 +
.../selftests/coredump/coredump_socket_test.c | 175 ++++++
tools/testing/selftests/coredump/coredump_test.h | 2 +
.../selftests/coredump/coredump_test_helpers.c | 49 ++
tools/testing/selftests/net/af_unix/Makefile | 2 +
tools/testing/selftests/net/af_unix/scm_pidfd.c | 602 +++++++++++++++++++++
29 files changed, 1137 insertions(+), 113 deletions(-)