[PATCH net-next 0/3] net: add SO_PASSCRED_THREAD to get a thread-specific SCM_CREDENTIALS

From: Andrew Halaney

Date: Mon Nov 02 2026 - 18:13:39 EST


Currently, SCM_CREDENTIALS carries the pid of the thread-group leader,
despite carrying the uid/gid of the actual sending thread.
SO_PASSPIDFD_THREAD lets a receiver identify the sending thread, but
only through a pidfd. If you just want to know what the tid of the
sending thread is you have to do something like:

1. Setup SO_PASSPIDFD_THREAD on the socket
2. ioctl(thread_pidfd, PIDFD_GET_INFO) per message
3. close(thread_pidfd) per message

For example systemd-journald wants to log the tid as "trusted field"
(aka provided by the kernel) but doesn't have a great way to do so
right now, unlike the options for uid/gid/pid which are covered by
SO_PASSCRED currently.

So add SO_PASSCRED_THREAD as a sibling of SO_PASSCRED. It delivers
SCM_CREDENTIALS_THREAD whose ucred carries the tid of the sending
thread instead of the thread-group leader. This is completely
independent of SO_PASSCRED, so a receiver can ask for both. Use
a new cmsg rather than changing SCM_CREDENTIALS because users
expect ucred.pid in that context to be the thread-group leader.

As with SO_PASSPIDFD_THREAD, recvmsg() on SOCK_STREAM sockets stops
merging data at a thread boundary once SO_PASSCRED_THREAD is set.

Signed-off-by: Andrew Halaney <andrew@xxxxxxxxxxxx>
---
Andrew Halaney (3):
selftests/net: pass socket options to the scm_pidfd test flows
net: add SO_PASSCRED_THREAD to get a thread-specific SCM_CREDENTIALS
selftests/net: Add tests for SO_PASSCRED_THREAD

arch/alpha/include/uapi/asm/socket.h | 2 +
arch/mips/include/uapi/asm/socket.h | 2 +
arch/parisc/include/uapi/asm/socket.h | 2 +
arch/sparc/include/uapi/asm/socket.h | 2 +
include/linux/socket.h | 1 +
include/net/sock.h | 4 +-
include/uapi/asm-generic/socket.h | 2 +
net/core/scm.c | 32 ++--
net/core/sock.c | 14 ++
net/unix/af_unix.c | 6 +-
tools/testing/selftests/net/af_unix/scm_pidfd.c | 229 ++++++++++++++++++++----
11 files changed, 242 insertions(+), 54 deletions(-)
---
base-commit: 4dd16e31135ea8437a720222df34e8745f385d6d
change-id: 20261012-halaney-scm-creds-thread-7170680f8c5c

Best regards,
--
Andrew Halaney <andrew@xxxxxxxxxxxx>