AI Trajectory


Trajectory: (Expand/Collapse All)
Seq Timestamp Type Name Duration
0/0 2026/09/29 11:02 flow patch-triage
8m Args:
null

Results:
{
  "EnableConfigs": [
    "UNIX",
    "COREDUMP"
  ],
  "FocusSymbols": [
    "__pidfs_register_pids",
    "pidfs_coredump",
    "scm_recv_unix",
    "sk_getsockopt_peerpidfd",
    "scm_pidfd_recv",
    "unix_maybe_add_creds",
    "unix_skb_scm_eq",
    "coredump_sock_connect"
  ],
  "KMSANReasoning": "The patch series introduces thread-specific pidfd support for Unix domain sockets and coredump socket connections (SO_PASSPIDFD_THREAD, SO_PEERPIDFD_THREAD, SCM_PIDFD_THREAD), converting single struct pid pointers to pid arrays via DECLARE_PIDS(..., PIDTYPE_TGID).\n\nAn inspection of the changes and surrounding code confirms that all touched data structures and memory buffers are fully initialized:\n1. struct sock: sk-\u003esk_peer_pid is zeroed in sock_init_data_uid() via memset(), and socket allocation zeroes the struct via sk_alloc(). The new sk_scm_pidfd_thread bitfield is part of the zero-initialized bitfield group.\n2. struct scm_cookie: Zero-initialized with memset() in __scm_send(), unix_destruct_scm(), and other caller wrappers. scm_replace_pid() and unix_skb_to_scm() explicitly initialize both PIDTYPE_TGID and PIDTYPE_PID entries.\n3. sk_buff: UNIXCB(skb) is embedded in skb-\u003ecb, which is zeroed upon allocation in skbuff_clear(). In unix_maybe_add_creds(), get_task_pids() populates both pid elements; on error, put_pids() clears them back to NULL.\n4. struct coredump_params: cprm is initialized in vfs_coredump() via designated initializers (ensuring all unmentioned fields, including cprm.pid, are zeroed).\n5. User copying: sk_getsockopt_peerpidfd() writes a local int pidfd and int len to optval/optlen after pidfd_prepare(); scm_pidfd_recv() writes pidfd via put_cmsg(). No uninitialized struct padding or uninitialized stack bytes are copied to user space.\n\nSince all structures are fully zeroed or initialized prior to use and no uninitialized memory risks or info-leaks are introduced, a dedicated KMSAN fuzzing session is not warranted. Any potential memory safety bugs (such as reference counting or socket locking) are covered by KASAN and standard debuggers.",
  "NeedsKMSAN": false,
  "Reasoning": "The patch series adds thread-level pidfd support to UNIX domain sockets (SO_PASSPIDFD_THREAD, SO_PEERPIDFD_THREAD, and SCM_PIDFD_THREAD), expanding peer and scm pid tracking to arrays indexed by pid type. It modifies core socket state management, credentials passing/comparison logic, pidfs registration, and coredump socket connect handling with new WARN_ON_ONCE assertions. These are reachable core networking and IPC changes that warrant fuzzing.",
  "WorthFuzzing": true
}

1/1 2026/09/29 11:02 action read-patch-diff
0m Args:
null

Results:
{
  "PatchDiff": "commit 4b1bcdf04ef59a561451aa72c8d69309ad45a6ec\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate:   Tue Sep 29 11:02:44 2026 +0000\n\n    syz-cluster: applied patch under review\n\ndiff --git a/arch/alpha/include/uapi/asm/socket.h b/arch/alpha/include/uapi/asm/socket.h\nindex 946a5fad26912..5d3524c26b2bc 100644\n--- a/arch/alpha/include/uapi/asm/socket.h\n+++ b/arch/alpha/include/uapi/asm/socket.h\n@@ -157,6 +157,10 @@\n \n #define SO_RIGHTS_NOTRUNC      85\n \n+#define SO_PASSPIDFD_THREAD    86\n+\n+#define SO_PEERPIDFD_THREAD    87\n+\n #if !defined(__KERNEL__)\n \n #if __BITS_PER_LONG == 64\ndiff --git a/arch/mips/include/uapi/asm/socket.h b/arch/mips/include/uapi/asm/socket.h\nindex f1641dde135fc..245a43f52fb1a 100644\n--- a/arch/mips/include/uapi/asm/socket.h\n+++ b/arch/mips/include/uapi/asm/socket.h\n@@ -168,6 +168,10 @@\n \n #define SO_RIGHTS_NOTRUNC      85\n \n+#define SO_PASSPIDFD_THREAD    86\n+\n+#define SO_PEERPIDFD_THREAD    87\n+\n #if !defined(__KERNEL__)\n \n #if __BITS_PER_LONG == 64\ndiff --git a/arch/parisc/include/uapi/asm/socket.h b/arch/parisc/include/uapi/asm/socket.h\nindex f3a3815c7dc29..f23710e1c6714 100644\n--- a/arch/parisc/include/uapi/asm/socket.h\n+++ b/arch/parisc/include/uapi/asm/socket.h\n@@ -149,6 +149,10 @@\n \n #define SO_RIGHTS_NOTRUNC\t0x4053\n \n+#define SO_PASSPIDFD_THREAD\t0x4054\n+\n+#define SO_PEERPIDFD_THREAD\t0x4055\n+\n #if !defined(__KERNEL__)\n \n #if __BITS_PER_LONG == 64\ndiff --git a/arch/sparc/include/uapi/asm/socket.h b/arch/sparc/include/uapi/asm/socket.h\nindex 7907f3b1f0ee0..b35b25bdefc2b 100644\n--- a/arch/sparc/include/uapi/asm/socket.h\n+++ b/arch/sparc/include/uapi/asm/socket.h\n@@ -150,6 +150,10 @@\n \n #define SO_RIGHTS_NOTRUNC        0x005e\n \n+#define SO_PASSPIDFD_THREAD      0x005f\n+\n+#define SO_PEERPIDFD_THREAD      0x0060\n+\n #if !defined(__KERNEL__)\n \n \ndiff --git a/fs/coredump.c b/fs/coredump.c\nindex 6114839f5178b..870ad720b2152 100644\n--- a/fs/coredump.c\n+++ b/fs/coredump.c\n@@ -454,7 +454,7 @@ static bool coredump_parse(struct core_name *cn, struct coredump_params *cprm,\n \t\t\t\t * leader we know that the thread-group leader\n \t\t\t\t * cannot be reaped until @current has exited.\n \t\t\t\t */\n-\t\t\t\tcprm-\u003epid = task_tgid(current);\n+\t\t\t\ttask_pids(cprm-\u003epid, current);\n \t\t\t\terr = cn_printf(cn, \"%d\", COREDUMP_PIDFD_NUMBER);\n \t\t\t\tbreak;\n \t\t\t}\n@@ -626,13 +626,17 @@ static int umh_coredump_setup(struct subprocess_info *info, struct cred *new)\n \tstruct coredump_params *cp = (struct coredump_params *)info-\u003edata;\n \tint err;\n \n-\tif (cp-\u003epid) {\n+\tif (cp-\u003epid[PIDTYPE_TGID]) {\n \t\tstruct file *pidfs_file __free(fput) = NULL;\n \n-\t\tpidfs_file = pidfs_alloc_file(cp-\u003epid, 0);\n+\t\tpidfs_file = pidfs_alloc_file(cp-\u003epid[PIDTYPE_TGID], 0);\n \t\tif (IS_ERR(pidfs_file))\n \t\t\treturn PTR_ERR(pidfs_file);\n \n+\t\terr = pidfs_register_pids(cp-\u003epid);\n+\t\tif (err)\n+\t\t\treturn err;\n+\n \t\tpidfs_coredump(cp);\n \n \t\t/*\n@@ -695,12 +699,12 @@ static bool coredump_sock_connect(struct core_name *cn, struct coredump_params *\n \t\treturn false;\n \n \t/*\n-\t * Set the thread-group leader pid which is used for the peer\n-\t * credentials during connect() below. Then immediately register\n-\t * it in pidfs...\n+\t * Set the pids of the dumping thread and its thread-group leader\n+\t * which are used for the peer credentials during connect() below.\n+\t * Then immediately register them in pidfs...\n \t */\n-\tcprm-\u003epid = task_tgid(current);\n-\tretval = pidfs_register_pid(cprm-\u003epid);\n+\ttask_pids(cprm-\u003epid, current);\n+\tretval = pidfs_register_pids(cprm-\u003epid);\n \tif (retval)\n \t\treturn false;\n \n@@ -722,7 +726,7 @@ static bool coredump_sock_connect(struct core_name *cn, struct coredump_params *\n \t}\n \n \t/* ... and validate that @sk_peer_pid matches @cprm.pid. */\n-\tif (WARN_ON_ONCE(unix_peer(socket-\u003esk)-\u003esk_peer_pid != cprm-\u003epid))\n+\tif (WARN_ON_ONCE(!pids_equal(unix_peer(socket-\u003esk)-\u003esk_peer_pid, cprm-\u003epid)))\n \t\treturn false;\n \n \tcprm-\u003elimit = RLIM_INFINITY;\ndiff --git a/fs/pidfs.c b/fs/pidfs.c\nindex a6a643f15d08a..29299b2c7ca71 100644\n--- a/fs/pidfs.c\n+++ b/fs/pidfs.c\n@@ -793,9 +793,9 @@ void pidfs_exit(struct task_struct *tsk)\n }\n \n #ifdef CONFIG_COREDUMP\n-void pidfs_coredump(const struct coredump_params *cprm)\n+static void pidfs_coredump_pid(struct pid *pid,\n+\t\t\t       const struct coredump_params *cprm)\n {\n-\tstruct pid *pid = cprm-\u003epid;\n \tstruct pidfs_attr *attr;\n \n \tattr = READ_ONCE(pid-\u003eattr);\n@@ -814,6 +814,13 @@ void pidfs_coredump(const struct coredump_params *cprm)\n \tsmp_wmb();\n \tset_bit(PIDFS_ATTR_BIT_COREDUMP, \u0026attr-\u003eattr_mask);\n }\n+\n+void pidfs_coredump(const struct coredump_params *cprm)\n+{\n+\t/* The dumping thread's pidfd reports the coredump as well. */\n+\tfor (enum pid_type type = PIDTYPE_PID; type \u003c= pids_last(cprm-\u003epid); type++)\n+\t\tpidfs_coredump_pid(cprm-\u003epid[type], cprm);\n+}\n #endif\n \n static struct vfsmount *pidfs_mnt __ro_after_init;\n@@ -1070,6 +1077,22 @@ int pidfs_register_pid_gfp(struct pid *pid, gfp_t gfp)\n \treturn 0;\n }\n \n+/* Register the pids up to pid type @last of @pids in pidfs. */\n+int __pidfs_register_pids(struct pid *const *pids, enum pid_type last)\n+{\n+\tif (WARN_ON_ONCE(last \u003e= PIDTYPE_MAX))\n+\t\treturn -EINVAL;\n+\n+\tfor (enum pid_type type = PIDTYPE_PID; type \u003c= last; type++) {\n+\t\tint ret = pidfs_register_pid(pids[type]);\n+\n+\t\tif (unlikely(ret))\n+\t\t\treturn ret;\n+\t}\n+\n+\treturn 0;\n+}\n+\n static struct dentry *pidfs_stash_dentry(struct dentry **stashed,\n \t\t\t\t\t struct dentry *dentry)\n {\ndiff --git a/include/linux/coredump.h b/include/linux/coredump.h\nindex 7b38ee2e7913b..0bbb7de6a4021 100644\n--- a/include/linux/coredump.h\n+++ b/include/linux/coredump.h\n@@ -5,6 +5,7 @@\n #include \u003clinux/types.h\u003e\n #include \u003clinux/mm.h\u003e\n #include \u003clinux/fs.h\u003e\n+#include \u003clinux/pid_types.h\u003e\n #include \u003clinux/sched/coredump.h\u003e\n #include \u003casm/siginfo.h\u003e\n \n@@ -32,7 +33,8 @@ struct coredump_params {\n \tint vma_count;\n \tsize_t vma_data_size;\n \tstruct core_vma_metadata *vma_meta;\n-\tstruct pid *pid;\n+\t/* Dumping thread and its thread-group leader by pid type. */\n+\tDECLARE_PIDS(pid, PIDTYPE_TGID);\n };\n \n extern unsigned int core_file_note_size_limit;\ndiff --git a/include/linux/pid.h b/include/linux/pid.h\nindex ddaef0bbc8ba3..87635d0cc1f71 100644\n--- a/include/linux/pid.h\n+++ b/include/linux/pid.h\n@@ -2,6 +2,9 @@\n #ifndef _LINUX_PID_H\n #define _LINUX_PID_H\n \n+#include \u003clinux/array_size.h\u003e\n+#include \u003clinux/build_bug.h\u003e\n+#include \u003clinux/minmax.h\u003e\n #include \u003clinux/pid_types.h\u003e\n #include \u003clinux/rculist.h\u003e\n #include \u003clinux/rcupdate.h\u003e\n@@ -92,6 +95,56 @@ static inline struct pid *get_pid(struct pid *pid)\n }\n \n extern void put_pid(struct pid *pid);\n+\n+/*\n+ * Helpers for arrays of struct pid indexed by pid type declared with\n+ * DECLARE_PIDS(). The array covers PIDTYPE_PID up to the pid type it\n+ * was declared with and the helpers take that bound from the array.\n+ */\n+static inline void __get_pids(struct pid **dst, struct pid *const *src,\n+\t\t\t      enum pid_type last)\n+{\n+\tfor (enum pid_type type = PIDTYPE_PID; type \u003c= last; type++)\n+\t\tdst[type] = get_pid(src[type]);\n+}\n+\n+static inline void __put_pids(struct pid **pids, enum pid_type last)\n+{\n+\tfor (enum pid_type type = PIDTYPE_PID; type \u003c= last; type++) {\n+\t\tput_pid(pids[type]);\n+\t\tpids[type] = NULL;\n+\t}\n+}\n+\n+static inline void __swap_pids(struct pid **a, struct pid **b,\n+\t\t\t       enum pid_type last)\n+{\n+\tfor (enum pid_type type = PIDTYPE_PID; type \u003c= last; type++)\n+\t\tswap(a[type], b[type]);\n+}\n+\n+static inline bool __pids_equal(struct pid *const *a, struct pid *const *b,\n+\t\t\t\tenum pid_type last)\n+{\n+\tfor (enum pid_type type = PIDTYPE_PID; type \u003c= last; type++)\n+\t\tif (a[type] != b[type])\n+\t\t\treturn false;\n+\treturn true;\n+}\n+\n+/* The last pid type an array declared with DECLARE_PIDS() covers. */\n+#define pids_last(pids)\t\t\t\t\t\t\t\\\n+\t((enum pid_type)(ARRAY_SIZE(pids) - 1 +\t\t\t\t\\\n+\t\t\t BUILD_BUG_ON_ZERO(ARRAY_SIZE(pids) \u003e PIDTYPE_MAX)))\n+\n+#define __pids_last2(a, b)\t\t\t\t\t\t\\\n+\t(pids_last(a) + BUILD_BUG_ON_ZERO(ARRAY_SIZE(a) != ARRAY_SIZE(b)))\n+\n+#define get_pids(dst, src)\t__get_pids(dst, src, __pids_last2(dst, src))\n+#define put_pids(pids)\t\t__put_pids(pids, pids_last(pids))\n+#define swap_pids(a, b)\t\t__swap_pids(a, b, __pids_last2(a, b))\n+#define pids_equal(a, b)\t__pids_equal(a, b, __pids_last2(a, b))\n+\n extern struct task_struct *pid_task(struct pid *pid, enum pid_type);\n static inline bool pid_has_task(struct pid *pid, enum pid_type type)\n {\ndiff --git a/include/linux/pid_types.h b/include/linux/pid_types.h\nindex c2aee1d91dcfd..3302690a2a281 100644\n--- a/include/linux/pid_types.h\n+++ b/include/linux/pid_types.h\n@@ -2,6 +2,8 @@\n #ifndef _LINUX_PID_TYPES_H\n #define _LINUX_PID_TYPES_H\n \n+#include \u003clinux/build_bug.h\u003e\n+\n enum pid_type {\n \tPIDTYPE_PID,\n \tPIDTYPE_TGID,\n@@ -10,6 +12,12 @@ enum pid_type {\n \tPIDTYPE_MAX,\n };\n \n+struct pid;\n+\n+/* An array of struct pid indexed by pid type, PIDTYPE_PID up to @last. */\n+#define DECLARE_PIDS(name, last)\t\t\t\t\t\\\n+\tstruct pid *name[(last) + 1 + BUILD_BUG_ON_ZERO((last) \u003e= PIDTYPE_MAX)]\n+\n struct pid_namespace;\n extern struct pid_namespace init_pid_ns;\n \ndiff --git a/include/linux/pidfs.h b/include/linux/pidfs.h\nindex 0abf7da9ab236..3c1e82f1a3691 100644\n--- a/include/linux/pidfs.h\n+++ b/include/linux/pidfs.h\n@@ -3,6 +3,7 @@\n #define _LINUX_PID_FS_H\n \n #include \u003clinux/gfp_types.h\u003e\n+#include \u003clinux/pid.h\u003e\n \n struct coredump_params;\n \n@@ -32,5 +33,9 @@ static inline int pidfs_register_pid(struct pid *pid)\n }\n \n void pidfs_free_pid(struct pid *pid);\n+int __pidfs_register_pids(struct pid *const *pids, enum pid_type last);\n+\n+/* Register the pids of an array declared with DECLARE_PIDS(). */\n+#define pidfs_register_pids(pids)\t__pidfs_register_pids(pids, pids_last(pids))\n \n #endif /* _LINUX_PID_FS_H */\ndiff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h\nindex d45a5476b97de..3149cdb976c60 100644\n--- a/include/linux/sched/signal.h\n+++ b/include/linux/sched/signal.h\n@@ -674,6 +674,24 @@ struct pid *task_pid_type(struct task_struct *task, enum pid_type type)\n \treturn pid;\n }\n \n+/* Fill @pids with the pid types of @task up to @last, without references. */\n+static inline void __task_pids(struct pid **pids, enum pid_type last,\n+\t\t\t       struct task_struct *task)\n+{\n+\tfor (enum pid_type type = PIDTYPE_PID; type \u003c= last; type++)\n+\t\tpids[type] = task_pid_type(task, type);\n+}\n+\n+static inline void __get_task_pids(struct pid **pids, enum pid_type last,\n+\t\t\t\t   struct task_struct *task)\n+{\n+\tfor (enum pid_type type = PIDTYPE_PID; type \u003c= last; type++)\n+\t\tpids[type] = get_pid(task_pid_type(task, type));\n+}\n+\n+#define task_pids(pids, task)\t\t__task_pids(pids, pids_last(pids), task)\n+#define get_task_pids(pids, task)\t__get_task_pids(pids, pids_last(pids), task)\n+\n static inline struct pid *task_tgid(struct task_struct *task)\n {\n \treturn task-\u003esignal-\u003epids[PIDTYPE_TGID];\ndiff --git a/include/linux/socket.h b/include/linux/socket.h\nindex 5a5eb12501032..b17fdb7d38a77 100644\n--- a/include/linux/socket.h\n+++ b/include/linux/socket.h\n@@ -189,10 +189,11 @@ static inline size_t msg_data_left(const struct msghdr *msg)\n \n /* \"Socket\"-level control message types: */\n \n-#define\tSCM_RIGHTS\t0x01\t\t/* rw: access rights (array of int) */\n-#define SCM_CREDENTIALS 0x02\t\t/* rw: struct ucred\t\t*/\n-#define SCM_SECURITY\t0x03\t\t/* rw: security label\t\t*/\n-#define SCM_PIDFD\t0x04\t\t/* ro: pidfd (int)\t\t*/\n+#define\tSCM_RIGHTS\t\t0x01\t/* rw: access rights (array of int) */\n+#define SCM_CREDENTIALS\t\t0x02\t/* rw: struct ucred\t\t*/\n+#define SCM_SECURITY\t\t0x03\t/* rw: security label\t\t*/\n+#define SCM_PIDFD\t\t0x04\t/* ro: pidfd (int)\t\t*/\n+#define SCM_PIDFD_THREAD\t0x05\t/* ro: thread pidfd (int)\t*/\n \n struct ucred {\n \t__u32\tpid;\ndiff --git a/include/net/scm.h b/include/net/scm.h\nindex 86ae6bc109ec6..aa7d15c5fc271 100644\n--- a/include/net/scm.h\n+++ b/include/net/scm.h\n@@ -42,7 +42,7 @@ struct scm_fp_list {\n };\n \n struct scm_cookie {\n-\tstruct pid\t\t*pid;\t\t/* Skb credentials */\n+\tDECLARE_PIDS(pid, PIDTYPE_TGID);\t/* Skb credentials by pid type */\n \tstruct scm_fp_list\t*fp;\t\t/* Passed files\t\t*/\n \tstruct scm_creds\tcreds;\t\t/* Skb credentials\t*/\n #ifdef CONFIG_SECURITY_NETWORK\n@@ -69,7 +69,7 @@ static __inline__ void unix_get_peersec_dgram(struct socket *sock, struct scm_co\n static __inline__ void scm_set_cred(struct scm_cookie *scm,\n \t\t\t\t    struct pid *pid, kuid_t uid, kgid_t gid)\n {\n-\tscm-\u003epid = get_pid(pid);\n+\tscm-\u003epid[PIDTYPE_TGID] = get_pid(pid);\n \tscm-\u003ecreds.pid = pid_vnr(pid);\n \tscm-\u003ecreds.uid = uid;\n \tscm-\u003ecreds.gid = gid;\n@@ -77,8 +77,7 @@ static __inline__ void scm_set_cred(struct scm_cookie *scm,\n \n static __inline__ void scm_destroy_cred(struct scm_cookie *scm)\n {\n-\tput_pid(scm-\u003epid);\n-\tscm-\u003epid = NULL;\n+\tput_pids(scm-\u003epid);\n }\n \n static __inline__ void scm_destroy(struct scm_cookie *scm)\ndiff --git a/include/net/sock.h b/include/net/sock.h\nindex 60ea55dc18854..efc64c60e4ac3 100644\n--- a/include/net/sock.h\n+++ b/include/net/sock.h\n@@ -301,7 +301,7 @@ struct sk_filter;\n   *\t@sk_type: socket type (%SOCK_STREAM, etc)\n   *\t@sk_protocol: which protocol this socket belongs in this network family\n   *\t@sk_peer_lock: lock protecting @sk_peer_pid and @sk_peer_cred\n-  *\t@sk_peer_pid: \u0026struct pid for this socket's peer\n+  *\t@sk_peer_pid: \u0026struct pid for this socket's peer, by pid type\n   *\t@sk_peer_cred: %SO_PEERCRED setting\n   *\t@sk_rcvlowat: %SO_RCVLOWAT setting\n   *\t@sk_rcvtimeo: %SO_RCVTIMEO setting\n@@ -356,6 +356,7 @@ struct sk_filter;\n   *\t@sk_scm_security: flagged by SO_PASSSEC to recv SCM_SECURITY\n   *\t@sk_scm_pidfd: flagged by SO_PASSPIDFD to recv SCM_PIDFD\n   *\t@sk_scm_rights: flagged by SO_PASSRIGHTS to recv SCM_RIGHTS\n+  *\t@sk_scm_pidfd_thread: flagged by SO_PASSPIDFD_THREAD to recv a thread SCM_PIDFD\n   *\t@sk_scm_unused: unused flags for scm_recv()\n   *\t@ns_tracker: tracker for netns reference\n   *\t@sk_user_frags: xarray of pages the user is holding a reference on.\n@@ -545,7 +546,7 @@ struct sock {\n \tu64\t\t\tsk_ino;\n \tspinlock_t\t\tsk_peer_lock;\n \tint\t\t\tsk_bind_phc;\n-\tstruct pid\t\t*sk_peer_pid;\n+\tDECLARE_PIDS(sk_peer_pid, PIDTYPE_TGID);\n \tconst struct cred\t*sk_peer_cred;\n \n \tktime_t\t\t\tsk_stamp;\n@@ -562,7 +563,8 @@ struct sock {\n \t\t\t\tsk_scm_security : 1,\n \t\t\t\tsk_scm_pidfd : 1,\n \t\t\t\tsk_scm_rights : 1,\n-\t\t\t\tsk_scm_unused : 4;\n+\t\t\t\tsk_scm_pidfd_thread : 1,\n+\t\t\t\tsk_scm_unused : 3;\n \t\t};\n \t};\n \tu8\t\t\tsk_clockid;\n@@ -2988,6 +2990,16 @@ static inline bool sk_is_stream_unix(const struct sock *sk)\n \treturn sk_is_unix(sk) \u0026\u0026 sk-\u003esk_type == SOCK_STREAM;\n }\n \n+static inline bool sk_scm_pidfd_wanted(const struct sock *sk)\n+{\n+\treturn sk-\u003esk_scm_pidfd;\n+}\n+\n+static inline bool sk_scm_pidfd_thread_wanted(const struct sock *sk)\n+{\n+\treturn sk-\u003esk_scm_pidfd_thread;\n+}\n+\n static inline bool sk_is_vsock(const struct sock *sk)\n {\n \treturn sk-\u003esk_family == AF_VSOCK;\ndiff --git a/include/trace/events/landlock.h b/include/trace/events/landlock.h\nindex 3a43638c9bc29..9e172ea22d95c 100644\n--- a/include/trace/events/landlock.h\n+++ b/include/trace/events/landlock.h\n@@ -1037,7 +1037,7 @@ TRACE_EVENT(landlock_deny_scope_abstract_unix_socket,\n \t\t * updates.  The peer socket keeps a reference to sk_peer_pid\n \t\t * through pid_nr(); sun_path is the reliable identifier.\n \t\t */\n-\t\tpeer_pid\t\t= READ_ONCE(peer-\u003esk_peer_pid);\n+\t\tpeer_pid\t\t= READ_ONCE(peer-\u003esk_peer_pid[PIDTYPE_TGID]);\n \t\t__entry-\u003epeer_pid\t= peer_pid ? pid_nr(peer_pid) : 0;\n \t\t__assign_str(sun_path);\n \t),\ndiff --git a/include/uapi/asm-generic/socket.h b/include/uapi/asm-generic/socket.h\nindex 84ea7b92936e2..56fed7ab27ab8 100644\n--- a/include/uapi/asm-generic/socket.h\n+++ b/include/uapi/asm-generic/socket.h\n@@ -152,6 +152,10 @@\n \n #define SO_RIGHTS_NOTRUNC\t85\n \n+#define SO_PASSPIDFD_THREAD\t86\n+\n+#define SO_PEERPIDFD_THREAD\t87\n+\n #if !defined(__KERNEL__)\n \n #if __BITS_PER_LONG == 64 || (defined(__x86_64__) \u0026\u0026 defined(__ILP32__))\ndiff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c\nindex 411d66f24393d..7758e9ea3848c 100644\n--- a/net/bluetooth/af_bluetooth.c\n+++ b/net/bluetooth/af_bluetooth.c\n@@ -161,7 +161,7 @@ struct sock *bt_sock_alloc(struct net *net, struct socket *sock,\n \t/* Init peer information so it can be properly monitored */\n \tif (!kern) {\n \t\tspin_lock(\u0026sk-\u003esk_peer_lock);\n-\t\tsk-\u003esk_peer_pid  = get_pid(task_tgid(current));\n+\t\tsk-\u003esk_peer_pid[PIDTYPE_TGID]  = get_pid(task_tgid(current));\n \t\tsk-\u003esk_peer_cred = get_current_cred();\n \t\tspin_unlock(\u0026sk-\u003esk_peer_lock);\n \t}\n@@ -235,9 +235,9 @@ void bt_accept_enqueue(struct sock *parent, struct sock *sk, bool bh)\n \t * socket is allocated by the kernel.\n \t */\n \tspin_lock(\u0026sk-\u003esk_peer_lock);\n-\told_pid = sk-\u003esk_peer_pid;\n+\told_pid = sk-\u003esk_peer_pid[PIDTYPE_TGID];\n \told_cred = sk-\u003esk_peer_cred;\n-\tsk-\u003esk_peer_pid = get_pid(parent-\u003esk_peer_pid);\n+\tsk-\u003esk_peer_pid[PIDTYPE_TGID] = get_pid(parent-\u003esk_peer_pid[PIDTYPE_TGID]);\n \tsk-\u003esk_peer_cred = get_cred(parent-\u003esk_peer_cred);\n \tspin_unlock(\u0026sk-\u003esk_peer_lock);\n \ndiff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c\nindex 6d56c77741e19..4c40068ba5fb2 100644\n--- a/net/bluetooth/hci_sock.c\n+++ b/net/bluetooth/hci_sock.c\n@@ -284,21 +284,21 @@ static void hci_sock_copy_creds(struct sock *sk, struct sk_buff *skb)\n \tcreds = \u0026bt_cb(skb)-\u003ecreds;\n \n \t/* Check if peer credentials is set */\n-\tif (!sk-\u003esk_peer_pid) {\n+\tif (!sk-\u003esk_peer_pid[PIDTYPE_TGID]) {\n \t\t/* Check if parent peer credentials is set */\n-\t\tif (bt_sk(sk)-\u003eparent \u0026\u0026 bt_sk(sk)-\u003eparent-\u003esk_peer_pid)\n+\t\tif (bt_sk(sk)-\u003eparent \u0026\u0026 bt_sk(sk)-\u003eparent-\u003esk_peer_pid[PIDTYPE_TGID])\n \t\t\tsk = bt_sk(sk)-\u003eparent;\n \t\telse\n \t\t\treturn;\n \t}\n \n \t/* Check if scm_creds already set */\n-\tif (creds-\u003epid == pid_vnr(sk-\u003esk_peer_pid))\n+\tif (creds-\u003epid == pid_vnr(sk-\u003esk_peer_pid[PIDTYPE_TGID]))\n \t\treturn;\n \n \tmemset(creds, 0, sizeof(*creds));\n \n-\tcreds-\u003epid = pid_vnr(sk-\u003esk_peer_pid);\n+\tcreds-\u003epid = pid_vnr(sk-\u003esk_peer_pid[PIDTYPE_TGID]);\n \tif (sk-\u003esk_peer_cred) {\n \t\tcreds-\u003euid = sk-\u003esk_peer_cred-\u003euid;\n \t\tcreds-\u003egid = sk-\u003esk_peer_cred-\u003egid;\ndiff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c\nindex 1194c37e466f1..872d8fb31b6fb 100644\n--- a/net/bluetooth/l2cap_sock.c\n+++ b/net/bluetooth/l2cap_sock.c\n@@ -1890,7 +1890,7 @@ static struct pid *l2cap_sock_get_peer_pid_cb(struct l2cap_chan *chan)\n {\n \tstruct sock *sk = chan-\u003edata;\n \n-\treturn sk-\u003esk_peer_pid;\n+\treturn sk-\u003esk_peer_pid[PIDTYPE_TGID];\n }\n \n static void l2cap_sock_suspend_cb(struct l2cap_chan *chan)\ndiff --git a/net/core/scm.c b/net/core/scm.c\nindex f0d44ecdb11fc..ba43d76027af5 100644\n--- a/net/core/scm.c\n+++ b/net/core/scm.c\n@@ -149,6 +149,7 @@ EXPORT_SYMBOL(__scm_destroy);\n \n static inline int scm_replace_pid(struct scm_cookie *scm, struct pid *pid)\n {\n+\tstruct pid *thread_pid;\n \tint err;\n \n \t/* drop all previous references */\n@@ -158,7 +159,18 @@ static inline int scm_replace_pid(struct scm_cookie *scm, struct pid *pid)\n \tif (unlikely(err))\n \t\treturn err;\n \n-\tscm-\u003epid = pid;\n+\t/* A sender naming its own thread-group sends from the current thread. */\n+\tif (pid == task_tgid(current))\n+\t\tthread_pid = task_pid(current);\n+\telse\n+\t\tthread_pid = pid;\n+\n+\terr = pidfs_register_pid(thread_pid);\n+\tif (unlikely(err))\n+\t\treturn err;\n+\n+\tscm-\u003epid[PIDTYPE_TGID] = pid;\n+\tscm-\u003epid[PIDTYPE_PID] = get_pid(thread_pid);\n \tscm-\u003ecreds.pid = pid_vnr(pid);\n \treturn 0;\n }\n@@ -207,7 +219,8 @@ int __scm_send(struct socket *sock, struct msghdr *msg, struct scm_cookie *p)\n \t\t\tif (err)\n \t\t\t\tgoto error;\n \n-\t\t\tif (!p-\u003epid || pid_vnr(p-\u003epid) != creds.pid) {\n+\t\t\tif (!p-\u003epid[PIDTYPE_TGID] ||\n+\t\t\t    pid_vnr(p-\u003epid[PIDTYPE_TGID]) != creds.pid) {\n \t\t\t\tstruct pid *pid;\n \t\t\t\terr = -ESRCH;\n \t\t\t\tpid = find_get_pid(creds.pid);\n@@ -486,11 +499,16 @@ static bool scm_has_secdata(struct sock *sk)\n }\n #endif\n \n-static void scm_pidfd_recv(struct msghdr *msg, struct scm_cookie *scm)\n+static void scm_pidfd_recv(struct msghdr *msg, struct scm_cookie *scm,\n+\t\t\t   enum pid_type type, int cmsg_type)\n {\n+\tunsigned int flags = PIDFD_STALE;\n \tstruct file *pidfd_file = NULL;\n+\tstruct pid *pid;\n \tint len, pidfd;\n \n+\tpid = scm-\u003epid[type];\n+\n \t/* put_cmsg() doesn't return an error if CMSG is truncated,\n \t * that's why we need to opencode these checks here.\n \t */\n@@ -504,12 +522,15 @@ static void scm_pidfd_recv(struct msghdr *msg, struct scm_cookie *scm)\n \t\treturn;\n \t}\n \n-\tif (!scm-\u003epid)\n+\tif (!pid)\n \t\treturn;\n \n-\tpidfd = pidfd_prepare(scm-\u003epid, PIDFD_STALE, \u0026pidfd_file);\n+\tif (type == PIDTYPE_PID)\n+\t\tflags |= PIDFD_THREAD;\n \n-\tif (put_cmsg(msg, SOL_SOCKET, SCM_PIDFD, sizeof(int), \u0026pidfd)) {\n+\tpidfd = pidfd_prepare(pid, flags, \u0026pidfd_file);\n+\n+\tif (put_cmsg(msg, SOL_SOCKET, cmsg_type, sizeof(int), \u0026pidfd)) {\n \t\tif (pidfd_file) {\n \t\t\tput_unused_fd(pidfd);\n \t\t\tfput(pidfd_file);\n@@ -526,8 +547,8 @@ static bool __scm_recv_common(struct sock *sk, struct msghdr *msg,\n \t\t\t      struct scm_cookie *scm, int flags)\n {\n \tif (!msg-\u003emsg_control) {\n-\t\tif (sk-\u003esk_scm_credentials || sk-\u003esk_scm_pidfd ||\n-\t\t    scm-\u003efp || scm_has_secdata(sk))\n+\t\tif (sk-\u003esk_scm_credentials || sk_scm_pidfd_wanted(sk) ||\n+\t\t    sk_scm_pidfd_thread_wanted(sk) || scm-\u003efp || scm_has_secdata(sk))\n \t\t\tmsg-\u003emsg_flags |= MSG_CTRUNC;\n \n \t\tscm_destroy(scm);\n@@ -573,8 +594,11 @@ void scm_recv_unix(struct socket *sock, struct msghdr *msg,\n \t\tscm_detach_fds(msg, scm, READ_ONCE(u-\u003escm_rights_notrunc));\n \t}\n \n-\tif (sock-\u003esk-\u003esk_scm_pidfd)\n-\t\tscm_pidfd_recv(msg, scm);\n+\tif (sk_scm_pidfd_wanted(sock-\u003esk))\n+\t\tscm_pidfd_recv(msg, scm, PIDTYPE_TGID, SCM_PIDFD);\n+\n+\tif (sk_scm_pidfd_thread_wanted(sock-\u003esk))\n+\t\tscm_pidfd_recv(msg, scm, PIDTYPE_PID, SCM_PIDFD_THREAD);\n \n \tscm_destroy_cred(scm);\n }\ndiff --git a/net/core/sock.c b/net/core/sock.c\nindex d23333bb4f3fa..c970f8beae3ba 100644\n--- a/net/core/sock.c\n+++ b/net/core/sock.c\n@@ -1578,6 +1578,13 @@ int sk_setsockopt(struct sock *sk, int level, int optname,\n \t\t\tret = -EOPNOTSUPP;\n \t\tbreak;\n \n+\tcase SO_PASSPIDFD_THREAD:\n+\t\tif (sk_is_unix(sk))\n+\t\t\tsk-\u003esk_scm_pidfd_thread = valbool;\n+\t\telse\n+\t\t\tret = -EOPNOTSUPP;\n+\t\tbreak;\n+\n \tcase SO_PASSRIGHTS:\n \t\tif (sk_is_unix(sk))\n \t\t\tsk-\u003esk_scm_rights = valbool;\n@@ -1729,6 +1736,50 @@ static int groups_to_user(sockptr_t dst, const struct group_info *src)\n \treturn 0;\n }\n \n+/* Hand out a pidfd for @type of the socket's peer via SO_PEERPIDFD*. */\n+static int sk_getsockopt_peerpidfd(struct sock *sk, enum pid_type type,\n+\t\t\t\t   sockptr_t optval, sockptr_t optlen, int len)\n+{\n+\tstruct file *pidfd_file = NULL;\n+\tunsigned int flags = 0;\n+\tstruct pid *peer_pid;\n+\tint pidfd;\n+\n+\tif (len \u003e sizeof(pidfd))\n+\t\tlen = sizeof(pidfd);\n+\n+\tspin_lock(\u0026sk-\u003esk_peer_lock);\n+\tpeer_pid = get_pid(sk-\u003esk_peer_pid[type]);\n+\tspin_unlock(\u0026sk-\u003esk_peer_lock);\n+\n+\tif (!peer_pid)\n+\t\treturn -ENODATA;\n+\n+\t/* The use of PIDFD_STALE requires stashing of struct pid on pidfs\n+\t * with pidfs_register_pid() and only AF_UNIX is prepared for this.\n+\t */\n+\tif (sk_is_unix(sk))\n+\t\tflags |= PIDFD_STALE;\n+\tif (type == PIDTYPE_PID)\n+\t\tflags |= PIDFD_THREAD;\n+\n+\tpidfd = pidfd_prepare(peer_pid, flags, \u0026pidfd_file);\n+\tput_pid(peer_pid);\n+\tif (pidfd \u003c 0)\n+\t\treturn pidfd;\n+\n+\tif (copy_to_sockptr(optval, \u0026pidfd, len) ||\n+\t    copy_to_sockptr(optlen, \u0026len, sizeof(int))) {\n+\t\tput_unused_fd(pidfd);\n+\t\tfput(pidfd_file);\n+\n+\t\treturn -EFAULT;\n+\t}\n+\n+\tfd_install(pidfd, pidfd_file);\n+\treturn 0;\n+}\n+\n int sk_getsockopt(struct sock *sk, int level, int optname,\n \t\t  sockptr_t optval, sockptr_t optlen)\n {\n@@ -1893,6 +1944,13 @@ int sk_getsockopt(struct sock *sk, int level, int optname,\n \t\tv.val = sk-\u003esk_scm_pidfd;\n \t\tbreak;\n \n+\tcase SO_PASSPIDFD_THREAD:\n+\t\tif (!sk_is_unix(sk))\n+\t\t\treturn -EOPNOTSUPP;\n+\n+\t\tv.val = sk-\u003esk_scm_pidfd_thread;\n+\t\tbreak;\n+\n \tcase SO_PASSRIGHTS:\n \t\tif (!sk_is_unix(sk))\n \t\t\treturn -EOPNOTSUPP;\n@@ -1907,7 +1965,8 @@ int sk_getsockopt(struct sock *sk, int level, int optname,\n \t\t\tlen = sizeof(peercred);\n \n \t\tspin_lock(\u0026sk-\u003esk_peer_lock);\n-\t\tcred_to_ucred(sk-\u003esk_peer_pid, sk-\u003esk_peer_cred, \u0026peercred);\n+\t\tcred_to_ucred(sk-\u003esk_peer_pid[PIDTYPE_TGID], sk-\u003esk_peer_cred,\n+\t\t\t      \u0026peercred);\n \t\tspin_unlock(\u0026sk-\u003esk_peer_lock);\n \n \t\tif (copy_to_sockptr(optval, \u0026peercred, len))\n@@ -1916,45 +1975,14 @@ int sk_getsockopt(struct sock *sk, int level, int optname,\n \t}\n \n \tcase SO_PEERPIDFD:\n-\t{\n-\t\tstruct pid *peer_pid;\n-\t\tstruct file *pidfd_file = NULL;\n-\t\tunsigned int flags = 0;\n-\t\tint pidfd;\n-\n-\t\tif (len \u003e sizeof(pidfd))\n-\t\t\tlen = sizeof(pidfd);\n-\n-\t\tspin_lock(\u0026sk-\u003esk_peer_lock);\n-\t\tpeer_pid = get_pid(sk-\u003esk_peer_pid);\n-\t\tspin_unlock(\u0026sk-\u003esk_peer_lock);\n-\n-\t\tif (!peer_pid)\n-\t\t\treturn -ENODATA;\n-\n-\t\t/* The use of PIDFD_STALE requires stashing of struct pid\n-\t\t * on pidfs with pidfs_register_pid() and only AF_UNIX\n-\t\t * were prepared for this.\n-\t\t */\n-\t\tif (sk-\u003esk_family == AF_UNIX)\n-\t\t\tflags = PIDFD_STALE;\n+\t\treturn sk_getsockopt_peerpidfd(sk, PIDTYPE_TGID, optval, optlen, len);\n \n-\t\tpidfd = pidfd_prepare(peer_pid, flags, \u0026pidfd_file);\n-\t\tput_pid(peer_pid);\n-\t\tif (pidfd \u003c 0)\n-\t\t\treturn pidfd;\n-\n-\t\tif (copy_to_sockptr(optval, \u0026pidfd, len) ||\n-\t\t    copy_to_sockptr(optlen, \u0026len, sizeof(int))) {\n-\t\t\tput_unused_fd(pidfd);\n-\t\t\tfput(pidfd_file);\n-\n-\t\t\treturn -EFAULT;\n-\t\t}\n+\tcase SO_PEERPIDFD_THREAD:\n+\t\t/* Only AF_UNIX records the peer's connecting thread. */\n+\t\tif (!sk_is_unix(sk))\n+\t\t\treturn -EOPNOTSUPP;\n \n-\t\tfd_install(pidfd, pidfd_file);\n-\t\treturn 0;\n-\t}\n+\t\treturn sk_getsockopt_peerpidfd(sk, PIDTYPE_PID, optval, optlen, len);\n \n \tcase SO_PEERGROUPS:\n \t{\n@@ -2380,7 +2408,7 @@ static void __sk_destruct(struct rcu_head *head)\n \n \t/* We do not need to acquire sk-\u003esk_peer_lock, we are the last user. */\n \tput_cred(sk-\u003esk_peer_cred);\n-\tput_pid(sk-\u003esk_peer_pid);\n+\tput_pids(sk-\u003esk_peer_pid);\n \n \tif (likely(sk-\u003esk_net_refcnt)) {\n \t\tput_net_track(net, \u0026sk-\u003ens_tracker);\n@@ -3785,7 +3813,7 @@ void sock_init_data_uid(struct socket *sock, struct sock *sk, kuid_t uid)\n \tsk-\u003esk_frag.offset\t=\t0;\n \tsk-\u003esk_peek_off\t\t=\t-1;\n \n-\tsk-\u003esk_peer_pid \t=\tNULL;\n+\tmemset(sk-\u003esk_peer_pid, 0, sizeof(sk-\u003esk_peer_pid));\n \tsk-\u003esk_peer_cred\t=\tNULL;\n \tspin_lock_init(\u0026sk-\u003esk_peer_lock);\n \ndiff --git a/net/unix/af_unix.c b/net/unix/af_unix.c\nindex 42cffeafc8c14..54f122952979a 100644\n--- a/net/unix/af_unix.c\n+++ b/net/unix/af_unix.c\n@@ -737,57 +737,53 @@ static void unix_release_sock(struct sock *sk, int embrion)\n }\n \n struct unix_peercred {\n-\tstruct pid *peer_pid;\n+\tDECLARE_PIDS(peer_pid, PIDTYPE_TGID);\n \tconst struct cred *peer_cred;\n };\n \n static inline int prepare_peercred(struct unix_peercred *peercred)\n {\n-\tstruct pid *pid;\n \tint err;\n \n-\tpid = task_tgid(current);\n-\terr = pidfs_register_pid(pid);\n-\tif (likely(!err)) {\n-\t\tpeercred-\u003epeer_pid = get_pid(pid);\n-\t\tpeercred-\u003epeer_cred = get_current_cred();\n+\tget_task_pids(peercred-\u003epeer_pid, current);\n+\terr = pidfs_register_pids(peercred-\u003epeer_pid);\n+\tif (unlikely(err)) {\n+\t\tput_pids(peercred-\u003epeer_pid);\n+\t\treturn err;\n \t}\n-\treturn err;\n+\n+\tpeercred-\u003epeer_cred = get_current_cred();\n+\treturn 0;\n }\n \n static void drop_peercred(struct unix_peercred *peercred)\n {\n \tconst struct cred *cred = NULL;\n-\tstruct pid *pid = NULL;\n \n \tmight_sleep();\n \n-\tswap(peercred-\u003epeer_pid, pid);\n+\tput_pids(peercred-\u003epeer_pid);\n \tswap(peercred-\u003epeer_cred, cred);\n-\n-\tput_pid(pid);\n \tput_cred(cred);\n }\n \n static inline void init_peercred(struct sock *sk,\n \t\t\t\t const struct unix_peercred *peercred)\n {\n-\tsk-\u003esk_peer_pid = peercred-\u003epeer_pid;\n+\tmemcpy(sk-\u003esk_peer_pid, peercred-\u003epeer_pid, sizeof(sk-\u003esk_peer_pid));\n \tsk-\u003esk_peer_cred = peercred-\u003epeer_cred;\n }\n \n static void update_peercred(struct sock *sk, struct unix_peercred *peercred)\n {\n \tconst struct cred *old_cred;\n-\tstruct pid *old_pid;\n \n \tspin_lock(\u0026sk-\u003esk_peer_lock);\n-\told_pid = sk-\u003esk_peer_pid;\n+\tswap_pids(sk-\u003esk_peer_pid, peercred-\u003epeer_pid);\n \told_cred = sk-\u003esk_peer_cred;\n-\tinit_peercred(sk, peercred);\n+\tsk-\u003esk_peer_cred = peercred-\u003epeer_cred;\n \tspin_unlock(\u0026sk-\u003esk_peer_lock);\n \n-\tpeercred-\u003epeer_pid = old_pid;\n \tpeercred-\u003epeer_cred = old_cred;\n }\n \n@@ -796,14 +792,15 @@ static void copy_peercred(struct sock *sk, struct sock *peersk)\n \tlockdep_assert_held(\u0026unix_sk(peersk)-\u003elock);\n \n \tspin_lock(\u0026sk-\u003esk_peer_lock);\n-\tsk-\u003esk_peer_pid = get_pid(peersk-\u003esk_peer_pid);\n+\tget_pids(sk-\u003esk_peer_pid, peersk-\u003esk_peer_pid);\n \tsk-\u003esk_peer_cred = get_cred(peersk-\u003esk_peer_cred);\n \tspin_unlock(\u0026sk-\u003esk_peer_lock);\n }\n \n static bool unix_may_passcred(const struct sock *sk)\n {\n-\treturn sk-\u003esk_scm_credentials || sk-\u003esk_scm_pidfd;\n+\treturn sk-\u003esk_scm_credentials || sk_scm_pidfd_wanted(sk) ||\n+\t\tsk_scm_pidfd_thread_wanted(sk);\n }\n \n static int unix_listen(struct socket *sock, int backlog)\n@@ -1060,6 +1057,7 @@ static bool unix_bpf_bypass_getsockopt(int level, int optname)\n \tif (level == SOL_SOCKET) {\n \t\tswitch (optname) {\n \t\tcase SO_PEERPIDFD:\n+\t\tcase SO_PEERPIDFD_THREAD:\n \t\t\treturn true;\n \t\tdefault:\n \t\t\treturn false;\n@@ -1973,7 +1971,7 @@ static void unix_destruct_scm(struct sk_buff *skb)\n {\n \tstruct scm_cookie scm = {};\n \n-\tswap(scm.pid, UNIXCB(skb).pid);\n+\tswap_pids(scm.pid, UNIXCB(skb).pid);\n \n \tif (UNIXCB(skb).fp)\n \t\tunix_detach_fds(\u0026scm, skb);\n@@ -1991,7 +1989,7 @@ static int unix_scm_to_skb(struct scm_cookie *scm, struct sk_buff *skb, bool sen\n {\n \tint err = 0;\n \n-\tUNIXCB(skb).pid = get_pid(scm-\u003epid);\n+\tget_pids(UNIXCB(skb).pid, scm-\u003epid);\n \tUNIXCB(skb).uid = scm-\u003ecreds.uid;\n \tUNIXCB(skb).gid = scm-\u003ecreds.gid;\n \tUNIXCB(skb).fp = NULL;\n@@ -2005,7 +2003,10 @@ static int unix_scm_to_skb(struct scm_cookie *scm, struct sk_buff *skb, bool sen\n \n static void unix_skb_to_scm(struct sk_buff *skb, struct scm_cookie *scm)\n {\n-\tscm_set_cred(scm, UNIXCB(skb).pid, UNIXCB(skb).uid, UNIXCB(skb).gid);\n+\tget_pids(scm-\u003epid, UNIXCB(skb).pid);\n+\tscm-\u003ecreds.pid = pid_vnr(scm-\u003epid[PIDTYPE_TGID]);\n+\tscm-\u003ecreds.uid = UNIXCB(skb).uid;\n+\tscm-\u003ecreds.gid = UNIXCB(skb).gid;\n \tunix_set_secdata(scm, skb);\n }\n \n@@ -2025,30 +2026,35 @@ static void unix_skb_to_scm(struct sk_buff *skb, struct scm_cookie *scm)\n static int unix_maybe_add_creds(struct sk_buff *skb, const struct sock *sk,\n \t\t\t\tconst struct sock *other)\n {\n-\tif (UNIXCB(skb).pid)\n+\tif (UNIXCB(skb).pid[PIDTYPE_TGID])\n \t\treturn 0;\n \n \tif (unix_may_passcred(sk) || unix_may_passcred(other) ||\n \t    !other-\u003esk_socket) {\n-\t\tstruct pid *pid;\n \t\tint err;\n \n-\t\tpid = task_tgid(current);\n-\t\terr = pidfs_register_pid(pid);\n-\t\tif (unlikely(err))\n+\t\tget_task_pids(UNIXCB(skb).pid, current);\n+\t\terr = pidfs_register_pids(UNIXCB(skb).pid);\n+\t\tif (unlikely(err)) {\n+\t\t\tput_pids(UNIXCB(skb).pid);\n \t\t\treturn err;\n+\t\t}\n \n-\t\tUNIXCB(skb).pid = get_pid(pid);\n \t\tcurrent_uid_gid(\u0026UNIXCB(skb).uid, \u0026UNIXCB(skb).gid);\n \t}\n \n \treturn 0;\n }\n \n-static bool unix_skb_scm_eq(struct sk_buff *skb,\n+static bool unix_skb_scm_eq(const struct sock *sk, struct sk_buff *skb,\n \t\t\t    struct scm_cookie *scm)\n {\n-\treturn UNIXCB(skb).pid == scm-\u003epid \u0026\u0026\n+\t/* Only a thread pidfd receiver can tell threads of one process apart. */\n+\tif (sk-\u003esk_scm_pidfd_thread \u0026\u0026\n+\t    UNIXCB(skb).pid[PIDTYPE_PID] != scm-\u003epid[PIDTYPE_PID])\n+\t\treturn false;\n+\n+\treturn UNIXCB(skb).pid[PIDTYPE_TGID] == scm-\u003epid[PIDTYPE_TGID] \u0026\u0026\n \t       uid_eq(UNIXCB(skb).uid, scm-\u003ecreds.uid) \u0026\u0026\n \t       gid_eq(UNIXCB(skb).gid, scm-\u003ecreds.gid) \u0026\u0026\n \t       unix_secdata_eq(scm, skb);\n@@ -3030,7 +3036,7 @@ static int unix_stream_read_generic(struct unix_stream_read_state *state,\n \n \t\tif (check_creds) {\n \t\t\t/* Never glue messages from different writers */\n-\t\t\tif (!unix_skb_scm_eq(skb, \u0026scm))\n+\t\t\tif (!unix_skb_scm_eq(sk, skb, \u0026scm))\n \t\t\t\tbreak;\n \t\t} else if (unix_may_passcred(sk)) {\n \t\t\t/* Copy credentials */\ndiff --git a/net/unix/af_unix.h b/net/unix/af_unix.h\nindex 8119dbeef3a3c..402742895acca 100644\n--- a/net/unix/af_unix.h\n+++ b/net/unix/af_unix.h\n@@ -2,6 +2,7 @@\n #ifndef __AF_UNIX_H\n #define __AF_UNIX_H\n \n+#include \u003clinux/pid_types.h\u003e\n #include \u003clinux/uidgid.h\u003e\n \n #define UNIX_HASH_MOD\t(256 - 1)\n@@ -11,7 +12,7 @@\n struct sock *unix_peer_get(struct sock *sk);\n \n struct unix_skb_parms {\n-\tstruct pid\t\t*pid;\t\t/* skb credentials\t*/\n+\tDECLARE_PIDS(pid, PIDTYPE_TGID);\t/* skb credentials by pid type */\n \tkuid_t\t\t\tuid;\n \tkgid_t\t\t\tgid;\n \tstruct scm_fp_list\t*fp;\t\t/* Passed files\t\t*/\ndiff --git a/tools/lib/python/kdoc/xforms_lists.py b/tools/lib/python/kdoc/xforms_lists.py\nindex e3dda2fe8a537..e792785a15ec6 100644\n--- a/tools/lib/python/kdoc/xforms_lists.py\n+++ b/tools/lib/python/kdoc/xforms_lists.py\n@@ -45,6 +45,7 @@ class CTransforms:\n         (CMatch(\"DECLARE_HASHTABLE\"), r\"unsigned long \\1[1 \u003c\u003c ((\\2) - 1)]\"),\n         (CMatch(\"DECLARE_KFIFO\"), r\"\\2 *\\1\"),\n         (CMatch(\"DECLARE_KFIFO_PTR\"), r\"\\2 *\\1\"),\n+        (CMatch(\"DECLARE_PIDS\"), r\"struct pid *\\1[(\\2) + 1]\"),\n         (CMatch(\"(?:__)?DECLARE_FLEX_ARRAY\"), r\"\\1 \\2[]\"),\n         (CMatch(\"DEFINE_DMA_UNMAP_ADDR\"), r\"dma_addr_t \\1\"),\n         (CMatch(\"DEFINE_DMA_UNMAP_LEN\"), r\"__u32 \\1\"),\ndiff --git a/tools/testing/selftests/coredump/coredump_socket_test.c b/tools/testing/selftests/coredump/coredump_socket_test.c\nindex 422728f632ca6..ec73bb690bbcb 100644\n--- a/tools/testing/selftests/coredump/coredump_socket_test.c\n+++ b/tools/testing/selftests/coredump/coredump_socket_test.c\n@@ -592,6 +592,181 @@ TEST_F(coredump, socket_coredump_signal_sigsegv)\n \twait_and_check_coredump_server(pid_coredump_server, _metadata, self);\n }\n \n+static bool check_coredump_info(const struct pidfd_info *info, const char *what)\n+{\n+\tif (!(info-\u003emask \u0026 PIDFD_INFO_COREDUMP)) {\n+\t\tfprintf(stderr, \"%s: PIDFD_INFO_COREDUMP not set in mask\\n\", what);\n+\t\treturn false;\n+\t}\n+\n+\tif (!(info-\u003ecoredump_mask \u0026 PIDFD_COREDUMPED)) {\n+\t\tfprintf(stderr, \"%s: PIDFD_COREDUMPED not set in coredump_mask\\n\", what);\n+\t\treturn false;\n+\t}\n+\n+\tif (!(info-\u003emask \u0026 PIDFD_INFO_COREDUMP_SIGNAL) || info-\u003ecoredump_signal != SIGSEGV) {\n+\t\tfprintf(stderr, \"%s: coredump_signal=%d, expected SIGSEGV=%d\\n\",\n+\t\t\twhat, info-\u003ecoredump_signal, SIGSEGV);\n+\t\treturn false;\n+\t}\n+\n+\tif (!(info-\u003emask \u0026 PIDFD_INFO_COREDUMP_CODE) || info-\u003ecoredump_code != SEGV_MAPERR) {\n+\t\tfprintf(stderr, \"%s: coredump_code=%d, expected SEGV_MAPERR=%d\\n\",\n+\t\t\twhat, info-\u003ecoredump_code, SEGV_MAPERR);\n+\t\treturn false;\n+\t}\n+\n+\treturn true;\n+}\n+\n+/*\n+ * Test: PIDFD_INFO_COREDUMP on the dumping thread's pidfd\n+ *\n+ * Crash from a non-leader thread and verify that the pidfd from\n+ * SO_PEERPIDFD_THREAD refers to that thread and reports the coredump\n+ * like the thread-group leader's pidfd from SO_PEERPIDFD does.\n+ */\n+TEST_F(coredump, socket_coredump_thread)\n+{\n+\tint pidfd, ret, status;\n+\tpid_t pid, pid_coredump_server;\n+\tstruct pidfd_info info = {};\n+\tint ipc_sockets[2];\n+\tchar c;\n+\n+\tASSERT_TRUE(set_core_pattern(\"@/tmp/coredump.socket\"));\n+\n+\tret = socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, ipc_sockets);\n+\tASSERT_EQ(ret, 0);\n+\n+\tpid_coredump_server = fork();\n+\tASSERT_GE(pid_coredump_server, 0);\n+\tif (pid_coredump_server == 0) {\n+\t\tint fd_server = -1, fd_coredump = -1, fd_peer_pidfd = -1;\n+\t\tint fd_thread_pidfd = -1, fd_core_file = -1;\n+\t\tstruct pidfd_info thread_info = {};\n+\t\tint exit_code = EXIT_FAILURE;\n+\n+\t\tclose(ipc_sockets[0]);\n+\n+\t\tfd_server = create_and_listen_unix_socket(\"/tmp/coredump.socket\");\n+\t\tif (fd_server \u003c 0) {\n+\t\t\tfprintf(stderr, \"socket_coredump_thread: listen socket failed: %m\\n\");\n+\t\t\tgoto out;\n+\t\t}\n+\n+\t\tif (write_nointr(ipc_sockets[1], \"1\", 1) \u003c 0) {\n+\t\t\tfprintf(stderr, \"socket_coredump_thread: ipc write failed: %m\\n\");\n+\t\t\tgoto out;\n+\t\t}\n+\n+\t\tclose(ipc_sockets[1]);\n+\n+\t\tfd_coredump = accept4(fd_server, NULL, NULL, SOCK_CLOEXEC);\n+\t\tif (fd_coredump \u003c 0) {\n+\t\t\tfprintf(stderr, \"socket_coredump_thread: accept4 failed: %m\\n\");\n+\t\t\tgoto out;\n+\t\t}\n+\n+\t\tfd_peer_pidfd = get_peer_pidfd(fd_coredump);\n+\t\tif (fd_peer_pidfd \u003c 0) {\n+\t\t\tfprintf(stderr, \"socket_coredump_thread: get_peer_pidfd failed\\n\");\n+\t\t\tgoto out;\n+\t\t}\n+\n+\t\tfd_thread_pidfd = get_peer_pidfd_thread(fd_coredump);\n+\t\tif (fd_thread_pidfd \u003c 0) {\n+\t\t\tfprintf(stderr, \"socket_coredump_thread: get_peer_pidfd_thread failed\\n\");\n+\t\t\tgoto out;\n+\t\t}\n+\n+\t\tif (!get_pidfd_info(fd_peer_pidfd, \u0026info) ||\n+\t\t    !get_pidfd_info(fd_thread_pidfd, \u0026thread_info)) {\n+\t\t\tfprintf(stderr, \"socket_coredump_thread: get_pidfd_info failed\\n\");\n+\t\t\tgoto out;\n+\t\t}\n+\n+\t\t/* The peer is the thread-group leader, the dumping thread is not. */\n+\t\tif (info.pid != info.tgid || thread_info.tgid != info.tgid ||\n+\t\t    thread_info.pid == thread_info.tgid) {\n+\t\t\tfprintf(stderr, \"socket_coredump_thread: unexpected ids %d/%d and %d/%d\\n\",\n+\t\t\t\tinfo.pid, info.tgid, thread_info.pid, thread_info.tgid);\n+\t\t\tgoto out;\n+\t\t}\n+\n+\t\tif (!check_coredump_info(\u0026info, \"SO_PEERPIDFD\") ||\n+\t\t    !check_coredump_info(\u0026thread_info, \"SO_PEERPIDFD_THREAD\"))\n+\t\t\tgoto out;\n+\n+\t\tfd_core_file = open_coredump_tmpfile(self-\u003efd_tmpfs_detached);\n+\t\tif (fd_core_file \u003c 0) {\n+\t\t\tfprintf(stderr, \"socket_coredump_thread: core tmpfile failed: %m\\n\");\n+\t\t\tgoto out;\n+\t\t}\n+\n+\t\tfor (;;) {\n+\t\t\tchar buffer[4096];\n+\t\t\tssize_t bytes_read, bytes_write;\n+\n+\t\t\tbytes_read = read(fd_coredump, buffer, sizeof(buffer));\n+\t\t\tif (bytes_read \u003c 0) {\n+\t\t\t\tfprintf(stderr, \"socket_coredump_thread: core read failed: %m\\n\");\n+\t\t\t\tgoto out;\n+\t\t\t}\n+\n+\t\t\tif (bytes_read == 0)\n+\t\t\t\tbreak;\n+\n+\t\t\tbytes_write = write(fd_core_file, buffer, bytes_read);\n+\t\t\tif (bytes_read != bytes_write) {\n+\t\t\t\tfprintf(stderr, \"socket_coredump_thread: core write %zd/%zd: %m\\n\",\n+\t\t\t\t\tbytes_read, bytes_write);\n+\t\t\t\tgoto out;\n+\t\t\t}\n+\t\t}\n+\n+\t\texit_code = EXIT_SUCCESS;\n+\t\tfprintf(stderr, \"socket_coredump_thread: completed successfully\\n\");\n+out:\n+\t\tif (fd_core_file \u003e= 0)\n+\t\t\tclose(fd_core_file);\n+\t\tif (fd_thread_pidfd \u003e= 0)\n+\t\t\tclose(fd_thread_pidfd);\n+\t\tif (fd_peer_pidfd \u003e= 0)\n+\t\t\tclose(fd_peer_pidfd);\n+\t\tif (fd_coredump \u003e= 0)\n+\t\t\tclose(fd_coredump);\n+\t\tif (fd_server \u003e= 0)\n+\t\t\tclose(fd_server);\n+\t\t_exit(exit_code);\n+\t}\n+\tself-\u003epid_coredump_server = pid_coredump_server;\n+\n+\tEXPECT_EQ(close(ipc_sockets[1]), 0);\n+\tASSERT_EQ(read_nointr(ipc_sockets[0], \u0026c, 1), 1);\n+\tEXPECT_EQ(close(ipc_sockets[0]), 0);\n+\n+\tpid = fork();\n+\tASSERT_GE(pid, 0);\n+\tif (pid == 0)\n+\t\tcrashing_child_thread();\n+\n+\tpidfd = sys_pidfd_open(pid, 0);\n+\tASSERT_GE(pidfd, 0);\n+\n+\twaitpid(pid, \u0026status, 0);\n+\tASSERT_TRUE(WIFSIGNALED(status));\n+\tASSERT_EQ(WTERMSIG(status), SIGSEGV);\n+\tASSERT_TRUE(WCOREDUMP(status));\n+\n+\tASSERT_TRUE(get_pidfd_info(pidfd, \u0026info));\n+\tASSERT_TRUE(!!(info.mask \u0026 PIDFD_INFO_COREDUMP));\n+\tASSERT_TRUE(!!(info.coredump_mask \u0026 PIDFD_COREDUMPED));\n+\tASSERT_EQ(info.coredump_signal, SIGSEGV);\n+\n+\twait_and_check_coredump_server(pid_coredump_server, _metadata, self);\n+}\n+\n /*\n  * Test: PIDFD_INFO_COREDUMP_SIGNAL via simple socket coredump with SIGABRT\n  *\ndiff --git a/tools/testing/selftests/coredump/coredump_test.h b/tools/testing/selftests/coredump/coredump_test.h\nindex ed47f01fa53c5..4212656e31f01 100644\n--- a/tools/testing/selftests/coredump/coredump_test.h\n+++ b/tools/testing/selftests/coredump/coredump_test.h\n@@ -27,10 +27,12 @@ FIXTURE(coredump)\n /* Shared helper function declarations */\n void *do_nothing(void *arg);\n void crashing_child(void);\n+void crashing_child_thread(void);\n int create_detached_tmpfs(void);\n int create_and_listen_unix_socket(const char *path);\n bool set_core_pattern(const char *pattern);\n int get_peer_pidfd(int fd);\n+int get_peer_pidfd_thread(int fd);\n bool get_pidfd_info(int fd_peer_pidfd, struct pidfd_info *info);\n \n /* Inline helper that uses harness types */\ndiff --git a/tools/testing/selftests/coredump/coredump_test_helpers.c b/tools/testing/selftests/coredump/coredump_test_helpers.c\nindex 2a20faf9cb0ad..36306069f62e5 100644\n--- a/tools/testing/selftests/coredump/coredump_test_helpers.c\n+++ b/tools/testing/selftests/coredump/coredump_test_helpers.c\n@@ -13,6 +13,7 @@\n #include \u003cstring.h\u003e\n #include \u003csys/epoll.h\u003e\n #include \u003csys/ioctl.h\u003e\n+#include \u003csys/mman.h\u003e\n #include \u003csys/socket.h\u003e\n #include \u003csys/types.h\u003e\n #include \u003csys/un.h\u003e\n@@ -38,6 +39,10 @@ struct _fixture_coredump_data {\n \n #define NUM_THREAD_SPAWN 128\n \n+#ifndef SO_PEERPIDFD_THREAD\n+#define SO_PEERPIDFD_THREAD 87\n+#endif\n+\n void *do_nothing(void *arg)\n {\n \t(void)arg;\n@@ -59,6 +64,36 @@ void crashing_child(void)\n \ti = *(volatile int *)NULL;\n }\n \n+static void *crashing_thread(void *arg)\n+{\n+\tint *p;\n+\n+\t(void)arg;\n+\n+\t/* crash on purpose with SEGV_MAPERR */\n+\tp = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE,\n+\t\t MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);\n+\tif (p == MAP_FAILED)\n+\t\treturn NULL;\n+\tmunmap(p, PAGE_SIZE);\n+\t*p = 0;\n+\n+\treturn NULL;\n+}\n+\n+void crashing_child_thread(void)\n+{\n+\tpthread_t thread;\n+\tint i;\n+\n+\tfor (i = 0; i \u003c NUM_THREAD_SPAWN; ++i)\n+\t\tpthread_create(\u0026thread, NULL, do_nothing, NULL);\n+\n+\t/* crash from a non-leader thread */\n+\tpthread_create(\u0026thread, NULL, crashing_thread, NULL);\n+\tpause();\n+}\n+\n int create_detached_tmpfs(void)\n {\n \tint fd_context, fd_tmpfs;\n@@ -138,6 +173,20 @@ int get_peer_pidfd(int fd)\n \treturn fd_peer_pidfd;\n }\n \n+int get_peer_pidfd_thread(int fd)\n+{\n+\tint fd_peer_pidfd;\n+\tsocklen_t fd_peer_pidfd_len = sizeof(fd_peer_pidfd);\n+\tint ret = getsockopt(fd, SOL_SOCKET, SO_PEERPIDFD_THREAD, \u0026fd_peer_pidfd,\n+\t\t\t     \u0026fd_peer_pidfd_len);\n+\tif (ret \u003c 0) {\n+\t\tfprintf(stderr, \"%s: getsockopt(SO_PEERPIDFD_THREAD) failed: %m\\n\", __func__);\n+\t\treturn -1;\n+\t}\n+\tfprintf(stderr, \"%s: successfully retrieved pidfd %d\\n\", __func__, fd_peer_pidfd);\n+\treturn fd_peer_pidfd;\n+}\n+\n bool get_pidfd_info(int fd_peer_pidfd, struct pidfd_info *info)\n {\n \tint ret;\ndiff --git a/tools/testing/selftests/net/af_unix/Makefile b/tools/testing/selftests/net/af_unix/Makefile\nindex a66f10fb0c231..45b841758f1bf 100644\n--- a/tools/testing/selftests/net/af_unix/Makefile\n+++ b/tools/testing/selftests/net/af_unix/Makefile\n@@ -23,6 +23,8 @@ TEST_GEN_FILES := scm_rights_denial_lsm.bpf.o\n include ../../lib.mk\n include ../bpf.mk\n \n+$(OUTPUT)/scm_pidfd: CFLAGS += -pthread\n+\n $(OUTPUT)/scm_rights_denial_lsm: $(BPFOBJ)\n $(OUTPUT)/scm_rights_denial_lsm: CFLAGS += -I$(SCRATCH_DIR)/include\n $(OUTPUT)/scm_rights_denial_lsm: LDLIBS += -lelf -lz\ndiff --git a/tools/testing/selftests/net/af_unix/scm_pidfd.c b/tools/testing/selftests/net/af_unix/scm_pidfd.c\nindex 2c18b92a26035..cbe53fab44fc5 100644\n--- a/tools/testing/selftests/net/af_unix/scm_pidfd.c\n+++ b/tools/testing/selftests/net/af_unix/scm_pidfd.c\n@@ -10,6 +10,7 @@\n #include \u003cunistd.h\u003e\n #include \u003cstring.h\u003e\n #include \u003cerrno.h\u003e\n+#include \u003cpthread.h\u003e\n #include \u003csys/un.h\u003e\n #include \u003csys/signal.h\u003e\n #include \u003csys/types.h\u003e\n@@ -27,6 +28,18 @@\n #define SCM_PIDFD 0x04\n #endif\n \n+#ifndef SCM_PIDFD_THREAD\n+#define SCM_PIDFD_THREAD 0x05\n+#endif\n+\n+#ifndef SO_PASSPIDFD_THREAD\n+#define SO_PASSPIDFD_THREAD 86\n+#endif\n+\n+#ifndef SO_PEERPIDFD_THREAD\n+#define SO_PEERPIDFD_THREAD 87\n+#endif\n+\n #define CHILD_EXIT_CODE_OK 123\n \n static void child_die()\n@@ -553,4 +566,593 @@ TEST_F(scm_pidfd, test)\n \tclose(pfd);\n }\n \n+struct thread_ids {\n+\tpid_t pid;\n+\tpid_t tid;\n+};\n+\n+#define MAX_WRITERS 2\n+\n+/* Used by writers to signal they've written, so we can sequence multiple writers */\n+static int seq_pipe[2];\n+\n+static void *send_ids_thread(void *arg)\n+{\n+\tint fd = *(int *)arg;\n+\tstruct thread_ids ids = {\n+\t\t.pid = getpid(),\n+\t\t.tid = gettid(),\n+\t};\n+\tchar sync;\n+\n+\tif (send(fd, \u0026ids, sizeof(ids), 0) != sizeof(ids))\n+\t\treturn (void *)1;\n+\n+\t/* let the client start the next writer, so the queue order is known */\n+\tif (write(seq_pipe[1], \"1\", 1) != 1)\n+\t\treturn (void *)1;\n+\n+\t/* stay alive until the receiver has looked at our pidfd */\n+\tif (read(fd, \u0026sync, 1) != 1)\n+\t\treturn (void *)1;\n+\n+\treturn NULL;\n+}\n+\n+static void *send_ids_creds_thread(void *arg)\n+{\n+\tint fd = *(int *)arg;\n+\tstruct thread_ids ids = {\n+\t\t.pid = getpid(),\n+\t\t.tid = gettid(),\n+\t};\n+\tstruct ucred ucred = {\n+\t\t.pid = getpid(),\n+\t\t.uid = getuid(),\n+\t\t.gid = getgid(),\n+\t};\n+\tchar control[CMSG_SPACE(sizeof(ucred))] = { 0 };\n+\tstruct iovec iov;\n+\tstruct msghdr msg = { 0 };\n+\tstruct cmsghdr *cmsg;\n+\tchar sync;\n+\n+\tiov.iov_base = \u0026ids;\n+\tiov.iov_len = sizeof(ids);\n+\n+\tmsg.msg_iov = \u0026iov;\n+\tmsg.msg_iovlen = 1;\n+\tmsg.msg_control = control;\n+\tmsg.msg_controllen = sizeof(control);\n+\n+\tcmsg = CMSG_FIRSTHDR(\u0026msg);\n+\tcmsg-\u003ecmsg_level = SOL_SOCKET;\n+\tcmsg-\u003ecmsg_type = SCM_CREDENTIALS;\n+\tcmsg-\u003ecmsg_len = CMSG_LEN(sizeof(ucred));\n+\tmemcpy(CMSG_DATA(cmsg), \u0026ucred, sizeof(ucred));\n+\n+\tif (sendmsg(fd, \u0026msg, 0) != sizeof(ids))\n+\t\treturn (void *)1;\n+\n+\t/* signal we've written our info */\n+\tif (write(seq_pipe[1], \"1\", 1) != 1)\n+\t\treturn (void *)1;\n+\n+\t/* stay alive until the receiver has looked at our pidfd */\n+\tif (read(fd, \u0026sync, 1) != 1)\n+\t\treturn (void *)1;\n+\n+\treturn NULL;\n+}\n+\n+/*\n+ * Runs @nwriters copies of @sender, each in its own non-leader thread, one\n+ * at a time so the queue order is known, then tells the parent on @ackfd\n+ * that everything is queued.\n+ */\n+static void thread_client(int fd, int syncfd, int ackfd,\n+\t\t\t  void *(*sender)(void *), int nwriters)\n+{\n+\tpthread_t writers[MAX_WRITERS];\n+\tvoid *ret;\n+\tchar sync;\n+\tint i;\n+\n+\t/* wait until the receiver enabled the options it wants */\n+\tif (read(syncfd, \u0026sync, 1) != 1)\n+\t\tchild_die();\n+\n+\tfor (i = 0; i \u003c nwriters; i++) {\n+\t\tif (pthread_create(\u0026writers[i], NULL, sender, \u0026fd))\n+\t\t\tchild_die();\n+\n+\t\tif (read(seq_pipe[0], \u0026sync, 1) != 1)\n+\t\t\tchild_die();\n+\t}\n+\n+\tif (write(ackfd, \"1\", 1) != 1)\n+\t\tchild_die();\n+\n+\tfor (i = 0; i \u003c nwriters; i++)\n+\t\tif (pthread_join(writers[i], \u0026ret) || ret)\n+\t\t\tchild_die();\n+\n+\texit(0);\n+}\n+\n+struct pidfd_msg {\n+\tssize_t len;\n+\tstruct thread_ids ids;\n+\tstruct pidfd_info tgid_info;\n+\tstruct pidfd_info thread_info;\n+\tint tgid_flags;\n+\tint thread_flags;\n+\tbool have_tgid;\n+\tbool have_thread;\n+};\n+\n+static int get_pidfd_info(int pidfd, struct pidfd_info *info)\n+{\n+\tinfo-\u003emask = PIDFD_INFO_PID;\n+\tif (ioctl(pidfd, PIDFD_GET_INFO, info)) {\n+\t\tlog_err(\"ioctl(PIDFD_GET_INFO)\");\n+\t\treturn -1;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+/* One recvmsg(), reporting how many bytes came back and what the pidfd\n+ * cmsgs that came with them say.\n+ */\n+static int read_pidfd_msg(int fd, struct pidfd_msg *out)\n+{\n+\tchar control[CMSG_SPACE(sizeof(int)) * 2] = { 0 };\n+\tint tgid_pidfd = -1, thread_pidfd = -1;\n+\tstruct thread_ids buf[2] = { 0 };\n+\tstruct msghdr msg = { 0 };\n+\tstruct cmsghdr *cmsg;\n+\tstruct iovec iov;\n+\n+\tiov.iov_base = buf;\n+\tiov.iov_len = sizeof(buf);\n+\tmsg.msg_iov = \u0026iov;\n+\tmsg.msg_iovlen = 1;\n+\tmsg.msg_control = control;\n+\tmsg.msg_controllen = sizeof(control);\n+\n+\tout-\u003elen = recvmsg(fd, \u0026msg, 0);\n+\tif (out-\u003elen \u003c 0) {\n+\t\tlog_err(\"recvmsg\");\n+\t\treturn -1;\n+\t}\n+\n+\tif (msg.msg_flags \u0026 MSG_CTRUNC) {\n+\t\tlog_err(\"recvmsg: control truncated\");\n+\t\treturn -1;\n+\t}\n+\n+\tout-\u003eids = buf[0];\n+\n+\tfor (cmsg = CMSG_FIRSTHDR(\u0026msg); cmsg != NULL;\n+\t     cmsg = CMSG_NXTHDR(\u0026msg, cmsg)) {\n+\t\tif (cmsg-\u003ecmsg_level != SOL_SOCKET)\n+\t\t\tcontinue;\n+\n+\t\tif (cmsg-\u003ecmsg_type == SCM_PIDFD)\n+\t\t\tmemcpy(\u0026tgid_pidfd, CMSG_DATA(cmsg), sizeof(tgid_pidfd));\n+\t\telse if (cmsg-\u003ecmsg_type == SCM_PIDFD_THREAD)\n+\t\t\tmemcpy(\u0026thread_pidfd, CMSG_DATA(cmsg), sizeof(thread_pidfd));\n+\t}\n+\n+\tout-\u003ehave_tgid = tgid_pidfd \u003e= 0;\n+\tout-\u003ehave_thread = thread_pidfd \u003e= 0;\n+\n+\tif (out-\u003ehave_tgid) {\n+\t\tif (get_pidfd_info(tgid_pidfd, \u0026out-\u003etgid_info))\n+\t\t\treturn -1;\n+\t\tout-\u003etgid_flags = fcntl(tgid_pidfd, F_GETFL);\n+\t\tclose(tgid_pidfd);\n+\t}\n+\n+\tif (out-\u003ehave_thread) {\n+\t\tif (get_pidfd_info(thread_pidfd, \u0026out-\u003ethread_info))\n+\t\t\treturn -1;\n+\t\tout-\u003ethread_flags = fcntl(thread_pidfd, F_GETFL);\n+\t\tclose(thread_pidfd);\n+\t}\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * Runs @nwriters threads of one child process against a SOCK_STREAM pair,\n+ * all of them queued before the parent reads. SO_PASSPIDFD is set when\n+ * @want_tgid is given, SO_PASSPIDFD_THREAD when @want_thread is. @nread\n+ * reads are returned in @out.\n+ */\n+static int pidfd_flow(void *(*sender)(void *), int nwriters, bool want_tgid,\n+\t\t      bool want_thread, struct pidfd_msg *out, int nread)\n+{\n+\tint child_status = 0;\n+\tint syncpipe[2];\n+\tint ackpipe[2];\n+\tint sk[2];\n+\tint on = 1;\n+\tchar sync;\n+\tpid_t child;\n+\tint i;\n+\n+\tif (nwriters \u003e MAX_WRITERS)\n+\t\treturn -1;\n+\n+\tif (socketpair(AF_UNIX, SOCK_STREAM, 0, sk))\n+\t\treturn -1;\n+\tif (pipe(syncpipe) || pipe(ackpipe) || pipe(seq_pipe))\n+\t\treturn -1;\n+\n+\tchild = fork();\n+\tif (child \u003c 0)\n+\t\treturn -1;\n+\n+\tif (child == 0) {\n+\t\tclose(sk[0]);\n+\t\tclose(syncpipe[1]);\n+\t\tclose(ackpipe[0]);\n+\t\tthread_client(sk[1], syncpipe[0], ackpipe[1], sender, nwriters);\n+\t}\n+\tclose(sk[1]);\n+\tclose(syncpipe[0]);\n+\tclose(ackpipe[1]);\n+\tclose(seq_pipe[0]);\n+\tclose(seq_pipe[1]);\n+\n+\tif (want_tgid \u0026\u0026\n+\t    setsockopt(sk[0], SOL_SOCKET, SO_PASSPIDFD, \u0026on, sizeof(on))) {\n+\t\tlog_err(\"Failed to set SO_PASSPIDFD\");\n+\t\treturn -1;\n+\t}\n+\n+\tif (want_thread \u0026\u0026\n+\t    setsockopt(sk[0], SOL_SOCKET, SO_PASSPIDFD_THREAD, \u0026on, sizeof(on))) {\n+\t\tlog_err(\"Failed to set SO_PASSPIDFD_THREAD\");\n+\t\treturn -1;\n+\t}\n+\n+\t/* let the child know the options are set, it can write now */\n+\tif (write(syncpipe[1], \"1\", 1) != 1)\n+\t\treturn -1;\n+\tclose(syncpipe[1]);\n+\n+\t/* wait until every writer has queued its message */\n+\tif (read(ackpipe[0], \u0026sync, 1) != 1)\n+\t\treturn -1;\n+\tclose(ackpipe[0]);\n+\n+\tfor (i = 0; i \u003c nread; i++)\n+\t\tif (read_pidfd_msg(sk[0], \u0026out[i]))\n+\t\t\treturn -1;\n+\n+\t/* release the writers */\n+\tfor (i = 0; i \u003c nwriters; i++)\n+\t\tif (write(sk[0], \"x\", 1) != 1)\n+\t\t\treturn -1;\n+\tclose(sk[0]);\n+\n+\twaitpid(child, \u0026child_status, 0);\n+\tif (!WIFEXITED(child_status) || WEXITSTATUS(child_status))\n+\t\treturn -1;\n+\n+\treturn 0;\n+}\n+\n+static int sockopt_set(int fd, int optname, int val)\n+{\n+\treturn setsockopt(fd, SOL_SOCKET, optname, \u0026val, sizeof(val));\n+}\n+\n+static int sockopt_get(int fd, int optname)\n+{\n+\tsocklen_t len = sizeof(int);\n+\tint val = -1;\n+\n+\tif (getsockopt(fd, SOL_SOCKET, optname, \u0026val, \u0026len))\n+\t\treturn -1;\n+\n+\treturn val;\n+}\n+\n+TEST(scm_pidfd_setsockopt_values)\n+{\n+\tint sk[2];\n+\n+\tASSERT_EQ(0, socketpair(AF_UNIX, SOCK_STREAM, 0, sk));\n+\n+\t/* Verify that the options are truly set independently */\n+\tASSERT_EQ(0, sockopt_set(sk[0], SO_PASSPIDFD_THREAD, 1));\n+\tASSERT_EQ(1, sockopt_get(sk[0], SO_PASSPIDFD_THREAD));\n+\tASSERT_EQ(0, sockopt_get(sk[0], SO_PASSPIDFD));\n+\n+\tASSERT_EQ(0, sockopt_set(sk[0], SO_PASSPIDFD, 1));\n+\tASSERT_EQ(1, sockopt_get(sk[0], SO_PASSPIDFD));\n+\tASSERT_EQ(1, sockopt_get(sk[0], SO_PASSPIDFD_THREAD));\n+\n+\t/* Verify that the options are truly cleared independently */\n+\tASSERT_EQ(0, sockopt_set(sk[0], SO_PASSPIDFD, 0));\n+\tASSERT_EQ(0, sockopt_get(sk[0], SO_PASSPIDFD));\n+\tASSERT_EQ(1, sockopt_get(sk[0], SO_PASSPIDFD_THREAD));\n+\n+\tASSERT_EQ(0, sockopt_set(sk[0], SO_PASSPIDFD_THREAD, 0));\n+\tASSERT_EQ(0, sockopt_get(sk[0], SO_PASSPIDFD_THREAD));\n+\tASSERT_EQ(0, sockopt_get(sk[0], SO_PASSPIDFD));\n+\n+\tclose(sk[0]);\n+\tclose(sk[1]);\n+}\n+\n+/* A receiver that only asked about the process cannot tell the two\n+ * threads apart, so their writes are glued into one read.\n+ */\n+TEST(scm_pidfd_stream_glues_threads)\n+{\n+\tstruct pidfd_msg msg[1] = { 0 };\n+\n+\tASSERT_EQ(0, pidfd_flow(send_ids_thread, 2, true, false, msg, 1));\n+\tEXPECT_EQ(sizeof(struct thread_ids) * 2, msg[0].len);\n+\n+\tEXPECT_TRUE(msg[0].have_tgid);\n+\tEXPECT_FALSE(msg[0].have_thread);\n+\tEXPECT_EQ(msg[0].ids.pid, msg[0].tgid_info.pid);\n+\tEXPECT_EQ(msg[0].ids.pid, msg[0].tgid_info.tgid);\n+}\n+\n+/* A receiver asking for both thread and process pidfd should get a unique\n+ * msg for each thread writing\n+ */\n+TEST(scm_pidfd_thread_stream_splits_on_threads)\n+{\n+\tstruct pidfd_msg msg[2] = { 0 };\n+\tint i;\n+\n+\tASSERT_EQ(0, pidfd_flow(send_ids_thread, 2, true, true, msg, 2));\n+\n+\tfor (i = 0; i \u003c 2; i++) {\n+\t\tEXPECT_EQ(sizeof(struct thread_ids), msg[i].len);\n+\t\tEXPECT_TRUE(msg[i].have_tgid);\n+\t\tEXPECT_TRUE(msg[i].have_thread);\n+\n+\t\t/* Make sure the info makes sense for the pidfd type */\n+\t\tEXPECT_EQ(msg[i].ids.pid, msg[i].tgid_info.pid);\n+\t\tEXPECT_EQ(msg[i].ids.pid, msg[i].tgid_info.tgid);\n+\t\tEXPECT_EQ(msg[i].ids.tid, msg[i].thread_info.pid);\n+\t\tEXPECT_EQ(msg[i].ids.pid, msg[i].thread_info.tgid);\n+\t\tEXPECT_NE(msg[i].ids.pid, msg[i].ids.tid);\n+\t}\n+\n+\t/* Make sure we really got unique threads per message */\n+\tEXPECT_NE(msg[0].ids.tid, msg[1].ids.tid);\n+\tEXPECT_EQ(msg[0].ids.pid, msg[1].ids.pid);\n+\tEXPECT_EQ(msg[0].tgid_info.pid, msg[1].tgid_info.pid);\n+\tEXPECT_NE(msg[0].thread_info.pid, msg[1].thread_info.pid);\n+}\n+\n+/* Sends from the thread-group leader */\n+static int leader_flow(bool want_thread, struct pidfd_msg *out)\n+{\n+\tstruct thread_ids ids = {\n+\t\t.pid = getpid(),\n+\t\t.tid = gettid(),\n+\t};\n+\tint sk[2];\n+\tint on = 1;\n+\tint ret;\n+\n+\tif (socketpair(AF_UNIX, SOCK_STREAM, 0, sk))\n+\t\treturn -1;\n+\n+\tif (setsockopt(sk[0], SOL_SOCKET, SO_PASSPIDFD, \u0026on, sizeof(on))) {\n+\t\tlog_err(\"Failed to set SO_PASSPIDFD\");\n+\t\treturn -1;\n+\t}\n+\n+\tif (want_thread \u0026\u0026\n+\t    setsockopt(sk[0], SOL_SOCKET, SO_PASSPIDFD_THREAD, \u0026on, sizeof(on))) {\n+\t\tlog_err(\"Failed to set SO_PASSPIDFD_THREAD\");\n+\t\treturn -1;\n+\t}\n+\n+\tif (send(sk[1], \u0026ids, sizeof(ids), 0) != sizeof(ids)) {\n+\t\tlog_err(\"send\");\n+\t\treturn -1;\n+\t}\n+\n+\tret = read_pidfd_msg(sk[0], out);\n+\n+\tclose(sk[0]);\n+\tclose(sk[1]);\n+\n+\treturn ret;\n+}\n+\n+TEST(scm_pidfd_leader_sender)\n+{\n+\tstruct pidfd_msg msg = { 0 };\n+\n+\tASSERT_EQ(getpid(), gettid());\n+\n+\tASSERT_EQ(0, leader_flow(false, \u0026msg));\n+\tASSERT_TRUE(msg.have_tgid);\n+\tEXPECT_FALSE(msg.have_thread);\n+\n+\tEXPECT_EQ(getpid(), msg.tgid_info.pid);\n+\tEXPECT_EQ(getpid(), msg.tgid_info.tgid);\n+\tEXPECT_FALSE(msg.tgid_flags \u0026 O_EXCL);\n+}\n+\n+TEST(scm_pidfd_thread_leader_sender)\n+{\n+\tstruct pidfd_msg msg = { 0 };\n+\n+\tASSERT_EQ(getpid(), gettid());\n+\n+\tASSERT_EQ(0, leader_flow(true, \u0026msg));\n+\tASSERT_TRUE(msg.have_tgid);\n+\tASSERT_TRUE(msg.have_thread);\n+\n+\tEXPECT_EQ(getpid(), msg.tgid_info.pid);\n+\tEXPECT_EQ(getpid(), msg.tgid_info.tgid);\n+\tEXPECT_EQ(getpid(), msg.thread_info.pid);\n+\tEXPECT_EQ(getpid(), msg.thread_info.tgid);\n+\n+\tEXPECT_FALSE(msg.tgid_flags \u0026 O_EXCL);\n+\tEXPECT_TRUE(msg.thread_flags \u0026 O_EXCL);\n+}\n+\n+TEST(scm_pidfd_thread_and_group)\n+{\n+\tstruct pidfd_msg msg = { 0 };\n+\n+\tASSERT_EQ(0, pidfd_flow(send_ids_thread, 1, true, true, \u0026msg, 1));\n+\tASSERT_NE(msg.ids.pid, msg.ids.tid);\n+\tASSERT_TRUE(msg.have_tgid);\n+\tASSERT_TRUE(msg.have_thread);\n+\n+\tEXPECT_EQ(msg.ids.pid, msg.tgid_info.pid);\n+\tEXPECT_EQ(msg.ids.pid, msg.tgid_info.tgid);\n+\n+\tEXPECT_EQ(msg.ids.tid, msg.thread_info.pid);\n+\tEXPECT_EQ(msg.ids.pid, msg.thread_info.tgid);\n+}\n+\n+TEST(scm_pidfd_thread)\n+{\n+\tstruct pidfd_msg msg = { 0 };\n+\n+\tASSERT_EQ(0, pidfd_flow(send_ids_thread, 1, false, true, \u0026msg, 1));\n+\tASSERT_NE(msg.ids.pid, msg.ids.tid);\n+\tASSERT_TRUE(msg.have_thread);\n+\tEXPECT_FALSE(msg.have_tgid);\n+\tEXPECT_EQ(msg.ids.tid, msg.thread_info.pid);\n+\tEXPECT_EQ(msg.ids.pid, msg.thread_info.tgid);\n+}\n+\n+TEST(scm_pidfd_thread_group)\n+{\n+\tstruct pidfd_msg msg = { 0 };\n+\n+\tASSERT_EQ(0, pidfd_flow(send_ids_thread, 1, true, false, \u0026msg, 1));\n+\tASSERT_NE(msg.ids.pid, msg.ids.tid);\n+\tASSERT_TRUE(msg.have_tgid);\n+\tEXPECT_FALSE(msg.have_thread);\n+\tEXPECT_EQ(msg.ids.pid, msg.tgid_info.pid);\n+\tEXPECT_EQ(msg.ids.pid, msg.tgid_info.tgid);\n+}\n+\n+TEST(scm_pidfd_thread_creds)\n+{\n+\tstruct pidfd_msg msg = { 0 };\n+\n+\tASSERT_EQ(0, pidfd_flow(send_ids_creds_thread, 1, true, true, \u0026msg, 1));\n+\tASSERT_NE(msg.ids.pid, msg.ids.tid);\n+\tASSERT_TRUE(msg.have_tgid);\n+\tASSERT_TRUE(msg.have_thread);\n+\tEXPECT_EQ(msg.ids.pid, msg.tgid_info.pid);\n+\tEXPECT_EQ(msg.ids.pid, msg.tgid_info.tgid);\n+\tEXPECT_EQ(msg.ids.tid, msg.thread_info.pid);\n+\tEXPECT_EQ(msg.ids.pid, msg.thread_info.tgid);\n+}\n+\n+static void *peer_connect_thread(void *arg)\n+{\n+\tstruct sock_addr *sa = arg;\n+\tstruct thread_ids ids = {\n+\t\t.pid = getpid(),\n+\t\t.tid = gettid(),\n+\t};\n+\tint fd;\n+\tchar sync;\n+\n+\tfd = socket(AF_UNIX, SOCK_STREAM, 0);\n+\tif (fd \u003c 0)\n+\t\treturn (void *)1;\n+\n+\tif (connect(fd, (struct sockaddr *)\u0026sa-\u003elisten_addr, sa-\u003eaddrlen))\n+\t\treturn (void *)1;\n+\n+\tif (send(fd, \u0026ids, sizeof(ids), 0) != sizeof(ids))\n+\t\treturn (void *)1;\n+\n+\t/* stay alive until the server has looked at our pidfd */\n+\tif (read(fd, \u0026sync, 1) != 1)\n+\t\treturn (void *)1;\n+\n+\tclose(fd);\n+\treturn NULL;\n+}\n+\n+static int peer_pidfd_info(int fd, int optname, struct pidfd_info *info)\n+{\n+\tint pidfd;\n+\tsocklen_t len = sizeof(pidfd);\n+\n+\tif (getsockopt(fd, SOL_SOCKET, optname, \u0026pidfd, \u0026len)) {\n+\t\tlog_err(\"getsockopt(SO_PEERPIDFD*)\");\n+\t\treturn -1;\n+\t}\n+\n+\tinfo-\u003emask = PIDFD_INFO_PID;\n+\tif (ioctl(pidfd, PIDFD_GET_INFO, info)) {\n+\t\tlog_err(\"ioctl(PIDFD_GET_INFO)\");\n+\t\tclose(pidfd);\n+\t\treturn -1;\n+\t}\n+\n+\tclose(pidfd);\n+\treturn 0;\n+}\n+\n+/* SO_PEERPIDFD_THREAD returns a pidfd for the peer's connecting thread. */\n+TEST(so_peerpidfd_thread)\n+{\n+\tstruct sock_addr sa;\n+\tstruct thread_ids ids;\n+\tstruct pidfd_info info;\n+\tpthread_t thread;\n+\tvoid *tret;\n+\tint server, cfd;\n+\n+\tserver = socket(AF_UNIX, SOCK_STREAM, 0);\n+\tASSERT_LE(0, server);\n+\n+\tfill_sockaddr(\u0026sa, true);\n+\tASSERT_EQ(0, bind(server, (struct sockaddr *)\u0026sa.listen_addr, sa.addrlen));\n+\tASSERT_EQ(0, listen(server, 1));\n+\n+\tASSERT_EQ(0, pthread_create(\u0026thread, NULL, peer_connect_thread, \u0026sa));\n+\n+\tcfd = accept(server, NULL, NULL);\n+\tASSERT_LE(0, cfd);\n+\n+\tASSERT_EQ(sizeof(ids), recv(cfd, \u0026ids, sizeof(ids), MSG_WAITALL));\n+\tASSERT_NE(ids.pid, ids.tid);\n+\n+\t/* SO_PEERPIDFD refers to the peer's thread-group. */\n+\tASSERT_EQ(0, peer_pidfd_info(cfd, SO_PEERPIDFD, \u0026info));\n+\tEXPECT_EQ(ids.pid, info.pid);\n+\tEXPECT_EQ(ids.pid, info.tgid);\n+\n+\t/* SO_PEERPIDFD_THREAD refers to the connecting thread. */\n+\tASSERT_EQ(0, peer_pidfd_info(cfd, SO_PEERPIDFD_THREAD, \u0026info));\n+\tEXPECT_EQ(ids.tid, info.pid);\n+\tEXPECT_EQ(ids.pid, info.tgid);\n+\n+\t/* release the connecting thread */\n+\tASSERT_EQ(1, write(cfd, \"x\", 1));\n+\tASSERT_EQ(0, pthread_join(thread, \u0026tret));\n+\tASSERT_EQ(NULL, tret);\n+\n+\tclose(cfd);\n+\tclose(server);\n+}\n+\n TEST_HARNESS_MAIN\n"
}

2/1 2026/09/29 11:02 agent patch-evaluator
1m Model:
core

Args:
null

Results:
{
  "EnableConfigs": [
    "UNIX",
    "COREDUMP"
  ],
  "FocusSymbols": [
    "__pidfs_register_pids",
    "pidfs_coredump",
    "scm_recv_unix",
    "sk_getsockopt_peerpidfd",
    "scm_pidfd_recv",
    "unix_maybe_add_creds",
    "unix_skb_scm_eq",
    "coredump_sock_connect"
  ],
  "Reasoning": "The patch series adds thread-level pidfd support to UNIX domain sockets (SO_PASSPIDFD_THREAD, SO_PEERPIDFD_THREAD, and SCM_PIDFD_THREAD), expanding peer and scm pid tracking to arrays indexed by pid type. It modifies core socket state management, credentials passing/comparison logic, pidfs registration, and coredump socket connect handling with new WARN_ON_ONCE assertions. These are reachable core networking and IPC changes that warrant fuzzing.",
  "WorthFuzzing": true
}

Instruction:
You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.

IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.

================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.

- REACHABILITY IS THE PRIMARY GATE:
  Fuzzing can only discover bugs in code that can actually execute in standard virtualized
  environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
  If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
  regardless of whether it adds assertions or complex logic.

- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
  Patch authors routinely label changes as "cleanups", "refactorings", or state
  "No functional change intended". Do NOT take these claims at face value.
  Code refactorings that rearrange logic, introduce helper functions, or alter state management
  in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
  If reachable executable code is modified or refactored, it MUST be fuzzed.

- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
  When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
  BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
  Even if the author believes the invariant always holds, fuzzing is essential to verify whether
  an unusual sequence of operations can violate it.

================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:

- Non-kernel and non-executable changes:
  * Modifications to Documentation/, comments, or spelling fixes.
  * User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
    that do not affect the compiled kernel image (vmlinux) or kernel modules.
  * Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
    that do not alter control flow or data structures.
  * Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
  * Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
    ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
  * Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
    physical PCI hot-unplug or manual sysfs driver unbinding.
  * Code paths exclusive to architectures other than the target architecture.

================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
  * Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
    BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
  * Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
  * Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
  * Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).

================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:

- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
  Do NOT list generic, ubiquitous functions called by almost every program in the corpus
  (including, but not limited to: general memory allocators and deallocators, page fault
  and trap handlers, or core synchronization primitives; this is not an exhaustive list).
  Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
  which severely dilutes fuzzing effort away from the actual changes.

- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
  List functions that specifically implement the logic being added or altered, or direct API entrypoints
  for the subsystem feature under review.

- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
  Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
  distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
  If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
  functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).

================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.


Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.

Prompt:
Target architecture: amd64

For your convenience, here is the diff of the changes:
commit 4b1bcdf04ef59a561451aa72c8d69309ad45a6ec
Author: syz-cluster <triage@syzkaller.com>
Date:   Tue Sep 29 11:02:44 2026 +0000

    syz-cluster: applied patch under review

diff --git a/arch/alpha/include/uapi/asm/socket.h b/arch/alpha/include/uapi/asm/socket.h
index 946a5fad26912..5d3524c26b2bc 100644
--- a/arch/alpha/include/uapi/asm/socket.h
+++ b/arch/alpha/include/uapi/asm/socket.h
@@ -157,6 +157,10 @@
 
 #define SO_RIGHTS_NOTRUNC      85
 
+#define SO_PASSPIDFD_THREAD    86
+
+#define SO_PEERPIDFD_THREAD    87
+
 #if !defined(__KERNEL__)
 
 #if __BITS_PER_LONG == 64
diff --git a/arch/mips/include/uapi/asm/socket.h b/arch/mips/include/uapi/asm/socket.h
index f1641dde135fc..245a43f52fb1a 100644
--- a/arch/mips/include/uapi/asm/socket.h
+++ b/arch/mips/include/uapi/asm/socket.h
@@ -168,6 +168,10 @@
 
 #define SO_RIGHTS_NOTRUNC      85
 
+#define SO_PASSPIDFD_THREAD    86
+
+#define SO_PEERPIDFD_THREAD    87
+
 #if !defined(__KERNEL__)
 
 #if __BITS_PER_LONG == 64
diff --git a/arch/parisc/include/uapi/asm/socket.h b/arch/parisc/include/uapi/asm/socket.h
index f3a3815c7dc29..f23710e1c6714 100644
--- a/arch/parisc/include/uapi/asm/socket.h
+++ b/arch/parisc/include/uapi/asm/socket.h
@@ -149,6 +149,10 @@
 
 #define SO_RIGHTS_NOTRUNC	0x4053
 
+#define SO_PASSPIDFD_THREAD	0x4054
+
+#define SO_PEERPIDFD_THREAD	0x4055
+
 #if !defined(__KERNEL__)
 
 #if __BITS_PER_LONG == 64
diff --git a/arch/sparc/include/uapi/asm/socket.h b/arch/sparc/include/uapi/asm/socket.h
index 7907f3b1f0ee0..b35b25bdefc2b 100644
--- a/arch/sparc/include/uapi/asm/socket.h
+++ b/arch/sparc/include/uapi/asm/socket.h
@@ -150,6 +150,10 @@
 
 #define SO_RIGHTS_NOTRUNC        0x005e
 
+#define SO_PASSPIDFD_THREAD      0x005f
+
+#define SO_PEERPIDFD_THREAD      0x0060
+
 #if !defined(__KERNEL__)
 
 
diff --git a/fs/coredump.c b/fs/coredump.c
index 6114839f5178b..870ad720b2152 100644
--- a/fs/coredump.c
+++ b/fs/coredump.c
@@ -454,7 +454,7 @@ static bool coredump_parse(struct core_name *cn, struct coredump_params *cprm,
 				 * leader we know that the thread-group leader
 				 * cannot be reaped until @current has exited.
 				 */
-				cprm->pid = task_tgid(current);
+				task_pids(cprm->pid, current);
 				err = cn_printf(cn, "%d", COREDUMP_PIDFD_NUMBER);
 				break;
 			}
@@ -626,13 +626,17 @@ static int umh_coredump_setup(struct subprocess_info *info, struct cred *new)
 	struct coredump_params *cp = (struct coredump_params *)info->data;
 	int err;
 
-	if (cp->pid) {
+	if (cp->pid[PIDTYPE_TGID]) {
 		struct file *pidfs_file __free(fput) = NULL;
 
-		pidfs_file = pidfs_alloc_file(cp->pid, 0);
+		pidfs_file = pidfs_alloc_file(cp->pid[PIDTYPE_TGID], 0);
 		if (IS_ERR(pidfs_file))
 			return PTR_ERR(pidfs_file);
 
+		err = pidfs_register_pids(cp->pid);
+		if (err)
+			return err;
+
 		pidfs_coredump(cp);
 
 		/*
@@ -695,12 +699,12 @@ static bool coredump_sock_connect(struct core_name *cn, struct coredump_params *
 		return false;
 
 	/*
-	 * Set the thread-group leader pid which is used for the peer
-	 * credentials during connect() below. Then immediately register
-	 * it in pidfs...
+	 * Set the pids of the dumping thread and its thread-group leader
+	 * which are used for the peer credentials during connect() below.
+	 * Then immediately register them in pidfs...
 	 */
-	cprm->pid = task_tgid(current);
-	retval = pidfs_register_pid(cprm->pid);
+	task_pids(cprm->pid, current);
+	retval = pidfs_register_pids(cprm->pid);
 	if (retval)
 		return false;
 
@@ -722,7 +726,7 @@ static bool coredump_sock_connect(struct core_name *cn, struct coredump_params *
 	}
 
 	/* ... and validate that @sk_peer_pid matches @cprm.pid. */
-	if (WARN_ON_ONCE(unix_peer(socket->sk)->sk_peer_pid != cprm->pid))
+	if (WARN_ON_ONCE(!pids_equal(unix_peer(socket->sk)->sk_peer_pid, cprm->pid)))
 		return false;
 
 	cprm->limit = RLIM_INFINITY;
diff --git a/fs/pidfs.c b/fs/pidfs.c
index a6a643f15d08a..29299b2c7ca71 100644
--- a/fs/pidfs.c
+++ b/fs/pidfs.c
@@ -793,9 +793,9 @@ void pidfs_exit(struct task_struct *tsk)
 }
 
 #ifdef CONFIG_COREDUMP
-void pidfs_coredump(const struct coredump_params *cprm)
+static void pidfs_coredump_pid(struct pid *pid,
+			       const struct coredump_params *cprm)
 {
-	struct pid *pid = cprm->pid;
 	struct pidfs_attr *attr;
 
 	attr = READ_ONCE(pid->attr);
@@ -814,6 +814,13 @@ void pidfs_coredump(const struct coredump_params *cprm)
 	smp_wmb();
 	set_bit(PIDFS_ATTR_BIT_COREDUMP, &attr->attr_mask);
 }
+
+void pidfs_coredump(const struct coredump_params *cprm)
+{
+	/* The dumping thread's pidfd reports the coredump as well. */
+	for (enum pid_type type = PIDTYPE_PID; type <= pids_last(cprm->pid); type++)
+		pidfs_coredump_pid(cprm->pid[type], cprm);
+}
 #endif
 
 static struct vfsmount *pidfs_mnt __ro_after_init;
@@ -1070,6 +1077,22 @@ int pidfs_register_pid_gfp(struct pid *pid, gfp_t gfp)
 	return 0;
 }
 
+/* Register the pids up to pid type @last of @pids in pidfs. */
+int __pidfs_register_pids(struct pid *const *pids, enum pid_type last)
+{
+	if (WARN_ON_ONCE(last >= PIDTYPE_MAX))
+		return -EINVAL;
+
+	for (enum pid_type type = PIDTYPE_PID; type <= last; type++) {
+		int ret = pidfs_register_pid(pids[type]);
+
+		if (unlikely(ret))
+			return ret;
+	}
+
+	return 0;
+}
+
 static struct dentry *pidfs_stash_dentry(struct dentry **stashed,
 					 struct dentry *dentry)
 {
diff --git a/include/linux/coredump.h b/include/linux/coredump.h
index 7b38ee2e7913b..0bbb7de6a4021 100644
--- a/include/linux/coredump.h
+++ b/include/linux/coredump.h
@@ -5,6 +5,7 @@
 #include <linux/types.h>
 #include <linux/mm.h>
 #include <linux/fs.h>
+#include <linux/pid_types.h>
 #include <linux/sched/coredump.h>
 #include <asm/siginfo.h>
 
@@ -32,7 +33,8 @@ struct coredump_params {
 	int vma_count;
 	size_t vma_data_size;
 	struct core_vma_metadata *vma_meta;
-	struct pid *pid;
+	/* Dumping thread and its thread-group leader by pid type. */
+	DECLARE_PIDS(pid, PIDTYPE_TGID);
 };
 
 extern unsigned int core_file_note_size_limit;
diff --git a/include/linux/pid.h b/include/linux/pid.h
index ddaef0bbc8ba3..87635d0cc1f71 100644
--- a/include/linux/pid.h
+++ b/include/linux/pid.h
@@ -2,6 +2,9 @@
 #ifndef _LINUX_PID_H
 #define _LINUX_PID_H
 
+#include <linux/array_size.h>
+#include <linux/build_bug.h>
+#include <linux/minmax.h>
 #include <linux/pid_types.h>
 #include <linux/rculist.h>
 #include <linux/rcupdate.h>
@@ -92,6 +95,56 @@ static inline struct pid *get_pid(struct pid *pid)
 }
 
 extern void put_pid(struct pid *pid);
+
+/*
+ * Helpers for arrays of struct pid indexed by pid type declared with
+ * DECLARE_PIDS(). The array covers PIDTYPE_PID up to the pid type it
+ * was declared with and the helpers take that bound from the array.
+ */
+static inline void __get_pids(struct pid **dst, struct pid *const *src,
+			      enum pid_type last)
+{
+	for (enum pid_type type = PIDTYPE_PID; type <= last; type++)
+		dst[type] = get_pid(src[type]);
+}
+
+static inline void __put_pids(struct pid **pids, enum pid_type last)
+{
+	for (enum pid_type type = PIDTYPE_PID; type <= last; type++) {
+		put_pid(pids[type]);
+		pids[type] = NULL;
+	}
+}
+
+static inline void __swap_pids(struct pid **a, struct pid **b,
+			       enum pid_type last)
+{
+	for (enum pid_type type = PIDTYPE_PID; type <= last; type++)
+		swap(a[type], b[type]);
+}
+
+static inline bool __pids_equal(struct pid *const *a, struct pid *const *b,
+				enum pid_type last)
+{
+	for (enum pid_type type = PIDTYPE_PID; type <= last; type++)
+		if (a[type] != b[type])
+			return false;
+	return true;
+}
+
+/* The last pid type an array declared with DECLARE_PIDS() covers. */
+#define pids_last(pids)							\
+	((enum pid_type)(ARRAY_SIZE(pids) - 1 +				\
+			 BUILD_BUG_ON_ZERO(ARRAY_SIZE(pids) > PIDTYPE_MAX)))
+
+#define __pids_last2(a, b)						\
+	(pids_last(a) + BUILD_BUG_ON_ZERO(ARRAY_SIZE(a) != ARRAY_SIZE(b)))
+
+#define get_pids(dst, src)	__get_pids(dst, src, __pids_last2(dst, src))
+#define put_pids(pids)		__put_pids(pids, pids_last(pids))
+#define swap_pids(a, b)		__swap_pids(a, b, __pids_last2(a, b))
+#define pids_equal(a, b)	__pids_equal(a, b, __pids_last2(a, b))
+
 extern struct task_struct *pid_task(struct pid *pid, enum pid_type);
 static inline bool pid_has_task(struct pid *pid, enum pid_type type)
 {
diff --git a/include/linux/pid_types.h b/include/linux/pid_types.h
index c2aee1d91dcfd..3302690a2a281 100644
--- a/include/linux/pid_types.h
+++ b/include/linux/pid_types.h
@@ -2,6 +2,8 @@
 #ifndef _LINUX_PID_TYPES_H
 #define _LINUX_PID_TYPES_H
 
+#include <linux/build_bug.h>
+
 enum pid_type {
 	PIDTYPE_PID,
 	PIDTYPE_TGID,
@@ -10,6 +12,12 @@ enum pid_type {
 	PIDTYPE_MAX,
 };
 
+struct pid;
+
+/* An array of struct pid indexed by pid type, PIDTYPE_PID up to @last. */
+#define DECLARE_PIDS(name, last)					\
+	struct pid *name[(last) + 1 + BUILD_BUG_ON_ZERO((last) >= PIDTYPE_MAX)]
+
 struct pid_namespace;
 extern struct pid_namespace init_pid_ns;
 
diff --git a/include/linux/pidfs.h b/include/linux/pidfs.h
index 0abf7da9ab236..3c1e82f1a3691 100644
--- a/include/linux/pidfs.h
+++ b/include/linux/pidfs.h
@@ -3,6 +3,7 @@
 #define _LINUX_PID_FS_H
 
 #include <linux/gfp_types.h>
+#include <linux/pid.h>
 
 struct coredump_params;
 
@@ -32,5 +33,9 @@ static inline int pidfs_register_pid(struct pid *pid)
 }
 
 void pidfs_free_pid(struct pid *pid);
+int __pidfs_register_pids(struct pid *const *pids, enum pid_type last);
+
+/* Register the pids of an array declared with DECLARE_PIDS(). */
+#define pidfs_register_pids(pids)	__pidfs_register_pids(pids, pids_last(pids))
 
 #endif /* _LINUX_PID_FS_H */
diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h
index d45a5476b97de..3149cdb976c60 100644
--- a/include/linux/sched/signal.h
+++ b/include/linux/sched/signal.h
@@ -674,6 +674,24 @@ struct pid *task_pid_type(struct task_struct *task, enum pid_type type)
 	return pid;
 }
 
+/* Fill @pids with the pid types of @task up to @last, without references. */
+static inline void __task_pids(struct pid **pids, enum pid_type last,
+			       struct task_struct *task)
+{
+	for (enum pid_type type = PIDTYPE_PID; type <= last; type++)
+		pids[type] = task_pid_type(task, type);
+}
+
+static inline void __get_task_pids(struct pid **pids, enum pid_type last,
+				   struct task_struct *task)
+{
+	for (enum pid_type type = PIDTYPE_PID; type <= last; type++)
+		pids[type] = get_pid(task_pid_type(task, type));
+}
+
+#define task_pids(pids, task)		__task_pids(pids, pids_last(pids), task)
+#define get_task_pids(pids, task)	__get_task_pids(pids, pids_last(pids), task)
+
 static inline struct pid *task_tgid(struct task_struct *task)
 {
 	return task->signal->pids[PIDTYPE_TGID];
diff --git a/include/linux/socket.h b/include/linux/socket.h
index 5a5eb12501032..b17fdb7d38a77 100644
--- a/include/linux/socket.h
+++ b/include/linux/socket.h
@@ -189,10 +189,11 @@ static inline size_t msg_data_left(const struct msghdr *msg)
 
 /* "Socket"-level control message types: */
 
-#define	SCM_RIGHTS	0x01		/* rw: access rights (array of int) */
-#define SCM_CREDENTIALS 0x02		/* rw: struct ucred		*/
-#define SCM_SECURITY	0x03		/* rw: security label		*/
-#define SCM_PIDFD	0x04		/* ro: pidfd (int)		*/
+#define	SCM_RIGHTS		0x01	/* rw: access rights (array of int) */
+#define SCM_CREDENTIALS		0x02	/* rw: struct ucred		*/
+#define SCM_SECURITY		0x03	/* rw: security label		*/
+#define SCM_PIDFD		0x04	/* ro: pidfd (int)		*/
+#define SCM_PIDFD_THREAD	0x05	/* ro: thread pidfd (int)	*/
 
 struct ucred {
 	__u32	pid;
diff --git a/include/net/scm.h b/include/net/scm.h
index 86ae6bc109ec6..aa7d15c5fc271 100644
--- a/include/net/scm.h
+++ b/include/net/scm.h
@@ -42,7 +42,7 @@ struct scm_fp_list {
 };
 
 struct scm_cookie {
-	struct pid		*pid;		/* Skb credentials */
+	DECLARE_PIDS(pid, PIDTYPE_TGID);	/* Skb credentials by pid type */
 	struct scm_fp_list	*fp;		/* Passed files		*/
 	struct scm_creds	creds;		/* Skb credentials	*/
 #ifdef CONFIG_SECURITY_NETWORK
@@ -69,7 +69,7 @@ static __inline__ void unix_get_peersec_dgram(struct socket *sock, struct scm_co
 static __inline__ void scm_set_cred(struct scm_cookie *scm,
 				    struct pid *pid, kuid_t uid, kgid_t gid)
 {
-	scm->pid = get_pid(pid);
+	scm->pid[PIDTYPE_TGID] = get_pid(pid);
 	scm->creds.pid = pid_vnr(pid);
 	scm->creds.uid = uid;
 	scm->creds.gid = gid;
@@ -77,8 +77,7 @@ static __inline__ void scm_set_cred(struct scm_cookie *scm,
 
 static __inline__ void scm_destroy_cred(struct scm_cookie *scm)
 {
-	put_pid(scm->pid);
-	scm->pid = NULL;
+	put_pids(scm->pid);
 }
 
 static __inline__ void scm_destroy(struct scm_cookie *scm)
diff --git a/include/net/sock.h b/include/net/sock.h
index 60ea55dc18854..efc64c60e4ac3 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -301,7 +301,7 @@ struct sk_filter;
   *	@sk_type: socket type (%SOCK_STREAM, etc)
   *	@sk_protocol: which protocol this socket belongs in this network family
   *	@sk_peer_lock: lock protecting @sk_peer_pid and @sk_peer_cred
-  *	@sk_peer_pid: &struct pid for this socket's peer
+  *	@sk_peer_pid: &struct pid for this socket's peer, by pid type
   *	@sk_peer_cred: %SO_PEERCRED setting
   *	@sk_rcvlowat: %SO_RCVLOWAT setting
   *	@sk_rcvtimeo: %SO_RCVTIMEO setting
@@ -356,6 +356,7 @@ struct sk_filter;
   *	@sk_scm_security: flagged by SO_PASSSEC to recv SCM_SECURITY
   *	@sk_scm_pidfd: flagged by SO_PASSPIDFD to recv SCM_PIDFD
   *	@sk_scm_rights: flagged by SO_PASSRIGHTS to recv SCM_RIGHTS
+  *	@sk_scm_pidfd_thread: flagged by SO_PASSPIDFD_THREAD to recv a thread SCM_PIDFD
   *	@sk_scm_unused: unused flags for scm_recv()
   *	@ns_tracker: tracker for netns reference
   *	@sk_user_frags: xarray of pages the user is holding a reference on.
@@ -545,7 +546,7 @@ struct sock {
 	u64			sk_ino;
 	spinlock_t		sk_peer_lock;
 	int			sk_bind_phc;
-	struct pid		*sk_peer_pid;
+	DECLARE_PIDS(sk_peer_pid, PIDTYPE_TGID);
 	const struct cred	*sk_peer_cred;
 
 	ktime_t			sk_stamp;
@@ -562,7 +563,8 @@ struct sock {
 				sk_scm_security : 1,
 				sk_scm_pidfd : 1,
 				sk_scm_rights : 1,
-				sk_scm_unused : 4;
+				sk_scm_pidfd_thread : 1,
+				sk_scm_unused : 3;
 		};
 	};
 	u8			sk_clockid;
@@ -2988,6 +2990,16 @@ static inline bool sk_is_stream_unix(const struct sock *sk)
 	return sk_is_unix(sk) && sk->sk_type == SOCK_STREAM;
 }
 
+static inline bool sk_scm_pidfd_wanted(const struct sock *sk)
+{
+	return sk->sk_scm_pidfd;
+}
+
+static inline bool sk_scm_pidfd_thread_wanted(const struct sock *sk)
+{
+	return sk->sk_scm_pidfd_thread;
+}
+
 static inline bool sk_is_vsock(const struct sock *sk)
 {
 	return sk->sk_family == AF_VSOCK;
diff --git a/include/trace/events/landlock.h b/include/trace/events/landlock.h
index 3a43638c9bc29..9e172ea22d95c 100644
--- a/include/trace/events/landlock.h
+++ b/include/trace/events/landlock.h
@@ -1037,7 +1037,7 @@ TRACE_EVENT(landlock_deny_scope_abstract_unix_socket,
 		 * updates.  The peer socket keeps a reference to sk_peer_pid
 		 * through pid_nr(); sun_path is the reliable identifier.
 		 */
-		peer_pid		= READ_ONCE(peer->sk_peer_pid);
+		peer_pid		= READ_ONCE(peer->sk_peer_pid[PIDTYPE_TGID]);
 		__entry->peer_pid	= peer_pid ? pid_nr(peer_pid) : 0;
 		__assign_str(sun_path);
 	),
diff --git a/include/uapi/asm-generic/socket.h b/include/uapi/asm-generic/socket.h
index 84ea7b92936e2..56fed7ab27ab8 100644
--- a/include/uapi/asm-generic/socket.h
+++ b/include/uapi/asm-generic/socket.h
@@ -152,6 +152,10 @@
 
 #define SO_RIGHTS_NOTRUNC	85
 
+#define SO_PASSPIDFD_THREAD	86
+
+#define SO_PEERPIDFD_THREAD	87
+
 #if !defined(__KERNEL__)
 
 #if __BITS_PER_LONG == 64 || (defined(__x86_64__) && defined(__ILP32__))
diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c
index 411d66f24393d..7758e9ea3848c 100644
--- a/net/bluetooth/af_bluetooth.c
+++ b/net/bluetooth/af_bluetooth.c
@@ -161,7 +161,7 @@ struct sock *bt_sock_alloc(struct net *net, struct socket *sock,
 	/* Init peer information so it can be properly monitored */
 	if (!kern) {
 		spin_lock(&sk->sk_peer_lock);
-		sk->sk_peer_pid  = get_pid(task_tgid(current));
+		sk->sk_peer_pid[PIDTYPE_TGID]  = get_pid(task_tgid(current));
 		sk->sk_peer_cred = get_current_cred();
 		spin_unlock(&sk->sk_peer_lock);
 	}
@@ -235,9 +235,9 @@ void bt_accept_enqueue(struct sock *parent, struct sock *sk, bool bh)
 	 * socket is allocated by the kernel.
 	 */
 	spin_lock(&sk->sk_peer_lock);
-	old_pid = sk->sk_peer_pid;
+	old_pid = sk->sk_peer_pid[PIDTYPE_TGID];
 	old_cred = sk->sk_peer_cred;
-	sk->sk_peer_pid = get_pid(parent->sk_peer_pid);
+	sk->sk_peer_pid[PIDTYPE_TGID] = get_pid(parent->sk_peer_pid[PIDTYPE_TGID]);
 	sk->sk_peer_cred = get_cred(parent->sk_peer_cred);
 	spin_unlock(&sk->sk_peer_lock);
 
diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
index 6d56c77741e19..4c40068ba5fb2 100644
--- a/net/bluetooth/hci_sock.c
+++ b/net/bluetooth/hci_sock.c
@@ -284,21 +284,21 @@ static void hci_sock_copy_creds(struct sock *sk, struct sk_buff *skb)
 	creds = &bt_cb(skb)->creds;
 
 	/* Check if peer credentials is set */
-	if (!sk->sk_peer_pid) {
+	if (!sk->sk_peer_pid[PIDTYPE_TGID]) {
 		/* Check if parent peer credentials is set */
-		if (bt_sk(sk)->parent && bt_sk(sk)->parent->sk_peer_pid)
+		if (bt_sk(sk)->parent && bt_sk(sk)->parent->sk_peer_pid[PIDTYPE_TGID])
 			sk = bt_sk(sk)->parent;
 		else
 			return;
 	}
 
 	/* Check if scm_creds already set */
-	if (creds->pid == pid_vnr(sk->sk_peer_pid))
+	if (creds->pid == pid_vnr(sk->sk_peer_pid[PIDTYPE_TGID]))
 		return;
 
 	memset(creds, 0, sizeof(*creds));
 
-	creds->pid = pid_vnr(sk->sk_peer_pid);
+	creds->pid = pid_vnr(sk->sk_peer_pid[PIDTYPE_TGID]);
 	if (sk->sk_peer_cred) {
 		creds->uid = sk->sk_peer_cred->uid;
 		creds->gid = sk->sk_peer_cred->gid;
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index 1194c37e466f1..872d8fb31b6fb 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -1890,7 +1890,7 @@ static struct pid *l2cap_sock_get_peer_pid_cb(struct l2cap_chan *chan)
 {
 	struct sock *sk = chan->data;
 
-	return sk->sk_peer_pid;
+	return sk->sk_peer_pid[PIDTYPE_TGID];
 }
 
 static void l2cap_sock_suspend_cb(struct l2cap_chan *chan)
diff --git a/net/core/scm.c b/net/core/scm.c
index f0d44ecdb11fc..ba43d76027af5 100644
--- a/net/core/scm.c
+++ b/net/core/scm.c
@@ -149,6 +149,7 @@ EXPORT_SYMBOL(__scm_destroy);
 
 static inline int scm_replace_pid(struct scm_cookie *scm, struct pid *pid)
 {
+	struct pid *thread_pid;
 	int err;
 
 	/* drop all previous references */
@@ -158,7 +159,18 @@ static inline int scm_replace_pid(struct scm_cookie *scm, struct pid *pid)
 	if (unlikely(err))
 		return err;
 
-	scm->pid = pid;
+	/* A sender naming its own thread-group sends from the current thread. */
+	if (pid == task_tgid(current))
+		thread_pid = task_pid(current);
+	else
+		thread_pid = pid;
+
+	err = pidfs_register_pid(thread_pid);
+	if (unlikely(err))
+		return err;
+
+	scm->pid[PIDTYPE_TGID] = pid;
+	scm->pid[PIDTYPE_PID] = get_pid(thread_pid);
 	scm->creds.pid = pid_vnr(pid);
 	return 0;
 }
@@ -207,7 +219,8 @@ int __scm_send(struct socket *sock, struct msghdr *msg, struct scm_cookie *p)
 			if (err)
 				goto error;
 
-			if (!p->pid || pid_vnr(p->pid) != creds.pid) {
+			if (!p->pid[PIDTYPE_TGID] ||
+			    pid_vnr(p->pid[PIDTYPE_TGID]) != creds.pid) {
 				struct pid *pid;
 				err = -ESRCH;
 				pid = find_get_pid(creds.pid);
@@ -486,11 +499,16 @@ static bool scm_has_secdata(struct sock *sk)
 }
 #endif
 
-static void scm_pidfd_recv(struct msghdr *msg, struct scm_cookie *scm)
+static void scm_pidfd_recv(struct msghdr *msg, struct scm_cookie *scm,
+			   enum pid_type type, int cmsg_type)
 {
+	unsigned int flags = PIDFD_STALE;
 	struct file *pidfd_file = NULL;
+	struct pid *pid;
 	int len, pidfd;
 
+	pid = scm->pid[type];
+
 	/* put_cmsg() doesn't return an error if CMSG is truncated,
 	 * that's why we need to opencode these checks here.
 	 */
@@ -504,12 +522,15 @@ static void scm_pidfd_recv(struct msghdr *msg, struct scm_cookie *scm)
 		return;
 	}
 
-	if (!scm->pid)
+	if (!pid)
 		return;
 
-	pidfd = pidfd_prepare(scm->pid, PIDFD_STALE, &pidfd_file);
+	if (type == PIDTYPE_PID)
+		flags |= PIDFD_THREAD;
 
-	if (put_cmsg(msg, SOL_SOCKET, SCM_PIDFD, sizeof(int), &pidfd)) {
+	pidfd = pidfd_prepare(pid, flags, &pidfd_file);
+
+	if (put_cmsg(msg, SOL_SOCKET, cmsg_type, sizeof(int), &pidfd)) {
 		if (pidfd_file) {
 			put_unused_fd(pidfd);
 			fput(pidfd_file);
@@ -526,8 +547,8 @@ static bool __scm_recv_common(struct sock *sk, struct msghdr *msg,
 			      struct scm_cookie *scm, int flags)
 {
 	if (!msg->msg_control) {
-		if (sk->sk_scm_credentials || sk->sk_scm_pidfd ||
-		    scm->fp || scm_has_secdata(sk))
+		if (sk->sk_scm_credentials || sk_scm_pidfd_wanted(sk) ||
+		    sk_scm_pidfd_thread_wanted(sk) || scm->fp || scm_has_secdata(sk))
 			msg->msg_flags |= MSG_CTRUNC;
 
 		scm_destroy(scm);
@@ -573,8 +594,11 @@ void scm_recv_unix(struct socket *sock, struct msghdr *msg,
 		scm_detach_fds(msg, scm, READ_ONCE(u->scm_rights_notrunc));
 	}
 
-	if (sock->sk->sk_scm_pidfd)
-		scm_pidfd_recv(msg, scm);
+	if (sk_scm_pidfd_wanted(sock->sk))
+		scm_pidfd_recv(msg, scm, PIDTYPE_TGID, SCM_PIDFD);
+
+	if (sk_scm_pidfd_thread_wanted(sock->sk))
+		scm_pidfd_recv(msg, scm, PIDTYPE_PID, SCM_PIDFD_THREAD);
 
 	scm_destroy_cred(scm);
 }
diff --git a/net/core/sock.c b/net/core/sock.c
index d23333bb4f3fa..c970f8beae3ba 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -1578,6 +1578,13 @@ int sk_setsockopt(struct sock *sk, int level, int optname,
 			ret = -EOPNOTSUPP;
 		break;
 
+	case SO_PASSPIDFD_THREAD:
+		if (sk_is_unix(sk))
+			sk->sk_scm_pidfd_thread = valbool;
+		else
+			ret = -EOPNOTSUPP;
+		break;
+
 	case SO_PASSRIGHTS:
 		if (sk_is_unix(sk))
 			sk->sk_scm_rights = valbool;
@@ -1729,6 +1736,50 @@ static int groups_to_user(sockptr_t dst, const struct group_info *src)
 	return 0;
 }
 
+/* Hand out a pidfd for @type of the socket's peer via SO_PEERPIDFD*. */
+static int sk_getsockopt_peerpidfd(struct sock *sk, enum pid_type type,
+				   sockptr_t optval, sockptr_t optlen, int len)
+{
+	struct file *pidfd_file = NULL;
+	unsigned int flags = 0;
+	struct pid *peer_pid;
+	int pidfd;
+
+	if (len > sizeof(pidfd))
+		len = sizeof(pidfd);
+
+	spin_lock(&sk->sk_peer_lock);
+	peer_pid = get_pid(sk->sk_peer_pid[type]);
+	spin_unlock(&sk->sk_peer_lock);
+
+	if (!peer_pid)
+		return -ENODATA;
+
+	/* The use of PIDFD_STALE requires stashing of struct pid on pidfs
+	 * with pidfs_register_pid() and only AF_UNIX is prepared for this.
+	 */
+	if (sk_is_unix(sk))
+		flags |= PIDFD_STALE;
+	if (type == PIDTYPE_PID)
+		flags |= PIDFD_THREAD;
+
+	pidfd = pidfd_prepare(peer_pid, flags, &pidfd_file);
+	put_pid(peer_pid);
+	if (pidfd < 0)
+		return pidfd;
+
+	if (copy_to_sockptr(optval, &pidfd, len) ||
+	    copy_to_sockptr(optlen, &len, sizeof(int))) {
+		put_unused_fd(pidfd);
+		fput(pidfd_file);
+
+		return -EFAULT;
+	}
+
+	fd_install(pidfd, pidfd_file);
+	return 0;
+}
+
 int sk_getsockopt(struct sock *sk, int level, int optname,
 		  sockptr_t optval, sockptr_t optlen)
 {
@@ -1893,6 +1944,13 @@ int sk_getsockopt(struct sock *sk, int level, int optname,
 		v.val = sk->sk_scm_pidfd;
 		break;
 
+	case SO_PASSPIDFD_THREAD:
+		if (!sk_is_unix(sk))
+			return -EOPNOTSUPP;
+
+		v.val = sk->sk_scm_pidfd_thread;
+		break;
+
 	case SO_PASSRIGHTS:
 		if (!sk_is_unix(sk))
 			return -EOPNOTSUPP;
@@ -1907,7 +1965,8 @@ int sk_getsockopt(struct sock *sk, int level, int optname,
 			len = sizeof(peercred);
 
 		spin_lock(&sk->sk_peer_lock);
-		cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
+		cred_to_ucred(sk->sk_peer_pid[PIDTYPE_TGID], sk->sk_peer_cred,
+			      &peercred);
 		spin_unlock(&sk->sk_peer_lock);
 
 		if (copy_to_sockptr(optval, &peercred, len))
@@ -1916,45 +1975,14 @@ int sk_getsockopt(struct sock *sk, int level, int optname,
 	}
 
 	case SO_PEERPIDFD:
-	{
-		struct pid *peer_pid;
-		struct file *pidfd_file = NULL;
-		unsigned int flags = 0;
-		int pidfd;
-
-		if (len > sizeof(pidfd))
-			len = sizeof(pidfd);
-
-		spin_lock(&sk->sk_peer_lock);
-		peer_pid = get_pid(sk->sk_peer_pid);
-		spin_unlock(&sk->sk_peer_lock);
-
-		if (!peer_pid)
-			return -ENODATA;
-
-		/* The use of PIDFD_STALE requires stashing of struct pid
-		 * on pidfs with pidfs_register_pid() and only AF_UNIX
-		 * were prepared for this.
-		 */
-		if (sk->sk_family == AF_UNIX)
-			flags = PIDFD_STALE;
+		return sk_getsockopt_peerpidfd(sk, PIDTYPE_TGID, optval, optlen, len);
 
-		pidfd = pidfd_prepare(peer_pid, flags, &pidfd_file);
-		put_pid(peer_pid);
-		if (pidfd < 0)
-			return pidfd;
-
-		if (copy_to_sockptr(optval, &pidfd, len) ||
-		    copy_to_sockptr(optlen, &len, sizeof(int))) {
-			put_unused_fd(pidfd);
-			fput(pidfd_file);
-
-			return -EFAULT;
-		}
+	case SO_PEERPIDFD_THREAD:
+		/* Only AF_UNIX records the peer's connecting thread. */
+		if (!sk_is_unix(sk))
+			return -EOPNOTSUPP;
 
-		fd_install(pidfd, pidfd_file);
-		return 0;
-	}
+		return sk_getsockopt_peerpidfd(sk, PIDTYPE_PID, optval, optlen, len);
 
 	case SO_PEERGROUPS:
 	{
@@ -2380,7 +2408,7 @@ static void __sk_destruct(struct rcu_head *head)
 
 	/* We do not need to acquire sk->sk_peer_lock, we are the last user. */
 	put_cred(sk->sk_peer_cred);
-	put_pid(sk->sk_peer_pid);
+	put_pids(sk->sk_peer_pid);
 
 	if (likely(sk->sk_net_refcnt)) {
 		put_net_track(net, &sk->ns_tracker);
@@ -3785,7 +3813,7 @@ void sock_init_data_uid(struct socket *sock, struct sock *sk, kuid_t uid)
 	sk->sk_frag.offset	=	0;
 	sk->sk_peek_off		=	-1;
 
-	sk->sk_peer_pid 	=	NULL;
+	memset(sk->sk_peer_pid, 0, sizeof(sk->sk_peer_pid));
 	sk->sk_peer_cred	=	NULL;
 	spin_lock_init(&sk->sk_peer_lock);
 
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 42cffeafc8c14..54f122952979a 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -737,57 +737,53 @@ static void unix_release_sock(struct sock *sk, int embrion)
 }
 
 struct unix_peercred {
-	struct pid *peer_pid;
+	DECLARE_PIDS(peer_pid, PIDTYPE_TGID);
 	const struct cred *peer_cred;
 };
 
 static inline int prepare_peercred(struct unix_peercred *peercred)
 {
-	struct pid *pid;
 	int err;
 
-	pid = task_tgid(current);
-	err = pidfs_register_pid(pid);
-	if (likely(!err)) {
-		peercred->peer_pid = get_pid(pid);
-		peercred->peer_cred = get_current_cred();
+	get_task_pids(peercred->peer_pid, current);
+	err = pidfs_register_pids(peercred->peer_pid);
+	if (unlikely(err)) {
+		put_pids(peercred->peer_pid);
+		return err;
 	}
-	return err;
+
+	peercred->peer_cred = get_current_cred();
+	return 0;
 }
 
 static void drop_peercred(struct unix_peercred *peercred)
 {
 	const struct cred *cred = NULL;
-	struct pid *pid = NULL;
 
 	might_sleep();
 
-	swap(peercred->peer_pid, pid);
+	put_pids(peercred->peer_pid);
 	swap(peercred->peer_cred, cred);
-
-	put_pid(pid);
 	put_cred(cred);
 }
 
 static inline void init_peercred(struct sock *sk,
 				 const struct unix_peercred *peercred)
 {
-	sk->sk_peer_pid = peercred->peer_pid;
+	memcpy(sk->sk_peer_pid, peercred->peer_pid, sizeof(sk->sk_peer_pid));
 	sk->sk_peer_cred = peercred->peer_cred;
 }
 
 static void update_peercred(struct sock *sk, struct unix_peercred *peercred)
 {
 	const struct cred *old_cred;
-	struct pid *old_pid;
 
 	spin_lock(&sk->sk_peer_lock);
-	old_pid = sk->sk_peer_pid;
+	swap_pids(sk->sk_peer_pid, peercred->peer_pid);
 	old_cred = sk->sk_peer_cred;
-	init_peercred(sk, peercred);
+	sk->sk_peer_cred = peercred->peer_cred;
 	spin_unlock(&sk->sk_peer_lock);
 
-	peercred->peer_pid = old_pid;
 	peercred->peer_cred = old_cred;
 }
 
@@ -796,14 +792,15 @@ static void copy_peercred(struct sock *sk, struct sock *peersk)
 	lockdep_assert_held(&unix_sk(peersk)->lock);
 
 	spin_lock(&sk->sk_peer_lock);
-	sk->sk_peer_pid = get_pid(peersk->sk_peer_pid);
+	get_pids(sk->sk_peer_pid, peersk->sk_peer_pid);
 	sk->sk_peer_cred = get_cred(peersk->sk_peer_cred);
 	spin_unlock(&sk->sk_peer_lock);
 }
 
 static bool unix_may_passcred(const struct sock *sk)
 {
-	return sk->sk_scm_credentials || sk->sk_scm_pidfd;
+	return sk->sk_scm_credentials || sk_scm_pidfd_wanted(sk) ||
+		sk_scm_pidfd_thread_wanted(sk);
 }
 
 static int unix_listen(struct socket *sock, int backlog)
@@ -1060,6 +1057,7 @@ static bool unix_bpf_bypass_getsockopt(int level, int optname)
 	if (level == SOL_SOCKET) {
 		switch (optname) {
 		case SO_PEERPIDFD:
+		case SO_PEERPIDFD_THREAD:
 			return true;
 		default:
 			return false;
@@ -1973,7 +1971,7 @@ static void unix_destruct_scm(struct sk_buff *skb)
 {
 	struct scm_cookie scm = {};
 
-	swap(scm.pid, UNIXCB(skb).pid);
+	swap_pids(scm.pid, UNIXCB(skb).pid);
 
 	if (UNIXCB(skb).fp)
 		unix_detach_fds(&scm, skb);
@@ -1991,7 +1989,7 @@ static int unix_scm_to_skb(struct scm_cookie *scm, struct sk_buff *skb, bool sen
 {
 	int err = 0;
 
-	UNIXCB(skb).pid = get_pid(scm->pid);
+	get_pids(UNIXCB(skb).pid, scm->pid);
 	UNIXCB(skb).uid = scm->creds.uid;
 	UNIXCB(skb).gid = scm->creds.gid;
 	UNIXCB(skb).fp = NULL;
@@ -2005,7 +2003,10 @@ static int unix_scm_to_skb(struct scm_cookie *scm, struct sk_buff *skb, bool sen
 
 static void unix_skb_to_scm(struct sk_buff *skb, struct scm_cookie *scm)
 {
-	scm_set_cred(scm, UNIXCB(skb).pid, UNIXCB(skb).uid, UNIXCB(skb).gid);
+	get_pids(scm->pid, UNIXCB(skb).pid);
+	scm->creds.pid = pid_vnr(scm->pid[PIDTYPE_TGID]);
+	scm->creds.uid = UNIXCB(skb).uid;
+	scm->creds.gid = UNIXCB(skb).gid;
 	unix_set_secdata(scm, skb);
 }
 
@@ -2025,30 +2026,35 @@ static void unix_skb_to_scm(struct sk_buff *skb, struct scm_cookie *scm)
 static int unix_maybe_add_creds(struct sk_buff *skb, const struct sock *sk,
 				const struct sock *other)
 {
-	if (UNIXCB(skb).pid)
+	if (UNIXCB(skb).pid[PIDTYPE_TGID])
 		return 0;
 
 	if (unix_may_passcred(sk) || unix_may_passcred(other) ||
 	    !other->sk_socket) {
-		struct pid *pid;
 		int err;
 
-		pid = task_tgid(current);
-		err = pidfs_register_pid(pid);
-		if (unlikely(err))
+		get_task_pids(UNIXCB(skb).pid, current);
+		err = pidfs_register_pids(UNIXCB(skb).pid);
+		if (unlikely(err)) {
+			put_pids(UNIXCB(skb).pid);
 			return err;
+		}
 
-		UNIXCB(skb).pid = get_pid(pid);
 		current_uid_gid(&UNIXCB(skb).uid, &UNIXCB(skb).gid);
 	}
 
 	return 0;
 }
 
-static bool unix_skb_scm_eq(struct sk_buff *skb,
+static bool unix_skb_scm_eq(const struct sock *sk, struct sk_buff *skb,
 			    struct scm_cookie *scm)
 {
-	return UNIXCB(skb).pid == scm->pid &&
+	/* Only a thread pidfd receiver can tell threads of one process apart. */
+	if (sk->sk_scm_pidfd_thread &&
+	    UNIXCB(skb).pid[PIDTYPE_PID] != scm->pid[PIDTYPE_PID])
+		return false;
+
+	return UNIXCB(skb).pid[PIDTYPE_TGID] == scm->pid[PIDTYPE_TGID] &&
 	       uid_eq(UNIXCB(skb).uid, scm->creds.uid) &&
 	       gid_eq(UNIXCB(skb).gid, scm->creds.gid) &&
 	       unix_secdata_eq(scm, skb);
@@ -3030,7 +3036,7 @@ static int unix_stream_read_generic(struct unix_stream_read_state *state,
 
 		if (check_creds) {
 			/* Never glue messages from different writers */
-			if (!unix_skb_scm_eq(skb, &scm))
+			if (!unix_skb_scm_eq(sk, skb, &scm))
 				break;
 		} else if (unix_may_passcred(sk)) {
 			/* Copy credentials */
diff --git a/net/unix/af_unix.h b/net/unix/af_unix.h
index 8119dbeef3a3c..402742895acca 100644
--- a/net/unix/af_unix.h
+++ b/net/unix/af_unix.h
@@ -2,6 +2,7 @@
 #ifndef __AF_UNIX_H
 #define __AF_UNIX_H
 
+#include <linux/pid_types.h>
 #include <linux/uidgid.h>
 
 #define UNIX_HASH_MOD	(256 - 1)
@@ -11,7 +12,7 @@
 struct sock *unix_peer_get(struct sock *sk);
 
 struct unix_skb_parms {
-	struct pid		*pid;		/* skb credentials	*/
+	DECLARE_PIDS(pid, PIDTYPE_TGID);	/* skb credentials by pid type */
 	kuid_t			uid;
 	kgid_t			gid;
 	struct scm_fp_list	*fp;		/* Passed files		*/
diff --git a/tools/lib/python/kdoc/xforms_lists.py b/tools/lib/python/kdoc/xforms_lists.py
index e3dda2fe8a537..e792785a15ec6 100644
--- a/tools/lib/python/kdoc/xforms_lists.py
+++ b/tools/lib/python/kdoc/xforms_lists.py
@@ -45,6 +45,7 @@ class CTransforms:
         (CMatch("DECLARE_HASHTABLE"), r"unsigned long \1[1 << ((\2) - 1)]"),
         (CMatch("DECLARE_KFIFO"), r"\2 *\1"),
         (CMatch("DECLARE_KFIFO_PTR"), r"\2 *\1"),
+        (CMatch("DECLARE_PIDS"), r"struct pid *\1[(\2) + 1]"),
         (CMatch("(?:__)?DECLARE_FLEX_ARRAY"), r"\1 \2[]"),
         (CMatch("DEFINE_DMA_UNMAP_ADDR"), r"dma_addr_t \1"),
         (CMatch("DEFINE_DMA_UNMAP_LEN"), r"__u32 \1"),
diff --git a/tools/testing/selftests/coredump/coredump_socket_test.c b/tools/testing/selftests/coredump/coredump_socket_test.c
index 422728f632ca6..ec73bb690bbcb 100644
--- a/tools/testing/selftests/coredump/coredump_socket_test.c
+++ b/tools/testing/selftests/coredump/coredump_socket_test.c
@@ -592,6 +592,181 @@ TEST_F(coredump, socket_coredump_signal_sigsegv)
 	wait_and_check_coredump_server(pid_coredump_server, _metadata, self);
 }
 
+static bool check_coredump_info(const struct pidfd_info *info, const char *what)
+{
+	if (!(info->mask & PIDFD_INFO_COREDUMP)) {
+		fprintf(stderr, "%s: PIDFD_INFO_COREDUMP not set in mask\n", what);
+		return false;
+	}
+
+	if (!(info->coredump_mask & PIDFD_COREDUMPED)) {
+		fprintf(stderr, "%s: PIDFD_COREDUMPED not set in coredump_mask\n", what);
+		return false;
+	}
+
+	if (!(info->mask & PIDFD_INFO_COREDUMP_SIGNAL) || info->coredump_signal != SIGSEGV) {
+		fprintf(stderr, "%s: coredump_signal=%d, expected SIGSEGV=%d\n",
+			what, info->coredump_signal, SIGSEGV);
+		return false;
+	}
+
+	if (!(info->mask & PIDFD_INFO_COREDUMP_CODE) || info->coredump_code != SEGV_MAPERR) {
+		fprintf(stderr, "%s: coredump_code=%d, expected SEGV_MAPERR=%d\n",
+			what, info->coredump_code, SEGV_MAPERR);
+		return false;
+	}
+
+	return true;
+}
+
+/*
+ * Test: PIDFD_INFO_COREDUMP on the dumping thread's pidfd
+ *
+ * Crash from a non-leader thread and verify that the pidfd from
+ * SO_PEERPIDFD_THREAD refers to that thread and reports the coredump
+ * like the thread-group leader's pidfd from SO_PEERPIDFD does.
+ */
+TEST_F(coredump, socket_coredump_thread)
+{
+	int pidfd, ret, status;
+	pid_t pid, pid_coredump_server;
+	struct pidfd_info info = {};
+	int ipc_sockets[2];
+	char c;
+
+	ASSERT_TRUE(set_core_pattern("@/tmp/coredump.socket"));
+
+	ret = socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, ipc_sockets);
+	ASSERT_EQ(ret, 0);
+
+	pid_coredump_server = fork();
+	ASSERT_GE(pid_coredump_server, 0);
+	if (pid_coredump_server == 0) {
+		int fd_server = -1, fd_coredump = -1, fd_peer_pidfd = -1;
+		int fd_thread_pidfd = -1, fd_core_file = -1;
+		struct pidfd_info thread_info = {};
+		int exit_code = EXIT_FAILURE;
+
+		close(ipc_sockets[0]);
+
+		fd_server = create_and_listen_unix_socket("/tmp/coredump.socket");
+		if (fd_server < 0) {
+			fprintf(stderr, "socket_coredump_thread: listen socket failed: %m\n");
+			goto out;
+		}
+
+		if (write_nointr(ipc_sockets[1], "1", 1) < 0) {
+			fprintf(stderr, "socket_coredump_thread: ipc write failed: %m\n");
+			goto out;
+		}
+
+		close(ipc_sockets[1]);
+
+		fd_coredump = accept4(fd_server, NULL, NULL, SOCK_CLOEXEC);
+		if (fd_coredump < 0) {
+			fprintf(stderr, "socket_coredump_thread: accept4 failed: %m\n");
+			goto out;
+		}
+
+		fd_peer_pidfd = get_peer_pidfd(fd_coredump);
+		if (fd_peer_pidfd < 0) {
+			fprintf(stderr, "socket_coredump_thread: get_peer_pidfd failed\n");
+			goto out;
+		}
+
+		fd_thread_pidfd = get_peer_pidfd_thread(fd_coredump);
+		if (fd_thread_pidfd < 0) {
+			fprintf(stderr, "socket_coredump_thread: get_peer_pidfd_thread failed\n");
+			goto out;
+		}
+
+		if (!get_pidfd_info(fd_peer_pidfd, &info) ||
+		    !get_pidfd_info(fd_thread_pidfd, &thread_info)) {
+			fprintf(stderr, "socket_coredump_thread: get_pidfd_info failed\n");
+			goto out;
+		}
+
+		/* The peer is the thread-group leader, the dumping thread is not. */
+		if (info.pid != info.tgid || thread_info.tgid != info.tgid ||
+		    thread_info.pid == thread_info.tgid) {
+			fprintf(stderr, "socket_coredump_thread: unexpected ids %d/%d and %d/%d\n",
+				info.pid, info.tgid, thread_info.pid, thread_info.tgid);
+			goto out;
+		}
+
+		if (!check_coredump_info(&info, "SO_PEERPIDFD") ||
+		    !check_coredump_info(&thread_info, "SO_PEERPIDFD_THREAD"))
+			goto out;
+
+		fd_core_file = open_coredump_tmpfile(self->fd_tmpfs_detached);
+		if (fd_core_file < 0) {
+			fprintf(stderr, "socket_coredump_thread: core tmpfile failed: %m\n");
+			goto out;
+		}
+
+		for (;;) {
+			char buffer[4096];
+			ssize_t bytes_read, bytes_write;
+
+			bytes_read = read(fd_coredump, buffer, sizeof(buffer));
+			if (bytes_read < 0) {
+				fprintf(stderr, "socket_coredump_thread: core read failed: %m\n");
+				goto out;
+			}
+
+			if (bytes_read == 0)
+				break;
+
+			bytes_write = write(fd_core_file, buffer, bytes_read);
+			if (bytes_read != bytes_write) {
+				fprintf(stderr, "socket_coredump_thread: core write %zd/%zd: %m\n",
+					bytes_read, bytes_write);
+				goto out;
+			}
+		}
+
+		exit_code = EXIT_SUCCESS;
+		fprintf(stderr, "socket_coredump_thread: completed successfully\n");
+out:
+		if (fd_core_file >= 0)
+			close(fd_core_file);
+		if (fd_thread_pidfd >= 0)
+			close(fd_thread_pidfd);
+		if (fd_peer_pidfd >= 0)
+			close(fd_peer_pidfd);
+		if (fd_coredump >= 0)
+			close(fd_coredump);
+		if (fd_server >= 0)
+			close(fd_server);
+		_exit(exit_code);
+	}
+	self->pid_coredump_server = pid_coredump_server;
+
+	EXPECT_EQ(close(ipc_sockets[1]), 0);
+	ASSERT_EQ(read_nointr(ipc_sockets[0], &c, 1), 1);
+	EXPECT_EQ(close(ipc_sockets[0]), 0);
+
+	pid = fork();
+	ASSERT_GE(pid, 0);
+	if (pid == 0)
+		crashing_child_thread();
+
+	pidfd = sys_pidfd_open(pid, 0);
+	ASSERT_GE(pidfd, 0);
+
+	waitpid(pid, &status, 0);
+	ASSERT_TRUE(WIFSIGNALED(status));
+	ASSERT_EQ(WTERMSIG(status), SIGSEGV);
+	ASSERT_TRUE(WCOREDUMP(status));
+
+	ASSERT_TRUE(get_pidfd_info(pidfd, &info));
+	ASSERT_TRUE(!!(info.mask & PIDFD_INFO_COREDUMP));
+	ASSERT_TRUE(!!(info.coredump_mask & PIDFD_COREDUMPED));
+	ASSERT_EQ(info.coredump_signal, SIGSEGV);
+
+	wait_and_check_coredump_server(pid_coredump_server, _metadata, self);
+}
+
 /*
  * Test: PIDFD_INFO_COREDUMP_SIGNAL via simple socket coredump with SIGABRT
  *
diff --git a/tools/testing/selftests/coredump/coredump_test.h b/tools/testing/selftests/coredump/coredump_test.h
index ed47f01fa53c5..4212656e31f01 100644
--- a/tools/testing/selftests/coredump/coredump_test.h
+++ b/tools/testing/selftests/coredump/coredump_test.h
@@ -27,10 +27,12 @@ FIXTURE(coredump)
 /* Shared helper function declarations */
 void *do_nothing(void *arg);
 void crashing_child(void);
+void crashing_child_thread(void);
 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);
 
 /* Inline helper that uses harness types */
diff --git a/tools/testing/selftests/coredump/coredump_test_helpers.c b/tools/testing/selftests/coredump/coredump_test_helpers.c
index 2a20faf9cb0ad..36306069f62e5 100644
--- a/tools/testing/selftests/coredump/coredump_test_helpers.c
+++ b/tools/testing/selftests/coredump/coredump_test_helpers.c
@@ -13,6 +13,7 @@
 #include <string.h>
 #include <sys/epoll.h>
 #include <sys/ioctl.h>
+#include <sys/mman.h>
 #include <sys/socket.h>
 #include <sys/types.h>
 #include <sys/un.h>
@@ -38,6 +39,10 @@ struct _fixture_coredump_data {
 
 #define NUM_THREAD_SPAWN 128
 
+#ifndef SO_PEERPIDFD_THREAD
+#define SO_PEERPIDFD_THREAD 87
+#endif
+
 void *do_nothing(void *arg)
 {
 	(void)arg;
@@ -59,6 +64,36 @@ void crashing_child(void)
 	i = *(volatile int *)NULL;
 }
 
+static void *crashing_thread(void *arg)
+{
+	int *p;
+
+	(void)arg;
+
+	/* crash on purpose with SEGV_MAPERR */
+	p = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE,
+		 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+	if (p == MAP_FAILED)
+		return NULL;
+	munmap(p, PAGE_SIZE);
+	*p = 0;
+
+	return NULL;
+}
+
+void crashing_child_thread(void)
+{
+	pthread_t thread;
+	int i;
+
+	for (i = 0; i < NUM_THREAD_SPAWN; ++i)
+		pthread_create(&thread, NULL, do_nothing, NULL);
+
+	/* crash from a non-leader thread */
+	pthread_create(&thread, NULL, crashing_thread, NULL);
+	pause();
+}
+
 int create_detached_tmpfs(void)
 {
 	int fd_context, fd_tmpfs;
@@ -138,6 +173,20 @@ int get_peer_pidfd(int fd)
 	return fd_peer_pidfd;
 }
 
+int get_peer_pidfd_thread(int fd)
+{
+	int fd_peer_pidfd;
+	socklen_t fd_peer_pidfd_len = sizeof(fd_peer_pidfd);
+	int ret = getsockopt(fd, SOL_SOCKET, SO_PEERPIDFD_THREAD, &fd_peer_pidfd,
+			     &fd_peer_pidfd_len);
+	if (ret < 0) {
+		fprintf(stderr, "%s: getsockopt(SO_PEERPIDFD_THREAD) failed: %m\n", __func__);
+		return -1;
+	}
+	fprintf(stderr, "%s: successfully retrieved pidfd %d\n", __func__, fd_peer_pidfd);
+	return fd_peer_pidfd;
+}
+
 bool get_pidfd_info(int fd_peer_pidfd, struct pidfd_info *info)
 {
 	int ret;
diff --git a/tools/testing/selftests/net/af_unix/Makefile b/tools/testing/selftests/net/af_unix/Makefile
index a66f10fb0c231..45b841758f1bf 100644
--- a/tools/testing/selftests/net/af_unix/Makefile
+++ b/tools/testing/selftests/net/af_unix/Makefile
@@ -23,6 +23,8 @@ TEST_GEN_FILES := scm_rights_denial_lsm.bpf.o
 include ../../lib.mk
 include ../bpf.mk
 
+$(OUTPUT)/scm_pidfd: CFLAGS += -pthread
+
 $(OUTPUT)/scm_rights_denial_lsm: $(BPFOBJ)
 $(OUTPUT)/scm_rights_denial_lsm: CFLAGS += -I$(SCRATCH_DIR)/include
 $(OUTPUT)/scm_rights_denial_lsm: LDLIBS += -lelf -lz
diff --git a/tools/testing/selftests/net/af_unix/scm_pidfd.c b/tools/testing/selftests/net/af_unix/scm_pidfd.c
index 2c18b92a26035..cbe53fab44fc5 100644
--- a/tools/testing/selftests/net/af_unix/scm_pidfd.c
+++ b/tools/testing/selftests/net/af_unix/scm_pidfd.c
@@ -10,6 +10,7 @@
 #include <unistd.h>
 #include <string.h>
 #include <errno.h>
+#include <pthread.h>
 #include <sys/un.h>
 #include <sys/signal.h>
 #include <sys/types.h>
@@ -27,6 +28,18 @@
 #define SCM_PIDFD 0x04
 #endif
 
+#ifndef SCM_PIDFD_THREAD
+#define SCM_PIDFD_THREAD 0x05
+#endif
+
+#ifndef SO_PASSPIDFD_THREAD
+#define SO_PASSPIDFD_THREAD 86
+#endif
+
+#ifndef SO_PEERPIDFD_THREAD
+#define SO_PEERPIDFD_THREAD 87
+#endif
+
 #define CHILD_EXIT_CODE_OK 123
 
 static void child_die()
@@ -553,4 +566,593 @@ TEST_F(scm_pidfd, test)
 	close(pfd);
 }
 
+struct thread_ids {
+	pid_t pid;
+	pid_t tid;
+};
+
+#define MAX_WRITERS 2
+
+/* Used by writers to signal they've written, so we can sequence multiple writers */
+static int seq_pipe[2];
+
+static void *send_ids_thread(void *arg)
+{
+	int fd = *(int *)arg;
+	struct thread_ids ids = {
+		.pid = getpid(),
+		.tid = gettid(),
+	};
+	char sync;
+
+	if (send(fd, &ids, sizeof(ids), 0) != sizeof(ids))
+		return (void *)1;
+
+	/* let the client start the next writer, so the queue order is known */
+	if (write(seq_pipe[1], "1", 1) != 1)
+		return (void *)1;
+
+	/* stay alive until the receiver has looked at our pidfd */
+	if (read(fd, &sync, 1) != 1)
+		return (void *)1;
+
+	return NULL;
+}
+
+static void *send_ids_creds_thread(void *arg)
+{
+	int fd = *(int *)arg;
+	struct thread_ids ids = {
+		.pid = getpid(),
+		.tid = gettid(),
+	};
+	struct ucred ucred = {
+		.pid = getpid(),
+		.uid = getuid(),
+		.gid = getgid(),
+	};
+	char control[CMSG_SPACE(sizeof(ucred))] = { 0 };
+	struct iovec iov;
+	struct msghdr msg = { 0 };
+	struct cmsghdr *cmsg;
+	char sync;
+
+	iov.iov_base = &ids;
+	iov.iov_len = sizeof(ids);
+
+	msg.msg_iov = &iov;
+	msg.msg_iovlen = 1;
+	msg.msg_control = control;
+	msg.msg_controllen = sizeof(control);
+
+	cmsg = CMSG_FIRSTHDR(&msg);
+	cmsg->cmsg_level = SOL_SOCKET;
+	cmsg->cmsg_type = SCM_CREDENTIALS;
+	cmsg->cmsg_len = CMSG_LEN(sizeof(ucred));
+	memcpy(CMSG_DATA(cmsg), &ucred, sizeof(ucred));
+
+	if (sendmsg(fd, &msg, 0) != sizeof(ids))
+		return (void *)1;
+
+	/* signal we've written our info */
+	if (write(seq_pipe[1], "1", 1) != 1)
+		return (void *)1;
+
+	/* stay alive until the receiver has looked at our pidfd */
+	if (read(fd, &sync, 1) != 1)
+		return (void *)1;
+
+	return NULL;
+}
+
+/*
+ * Runs @nwriters copies of @sender, each in its own non-leader thread, one
+ * at a time so the queue order is known, then tells the parent on @ackfd
+ * that everything is queued.
+ */
+static void thread_client(int fd, int syncfd, int ackfd,
+			  void *(*sender)(void *), int nwriters)
+{
+	pthread_t writers[MAX_WRITERS];
+	void *ret;
+	char sync;
+	int i;
+
+	/* wait until the receiver enabled the options it wants */
+	if (read(syncfd, &sync, 1) != 1)
+		child_die();
+
+	for (i = 0; i < nwriters; i++) {
+		if (pthread_create(&writers[i], NULL, sender, &fd))
+			child_die();
+
+		if (read(seq_pipe[0], &sync, 1) != 1)
+			child_die();
+	}
+
+	if (write(ackfd, "1", 1) != 1)
+		child_die();
+
+	for (i = 0; i < nwriters; i++)
+		if (pthread_join(writers[i], &ret) || ret)
+			child_die();
+
+	exit(0);
+}
+
+struct pidfd_msg {
+	ssize_t len;
+	struct thread_ids ids;
+	struct pidfd_info tgid_info;
+	struct pidfd_info thread_info;
+	int tgid_flags;
+	int thread_flags;
+	bool have_tgid;
+	bool have_thread;
+};
+
+static int get_pidfd_info(int pidfd, struct pidfd_info *info)
+{
+	info->mask = PIDFD_INFO_PID;
+	if (ioctl(pidfd, PIDFD_GET_INFO, info)) {
+		log_err("ioctl(PIDFD_GET_INFO)");
+		return -1;
+	}
+
+	return 0;
+}
+
+/* One recvmsg(), reporting how many bytes came back and what the pidfd
+ * cmsgs that came with them say.
+ */
+static int read_pidfd_msg(int fd, struct pidfd_msg *out)
+{
+	char control[CMSG_SPACE(sizeof(int)) * 2] = { 0 };
+	int tgid_pidfd = -1, thread_pidfd = -1;
+	struct thread_ids buf[2] = { 0 };
+	struct msghdr msg = { 0 };
+	struct cmsghdr *cmsg;
+	struct iovec iov;
+
+	iov.iov_base = buf;
+	iov.iov_len = sizeof(buf);
+	msg.msg_iov = &iov;
+	msg.msg_iovlen = 1;
+	msg.msg_control = control;
+	msg.msg_controllen = sizeof(control);
+
+	out->len = recvmsg(fd, &msg, 0);
+	if (out->len < 0) {
+		log_err("recvmsg");
+		return -1;
+	}
+
+	if (msg.msg_flags & MSG_CTRUNC) {
+		log_err("recvmsg: control truncated");
+		return -1;
+	}
+
+	out->ids = buf[0];
+
+	for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL;
+	     cmsg = CMSG_NXTHDR(&msg, cmsg)) {
+		if (cmsg->cmsg_level != SOL_SOCKET)
+			continue;
+
+		if (cmsg->cmsg_type == SCM_PIDFD)
+			memcpy(&tgid_pidfd, CMSG_DATA(cmsg), sizeof(tgid_pidfd));
+		else if (cmsg->cmsg_type == SCM_PIDFD_THREAD)
+			memcpy(&thread_pidfd, CMSG_DATA(cmsg), sizeof(thread_pidfd));
+	}
+
+	out->have_tgid = tgid_pidfd >= 0;
+	out->have_thread = thread_pidfd >= 0;
+
+	if (out->have_tgid) {
+		if (get_pidfd_info(tgid_pidfd, &out->tgid_info))
+			return -1;
+		out->tgid_flags = fcntl(tgid_pidfd, F_GETFL);
+		close(tgid_pidfd);
+	}
+
+	if (out->have_thread) {
+		if (get_pidfd_info(thread_pidfd, &out->thread_info))
+			return -1;
+		out->thread_flags = fcntl(thread_pidfd, F_GETFL);
+		close(thread_pidfd);
+	}
+
+	return 0;
+}
+
+/*
+ * Runs @nwriters threads of one child process against a SOCK_STREAM pair,
+ * all of them queued before the parent reads. SO_PASSPIDFD is set when
+ * @want_tgid is given, SO_PASSPIDFD_THREAD when @want_thread is. @nread
+ * reads are returned in @out.
+ */
+static int pidfd_flow(void *(*sender)(void *), int nwriters, bool want_tgid,
+		      bool want_thread, struct pidfd_msg *out, int nread)
+{
+	int child_status = 0;
+	int syncpipe[2];
+	int ackpipe[2];
+	int sk[2];
+	int on = 1;
+	char sync;
+	pid_t child;
+	int i;
+
+	if (nwriters > MAX_WRITERS)
+		return -1;
+
+	if (socketpair(AF_UNIX, SOCK_STREAM, 0, sk))
+		return -1;
+	if (pipe(syncpipe) || pipe(ackpipe) || pipe(seq_pipe))
+		return -1;
+
+	child = fork();
+	if (child < 0)
+		return -1;
+
+	if (child == 0) {
+		close(sk[0]);
+		close(syncpipe[1]);
+		close(ackpipe[0]);
+		thread_client(sk[1], syncpipe[0], ackpipe[1], sender, nwriters);
+	}
+	close(sk[1]);
+	close(syncpipe[0]);
+	close(ackpipe[1]);
+	close(seq_pipe[0]);
+	close(seq_pipe[1]);
+
+	if (want_tgid &&
+	    setsockopt(sk[0], SOL_SOCKET, SO_PASSPIDFD, &on, sizeof(on))) {
+		log_err("Failed to set SO_PASSPIDFD");
+		return -1;
+	}
+
+	if (want_thread &&
+	    setsockopt(sk[0], SOL_SOCKET, SO_PASSPIDFD_THREAD, &on, sizeof(on))) {
+		log_err("Failed to set SO_PASSPIDFD_THREAD");
+		return -1;
+	}
+
+	/* let the child know the options are set, it can write now */
+	if (write(syncpipe[1], "1", 1) != 1)
+		return -1;
+	close(syncpipe[1]);
+
+	/* wait until every writer has queued its message */
+	if (read(ackpipe[0], &sync, 1) != 1)
+		return -1;
+	close(ackpipe[0]);
+
+	for (i = 0; i < nread; i++)
+		if (read_pidfd_msg(sk[0], &out[i]))
+			return -1;
+
+	/* release the writers */
+	for (i = 0; i < nwriters; i++)
+		if (write(sk[0], "x", 1) != 1)
+			return -1;
+	close(sk[0]);
+
+	waitpid(child, &child_status, 0);
+	if (!WIFEXITED(child_status) || WEXITSTATUS(child_status))
+		return -1;
+
+	return 0;
+}
+
+static int sockopt_set(int fd, int optname, int val)
+{
+	return setsockopt(fd, SOL_SOCKET, optname, &val, sizeof(val));
+}
+
+static int sockopt_get(int fd, int optname)
+{
+	socklen_t len = sizeof(int);
+	int val = -1;
+
+	if (getsockopt(fd, SOL_SOCKET, optname, &val, &len))
+		return -1;
+
+	return val;
+}
+
+TEST(scm_pidfd_setsockopt_values)
+{
+	int sk[2];
+
+	ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_STREAM, 0, sk));
+
+	/* Verify that the options are truly set independently */
+	ASSERT_EQ(0, sockopt_set(sk[0], SO_PASSPIDFD_THREAD, 1));
+	ASSERT_EQ(1, sockopt_get(sk[0], SO_PASSPIDFD_THREAD));
+	ASSERT_EQ(0, sockopt_get(sk[0], SO_PASSPIDFD));
+
+	ASSERT_EQ(0, sockopt_set(sk[0], SO_PASSPIDFD, 1));
+	ASSERT_EQ(1, sockopt_get(sk[0], SO_PASSPIDFD));
+	ASSERT_EQ(1, sockopt_get(sk[0], SO_PASSPIDFD_THREAD));
+
+	/* Verify that the options are truly cleared independently */
+	ASSERT_EQ(0, sockopt_set(sk[0], SO_PASSPIDFD, 0));
+	ASSERT_EQ(0, sockopt_get(sk[0], SO_PASSPIDFD));
+	ASSERT_EQ(1, sockopt_get(sk[0], SO_PASSPIDFD_THREAD));
+
+	ASSERT_EQ(0, sockopt_set(sk[0], SO_PASSPIDFD_THREAD, 0));
+	ASSERT_EQ(0, sockopt_get(sk[0], SO_PASSPIDFD_THREAD));
+	ASSERT_EQ(0, sockopt_get(sk[0], SO_PASSPIDFD));
+
+	close(sk[0]);
+	close(sk[1]);
+}
+
+/* A receiver that only asked about the process cannot tell the two
+ * threads apart, so their writes are glued into one read.
+ */
+TEST(scm_pidfd_stream_glues_threads)
+{
+	struct pidfd_msg msg[1] = { 0 };
+
+	ASSERT_EQ(0, pidfd_flow(send_ids_thread, 2, true, false, msg, 1));
+	EXPECT_EQ(sizeof(struct thread_ids) * 2, msg[0].len);
+
+	EXPECT_TRUE(msg[0].have_tgid);
+	EXPECT_FALSE(msg[0].have_thread);
+	EXPECT_EQ(msg[0].ids.pid, msg[0].tgid_info.pid);
+	EXPECT_EQ(msg[0].ids.pid, msg[0].tgid_info.tgid);
+}
+
+/* A receiver asking for both thread and process pidfd should get a unique
+ * msg for each thread writing
+ */
+TEST(scm_pidfd_thread_stream_splits_on_threads)
+{
+	struct pidfd_msg msg[2] = { 0 };
+	int i;
+
+	ASSERT_EQ(0, pidfd_flow(send_ids_thread, 2, true, true, msg, 2));
+
+	for (i = 0; i < 2; i++) {
+		EXPECT_EQ(sizeof(struct thread_ids), msg[i].len);
+		EXPECT_TRUE(msg[i].have_tgid);
+		EXPECT_TRUE(msg[i].have_thread);
+
+		/* Make sure the info makes sense for the pidfd type */
+		EXPECT_EQ(msg[i].ids.pid, msg[i].tgid_info.pid);
+		EXPECT_EQ(msg[i].ids.pid, msg[i].tgid_info.tgid);
+		EXPECT_EQ(msg[i].ids.tid, msg[i].thread_info.pid);
+		EXPECT_EQ(msg[i].ids.pid, msg[i].thread_info.tgid);
+		EXPECT_NE(msg[i].ids.pid, msg[i].ids.tid);
+	}
+
+	/* Make sure we really got unique threads per message */
+	EXPECT_NE(msg[0].ids.tid, msg[1].ids.tid);
+	EXPECT_EQ(msg[0].ids.pid, msg[1].ids.pid);
+	EXPECT_EQ(msg[0].tgid_info.pid, msg[1].tgid_info.pid);
+	EXPECT_NE(msg[0].thread_info.pid, msg[1].thread_info.pid);
+}
+
+/* Sends from the thread-group leader */
+static int leader_flow(bool want_thread, struct pidfd_msg *out)
+{
+	struct thread_ids ids = {
+		.pid = getpid(),
+		.tid = gettid(),
+	};
+	int sk[2];
+	int on = 1;
+	int ret;
+
+	if (socketpair(AF_UNIX, SOCK_STREAM, 0, sk))
+		return -1;
+
+	if (setsockopt(sk[0], SOL_SOCKET, SO_PASSPIDFD, &on, sizeof(on))) {
+		log_err("Failed to set SO_PASSPIDFD");
+		return -1;
+	}
+
+	if (want_thread &&
+	    setsockopt(sk[0], SOL_SOCKET, SO_PASSPIDFD_THREAD, &on, sizeof(on))) {
+		log_err("Failed to set SO_PASSPIDFD_THREAD");
+		return -1;
+	}
+
+	if (send(sk[1], &ids, sizeof(ids), 0) != sizeof(ids)) {
+		log_err("send");
+		return -1;
+	}
+
+	ret = read_pidfd_msg(sk[0], out);
+
+	close(sk[0]);
+	close(sk[1]);
+
+	return ret;
+}
+
+TEST(scm_pidfd_leader_sender)
+{
+	struct pidfd_msg msg = { 0 };
+
+	ASSERT_EQ(getpid(), gettid());
+
+	ASSERT_EQ(0, leader_flow(false, &msg));
+	ASSERT_TRUE(msg.have_tgid);
+	EXPECT_FALSE(msg.have_thread);
+
+	EXPECT_EQ(getpid(), msg.tgid_info.pid);
+	EXPECT_EQ(getpid(), msg.tgid_info.tgid);
+	EXPECT_FALSE(msg.tgid_flags & O_EXCL);
+}
+
+TEST(scm_pidfd_thread_leader_sender)
+{
+	struct pidfd_msg msg = { 0 };
+
+	ASSERT_EQ(getpid(), gettid());
+
+	ASSERT_EQ(0, leader_flow(true, &msg));
+	ASSERT_TRUE(msg.have_tgid);
+	ASSERT_TRUE(msg.have_thread);
+
+	EXPECT_EQ(getpid(), msg.tgid_info.pid);
+	EXPECT_EQ(getpid(), msg.tgid_info.tgid);
+	EXPECT_EQ(getpid(), msg.thread_info.pid);
+	EXPECT_EQ(getpid(), msg.thread_info.tgid);
+
+	EXPECT_FALSE(msg.tgid_flags & O_EXCL);
+	EXPECT_TRUE(msg.thread_flags & O_EXCL);
+}
+
+TEST(scm_pidfd_thread_and_group)
+{
+	struct pidfd_msg msg = { 0 };
+
+	ASSERT_EQ(0, pidfd_flow(send_ids_thread, 1, true, true, &msg, 1));
+	ASSERT_NE(msg.ids.pid, msg.ids.tid);
+	ASSERT_TRUE(msg.have_tgid);
+	ASSERT_TRUE(msg.have_thread);
+
+	EXPECT_EQ(msg.ids.pid, msg.tgid_info.pid);
+	EXPECT_EQ(msg.ids.pid, msg.tgid_info.tgid);
+
+	EXPECT_EQ(msg.ids.tid, msg.thread_info.pid);
+	EXPECT_EQ(msg.ids.pid, msg.thread_info.tgid);
+}
+
+TEST(scm_pidfd_thread)
+{
+	struct pidfd_msg msg = { 0 };
+
+	ASSERT_EQ(0, pidfd_flow(send_ids_thread, 1, false, true, &msg, 1));
+	ASSERT_NE(msg.ids.pid, msg.ids.tid);
+	ASSERT_TRUE(msg.have_thread);
+	EXPECT_FALSE(msg.have_tgid);
+	EXPECT_EQ(msg.ids.tid, msg.thread_info.pid);
+	EXPECT_EQ(msg.ids.pid, msg.thread_info.tgid);
+}
+
+TEST(scm_pidfd_thread_group)
+{
+	struct pidfd_msg msg = { 0 };
+
+	ASSERT_EQ(0, pidfd_flow(send_ids_thread, 1, true, false, &msg, 1));
+	ASSERT_NE(msg.ids.pid, msg.ids.tid);
+	ASSERT_TRUE(msg.have_tgid);
+	EXPECT_FALSE(msg.have_thread);
+	EXPECT_EQ(msg.ids.pid, msg.tgid_info.pid);
+	EXPECT_EQ(msg.ids.pid, msg.tgid_info.tgid);
+}
+
+TEST(scm_pidfd_thread_creds)
+{
+	struct pidfd_msg msg = { 0 };
+
+	ASSERT_EQ(0, pidfd_flow(send_ids_creds_thread, 1, true, true, &msg, 1));
+	ASSERT_NE(msg.ids.pid, msg.ids.tid);
+	ASSERT_TRUE(msg.have_tgid);
+	ASSERT_TRUE(msg.have_thread);
+	EXPECT_EQ(msg.ids.pid, msg.tgid_info.pid);
+	EXPECT_EQ(msg.ids.pid, msg.tgid_info.tgid);
+	EXPECT_EQ(msg.ids.tid, msg.thread_info.pid);
+	EXPECT_EQ(msg.ids.pid, msg.thread_info.tgid);
+}
+
+static void *peer_connect_thread(void *arg)
+{
+	struct sock_addr *sa = arg;
+	struct thread_ids ids = {
+		.pid = getpid(),
+		.tid = gettid(),
+	};
+	int fd;
+	char sync;
+
+	fd = socket(AF_UNIX, SOCK_STREAM, 0);
+	if (fd < 0)
+		return (void *)1;
+
+	if (connect(fd, (struct sockaddr *)&sa->listen_addr, sa->addrlen))
+		return (void *)1;
+
+	if (send(fd, &ids, sizeof(ids), 0) != sizeof(ids))
+		return (void *)1;
+
+	/* stay alive until the server has looked at our pidfd */
+	if (read(fd, &sync, 1) != 1)
+		return (void *)1;
+
+	close(fd);
+	return NULL;
+}
+
+static int peer_pidfd_info(int fd, int optname, struct pidfd_info *info)
+{
+	int pidfd;
+	socklen_t len = sizeof(pidfd);
+
+	if (getsockopt(fd, SOL_SOCKET, optname, &pidfd, &len)) {
+		log_err("getsockopt(SO_PEERPIDFD*)");
+		return -1;
+	}
+
+	info->mask = PIDFD_INFO_PID;
+	if (ioctl(pidfd, PIDFD_GET_INFO, info)) {
+		log_err("ioctl(PIDFD_GET_INFO)");
+		close(pidfd);
+		return -1;
+	}
+
+	close(pidfd);
+	return 0;
+}
+
+/* SO_PEERPIDFD_THREAD returns a pidfd for the peer's connecting thread. */
+TEST(so_peerpidfd_thread)
+{
+	struct sock_addr sa;
+	struct thread_ids ids;
+	struct pidfd_info info;
+	pthread_t thread;
+	void *tret;
+	int server, cfd;
+
+	server = socket(AF_UNIX, SOCK_STREAM, 0);
+	ASSERT_LE(0, server);
+
+	fill_sockaddr(&sa, true);
+	ASSERT_EQ(0, bind(server, (struct sockaddr *)&sa.listen_addr, sa.addrlen));
+	ASSERT_EQ(0, listen(server, 1));
+
+	ASSERT_EQ(0, pthread_create(&thread, NULL, peer_connect_thread, &sa));
+
+	cfd = accept(server, NULL, NULL);
+	ASSERT_LE(0, cfd);
+
+	ASSERT_EQ(sizeof(ids), recv(cfd, &ids, sizeof(ids), MSG_WAITALL));
+	ASSERT_NE(ids.pid, ids.tid);
+
+	/* SO_PEERPIDFD refers to the peer's thread-group. */
+	ASSERT_EQ(0, peer_pidfd_info(cfd, SO_PEERPIDFD, &info));
+	EXPECT_EQ(ids.pid, info.pid);
+	EXPECT_EQ(ids.pid, info.tgid);
+
+	/* SO_PEERPIDFD_THREAD refers to the connecting thread. */
+	ASSERT_EQ(0, peer_pidfd_info(cfd, SO_PEERPIDFD_THREAD, &info));
+	EXPECT_EQ(ids.tid, info.pid);
+	EXPECT_EQ(ids.pid, info.tgid);
+
+	/* release the connecting thread */
+	ASSERT_EQ(1, write(cfd, "x", 1));
+	ASSERT_EQ(0, pthread_join(thread, &tret));
+	ASSERT_EQ(NULL, tret);
+
+	close(cfd);
+	close(server);
+}
+
 TEST_HARNESS_MAIN

3/2 2026/09/29 11:02 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 27488
							output: 34
							thoughts: 1429
						

Thoughts:
**Fuzzing Analysis: Thread-Level PIDFD Support**

Okay, let's break this down. My initial assessment is that this patch, introducing thread-level PIDFD support within the socket credential and getsockopt/setsockopt mechanisms, is *definitely* worth fuzzing with syzkaller. The changes touch core networking components (AF_UNIX sockets, PIDFS), and specifically, new sock options (`SO_PASSPIDFD_THREAD`, `SO_PEERPIDFD_THREAD`, `SCM_PIDFD_THREAD`), so there's plenty of new surface area. The guideline checks are a formality at this point; we're dealing with reachable executable code, no question.

We're going to want to focus our fuzzing efforts. Let's list the functions that look promising:

1.  `sk_getsockopt_peerpidfd`: It's in `net/core/sock.c`. Is it static? Yes, it's static. Dang! We should double-check to see if the compiler inlines it or if it is still a symbol.
2.  `scm_pidfd_recv`: This is also static and in `net/core/scm.c`, not promising.
3.  `scm_recv_unix`: This is not static.
4.  `unix_skb_scm_eq`, `unix_maybe_add_creds`, `prepare_peercred`, `update_peercred`, `copy_peercred`: These are interesting in `net/unix/af_unix.c`. `unix_stream_read_generic` is a large function and likely deserves special attention.
5.  `__pidfs_register_pids`: This is the real gem in `fs/pidfs.c`. It's *not* static, so it's a good candidate!
6.  `pidfs_coredump`: This one is also in `fs/pidfs.c` and is not static.
7.  `coredump_sock_connect`, `umh_coredump_setup`: In `fs/coredump.c`, a good idea to focus on.

So, the focus symbol list is shaping up nicely. We need to verify the symbol table to be completely sure.



4/2 2026/09/29 11:02 tool grepper
0m Args:
{
  "Expression": "__pidfs_register_pids",
  "PathPrefix": "fs/pidfs.c"
}

Results:
{
  "Output": "fs/pidfs.c=1045=int pidfs_register_pid_gfp(struct pid *pid, gfp_t gfp)\n--\nfs/pidfs.c-1080-/* Register the pids up to pid type @last of @pids in pidfs. */\nfs/pidfs.c:1081:int __pidfs_register_pids(struct pid *const *pids, enum pid_type last)\nfs/pidfs.c-1082-{\n"
}

5/2 2026/09/29 11:02 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 29575
							output: 32
							thoughts: 56
						

Thoughts:
Here's my thought process, as if I were analyzing that code:

**Analyzing Potential Conflict Points in the Kernel**

Okay, so I'm looking for potential conflicts or areas that warrant further investigation. The first function I identified, `__pidfs_register_pids`, is clearly a non-static function residing within `fs/pidfs.c`. This suggests it's potentially exposed beyond the immediate scope of that file, making it a candidate for interaction with other parts of the kernel. This immediately flags it as something to keep in mind, even if I don't see an immediate issue.

Now, the next function on the list is `scm_recv_unix`. This one sounds like it might be involved in network communication, specifically Unix domain sockets, judging by the "scm" prefix. That's a different area of the kernel, potentially unrelated, but still worth cross-referencing.

Therefore, the logical next step is to examine `net/core/scm.c` to understand the context of `scm_recv_unix`. Understanding its purpose and how it interacts with the broader network stack will help me evaluate any potential interactions or conflicts that might arise with `__pidfs_register_pids`. I need to assess whether these functions are truly distinct and their operations isolated.



6/2 2026/09/29 11:02 tool grepper
0m Args:
{
  "Expression": "scm_recv_unix",
  "PathPrefix": "net/core/scm.c"
}

Results:
{
  "Output": "net/core/scm.c=582=EXPORT_SYMBOL(scm_recv);\nnet/core/scm.c-583-\nnet/core/scm.c:584:void scm_recv_unix(struct socket *sock, struct msghdr *msg,\nnet/core/scm.c-585-\t\t   struct scm_cookie *scm, int flags)\n"
}

7/2 2026/09/29 11:02 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 30039
							output: 36
							thoughts: 266
						

Thoughts:
**My Analysis of Socket Options and Inline Functions**

Okay, so I'm looking at `scm_recv_unix`, which I know is non-static and lives in `net/core/scm.c`. But what about `sk_getsockopt_peerpidfd`? I need to clarify whether it's static or not. Ah, yes, it's declared as `static int sk_getsockopt_peerpidfd(...)`. Now, the interesting question is whether this static function is inlined by the compiler. Because if it is inlined, then that could have performance implications.

Hold on, I see that `sk_getsockopt` calls `sk_getsockopt_peerpidfd` twice! Specifically:

```c
sk_getsockopt(..., SO_PEERPIDFD, ...) {
  return sk_getsockopt_peerpidfd(sk, PIDTYPE_TGID, ...);
}

sk_getsockopt(..., SO_PEERPIDFD_THREAD, ...) {
  return sk_getsockopt_peerpidfd(sk, PIDTYPE_PID, ...);
}
```

Wait, static functions *can* be inlined, or they can't be inlined. But then the whole inlining thing is complicated by the fact that `sk_getsockopt` *itself* is non-static. Though perhaps it is ubiquitous, and therefore a candidate for inlining? Hang on, `sk_getsockopt` is just the getsockopt handler for the `SOL_SOCKET` level.

Okay, let me shift gears and review what changed in `net/unix/af_unix.c`. That will help me understand the context of these `getsockopt` calls. Let's see...



8/2 2026/09/29 11:03 tool grepper
0m Args:
{
  "Expression": "unix_stream_read_generic",
  "PathPrefix": "net/unix/af_unix.c"
}

Results:
{
  "Output": "net/unix/af_unix.c=2878=static int unix_stream_read_skb(struct sock *sk, skb_read_actor_t recv_actor)\n--\nnet/unix/af_unix.c-2923-\nnet/unix/af_unix.c:2924:static int unix_stream_read_generic(struct unix_stream_read_state *state,\nnet/unix/af_unix.c-2925-\t\t\t\t    bool freezable)\n--\nnet/unix/af_unix.c=3144=int __unix_stream_recvmsg(struct sock *sk, struct msghdr *msg,\n--\nnet/unix/af_unix.c-3154-\nnet/unix/af_unix.c:3155:\treturn unix_stream_read_generic(\u0026state, true);\nnet/unix/af_unix.c-3156-}\n--\nnet/unix/af_unix.c=3158=static int unix_stream_recvmsg(struct socket *sock, struct msghdr *msg,\n--\nnet/unix/af_unix.c-3175-#endif\nnet/unix/af_unix.c:3176:\treturn unix_stream_read_generic(\u0026state, true);\nnet/unix/af_unix.c-3177-}\n--\nnet/unix/af_unix.c=3188=static ssize_t unix_stream_splice_read(struct socket *sock,  loff_t *ppos,\n--\nnet/unix/af_unix.c-3206-\nnet/unix/af_unix.c:3207:\treturn unix_stream_read_generic(\u0026state, false);\nnet/unix/af_unix.c-3208-}\n"
}

9/2 2026/09/29 11:03 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 31170
							output: 45
							thoughts: 93
						

Thoughts:
Here's my thought process, as it stands:

**Navigating Credential Management in the UNIX Domain Socket Code**

Okay, so I'm digging into how credentials are handled within the UNIX domain socket implementation – specifically, `net/unix/af_unix.c`. I've got a mental checklist: `prepare_peercred`, `update_peercred`, `copy_peercred`, `unix_skb_scm_eq`, and `unix_maybe_add_creds` are the key functions that immediately jump out as being relevant to how credentials are managed.

Now, I need to understand the call flow and dependencies. The next logical step is to figure out where those credential-related functions, specifically `prepare_peercred`, `update_peercred`, and `copy_peercred`, are actually *called* within this `af_unix.c` file. Time to deploy the trusty `grep` command, I think, and see what the code reveals about the invocation patterns. Let's see what's what!



10/2 2026/09/29 11:03 tool grepper
0m Args:
{
  "Expression": "(prepare_peercred|update_peercred|copy_peercred)",
  "PathPrefix": "net/unix/af_unix.c"
}

Results:
{
  "Output": "net/unix/af_unix.c=739=struct unix_peercred {\n--\nnet/unix/af_unix.c-743-\nnet/unix/af_unix.c:744:static inline int prepare_peercred(struct unix_peercred *peercred)\nnet/unix/af_unix.c-745-{\n--\nnet/unix/af_unix.c=770=static inline void init_peercred(struct sock *sk,\n--\nnet/unix/af_unix.c-776-\nnet/unix/af_unix.c:777:static void update_peercred(struct sock *sk, struct unix_peercred *peercred)\nnet/unix/af_unix.c-778-{\n--\nnet/unix/af_unix.c-789-\nnet/unix/af_unix.c:790:static void copy_peercred(struct sock *sk, struct sock *peersk)\nnet/unix/af_unix.c-791-{\n--\nnet/unix/af_unix.c=806=static int unix_listen(struct socket *sock, int backlog)\n--\nnet/unix/af_unix.c-818-\t\tgoto out;\t/* No listens on an unbound socket */\nnet/unix/af_unix.c:819:\terr = prepare_peercred(\u0026peercred);\nnet/unix/af_unix.c-820-\tif (err)\n--\nnet/unix/af_unix.c-831-\t/* set credentials so connect can copy them */\nnet/unix/af_unix.c:832:\tupdate_peercred(sk, \u0026peercred);\nnet/unix/af_unix.c-833-\terr = 0;\n--\nnet/unix/af_unix.c=1632=static int unix_stream_connect(struct socket *sock, struct sockaddr_unsized *uaddr,\n--\nnet/unix/af_unix.c-1660-\nnet/unix/af_unix.c:1661:\terr = prepare_peercred(\u0026peercred);\nnet/unix/af_unix.c-1662-\tif (err)\n--\nnet/unix/af_unix.c-1780-\t/* Set credentials */\nnet/unix/af_unix.c:1781:\tcopy_peercred(sk, other);\nnet/unix/af_unix.c-1782-\n--\nnet/unix/af_unix.c=1812=static int unix_socketpair(struct socket *socka, struct socket *sockb)\n--\nnet/unix/af_unix.c-1817-\nnet/unix/af_unix.c:1818:\terr = prepare_peercred(\u0026ska_peercred);\nnet/unix/af_unix.c-1819-\tif (err)\n--\nnet/unix/af_unix.c-1821-\nnet/unix/af_unix.c:1822:\terr = prepare_peercred(\u0026skb_peercred);\nnet/unix/af_unix.c-1823-\tif (err) {\n"
}

11/2 2026/09/29 11:03 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 32316
							output: 37
							thoughts: 54
						

Thoughts:
Okay, let's break this down.

**Analyzing Function Call Relationships in the Unix Domain Code**

Alright, my analysis begins with `prepare_peercred`. It's defined as `static inline`, so it's a simple, localized function. It's called by `unix_listen`, `unix_stream_connect`, and `unix_socketpair`. Okay, that's straightforward enough – those are the key points in this context. Now, the next logical question is, where does `unix_maybe_add_creds` fit into this picture? I need to understand its relationship to these other functions. I need to know where *it* gets called to understand the larger control flow and data flow. Knowing that would give me a more complete overview of the system.



12/2 2026/09/29 11:03 tool grepper
0m Args:
{
  "Expression": "unix_maybe_add_creds",
  "PathPrefix": "net/unix/af_unix.c"
}

Results:
{
  "Output": "net/unix/af_unix.c=2004=static void unix_skb_to_scm(struct sk_buff *skb, struct scm_cookie *scm)\n--\nnet/unix/af_unix.c-2013-/**\nnet/unix/af_unix.c:2014: * unix_maybe_add_creds() - Adds current task uid/gid and struct pid to skb if needed.\nnet/unix/af_unix.c-2015- * @skb: skb to attach creds to.\n--\nnet/unix/af_unix.c-2025- */\nnet/unix/af_unix.c:2026:static int unix_maybe_add_creds(struct sk_buff *skb, const struct sock *sk,\nnet/unix/af_unix.c-2027-\t\t\t\tconst struct sock *other)\n--\nnet/unix/af_unix.c=2096=static int unix_dgram_sendmsg(struct socket *sock, struct msghdr *msg,\n--\nnet/unix/af_unix.c-2190-\nnet/unix/af_unix.c:2191:\terr = unix_maybe_add_creds(skb, sk, other);\nnet/unix/af_unix.c-2192-\tif (err)\n--\nnet/unix/af_unix.c=2330=static int queue_oob(struct sock *sk, struct msghdr *msg, struct sock *other,\n--\nnet/unix/af_unix.c-2345-\nnet/unix/af_unix.c:2346:\terr = unix_maybe_add_creds(skb, sk, other);\nnet/unix/af_unix.c-2347-\tif (err)\n--\nnet/unix/af_unix.c=2390=static int unix_stream_sendmsg(struct socket *sock, struct msghdr *msg,\n--\nnet/unix/af_unix.c-2463-\nnet/unix/af_unix.c:2464:\t\terr = unix_maybe_add_creds(skb, sk, other);\nnet/unix/af_unix.c-2465-\t\tif (err)\n"
}

13/2 2026/09/29 11:03 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 33142
							output: 26
							thoughts: 309
						

Thoughts:
**Investigating the Reach of `unix_maybe_add_creds`**

Okay, so I'm digging into `unix_maybe_add_creds`. It's a static function, and from a quick glance, it's called by `unix_dgram_sendmsg`, `queue_oob`, and `unix_stream_sendmsg`. Hmm, a key question here is whether it's a distinct symbol or if it's potentially inlined. That's going to influence how widespread its effects are. Time to start the deep dive.

First stop, `net/core/scm.c`. I'll scan that quickly for related functions: `__scm_send`, `scm_pidfd_recv`, and `scm_recv_unix` are all on my radar. Then over to `net/core/sock.c` to look at stuff like `sk_getsockopt_peerpidfd`, `sk_setsockopt`, and `sk_getsockopt`, anything potentially interacting with the same underlying mechanisms. Next, I'll branch out to `fs/coredump.c`, curious about `coredump_sock_connect` and `umh_coredump_setup`. Finally, `fs/pidfs.c` is on the list, specifically `__pidfs_register_pids` and `pidfs_coredump`. The goal is to see how this function threads its way through the core.

Now, let's look for any relevant `CONFIG` dependencies. I need to figure out what configurations might gate its behavior or the behavior of code that calls it. Kconfig is the key here. I'll search for things like UNIX, PIDFD, COREDUMP, and anything else that looks relevant. Okay, in `fs/pidfs.c`, `pidfs_coredump` is guarded by `#ifdef CONFIG_COREDUMP` – that's a good data point. AF_UNIX is `CONFIG_UNIX` of course. But what about PIDFS itself? Is it always built, dependent on something, or a separate configuration option? Let's grep through Kconfig to figure that out.



14/2 2026/09/29 11:03 tool grepper
0m Error:
no matches

Args:
{
  "Expression": "config.*PIDFS",
  "PathPrefix": "fs/"
}

Results:
{
  "error": "no matches"
}

15/2 2026/09/29 11:03 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 33951
							output: 24
							thoughts: 12
						

Thoughts:
Okay, here's my take on those thoughts, tailored for an expert audience:

**Kernel Investigation: The Hunt for "pidfs"**

Alright, let's dive in. I need to track down how "pidfs" is handled within the kernel, specifically its integration points. My initial instinct is to start broad and quickly narrow the focus. The `fs/Makefile` feels like the logical jumping-off point. It's the central hub for filesystem-related build rules, so any inclusion or build-time configuration for "pidfs" should be declared or referenced there. I expect to find a potential source file related to pidfs that may reveal where pidfs is defined, or where other configuration or initilization happens. From there, I can trace the dependencies and understand how it gets incorporated into the broader filesystem landscape. I'm anticipating this to be a straightforward hunt, but experience tells me to be prepared for indirect inclusions or conditional builds. It's all about following the breadcrumbs from that `Makefile`.



16/2 2026/09/29 11:03 tool grepper
0m Args:
{
  "Expression": "pidfs",
  "PathPrefix": "fs/"
}

Results:
{
  "Output": "\nFull output is too long, showing 500 out of 536 lines.\nUse more precise expression if possible.\n\nfs/Makefile=10=obj-y :=\topen.o read_write.o file_table.o super.o \\\n--\nfs/Makefile-17-\t\tfs_dirent.o fs_context.o fs_parser.o fsopen.o init.o \\\nfs/Makefile:18:\t\tkernel_read_file.o mnt_idmapping.o remap_range.o pidfs.o \\\nfs/Makefile-19-\t\tfile_attr.o fserror.o nullfs.o failfs.o\n--\nfs/coredump.c-45-#include \u003clinux/elf.h\u003e\nfs/coredump.c:46:#include \u003clinux/pidfs.h\u003e\nfs/coredump.c-47-#include \u003clinux/net.h\u003e\n--\nfs/coredump.c=623=static int umh_coredump_setup(struct subprocess_info *info, struct cred *new)\n--\nfs/coredump.c-629-\tif (cp-\u003epid[PIDTYPE_TGID]) {\nfs/coredump.c:630:\t\tstruct file *pidfs_file __free(fput) = NULL;\nfs/coredump.c-631-\nfs/coredump.c:632:\t\tpidfs_file = pidfs_alloc_file(cp-\u003epid[PIDTYPE_TGID], 0);\nfs/coredump.c:633:\t\tif (IS_ERR(pidfs_file))\nfs/coredump.c:634:\t\t\treturn PTR_ERR(pidfs_file);\nfs/coredump.c-635-\nfs/coredump.c:636:\t\terr = pidfs_register_pids(cp-\u003epid);\nfs/coredump.c-637-\t\tif (err)\n--\nfs/coredump.c-639-\nfs/coredump.c:640:\t\tpidfs_coredump(cp);\nfs/coredump.c-641-\n--\nfs/coredump.c-648-\t\t */\nfs/coredump.c:649:\t\terr = replace_fd(COREDUMP_PIDFD_NUMBER, pidfs_file, 0);\nfs/coredump.c-650-\t\tif (err \u003c 0)\n--\nfs/coredump.c=672=static bool coredump_sock_connect(struct core_name *cn, struct coredump_params *cprm)\n--\nfs/coredump.c-703-\t * which are used for the peer credentials during connect() below.\nfs/coredump.c:704:\t * Then immediately register them in pidfs...\nfs/coredump.c-705-\t */\nfs/coredump.c-706-\ttask_pids(cprm-\u003epid, current);\nfs/coredump.c:707:\tretval = pidfs_register_pids(cprm-\u003epid);\nfs/coredump.c-708-\tif (retval)\n--\nfs/coredump.c-714-\t */\nfs/coredump.c:715:\tpidfs_coredump(cprm);\nfs/coredump.c-716-\n--\nfs/fhandle.c=170=static int get_path_anchor(int fd, struct path *root)\n--\nfs/fhandle.c-186-\tif (fd == FD_PIDFS_ROOT) {\nfs/fhandle.c:187:\t\tpidfs_get_root(root);\nfs/fhandle.c-188-\t\treturn 0;\n--\nfs/internal.h=362=int anon_inode_setattr(struct mnt_idmap *idmap, struct dentry *dentry,\nfs/internal.h-363-\t\t       struct iattr *attr);\nfs/internal.h:364:void pidfs_get_root(struct path *path);\nfs/internal.h-365-void nsfs_get_root(struct path *path);\n--\nfs/libfs.c-25-#include \u003clinux/fscrypt.h\u003e\nfs/libfs.c:26:#include \u003clinux/pidfs.h\u003e\nfs/libfs.c-27-\n--\nfs/libfs.c=2192=struct dentry *stash_dentry(struct dentry **stashed, struct dentry *dentry)\n--\nfs/libfs.c-2225- *\nfs/libfs.c:2226: * Special-purpose helper for nsfs and pidfs.\nfs/libfs.c-2227- *\n--\nfs/namespace.c-34-#include \u003clinux/mnt_idmapping.h\u003e\nfs/namespace.c:35:#include \u003clinux/pidfs.h\u003e\nfs/namespace.c-36-#include \u003clinux/nstree.h\u003e\n--\nfs/namespace.c=2881=static int do_change_type(const struct path *path, int ms_flags)\n--\nfs/namespace.c-2929- *     entry from nsfs.\nfs/namespace.c:2930: * (3) The caller tries to copy a pidfs mount referring to a pidfd.\nfs/namespace.c-2931- * (4) The caller is trying to copy a mount tree that belongs to an\n--\nfs/namespace.c=2960=static inline bool may_copy_tree(const struct path *path)\n--\nfs/namespace.c-2971-\nfs/namespace.c:2972:\tif (d_op == \u0026pidfs_dentry_operations)\nfs/namespace.c-2973-\t\treturn true;\n--\nfs/notify/fanotify/fanotify.c-16-#include \u003clinux/stringhash.h\u003e\nfs/notify/fanotify/fanotify.c:17:#include \u003clinux/pidfs.h\u003e\nfs/notify/fanotify/fanotify.c-18-\n--\nfs/notify/fanotify/fanotify.c=744=static struct fanotify_event *fanotify_alloc_event(\n--\nfs/notify/fanotify/fanotify.c-848-\tif (FAN_GROUP_FLAG(group, FAN_REPORT_PIDFD) \u0026\u0026\nfs/notify/fanotify/fanotify.c:849:\t    pidfs_register_pid_gfp(pid, gfp))\nfs/notify/fanotify/fanotify.c-850-\t\tgoto out;\n--\nfs/pidfs.c-10-#include \u003clinux/pid.h\u003e\nfs/pidfs.c:11:#include \u003clinux/pidfs.h\u003e\nfs/pidfs.c-12-#include \u003clinux/sched/signal.h\u003e\n--\nfs/pidfs.c-36-\nfs/pidfs.c:37:static struct kmem_cache *pidfs_attr_cachep __ro_after_init;\nfs/pidfs.c-38-\nfs/pidfs.c:39:static struct path pidfs_root_path = {};\nfs/pidfs.c-40-\nfs/pidfs.c:41:static struct simple_xattr_cache pidfs_xa_cache;\nfs/pidfs.c-42-\nfs/pidfs.c:43:void pidfs_get_root(struct path *path)\nfs/pidfs.c-44-{\nfs/pidfs.c:45:\t*path = pidfs_root_path;\nfs/pidfs.c-46-\tpath_get(path);\n--\nfs/pidfs.c-48-\nfs/pidfs.c:49:enum pidfs_attr_mask_bits {\nfs/pidfs.c-50-\tPIDFS_ATTR_BIT_EXIT\t= 0,\n--\nfs/pidfs.c-53-\nfs/pidfs.c:54:struct pidfs_anon_attr {\nfs/pidfs.c-55-\tunsigned long attr_mask;\n--\nfs/pidfs.c-64-\nfs/pidfs.c:65:static struct rhashtable pidfs_ino_ht;\nfs/pidfs.c-66-\nfs/pidfs.c:67:static const struct rhashtable_params pidfs_ino_ht_params = {\nfs/pidfs.c-68-\t.key_offset\t\t= offsetof(struct pid, ino),\nfs/pidfs.c-69-\t.key_len\t\t= sizeof(u64),\nfs/pidfs.c:70:\t.head_offset\t\t= offsetof(struct pid, pidfs_hash),\nfs/pidfs.c-71-\t.automatic_shrinking\t= true,\n--\nfs/pidfs.c-84- *\nfs/pidfs.c:85: * On 32 bit pidfs_ino() will return the lower 32 bit. When\nfs/pidfs.c:86: * pidfs_ino() returns zero a wrap around happened. When a\nfs/pidfs.c-87- * wraparound happens the 64 bit number will be incremented by 1\n--\nfs/pidfs.c-94- * same inode number are likely to exist (This isn't a problem\nfs/pidfs.c:95: * since before pidfs pidfds used the anonymous inode meaning\nfs/pidfs.c-96- * all pidfds had the same inode number.). Userspace can\n--\nfs/pidfs.c-100- */\nfs/pidfs.c:101:struct pidfs_attr {\nfs/pidfs.c-102-\tstruct list_head xattrs;\nfs/pidfs.c-103-\tunion {\nfs/pidfs.c:104:\t\tstruct pidfs_anon_attr;\nfs/pidfs.c:105:\t\tstruct llist_node pidfs_llist;\nfs/pidfs.c-106-\t};\n--\nfs/pidfs.c-110-\nfs/pidfs.c:111:static DEFINE_SPINLOCK(pidfs_ino_lock);\nfs/pidfs.c:112:static u64 pidfs_ino_nr = 1;\nfs/pidfs.c-113-\nfs/pidfs.c:114:static inline unsigned long pidfs_ino(u64 ino)\nfs/pidfs.c-115-{\n--\nfs/pidfs.c-119-/* On 32 bit the generation number are the upper 32 bits. */\nfs/pidfs.c:120:static inline u32 pidfs_gen(u64 ino)\nfs/pidfs.c-121-{\n--\nfs/pidfs.c-124-\nfs/pidfs.c:125:static inline u64 pidfs_alloc_ino(void)\nfs/pidfs.c-126-{\n--\nfs/pidfs.c-128-\nfs/pidfs.c:129:\tspin_lock(\u0026pidfs_ino_lock);\nfs/pidfs.c:130:\tif (pidfs_ino(pidfs_ino_nr) == 0)\nfs/pidfs.c:131:\t\tpidfs_ino_nr++;\nfs/pidfs.c:132:\tino = pidfs_ino_nr++;\nfs/pidfs.c:133:\tspin_unlock(\u0026pidfs_ino_lock);\nfs/pidfs.c-134-\treturn ino;\n--\nfs/pidfs.c-139-/* On 64 bit simply return ino. */\nfs/pidfs.c:140:static inline unsigned long pidfs_ino(u64 ino)\nfs/pidfs.c-141-{\n--\nfs/pidfs.c-145-/* On 64 bit the generation number is 0. */\nfs/pidfs.c:146:static inline u32 pidfs_gen(u64 ino)\nfs/pidfs.c-147-{\n--\nfs/pidfs.c-150-\nfs/pidfs.c:151:DEFINE_COOKIE(pidfs_ino_cookie);\nfs/pidfs.c-152-\nfs/pidfs.c:153:static u64 pidfs_alloc_ino(void)\nfs/pidfs.c-154-{\n--\nfs/pidfs.c-157-\tpreempt_disable();\nfs/pidfs.c:158:\tino = gen_cookie_next(\u0026pidfs_ino_cookie);\nfs/pidfs.c-159-\tpreempt_enable();\n--\nfs/pidfs.c-166-\nfs/pidfs.c:167:void pidfs_prepare_pid(struct pid *pid)\nfs/pidfs.c-168-{\n--\nfs/pidfs.c-173-\nfs/pidfs.c:174:int pidfs_add_pid(struct pid *pid)\nfs/pidfs.c-175-{\n--\nfs/pidfs.c-177-\nfs/pidfs.c:178:\tpid-\u003eino = pidfs_alloc_ino();\nfs/pidfs.c:179:\tret = rhashtable_insert_fast(\u0026pidfs_ino_ht, \u0026pid-\u003epidfs_hash,\nfs/pidfs.c:180:\t\t\t\t     pidfs_ino_ht_params);\nfs/pidfs.c-181-\tif (unlikely(ret))\n--\nfs/pidfs.c-185-\nfs/pidfs.c:186:void pidfs_remove_pid(struct pid *pid)\nfs/pidfs.c-187-{\nfs/pidfs.c-188-\tif (likely(pid-\u003eino))\nfs/pidfs.c:189:\t\trhashtable_remove_fast(\u0026pidfs_ino_ht, \u0026pid-\u003epidfs_hash,\nfs/pidfs.c:190:\t\t\t\t       pidfs_ino_ht_params);\nfs/pidfs.c-191-}\nfs/pidfs.c-192-\nfs/pidfs.c:193:static LLIST_HEAD(pidfs_free_list);\nfs/pidfs.c-194-\nfs/pidfs.c:195:static void pidfs_free_attr_work(struct work_struct *work)\nfs/pidfs.c-196-{\nfs/pidfs.c:197:\tstruct pidfs_attr *attr, *next;\nfs/pidfs.c-198-\tstruct llist_node *head;\nfs/pidfs.c-199-\nfs/pidfs.c:200:\thead = llist_del_all(\u0026pidfs_free_list);\nfs/pidfs.c:201:\tllist_for_each_entry_safe(attr, next, head, pidfs_llist) {\nfs/pidfs.c:202:\t\tsimple_xattrs_free(\u0026pidfs_xa_cache, \u0026attr-\u003exattrs, NULL);\nfs/pidfs.c-203-\t\tkfree(attr);\n--\nfs/pidfs.c-206-\nfs/pidfs.c:207:static DECLARE_WORK(pidfs_free_work, pidfs_free_attr_work);\nfs/pidfs.c-208-\nfs/pidfs.c:209:void pidfs_free_pid(struct pid *pid)\nfs/pidfs.c-210-{\nfs/pidfs.c:211:\tstruct pidfs_attr *attr = pid-\u003eattr;\nfs/pidfs.c-212-\n--\nfs/pidfs.c-231-\t\tkfree(attr);\nfs/pidfs.c:232:\telse if (llist_add(\u0026attr-\u003epidfs_llist, \u0026pidfs_free_list))\nfs/pidfs.c:233:\t\tschedule_work(\u0026pidfs_free_work);\nfs/pidfs.c-234-}\n--\nfs/pidfs.c=329=static inline bool pid_in_current_pidns(const struct pid *pid)\n--\nfs/pidfs.c-338-\nfs/pidfs.c:339:static __u32 pidfs_coredump_mask(enum task_dumpable dumpable)\nfs/pidfs.c-340-{\n--\nfs/pidfs.c=365=static long pidfd_info(struct file *file, unsigned int cmd, unsigned long arg)\n--\nfs/pidfs.c-372-\tstruct user_namespace *user_ns;\nfs/pidfs.c:373:\tstruct pidfs_attr *attr;\nfs/pidfs.c-374-\tconst struct cred *c;\n--\nfs/pidfs.c-433-\tif ((mask \u0026 PIDFD_INFO_COREDUMP) \u0026\u0026 !kinfo.coredump_mask) {\nfs/pidfs.c:434:\t\tkinfo.coredump_mask = pidfs_coredump_mask(task_exec_state_get_dumpable(task));\nfs/pidfs.c-435-\t\tkinfo.mask |= PIDFD_INFO_COREDUMP;\n--\nfs/pidfs.c-498-\nfs/pidfs.c:499:static bool pidfs_ioctl_valid(unsigned int cmd)\nfs/pidfs.c-500-{\n--\nfs/pidfs.c=530=static long pidfd_ioctl(struct file *file, unsigned int cmd, unsigned long arg)\n--\nfs/pidfs.c-536-\nfs/pidfs.c:537:\tif (!pidfs_ioctl_valid(cmd))\nfs/pidfs.c-538-\t\treturn -ENOIOCTLCMD;\n--\nfs/pidfs.c=683=static long pidfd_compat_ioctl(struct file *file, unsigned int cmd,\n--\nfs/pidfs.c-692-\nfs/pidfs.c:693:static int pidfs_file_release(struct inode *inode, struct file *file)\nfs/pidfs.c-694-{\n--\nfs/pidfs.c-712-\nfs/pidfs.c:713:static const struct file_operations pidfs_file_operations = {\nfs/pidfs.c:714:\t.release\t= pidfs_file_release,\nfs/pidfs.c-715-\t.poll\t\t= pidfd_poll,\n--\nfs/pidfs.c=725=struct pid *pidfd_pid(const struct file *file)\nfs/pidfs.c-726-{\nfs/pidfs.c:727:\tif (file-\u003ef_op != \u0026pidfs_file_operations)\nfs/pidfs.c-728-\t\treturn ERR_PTR(-EBADF);\n--\nfs/pidfs.c-739- * pid-\u003eattr will be allocated. If not we mark the struct pid as dead so\nfs/pidfs.c:740: * anyone who is trying to register it with pidfs will fail to do so.\nfs/pidfs.c:741: * Otherwise we would hand out pidfs for reaped tasks without having\nfs/pidfs.c-742- * exit information available.\n--\nfs/pidfs.c-745- * right away in free_pid() when no one holds a pidfd anymore. Since\nfs/pidfs.c:746: * pidfs_exit() currently is placed after exit_task_work() we know that\nfs/pidfs.c-747- * it cannot be us aka the exiting task holding a pidfd to itself.\nfs/pidfs.c-748- */\nfs/pidfs.c:749:void pidfs_exit(struct task_struct *tsk)\nfs/pidfs.c-750-{\nfs/pidfs.c-751-\tstruct pid *pid = task_pid(tsk);\nfs/pidfs.c:752:\tstruct pidfs_attr *attr;\nfs/pidfs.c-753-#ifdef CONFIG_CGROUPS\n--\nfs/pidfs.c-758-\nfs/pidfs.c:759:\t/* Synchronize with pidfs_register_pid(). */\nfs/pidfs.c-760-\tscoped_guard(spinlock_irq, \u0026pid-\u003ewait_pidfd.lock) {\n--\nfs/pidfs.c-764-\t\t\t * No one ever held a pidfd for this struct pid.\nfs/pidfs.c:765:\t\t\t * Mark it as dead so no one can add a pidfs\nfs/pidfs.c-766-\t\t\t * entry anymore. We're about to be reaped and\n--\nfs/pidfs.c-795-#ifdef CONFIG_COREDUMP\nfs/pidfs.c:796:static void pidfs_coredump_pid(struct pid *pid,\nfs/pidfs.c-797-\t\t\t       const struct coredump_params *cprm)\nfs/pidfs.c-798-{\nfs/pidfs.c:799:\tstruct pidfs_attr *attr;\nfs/pidfs.c-800-\n--\nfs/pidfs.c-806-\t/* Note how we were coredumped and that we coredumped. */\nfs/pidfs.c:807:\tattr-\u003ecoredump_mask = pidfs_coredump_mask(cprm-\u003edumpable) |\nfs/pidfs.c-808-\t\t\t      PIDFD_COREDUMPED;\n--\nfs/pidfs.c-817-\nfs/pidfs.c:818:void pidfs_coredump(const struct coredump_params *cprm)\nfs/pidfs.c-819-{\n--\nfs/pidfs.c-821-\tfor (enum pid_type type = PIDTYPE_PID; type \u003c= pids_last(cprm-\u003epid); type++)\nfs/pidfs.c:822:\t\tpidfs_coredump_pid(cprm-\u003epid[type], cprm);\nfs/pidfs.c-823-}\n--\nfs/pidfs.c-825-\nfs/pidfs.c:826:static struct vfsmount *pidfs_mnt __ro_after_init;\nfs/pidfs.c-827-\n--\nfs/pidfs.c-832- */\nfs/pidfs.c:833:static int pidfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,\nfs/pidfs.c-834-\t\t\t struct iattr *attr)\n--\nfs/pidfs.c-838-\nfs/pidfs.c:839:static int pidfs_getattr(struct mnt_idmap *idmap, const struct path *path,\nfs/pidfs.c-840-\t\t\t struct kstat *stat, u32 request_mask,\n--\nfs/pidfs.c-845-\nfs/pidfs.c:846:static ssize_t pidfs_listxattr(struct dentry *dentry, char *buf, size_t size)\nfs/pidfs.c-847-{\n--\nfs/pidfs.c-853-\nfs/pidfs.c:854:static const struct inode_operations pidfs_inode_operations = {\nfs/pidfs.c:855:\t.getattr\t= pidfs_getattr,\nfs/pidfs.c:856:\t.setattr\t= pidfs_setattr,\nfs/pidfs.c:857:\t.listxattr\t= pidfs_listxattr,\nfs/pidfs.c-858-};\nfs/pidfs.c-859-\nfs/pidfs.c:860:static void pidfs_evict_inode(struct inode *inode)\nfs/pidfs.c-861-{\n--\nfs/pidfs.c-867-\nfs/pidfs.c:868:static const struct super_operations pidfs_sops = {\nfs/pidfs.c-869-\t.drop_inode\t= inode_just_drop,\nfs/pidfs.c:870:\t.evict_inode\t= pidfs_evict_inode,\nfs/pidfs.c-871-\t.statfs\t\t= simple_statfs,\n--\nfs/pidfs.c-875- * 'lsof' has knowledge of out historical anon_inode use, and expects\nfs/pidfs.c:876: * the pidfs dentry name to start with 'anon_inode'.\nfs/pidfs.c-877- */\nfs/pidfs.c:878:static char *pidfs_dname(struct dentry *dentry, char *buffer, int buflen)\nfs/pidfs.c-879-{\n--\nfs/pidfs.c-882-\nfs/pidfs.c:883:const struct dentry_operations pidfs_dentry_operations = {\nfs/pidfs.c:884:\t.d_dname\t= pidfs_dname,\nfs/pidfs.c-885-\t.d_prune\t= stashed_dentry_prune,\n--\nfs/pidfs.c-887-\nfs/pidfs.c:888:static int pidfs_encode_fh(struct inode *inode, u32 *fh, int *max_len,\nfs/pidfs.c-889-\t\t\t   struct inode *parent)\n--\nfs/pidfs.c-903-/* Find a struct pid based on the inode number. */\nfs/pidfs.c:904:static struct pid *pidfs_ino_get_pid(u64 ino)\nfs/pidfs.c-905-{\nfs/pidfs.c-906-\tstruct pid *pid;\nfs/pidfs.c:907:\tstruct pidfs_attr *attr;\nfs/pidfs.c-908-\nfs/pidfs.c-909-\tguard(rcu)();\nfs/pidfs.c:910:\tpid = rhashtable_lookup(\u0026pidfs_ino_ht, \u0026ino, pidfs_ino_ht_params);\nfs/pidfs.c-911-\tif (!pid)\n--\nfs/pidfs.c-923-\nfs/pidfs.c:924:static struct dentry *pidfs_fh_to_dentry(struct super_block *sb,\nfs/pidfs.c-925-\t\t\t\t\t struct fid *fid, int fh_len,\n--\nfs/pidfs.c-943-\nfs/pidfs.c:944:\tpid = pidfs_ino_get_pid(pid_ino);\nfs/pidfs.c-945-\tif (!pid)\n--\nfs/pidfs.c-947-\nfs/pidfs.c:948:\tret = path_from_stashed(\u0026pid-\u003estashed, pidfs_mnt, pid, \u0026path);\nfs/pidfs.c-949-\tif (ret \u003c 0)\n--\nfs/pidfs.c-957-\nfs/pidfs.c:958:static struct file *pidfs_dentry_open(const struct path *path,\nfs/pidfs.c-959-\t\t\t\t      unsigned int flags,\n--\nfs/pidfs.c-979-\nfs/pidfs.c:980:static int pidfs_export_permission(struct handle_to_path_ctx *ctx,\nfs/pidfs.c-981-\t\t\t\t   unsigned int oflags)\n--\nfs/pidfs.c-993-\nfs/pidfs.c:994:static struct file *pidfs_export_open(const struct path *path, unsigned int oflags)\nfs/pidfs.c-995-{\n--\nfs/pidfs.c-1002-\t/* Clear O_LARGEFILE as open_by_handle_at() forces it. */\nfs/pidfs.c:1003:\treturn pidfs_dentry_open(path, oflags \u0026 ~O_LARGEFILE, current_cred());\nfs/pidfs.c-1004-}\nfs/pidfs.c-1005-\nfs/pidfs.c:1006:static const struct export_operations pidfs_export_operations = {\nfs/pidfs.c:1007:\t.encode_fh\t= pidfs_encode_fh,\nfs/pidfs.c:1008:\t.fh_to_dentry\t= pidfs_fh_to_dentry,\nfs/pidfs.c:1009:\t.open\t\t= pidfs_export_open,\nfs/pidfs.c:1010:\t.permission\t= pidfs_export_permission,\nfs/pidfs.c-1011-};\nfs/pidfs.c-1012-\nfs/pidfs.c:1013:static int pidfs_init_inode(struct inode *inode, void *data)\nfs/pidfs.c-1014-{\n--\nfs/pidfs.c-1021-\tinode-\u003ei_mode |= S_IRWXU;\nfs/pidfs.c:1022:\tinode-\u003ei_op = \u0026pidfs_inode_operations;\nfs/pidfs.c:1023:\tinode-\u003ei_fop = \u0026pidfs_file_operations;\nfs/pidfs.c:1024:\tinode-\u003ei_ino = pidfs_ino(pid-\u003eino);\nfs/pidfs.c:1025:\tinode-\u003ei_generation = pidfs_gen(pid-\u003eino);\nfs/pidfs.c-1026-\treturn 0;\n--\nfs/pidfs.c-1028-\nfs/pidfs.c:1029:static void pidfs_put_data(void *data)\nfs/pidfs.c-1030-{\n--\nfs/pidfs.c-1035-/**\nfs/pidfs.c:1036: * pidfs_register_pid_gfp - register a struct pid in pidfs with custom GFP\nfs/pidfs.c-1037- * flags\n--\nfs/pidfs.c-1040- *\nfs/pidfs.c:1041: * Register a struct pid in pidfs with custom GFP flags.\nfs/pidfs.c-1042- *\n--\nfs/pidfs.c-1044- */\nfs/pidfs.c:1045:int pidfs_register_pid_gfp(struct pid *pid, gfp_t gfp)\nfs/pidfs.c-1046-{\nfs/pidfs.c:1047:\tstruct pidfs_attr *new_attr __free(kfree) = NULL;\nfs/pidfs.c:1048:\tstruct pidfs_attr *attr;\nfs/pidfs.c-1049-\n--\nfs/pidfs.c-1060-\nfs/pidfs.c:1061:\tnew_attr = kmem_cache_zalloc(pidfs_attr_cachep, gfp);\nfs/pidfs.c-1062-\tif (!new_attr)\n--\nfs/pidfs.c-1066-\nfs/pidfs.c:1067:\t/* Synchronize with pidfs_exit(). */\nfs/pidfs.c-1068-\tguard(spinlock_irq)(\u0026pid-\u003ewait_pidfd.lock);\n--\nfs/pidfs.c-1079-\nfs/pidfs.c:1080:/* Register the pids up to pid type @last of @pids in pidfs. */\nfs/pidfs.c:1081:int __pidfs_register_pids(struct pid *const *pids, enum pid_type last)\nfs/pidfs.c-1082-{\n--\nfs/pidfs.c-1086-\tfor (enum pid_type type = PIDTYPE_PID; type \u003c= last; type++) {\nfs/pidfs.c:1087:\t\tint ret = pidfs_register_pid(pids[type]);\nfs/pidfs.c-1088-\n--\nfs/pidfs.c-1095-\nfs/pidfs.c:1096:static struct dentry *pidfs_stash_dentry(struct dentry **stashed,\nfs/pidfs.c-1097-\t\t\t\t\t struct dentry *dentry)\n--\nfs/pidfs.c-1103-\nfs/pidfs.c:1104:\tret = pidfs_register_pid(pid);\nfs/pidfs.c-1105-\tif (ret)\n--\nfs/pidfs.c-1110-\nfs/pidfs.c:1111:static const struct stashed_operations pidfs_stashed_ops = {\nfs/pidfs.c:1112:\t.stash_dentry\t= pidfs_stash_dentry,\nfs/pidfs.c:1113:\t.init_inode\t= pidfs_init_inode,\nfs/pidfs.c:1114:\t.put_data\t= pidfs_put_data,\nfs/pidfs.c-1115-};\nfs/pidfs.c-1116-\nfs/pidfs.c:1117:static int pidfs_xattr_get(const struct xattr_handler *handler,\nfs/pidfs.c-1118-\t\t\t   struct dentry *unused, struct inode *inode,\n--\nfs/pidfs.c-1123-\nfs/pidfs.c:1124:\treturn simple_xattr_get(\u0026pidfs_xa_cache, \u0026pid-\u003eattr-\u003exattrs, name, value, size);\nfs/pidfs.c-1125-}\nfs/pidfs.c-1126-\nfs/pidfs.c:1127:static int pidfs_xattr_set(const struct xattr_handler *handler,\nfs/pidfs.c-1128-\t\t\t   struct mnt_idmap *idmap, struct dentry *unused,\n--\nfs/pidfs.c-1138-\nfs/pidfs.c:1139:\told_xattr = simple_xattr_set(\u0026pidfs_xa_cache, \u0026pid-\u003eattr-\u003exattrs, name, value, size, flags);\nfs/pidfs.c-1140-\tif (IS_ERR(old_xattr))\n--\nfs/pidfs.c-1146-\nfs/pidfs.c:1147:static const struct xattr_handler pidfs_trusted_xattr_handler = {\nfs/pidfs.c-1148-\t.prefix = XATTR_TRUSTED_PREFIX,\nfs/pidfs.c:1149:\t.get\t= pidfs_xattr_get,\nfs/pidfs.c:1150:\t.set\t= pidfs_xattr_set,\nfs/pidfs.c-1151-};\nfs/pidfs.c-1152-\nfs/pidfs.c:1153:static const struct xattr_handler *const pidfs_xattr_handlers[] = {\nfs/pidfs.c:1154:\t\u0026pidfs_trusted_xattr_handler,\nfs/pidfs.c-1155-\tNULL\n--\nfs/pidfs.c-1157-\nfs/pidfs.c:1158:static int pidfs_init_fs_context(struct fs_context *fc)\nfs/pidfs.c-1159-{\n--\nfs/pidfs.c-1166-\tctx-\u003es_d_flags |= DCACHE_DONTCACHE;\nfs/pidfs.c:1167:\tctx-\u003eops = \u0026pidfs_sops;\nfs/pidfs.c:1168:\tctx-\u003eeops = \u0026pidfs_export_operations;\nfs/pidfs.c:1169:\tctx-\u003edops = \u0026pidfs_dentry_operations;\nfs/pidfs.c:1170:\tctx-\u003exattr = pidfs_xattr_handlers;\nfs/pidfs.c:1171:\tfc-\u003es_fs_info = (void *)\u0026pidfs_stashed_ops;\n\n"
}

17/2 2026/09/29 11:03 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 43277
							output: 25
							thoughts: 104
						

Thoughts:
**Investigating PIDFS and Coredump Compilation**

Okay, so `pidfs.o` is definitely baked into the kernel build. It's listed under `obj-y` in `fs/Makefile`, meaning it's always included. That's straightforward enough. Now, what's the deal with the coredump functionality within `pidfs`?

I recall `pidfs_coredump` is conditional. In `fs/pidfs.c`, that function is guarded by an `#ifdef CONFIG_COREDUMP`. Right, that makes sense. It's only compiled if `CONFIG_COREDUMP` is defined. And, I know `fs/coredump.c` is compiled when `CONFIG_COREDUMP` is enabled.

I need to confirm that `CONFIG_COREDUMP` is respected correctly in the build system. Let me quickly examine `fs/Makefile` again, to double-check that the `COREDUMP` configuration option is correctly influencing the compilation of the `pidfs` and `coredump` related code.



18/2 2026/09/29 11:03 tool grepper
0m Args:
{
  "Expression": "coredump",
  "PathPrefix": "fs/Makefile"
}

Results:
{
  "Output": "fs/Makefile=46=obj-$(CONFIG_NFS_COMMON)\t+= nfs_common/\nfs/Makefile:47:obj-$(CONFIG_COREDUMP)\t\t+= coredump.o\nfs/Makefile-48-obj-$(CONFIG_SYSCTL)\t\t+= drop_caches.o sysctls.o\n"
}

19/2 2026/09/29 11:03 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 43720
							output: 27
							thoughts: 117
						

Thoughts:
**Kernel Configuration Dependencies**

Okay, so I'm digging into this configuration, and it looks like `CONFIG_COREDUMP` is definitely a prerequisite. Specifically, it's tied to `coredump.o` and `pidfs_coredump`, which makes perfect sense. And obviously, `CONFIG_UNIX` is needed to handle `net/unix/af_unix.c`. But hold on, I just noticed some other files have been updated.

My initial thought was that this update only dealt with standard core dumps, which would explain the dependencies I listed. However, now I see that the Bluetooth code has been touched as well. We've got updates to `net/bluetooth/af_bluetooth.c`, `net/bluetooth/hci_sock.c`, and `net/bluetooth/l2cap_sock.c`. Given that, I'm going to assume `CONFIG_BT` is the key here. The Bluetooth functionality must be enabled for these changes to take effect. I'll need to double check the `net/bluetooth/Makefile` just to be sure, and to confirm the exact dependencies related to bluetooth.



20/2 2026/09/29 11:03 tool grepper
0m Args:
{
  "Expression": "obj-",
  "PathPrefix": "net/bluetooth/Makefile"
}

Results:
{
  "Output": "net/bluetooth/Makefile-5-\nnet/bluetooth/Makefile:6:obj-$(CONFIG_BT)\t+= bluetooth.o\nnet/bluetooth/Makefile:7:obj-$(CONFIG_BT_RFCOMM)\t+= rfcomm/\nnet/bluetooth/Makefile:8:obj-$(CONFIG_BT_BNEP)\t+= bnep/\nnet/bluetooth/Makefile:9:obj-$(CONFIG_BT_HIDP)\t+= hidp/\nnet/bluetooth/Makefile:10:obj-$(CONFIG_BT_6LOWPAN) += bluetooth_6lowpan.o\nnet/bluetooth/Makefile-11-\n"
}

21/2 2026/09/29 11:03 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 44258
							output: 28
							thoughts: 222
						

Thoughts:
**Bluetooth Changes and PIDFD Threading: A Quick Review**

Okay, so the Bluetooth update looks pretty straightforward—they're just adapting the `sk->sk_peer_pid` structure to accommodate the type change, from a simple `struct pid *` to the new `DECLARE_PIDS(sk_peer_pid, PIDTYPE_TGID)` format. Seems like a simple refactor to manage PIDs more robustly.

The core implementation is really focused on bringing in PIDFD capabilities, specifically:

*   Enhancing AF\_UNIX sockets with `SO_PASSPIDFD_THREAD` and `SO_PEERPIDFD_THREAD` options.
*   Integrating `SCM_PIDFD_THREAD` for SCM control messages.
*   And finally, setting up thread coredump tracking in pidfs.

Before diving deep, let's take a quick look at the kernel configs that are relevant:

*   I'll definitely need to confirm that `CONFIG_UNIX` is enabled; that’s the foundation for the AF\_UNIX sockets.
*   And `CONFIG_COREDUMP` seems like it should be checked, since it would be useful for the thread coredump tracking part.
*   `CONFIG_BT` is optional, but it might be worth a look just in case there are dependencies or interactions I should be aware of. I should probably check for any other dependencies, since I'm here.
*   I should check `net/unix/Kconfig` to be sure.



22/2 2026/09/29 11:03 tool grepper
0m Args:
{
  "Expression": "config UNIX",
  "PathPrefix": "net/unix/Kconfig"
}

Results:
{
  "Output": "net/unix/Kconfig-5-\nnet/unix/Kconfig:6:config UNIX\nnet/unix/Kconfig-7-\tbool \"Unix domain sockets\"\n--\nnet/unix/Kconfig=19=config\tAF_UNIX_OOB\n--\nnet/unix/Kconfig-25-\nnet/unix/Kconfig:26:config UNIX_DIAG\nnet/unix/Kconfig-27-\ttristate \"UNIX: socket monitoring interface\"\n"
}

23/2 2026/09/29 11:03 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 44960
							output: 27
							thoughts: 799
						

Thoughts:
**Focus Symbol Identification and Analysis**

Okay, so `CONFIG_UNIX` is a boolean, defaulting to 'y'. That's fine, nothing to see there. Now, I need to focus on identifying suitable symbols for `FocusSymbols`. Let's break this down systematically.

First, I see `__pidfs_register_pids`. Defined in `fs/pidfs.c`, line 1081. It's a non-static function, taking a `struct pid **` and an enum. It even has a `WARN_ON_ONCE`. Definitely a focus symbol, I'd say.

Next up, `pidfs_coredump`. Another non-static function, defined at line 818 in the same file. It calls another function, `pidfs_coredump_pid`. Looks like a solid candidate.

Then we have `sk_getsockopt_peerpidfd`. This one's in `net/core/sock.c` at line 1740. Hmm, it's static. But is it inlined into `sk_getsockopt`? Let's check the call sites: it's used in two places, `SO_PEERPIDFD` and `SO_PEERPIDFD_THREAD`. Okay, so it's not *completely* inlined, or syzkaller can handle compiler symbols. Still, a static function not inlined should be fine, and non-static caller functions even better.

Wait a second, what did the guidance say about static inline functions? Ah, yes. Instruction #4: It warns about static *inlines* in headers. In this case, it's in a .c file, and it is not inlined, so it's safe. However, the instruction emphasizes the importance of non-static caller functions, so I should be looking at `sk_getsockopt` since it's the caller. But is `sk_getsockopt` ubiquitous? I have to be careful not to dilute the fuzzing effort. Let's see... it's a `SOL_SOCKET` handler, called whenever `getsockopt()` is used on a socket. Every program using `getsockopt(SOL_SOCKET)` hits this function. Okay, it's pretty generic. Is it *too* generic? It's not memory allocation or a core primitive. The documentation says to "avoid generic, ubiquitous functions." If this is called in every program that calls `getsockopt` it might be too ubiquitous.

Let me think… what about `scm_recv_unix`? This function seems more specific, it is called for UNIX socket recvmsg when receiving SCM rights/creds/pidfds. That seems more focused. I'll need to check the call sites for `scm_recv_unix` to verify, but this looks like a stronger candidate than `sk_getsockopt` given the guidelines.



24/2 2026/09/29 11:03 tool grepper
0m Args:
{
  "Expression": "scm_recv_unix",
  "PathPrefix": "net/"
}

Results:
{
  "Output": "net/core/scm.c=582=EXPORT_SYMBOL(scm_recv);\nnet/core/scm.c-583-\nnet/core/scm.c:584:void scm_recv_unix(struct socket *sock, struct msghdr *msg,\nnet/core/scm.c-585-\t\t   struct scm_cookie *scm, int flags)\n--\nnet/unix/af_unix.c=2575=int __unix_dgram_recvmsg(struct sock *sk, struct msghdr *msg, size_t size,\n--\nnet/unix/af_unix.c-2674-\nnet/unix/af_unix.c:2675:\tscm_recv_unix(sock, msg, \u0026scm, flags);\nnet/unix/af_unix.c-2676-\n--\nnet/unix/af_unix.c=2924=static int unix_stream_read_generic(struct unix_stream_read_state *state,\n--\nnet/unix/af_unix.c-3117-\nnet/unix/af_unix.c:3118:\t\tscm_recv_unix(sock, msg, \u0026scm, flags);\nnet/unix/af_unix.c-3119-\n"
}

25/2 2026/09/29 11:03 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 46731
							output: 32
							thoughts: 282
						

Thoughts:
**Focusing on Unix SCM Reception and Core Dumps**

Okay, so I've been looking at some network code, specifically in `net/core/scm.c`. I noticed that `scm_recv_unix` has been modified, and that's interesting because it's a non-static, exported symbol, so I can really get a handle on it for unix SCM reception. That makes it a great point of focus! The modification now includes calls to `scm_pidfd_recv` based on flags on the socket.

I was also curious about how core dumps are handled, so I went to look for `coredump_sock_connect`. Interesting... it's in `fs/coredump.c`, but it's a `static` function. Hmm. That limits its broader utility. Same goes for `umh_coredump_setup`, also `static` within `fs/coredump.c`. So it looks like these are only used internally within that specific file and aren't directly exposed for broader use. I think I will just grep for it now, and see where else it's called.



26/2 2026/09/29 11:03 tool grepper
0m Args:
{
  "Expression": "coredump_sock_connect",
  "PathPrefix": "fs/coredump.c"
}

Results:
{
  "Output": "fs/coredump.c=623=static int umh_coredump_setup(struct subprocess_info *info, struct cred *new)\n--\nfs/coredump.c-671-#ifdef CONFIG_UNIX\nfs/coredump.c:672:static bool coredump_sock_connect(struct core_name *cn, struct coredump_params *cprm)\nfs/coredump.c-673-{\n--\nfs/coredump.c=862=static bool coredump_socket(struct core_name *cn, struct coredump_params *cprm)\nfs/coredump.c-863-{\nfs/coredump.c:864:\tif (!coredump_sock_connect(cn, cprm))\nfs/coredump.c-865-\t\treturn false;\n"
}

27/2 2026/09/29 11:03 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 47495
							output: 26
							thoughts: 1647
						

Thoughts:
**Analysis of Recent Kernel Changes**

Okay, let's break this down. My initial focus is on understanding the scope of these modifications. It appears we have several functions impacted, all concentrated in a relatively narrow area related to AF_UNIX sockets, PID file systems, and coredump functionality. Specifically, I see changes to `coredump_sock_connect` in `fs/coredump.c` – it now includes a WARN_ON_ONCE assertion. Similarly, `__pidfs_register_pids` in `fs/pidfs.c` also has a new WARN_ON_ONCE.

Looking at `af_unix.c`, several functions are modified: `unix_skb_scm_eq`, `unix_maybe_add_creds`, and numerous others related to SCM credentials handling (`unix_scm_to_skb`, `unix_skb_to_scm`, etc.) and peer credential management. We are also seeing a new `bpf_bypass` for `getsockopt` for the thread variant PIDFD option.

Moving to `net/core/scm.c`, I see `scm_replace_pid`, `__scm_send`, `scm_pidfd_recv`, and `scm_recv_unix` are all touched, again indicative of changes to the core SCM handling. `net/core/sock.c` has been touched with `sk_getsockopt_peerpidfd`, `sk_setsockopt` (with `SO_PASSPIDFD_THREAD`), and `sk_getsockopt` (with the new PIDFD options). And, finally, in `fs/pidfs.c` there's a reference to `pidfs_coredump` and `__pidfs_register_pids`.

Let's organize the candidates:
*   `__pidfs_register_pids` (exported / non-static, fs/pidfs.c)
*   `pidfs_coredump` (non-static, fs/pidfs.c)
*   `scm_recv_unix` (exported / non-static, net/core/scm.c)
*   `sk_getsockopt_peerpidfd` (net/core/sock.c)
*   `scm_pidfd_recv` (net/core/scm.c)
*   `unix_maybe_add_creds` (net/unix/af_unix.c)
*   `unix_skb_scm_eq` (net/unix/af_unix.c)
*   `coredump_sock_connect` (fs/coredump.c)

None of these are generic; they're all directly involved in the code modified by the patch. This strongly suggests that these functions directly exercise the intended functionality.

Now, concerning configurations, I can immediately identify `CONFIG_UNIX` as essential, as it's the core AF_UNIX support. `CONFIG_COREDUMP` is also necessary for the coredump-related changes. Bluetooth support (`CONFIG_BT`) is only a consumer of the new type, so less directly relevant. I do not see any other config options as being essential. No other config dependencies are apparent. `PIDFD` is a fundamental part of the filesystem. `fs/pidfs.c` is always built. Now, let's verify if `CONFIG_COREDUMP` depends on anything.



28/2 2026/09/29 11:03 tool grepper
0m Args:
{
  "Expression": "config COREDUMP",
  "PathPrefix": "fs/"
}

Results:
{
  "Output": "fs/Kconfig.binfmt=171=config BINFMT_MISC_BPF\n--\nfs/Kconfig.binfmt-184-\nfs/Kconfig.binfmt:185:config COREDUMP\nfs/Kconfig.binfmt-186-\tbool \"Enable core dump support\" if EXPERT\n"
}

29/2 2026/09/29 11:03 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 49999
							output: 35
							thoughts: 14
						

Thoughts:
Here's my take on the dependencies of `CONFIG_COREDUMP`.

**Dissecting CONFIG_COREDUMP Dependencies**

Okay, let's dive into this. `CONFIG_COREDUMP`... I need to refresh my mental model of its dependencies. Where does it fit in the larger kernel picture? Does it rely on specific memory management features? Perhaps it's tied to certain debug options, or related to the architecture's ability to handle traps or exceptions? I'll need to consider how coredumps are written. Are they written directly from the kernel, or is there userspace involvement? If the latter, it's very likely tied to process management and signal handling, and what would it mean to disable that? I'm thinking about whether enabling coredumps creates security implications if `CONFIG_COREDUMP` or its dependencies are poorly configured or vulnerable. I'll need to consider specific file system dependencies as well. I'm going to systematically trace the related code paths, looking for any conditional compilation based on the setting of `CONFIG_COREDUMP`. I need to figure out what functionality gets disabled or modified if `CONFIG_COREDUMP` is not enabled.



30/2 2026/09/29 11:04 tool read-file
0m Args:
{
  "File": "fs/Kconfig.binfmt",
  "FirstLine": 184,
  "LineCount": 15
}

Results:
{
  "Contents": " 184:\t\n 185:\tconfig COREDUMP\n 186:\t\tbool \"Enable core dump support\" if EXPERT\n 187:\t\tdefault y\n 188:\t\thelp\n 189:\t\t  This option enables support for performing core dumps. You almost\n 190:\t\t  certainly want to say Y here. Not necessary on systems that never\n 191:\t\t  need debugging or only ever run flawless code.\n 192:\t\n 193:\tconfig EXEC_KUNIT_TEST\n 194:\t\tbool \"Build execve tests\" if !KUNIT_ALL_TESTS\n 195:\t\tdepends on KUNIT=y\n 196:\t\tdefault KUNIT_ALL_TESTS\n 197:\t\thelp\n 198:\t\t  This builds the exec KUnit tests, which tests boundary conditions\n"
}

31/2 2026/09/29 11:04 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 50521
							output: 223
							thoughts: 522
						

Thoughts:
**Analyzing the Fuzzing Suitability of a Kernel Patch**

Okay, let's break this down. First, good, `COREDUMP` has no dependencies, and `UNIX` in `net/unix/Kconfig` is also standalone (a boolean, defaults to 'y'). That simplifies things from a configuration perspective.

Now, for `set-results`, I need the parameters. The patch is definitely "WorthFuzzing" – it's introducing thread-level pidfd support with new socket options (SO_PASSPIDFD_THREAD, SO_PEERPIDFD_THREAD, and control message SCM_PIDFD_THREAD).  It touches the core socket struct, credential handling in AF_UNIX and SCM, pidfs registration, and even coredump socket peer pid validation with those new assertions. Seems like a prime target. The "Reasoning" is clear; it highlights those key areas of change.

The core of this is going to be the `FocusSymbols`. Let me just verify those:

*   `__pidfs_register_pids` - Okay, from `fs/pidfs.c:1081`, checking for pidfs registration.
*   `pidfs_coredump` - Yep, `fs/pidfs.c:818`, related to coredump functionality.
*   `scm_recv_unix` - Looks good; `net/core/scm.c:584`, dealing with control message reception in Unix domain sockets.
*   `sk_getsockopt_peerpidfd` - Okay, `net/core/sock.c:1740`, sock option, and the new pidfd-related stuff.
*   `scm_pidfd_recv` - `net/core/scm.c:502`, more SCM reception.
*   `unix_maybe_add_creds` - And `net/unix/af_unix.c:2026`, credential handling within the Unix domain socket code.
*   `unix_skb_scm_eq` - Another check `net/unix/af_unix.c:2049`.
*   `coredump_sock_connect` - And `fs/coredump.c:672` to verify coredump-socket connections.

All symbols are present, and the paths match their definitions.  I can be confident about that list. The `EnableConfigs` are straightforward – `UNIX` and `COREDUMP` - and those configs are clearly valid, so let's strip that `CONFIG_` prefix.

Alright, the information is ready. Let's make the `set-results` call.



32/2 2026/09/29 11:04 tool set-results
0m Args:
{
  "EnableConfigs": [
    "UNIX",
    "COREDUMP"
  ],
  "FocusSymbols": [
    "__pidfs_register_pids",
    "pidfs_coredump",
    "scm_recv_unix",
    "sk_getsockopt_peerpidfd",
    "scm_pidfd_recv",
    "unix_maybe_add_creds",
    "unix_skb_scm_eq",
    "coredump_sock_connect"
  ],
  "Reasoning": "The patch series adds thread-level pidfd support to UNIX domain sockets (SO_PASSPIDFD_THREAD, SO_PEERPIDFD_THREAD, and SCM_PIDFD_THREAD), expanding peer and scm pid tracking to arrays indexed by pid type. It modifies core socket state management, credentials passing/comparison logic, pidfs registration, and coredump socket connect handling with new WARN_ON_ONCE assertions. These are reachable core networking and IPC changes that warrant fuzzing.",
  "WorthFuzzing": true
}

Results:
{
  "EnableConfigs": [
    "UNIX",
    "COREDUMP"
  ],
  "FocusSymbols": [
    "__pidfs_register_pids",
    "pidfs_coredump",
    "scm_recv_unix",
    "sk_getsockopt_peerpidfd",
    "scm_pidfd_recv",
    "unix_maybe_add_creds",
    "unix_skb_scm_eq",
    "coredump_sock_connect"
  ],
  "Reasoning": "The patch series adds thread-level pidfd support to UNIX domain sockets (SO_PASSPIDFD_THREAD, SO_PEERPIDFD_THREAD, and SCM_PIDFD_THREAD), expanding peer and scm pid tracking to arrays indexed by pid type. It modifies core socket state management, credentials passing/comparison logic, pidfs registration, and coredump socket connect handling with new WARN_ON_ONCE assertions. These are reachable core networking and IPC changes that warrant fuzzing.",
  "WorthFuzzing": true
}

33/1 2026/09/29 11:04 action If
6m Args:
{
  "WorthFuzzing": true
}

Results:
null

34/2 2026/09/29 11:04 agent kmsan-evaluator
6m Model:
core

Args:
null

Results:
{
  "KMSANReasoning": "The patch series introduces thread-specific pidfd support for Unix domain sockets and coredump socket connections (SO_PASSPIDFD_THREAD, SO_PEERPIDFD_THREAD, SCM_PIDFD_THREAD), converting single struct pid pointers to pid arrays via DECLARE_PIDS(..., PIDTYPE_TGID).\n\nAn inspection of the changes and surrounding code confirms that all touched data structures and memory buffers are fully initialized:\n1. struct sock: sk-\u003esk_peer_pid is zeroed in sock_init_data_uid() via memset(), and socket allocation zeroes the struct via sk_alloc(). The new sk_scm_pidfd_thread bitfield is part of the zero-initialized bitfield group.\n2. struct scm_cookie: Zero-initialized with memset() in __scm_send(), unix_destruct_scm(), and other caller wrappers. scm_replace_pid() and unix_skb_to_scm() explicitly initialize both PIDTYPE_TGID and PIDTYPE_PID entries.\n3. sk_buff: UNIXCB(skb) is embedded in skb-\u003ecb, which is zeroed upon allocation in skbuff_clear(). In unix_maybe_add_creds(), get_task_pids() populates both pid elements; on error, put_pids() clears them back to NULL.\n4. struct coredump_params: cprm is initialized in vfs_coredump() via designated initializers (ensuring all unmentioned fields, including cprm.pid, are zeroed).\n5. User copying: sk_getsockopt_peerpidfd() writes a local int pidfd and int len to optval/optlen after pidfd_prepare(); scm_pidfd_recv() writes pidfd via put_cmsg(). No uninitialized struct padding or uninitialized stack bytes are copied to user space.\n\nSince all structures are fully zeroed or initialized prior to use and no uninitialized memory risks or info-leaks are introduced, a dedicated KMSAN fuzzing session is not warranted. Any potential memory safety bugs (such as reference counting or socket locking) are covered by KASAN and standard debuggers.",
  "NeedsKMSAN": false
}

Instruction:
You are an expert Linux kernel security engineer specializing in kernel memory
error detectors (KASAN and KMSAN). Your job is to review the provided patch series and
determine if the code changes justify spawning a dedicated KMSAN (KernelMemorySanitizer)
fuzzing session in addition to standard KASAN fuzzing.

CRITICAL DISTINCTION BETWEEN KASAN AND KMSAN:
- Standard KASAN kernel builds (upstream-apparmor-kasan.config) already enable
  a comprehensive suite of debugging tools and sanitizers, including KASAN
  (out-of-bounds accesses, use-after-free, double free, invalid free), LOCKDEP
  (locking bugs and deadlocks), UB-sanitizers, and memory corruption checks.
- KMSAN (KernelMemorySanitizer) detects reads of UNINITIALIZED memory (stack, heap,
  or page allocations) and kernel-to-user memory info-leaks.

Rule: THERE IS NO SENSE IN RUNNING A KMSAN SESSION IF A BUG CAN BE CAUGHT BY KASAN,
LOCKDEP, OR OTHER STANDARD BUG DETECTORS.
A dedicated KMSAN fuzzing session incurs significant resource costs. You must ONLY
set NeedsKMSAN=true if the code changes introduce or expose UNINITIALIZED MEMORY risks
that are detected ONLY by KMSAN.

Look holistically at the patch series and surrounding code. Even if no direct
uninitialized field accesses or new buffer allocations are added in the diff itself,
a patch may alter control flow, bounds checking, or data length calculations in ways
that change how the rest of the code operates on existing buffers (e.g. allowing
uninitialized stack/heap memory to be read, copied to user space, or used in control
flow). Do not hesitate to use your code access tools to inspect the surrounding code,
called functions, and callers.

Set NeedsKMSAN=true ONLY IF the patch introduces or modifies:
1. Kernel structures sent to user space (via copy_to_user, put_user, netlink skb
   attributes, ioctl output arguments, socket options, or BPF buffers) where fields
   or structure padding might not be fully initialized/zeroed.
2. Conditional logic or branching that depends on potentially uninitialized variables
   or struct fields.
3. Allocation or initialization of complex data structures where uninitialized fields
   could be read later in reachable code paths.
4. Bounds checks, lengths, or logic in a way that allows surrounding code to access
   uninitialized bytes of existing buffers.

Set NeedsKMSAN=false IF:
- The code changes primarily risk out-of-bounds access, array overflows, NULL pointer
  dereferences, locking deadlocks, or use-after-free bugs (these are already caught
  by KASAN, LOCKDEP, or standard bug detectors).
- All stack/heap structures touched or introduced by the patch are fully zeroed
  or initialized (e.g. using = {0}, memset, kzalloc) before being read or copied.
- The patch does not introduce any risk of uninitialized memory usage or info-leaks.

Use your code access tools to inspect the surrounding code if necessary, then provide
detailed KMSANReasoning contrasting KASAN vs KMSAN applicability for this patch.
Prefer calling several tools at the same time to save round-trips.


Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.

Prompt:
Target architecture: amd64

For your convenience, here is the diff of the changes:
commit 4b1bcdf04ef59a561451aa72c8d69309ad45a6ec
Author: syz-cluster <triage@syzkaller.com>
Date:   Tue Sep 29 11:02:44 2026 +0000

    syz-cluster: applied patch under review

diff --git a/arch/alpha/include/uapi/asm/socket.h b/arch/alpha/include/uapi/asm/socket.h
index 946a5fad26912..5d3524c26b2bc 100644
--- a/arch/alpha/include/uapi/asm/socket.h
+++ b/arch/alpha/include/uapi/asm/socket.h
@@ -157,6 +157,10 @@
 
 #define SO_RIGHTS_NOTRUNC      85
 
+#define SO_PASSPIDFD_THREAD    86
+
+#define SO_PEERPIDFD_THREAD    87
+
 #if !defined(__KERNEL__)
 
 #if __BITS_PER_LONG == 64
diff --git a/arch/mips/include/uapi/asm/socket.h b/arch/mips/include/uapi/asm/socket.h
index f1641dde135fc..245a43f52fb1a 100644
--- a/arch/mips/include/uapi/asm/socket.h
+++ b/arch/mips/include/uapi/asm/socket.h
@@ -168,6 +168,10 @@
 
 #define SO_RIGHTS_NOTRUNC      85
 
+#define SO_PASSPIDFD_THREAD    86
+
+#define SO_PEERPIDFD_THREAD    87
+
 #if !defined(__KERNEL__)
 
 #if __BITS_PER_LONG == 64
diff --git a/arch/parisc/include/uapi/asm/socket.h b/arch/parisc/include/uapi/asm/socket.h
index f3a3815c7dc29..f23710e1c6714 100644
--- a/arch/parisc/include/uapi/asm/socket.h
+++ b/arch/parisc/include/uapi/asm/socket.h
@@ -149,6 +149,10 @@
 
 #define SO_RIGHTS_NOTRUNC	0x4053
 
+#define SO_PASSPIDFD_THREAD	0x4054
+
+#define SO_PEERPIDFD_THREAD	0x4055
+
 #if !defined(__KERNEL__)
 
 #if __BITS_PER_LONG == 64
diff --git a/arch/sparc/include/uapi/asm/socket.h b/arch/sparc/include/uapi/asm/socket.h
index 7907f3b1f0ee0..b35b25bdefc2b 100644
--- a/arch/sparc/include/uapi/asm/socket.h
+++ b/arch/sparc/include/uapi/asm/socket.h
@@ -150,6 +150,10 @@
 
 #define SO_RIGHTS_NOTRUNC        0x005e
 
+#define SO_PASSPIDFD_THREAD      0x005f
+
+#define SO_PEERPIDFD_THREAD      0x0060
+
 #if !defined(__KERNEL__)
 
 
diff --git a/fs/coredump.c b/fs/coredump.c
index 6114839f5178b..870ad720b2152 100644
--- a/fs/coredump.c
+++ b/fs/coredump.c
@@ -454,7 +454,7 @@ static bool coredump_parse(struct core_name *cn, struct coredump_params *cprm,
 				 * leader we know that the thread-group leader
 				 * cannot be reaped until @current has exited.
 				 */
-				cprm->pid = task_tgid(current);
+				task_pids(cprm->pid, current);
 				err = cn_printf(cn, "%d", COREDUMP_PIDFD_NUMBER);
 				break;
 			}
@@ -626,13 +626,17 @@ static int umh_coredump_setup(struct subprocess_info *info, struct cred *new)
 	struct coredump_params *cp = (struct coredump_params *)info->data;
 	int err;
 
-	if (cp->pid) {
+	if (cp->pid[PIDTYPE_TGID]) {
 		struct file *pidfs_file __free(fput) = NULL;
 
-		pidfs_file = pidfs_alloc_file(cp->pid, 0);
+		pidfs_file = pidfs_alloc_file(cp->pid[PIDTYPE_TGID], 0);
 		if (IS_ERR(pidfs_file))
 			return PTR_ERR(pidfs_file);
 
+		err = pidfs_register_pids(cp->pid);
+		if (err)
+			return err;
+
 		pidfs_coredump(cp);
 
 		/*
@@ -695,12 +699,12 @@ static bool coredump_sock_connect(struct core_name *cn, struct coredump_params *
 		return false;
 
 	/*
-	 * Set the thread-group leader pid which is used for the peer
-	 * credentials during connect() below. Then immediately register
-	 * it in pidfs...
+	 * Set the pids of the dumping thread and its thread-group leader
+	 * which are used for the peer credentials during connect() below.
+	 * Then immediately register them in pidfs...
 	 */
-	cprm->pid = task_tgid(current);
-	retval = pidfs_register_pid(cprm->pid);
+	task_pids(cprm->pid, current);
+	retval = pidfs_register_pids(cprm->pid);
 	if (retval)
 		return false;
 
@@ -722,7 +726,7 @@ static bool coredump_sock_connect(struct core_name *cn, struct coredump_params *
 	}
 
 	/* ... and validate that @sk_peer_pid matches @cprm.pid. */
-	if (WARN_ON_ONCE(unix_peer(socket->sk)->sk_peer_pid != cprm->pid))
+	if (WARN_ON_ONCE(!pids_equal(unix_peer(socket->sk)->sk_peer_pid, cprm->pid)))
 		return false;
 
 	cprm->limit = RLIM_INFINITY;
diff --git a/fs/pidfs.c b/fs/pidfs.c
index a6a643f15d08a..29299b2c7ca71 100644
--- a/fs/pidfs.c
+++ b/fs/pidfs.c
@@ -793,9 +793,9 @@ void pidfs_exit(struct task_struct *tsk)
 }
 
 #ifdef CONFIG_COREDUMP
-void pidfs_coredump(const struct coredump_params *cprm)
+static void pidfs_coredump_pid(struct pid *pid,
+			       const struct coredump_params *cprm)
 {
-	struct pid *pid = cprm->pid;
 	struct pidfs_attr *attr;
 
 	attr = READ_ONCE(pid->attr);
@@ -814,6 +814,13 @@ void pidfs_coredump(const struct coredump_params *cprm)
 	smp_wmb();
 	set_bit(PIDFS_ATTR_BIT_COREDUMP, &attr->attr_mask);
 }
+
+void pidfs_coredump(const struct coredump_params *cprm)
+{
+	/* The dumping thread's pidfd reports the coredump as well. */
+	for (enum pid_type type = PIDTYPE_PID; type <= pids_last(cprm->pid); type++)
+		pidfs_coredump_pid(cprm->pid[type], cprm);
+}
 #endif
 
 static struct vfsmount *pidfs_mnt __ro_after_init;
@@ -1070,6 +1077,22 @@ int pidfs_register_pid_gfp(struct pid *pid, gfp_t gfp)
 	return 0;
 }
 
+/* Register the pids up to pid type @last of @pids in pidfs. */
+int __pidfs_register_pids(struct pid *const *pids, enum pid_type last)
+{
+	if (WARN_ON_ONCE(last >= PIDTYPE_MAX))
+		return -EINVAL;
+
+	for (enum pid_type type = PIDTYPE_PID; type <= last; type++) {
+		int ret = pidfs_register_pid(pids[type]);
+
+		if (unlikely(ret))
+			return ret;
+	}
+
+	return 0;
+}
+
 static struct dentry *pidfs_stash_dentry(struct dentry **stashed,
 					 struct dentry *dentry)
 {
diff --git a/include/linux/coredump.h b/include/linux/coredump.h
index 7b38ee2e7913b..0bbb7de6a4021 100644
--- a/include/linux/coredump.h
+++ b/include/linux/coredump.h
@@ -5,6 +5,7 @@
 #include <linux/types.h>
 #include <linux/mm.h>
 #include <linux/fs.h>
+#include <linux/pid_types.h>
 #include <linux/sched/coredump.h>
 #include <asm/siginfo.h>
 
@@ -32,7 +33,8 @@ struct coredump_params {
 	int vma_count;
 	size_t vma_data_size;
 	struct core_vma_metadata *vma_meta;
-	struct pid *pid;
+	/* Dumping thread and its thread-group leader by pid type. */
+	DECLARE_PIDS(pid, PIDTYPE_TGID);
 };
 
 extern unsigned int core_file_note_size_limit;
diff --git a/include/linux/pid.h b/include/linux/pid.h
index ddaef0bbc8ba3..87635d0cc1f71 100644
--- a/include/linux/pid.h
+++ b/include/linux/pid.h
@@ -2,6 +2,9 @@
 #ifndef _LINUX_PID_H
 #define _LINUX_PID_H
 
+#include <linux/array_size.h>
+#include <linux/build_bug.h>
+#include <linux/minmax.h>
 #include <linux/pid_types.h>
 #include <linux/rculist.h>
 #include <linux/rcupdate.h>
@@ -92,6 +95,56 @@ static inline struct pid *get_pid(struct pid *pid)
 }
 
 extern void put_pid(struct pid *pid);
+
+/*
+ * Helpers for arrays of struct pid indexed by pid type declared with
+ * DECLARE_PIDS(). The array covers PIDTYPE_PID up to the pid type it
+ * was declared with and the helpers take that bound from the array.
+ */
+static inline void __get_pids(struct pid **dst, struct pid *const *src,
+			      enum pid_type last)
+{
+	for (enum pid_type type = PIDTYPE_PID; type <= last; type++)
+		dst[type] = get_pid(src[type]);
+}
+
+static inline void __put_pids(struct pid **pids, enum pid_type last)
+{
+	for (enum pid_type type = PIDTYPE_PID; type <= last; type++) {
+		put_pid(pids[type]);
+		pids[type] = NULL;
+	}
+}
+
+static inline void __swap_pids(struct pid **a, struct pid **b,
+			       enum pid_type last)
+{
+	for (enum pid_type type = PIDTYPE_PID; type <= last; type++)
+		swap(a[type], b[type]);
+}
+
+static inline bool __pids_equal(struct pid *const *a, struct pid *const *b,
+				enum pid_type last)
+{
+	for (enum pid_type type = PIDTYPE_PID; type <= last; type++)
+		if (a[type] != b[type])
+			return false;
+	return true;
+}
+
+/* The last pid type an array declared with DECLARE_PIDS() covers. */
+#define pids_last(pids)							\
+	((enum pid_type)(ARRAY_SIZE(pids) - 1 +				\
+			 BUILD_BUG_ON_ZERO(ARRAY_SIZE(pids) > PIDTYPE_MAX)))
+
+#define __pids_last2(a, b)						\
+	(pids_last(a) + BUILD_BUG_ON_ZERO(ARRAY_SIZE(a) != ARRAY_SIZE(b)))
+
+#define get_pids(dst, src)	__get_pids(dst, src, __pids_last2(dst, src))
+#define put_pids(pids)		__put_pids(pids, pids_last(pids))
+#define swap_pids(a, b)		__swap_pids(a, b, __pids_last2(a, b))
+#define pids_equal(a, b)	__pids_equal(a, b, __pids_last2(a, b))
+
 extern struct task_struct *pid_task(struct pid *pid, enum pid_type);
 static inline bool pid_has_task(struct pid *pid, enum pid_type type)
 {
diff --git a/include/linux/pid_types.h b/include/linux/pid_types.h
index c2aee1d91dcfd..3302690a2a281 100644
--- a/include/linux/pid_types.h
+++ b/include/linux/pid_types.h
@@ -2,6 +2,8 @@
 #ifndef _LINUX_PID_TYPES_H
 #define _LINUX_PID_TYPES_H
 
+#include <linux/build_bug.h>
+
 enum pid_type {
 	PIDTYPE_PID,
 	PIDTYPE_TGID,
@@ -10,6 +12,12 @@ enum pid_type {
 	PIDTYPE_MAX,
 };
 
+struct pid;
+
+/* An array of struct pid indexed by pid type, PIDTYPE_PID up to @last. */
+#define DECLARE_PIDS(name, last)					\
+	struct pid *name[(last) + 1 + BUILD_BUG_ON_ZERO((last) >= PIDTYPE_MAX)]
+
 struct pid_namespace;
 extern struct pid_namespace init_pid_ns;
 
diff --git a/include/linux/pidfs.h b/include/linux/pidfs.h
index 0abf7da9ab236..3c1e82f1a3691 100644
--- a/include/linux/pidfs.h
+++ b/include/linux/pidfs.h
@@ -3,6 +3,7 @@
 #define _LINUX_PID_FS_H
 
 #include <linux/gfp_types.h>
+#include <linux/pid.h>
 
 struct coredump_params;
 
@@ -32,5 +33,9 @@ static inline int pidfs_register_pid(struct pid *pid)
 }
 
 void pidfs_free_pid(struct pid *pid);
+int __pidfs_register_pids(struct pid *const *pids, enum pid_type last);
+
+/* Register the pids of an array declared with DECLARE_PIDS(). */
+#define pidfs_register_pids(pids)	__pidfs_register_pids(pids, pids_last(pids))
 
 #endif /* _LINUX_PID_FS_H */
diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h
index d45a5476b97de..3149cdb976c60 100644
--- a/include/linux/sched/signal.h
+++ b/include/linux/sched/signal.h
@@ -674,6 +674,24 @@ struct pid *task_pid_type(struct task_struct *task, enum pid_type type)
 	return pid;
 }
 
+/* Fill @pids with the pid types of @task up to @last, without references. */
+static inline void __task_pids(struct pid **pids, enum pid_type last,
+			       struct task_struct *task)
+{
+	for (enum pid_type type = PIDTYPE_PID; type <= last; type++)
+		pids[type] = task_pid_type(task, type);
+}
+
+static inline void __get_task_pids(struct pid **pids, enum pid_type last,
+				   struct task_struct *task)
+{
+	for (enum pid_type type = PIDTYPE_PID; type <= last; type++)
+		pids[type] = get_pid(task_pid_type(task, type));
+}
+
+#define task_pids(pids, task)		__task_pids(pids, pids_last(pids), task)
+#define get_task_pids(pids, task)	__get_task_pids(pids, pids_last(pids), task)
+
 static inline struct pid *task_tgid(struct task_struct *task)
 {
 	return task->signal->pids[PIDTYPE_TGID];
diff --git a/include/linux/socket.h b/include/linux/socket.h
index 5a5eb12501032..b17fdb7d38a77 100644
--- a/include/linux/socket.h
+++ b/include/linux/socket.h
@@ -189,10 +189,11 @@ static inline size_t msg_data_left(const struct msghdr *msg)
 
 /* "Socket"-level control message types: */
 
-#define	SCM_RIGHTS	0x01		/* rw: access rights (array of int) */
-#define SCM_CREDENTIALS 0x02		/* rw: struct ucred		*/
-#define SCM_SECURITY	0x03		/* rw: security label		*/
-#define SCM_PIDFD	0x04		/* ro: pidfd (int)		*/
+#define	SCM_RIGHTS		0x01	/* rw: access rights (array of int) */
+#define SCM_CREDENTIALS		0x02	/* rw: struct ucred		*/
+#define SCM_SECURITY		0x03	/* rw: security label		*/
+#define SCM_PIDFD		0x04	/* ro: pidfd (int)		*/
+#define SCM_PIDFD_THREAD	0x05	/* ro: thread pidfd (int)	*/
 
 struct ucred {
 	__u32	pid;
diff --git a/include/net/scm.h b/include/net/scm.h
index 86ae6bc109ec6..aa7d15c5fc271 100644
--- a/include/net/scm.h
+++ b/include/net/scm.h
@@ -42,7 +42,7 @@ struct scm_fp_list {
 };
 
 struct scm_cookie {
-	struct pid		*pid;		/* Skb credentials */
+	DECLARE_PIDS(pid, PIDTYPE_TGID);	/* Skb credentials by pid type */
 	struct scm_fp_list	*fp;		/* Passed files		*/
 	struct scm_creds	creds;		/* Skb credentials	*/
 #ifdef CONFIG_SECURITY_NETWORK
@@ -69,7 +69,7 @@ static __inline__ void unix_get_peersec_dgram(struct socket *sock, struct scm_co
 static __inline__ void scm_set_cred(struct scm_cookie *scm,
 				    struct pid *pid, kuid_t uid, kgid_t gid)
 {
-	scm->pid = get_pid(pid);
+	scm->pid[PIDTYPE_TGID] = get_pid(pid);
 	scm->creds.pid = pid_vnr(pid);
 	scm->creds.uid = uid;
 	scm->creds.gid = gid;
@@ -77,8 +77,7 @@ static __inline__ void scm_set_cred(struct scm_cookie *scm,
 
 static __inline__ void scm_destroy_cred(struct scm_cookie *scm)
 {
-	put_pid(scm->pid);
-	scm->pid = NULL;
+	put_pids(scm->pid);
 }
 
 static __inline__ void scm_destroy(struct scm_cookie *scm)
diff --git a/include/net/sock.h b/include/net/sock.h
index 60ea55dc18854..efc64c60e4ac3 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -301,7 +301,7 @@ struct sk_filter;
   *	@sk_type: socket type (%SOCK_STREAM, etc)
   *	@sk_protocol: which protocol this socket belongs in this network family
   *	@sk_peer_lock: lock protecting @sk_peer_pid and @sk_peer_cred
-  *	@sk_peer_pid: &struct pid for this socket's peer
+  *	@sk_peer_pid: &struct pid for this socket's peer, by pid type
   *	@sk_peer_cred: %SO_PEERCRED setting
   *	@sk_rcvlowat: %SO_RCVLOWAT setting
   *	@sk_rcvtimeo: %SO_RCVTIMEO setting
@@ -356,6 +356,7 @@ struct sk_filter;
   *	@sk_scm_security: flagged by SO_PASSSEC to recv SCM_SECURITY
   *	@sk_scm_pidfd: flagged by SO_PASSPIDFD to recv SCM_PIDFD
   *	@sk_scm_rights: flagged by SO_PASSRIGHTS to recv SCM_RIGHTS
+  *	@sk_scm_pidfd_thread: flagged by SO_PASSPIDFD_THREAD to recv a thread SCM_PIDFD
   *	@sk_scm_unused: unused flags for scm_recv()
   *	@ns_tracker: tracker for netns reference
   *	@sk_user_frags: xarray of pages the user is holding a reference on.
@@ -545,7 +546,7 @@ struct sock {
 	u64			sk_ino;
 	spinlock_t		sk_peer_lock;
 	int			sk_bind_phc;
-	struct pid		*sk_peer_pid;
+	DECLARE_PIDS(sk_peer_pid, PIDTYPE_TGID);
 	const struct cred	*sk_peer_cred;
 
 	ktime_t			sk_stamp;
@@ -562,7 +563,8 @@ struct sock {
 				sk_scm_security : 1,
 				sk_scm_pidfd : 1,
 				sk_scm_rights : 1,
-				sk_scm_unused : 4;
+				sk_scm_pidfd_thread : 1,
+				sk_scm_unused : 3;
 		};
 	};
 	u8			sk_clockid;
@@ -2988,6 +2990,16 @@ static inline bool sk_is_stream_unix(const struct sock *sk)
 	return sk_is_unix(sk) && sk->sk_type == SOCK_STREAM;
 }
 
+static inline bool sk_scm_pidfd_wanted(const struct sock *sk)
+{
+	return sk->sk_scm_pidfd;
+}
+
+static inline bool sk_scm_pidfd_thread_wanted(const struct sock *sk)
+{
+	return sk->sk_scm_pidfd_thread;
+}
+
 static inline bool sk_is_vsock(const struct sock *sk)
 {
 	return sk->sk_family == AF_VSOCK;
diff --git a/include/trace/events/landlock.h b/include/trace/events/landlock.h
index 3a43638c9bc29..9e172ea22d95c 100644
--- a/include/trace/events/landlock.h
+++ b/include/trace/events/landlock.h
@@ -1037,7 +1037,7 @@ TRACE_EVENT(landlock_deny_scope_abstract_unix_socket,
 		 * updates.  The peer socket keeps a reference to sk_peer_pid
 		 * through pid_nr(); sun_path is the reliable identifier.
 		 */
-		peer_pid		= READ_ONCE(peer->sk_peer_pid);
+		peer_pid		= READ_ONCE(peer->sk_peer_pid[PIDTYPE_TGID]);
 		__entry->peer_pid	= peer_pid ? pid_nr(peer_pid) : 0;
 		__assign_str(sun_path);
 	),
diff --git a/include/uapi/asm-generic/socket.h b/include/uapi/asm-generic/socket.h
index 84ea7b92936e2..56fed7ab27ab8 100644
--- a/include/uapi/asm-generic/socket.h
+++ b/include/uapi/asm-generic/socket.h
@@ -152,6 +152,10 @@
 
 #define SO_RIGHTS_NOTRUNC	85
 
+#define SO_PASSPIDFD_THREAD	86
+
+#define SO_PEERPIDFD_THREAD	87
+
 #if !defined(__KERNEL__)
 
 #if __BITS_PER_LONG == 64 || (defined(__x86_64__) && defined(__ILP32__))
diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c
index 411d66f24393d..7758e9ea3848c 100644
--- a/net/bluetooth/af_bluetooth.c
+++ b/net/bluetooth/af_bluetooth.c
@@ -161,7 +161,7 @@ struct sock *bt_sock_alloc(struct net *net, struct socket *sock,
 	/* Init peer information so it can be properly monitored */
 	if (!kern) {
 		spin_lock(&sk->sk_peer_lock);
-		sk->sk_peer_pid  = get_pid(task_tgid(current));
+		sk->sk_peer_pid[PIDTYPE_TGID]  = get_pid(task_tgid(current));
 		sk->sk_peer_cred = get_current_cred();
 		spin_unlock(&sk->sk_peer_lock);
 	}
@@ -235,9 +235,9 @@ void bt_accept_enqueue(struct sock *parent, struct sock *sk, bool bh)
 	 * socket is allocated by the kernel.
 	 */
 	spin_lock(&sk->sk_peer_lock);
-	old_pid = sk->sk_peer_pid;
+	old_pid = sk->sk_peer_pid[PIDTYPE_TGID];
 	old_cred = sk->sk_peer_cred;
-	sk->sk_peer_pid = get_pid(parent->sk_peer_pid);
+	sk->sk_peer_pid[PIDTYPE_TGID] = get_pid(parent->sk_peer_pid[PIDTYPE_TGID]);
 	sk->sk_peer_cred = get_cred(parent->sk_peer_cred);
 	spin_unlock(&sk->sk_peer_lock);
 
diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
index 6d56c77741e19..4c40068ba5fb2 100644
--- a/net/bluetooth/hci_sock.c
+++ b/net/bluetooth/hci_sock.c
@@ -284,21 +284,21 @@ static void hci_sock_copy_creds(struct sock *sk, struct sk_buff *skb)
 	creds = &bt_cb(skb)->creds;
 
 	/* Check if peer credentials is set */
-	if (!sk->sk_peer_pid) {
+	if (!sk->sk_peer_pid[PIDTYPE_TGID]) {
 		/* Check if parent peer credentials is set */
-		if (bt_sk(sk)->parent && bt_sk(sk)->parent->sk_peer_pid)
+		if (bt_sk(sk)->parent && bt_sk(sk)->parent->sk_peer_pid[PIDTYPE_TGID])
 			sk = bt_sk(sk)->parent;
 		else
 			return;
 	}
 
 	/* Check if scm_creds already set */
-	if (creds->pid == pid_vnr(sk->sk_peer_pid))
+	if (creds->pid == pid_vnr(sk->sk_peer_pid[PIDTYPE_TGID]))
 		return;
 
 	memset(creds, 0, sizeof(*creds));
 
-	creds->pid = pid_vnr(sk->sk_peer_pid);
+	creds->pid = pid_vnr(sk->sk_peer_pid[PIDTYPE_TGID]);
 	if (sk->sk_peer_cred) {
 		creds->uid = sk->sk_peer_cred->uid;
 		creds->gid = sk->sk_peer_cred->gid;
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index 1194c37e466f1..872d8fb31b6fb 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -1890,7 +1890,7 @@ static struct pid *l2cap_sock_get_peer_pid_cb(struct l2cap_chan *chan)
 {
 	struct sock *sk = chan->data;
 
-	return sk->sk_peer_pid;
+	return sk->sk_peer_pid[PIDTYPE_TGID];
 }
 
 static void l2cap_sock_suspend_cb(struct l2cap_chan *chan)
diff --git a/net/core/scm.c b/net/core/scm.c
index f0d44ecdb11fc..ba43d76027af5 100644
--- a/net/core/scm.c
+++ b/net/core/scm.c
@@ -149,6 +149,7 @@ EXPORT_SYMBOL(__scm_destroy);
 
 static inline int scm_replace_pid(struct scm_cookie *scm, struct pid *pid)
 {
+	struct pid *thread_pid;
 	int err;
 
 	/* drop all previous references */
@@ -158,7 +159,18 @@ static inline int scm_replace_pid(struct scm_cookie *scm, struct pid *pid)
 	if (unlikely(err))
 		return err;
 
-	scm->pid = pid;
+	/* A sender naming its own thread-group sends from the current thread. */
+	if (pid == task_tgid(current))
+		thread_pid = task_pid(current);
+	else
+		thread_pid = pid;
+
+	err = pidfs_register_pid(thread_pid);
+	if (unlikely(err))
+		return err;
+
+	scm->pid[PIDTYPE_TGID] = pid;
+	scm->pid[PIDTYPE_PID] = get_pid(thread_pid);
 	scm->creds.pid = pid_vnr(pid);
 	return 0;
 }
@@ -207,7 +219,8 @@ int __scm_send(struct socket *sock, struct msghdr *msg, struct scm_cookie *p)
 			if (err)
 				goto error;
 
-			if (!p->pid || pid_vnr(p->pid) != creds.pid) {
+			if (!p->pid[PIDTYPE_TGID] ||
+			    pid_vnr(p->pid[PIDTYPE_TGID]) != creds.pid) {
 				struct pid *pid;
 				err = -ESRCH;
 				pid = find_get_pid(creds.pid);
@@ -486,11 +499,16 @@ static bool scm_has_secdata(struct sock *sk)
 }
 #endif
 
-static void scm_pidfd_recv(struct msghdr *msg, struct scm_cookie *scm)
+static void scm_pidfd_recv(struct msghdr *msg, struct scm_cookie *scm,
+			   enum pid_type type, int cmsg_type)
 {
+	unsigned int flags = PIDFD_STALE;
 	struct file *pidfd_file = NULL;
+	struct pid *pid;
 	int len, pidfd;
 
+	pid = scm->pid[type];
+
 	/* put_cmsg() doesn't return an error if CMSG is truncated,
 	 * that's why we need to opencode these checks here.
 	 */
@@ -504,12 +522,15 @@ static void scm_pidfd_recv(struct msghdr *msg, struct scm_cookie *scm)
 		return;
 	}
 
-	if (!scm->pid)
+	if (!pid)
 		return;
 
-	pidfd = pidfd_prepare(scm->pid, PIDFD_STALE, &pidfd_file);
+	if (type == PIDTYPE_PID)
+		flags |= PIDFD_THREAD;
 
-	if (put_cmsg(msg, SOL_SOCKET, SCM_PIDFD, sizeof(int), &pidfd)) {
+	pidfd = pidfd_prepare(pid, flags, &pidfd_file);
+
+	if (put_cmsg(msg, SOL_SOCKET, cmsg_type, sizeof(int), &pidfd)) {
 		if (pidfd_file) {
 			put_unused_fd(pidfd);
 			fput(pidfd_file);
@@ -526,8 +547,8 @@ static bool __scm_recv_common(struct sock *sk, struct msghdr *msg,
 			      struct scm_cookie *scm, int flags)
 {
 	if (!msg->msg_control) {
-		if (sk->sk_scm_credentials || sk->sk_scm_pidfd ||
-		    scm->fp || scm_has_secdata(sk))
+		if (sk->sk_scm_credentials || sk_scm_pidfd_wanted(sk) ||
+		    sk_scm_pidfd_thread_wanted(sk) || scm->fp || scm_has_secdata(sk))
 			msg->msg_flags |= MSG_CTRUNC;
 
 		scm_destroy(scm);
@@ -573,8 +594,11 @@ void scm_recv_unix(struct socket *sock, struct msghdr *msg,
 		scm_detach_fds(msg, scm, READ_ONCE(u->scm_rights_notrunc));
 	}
 
-	if (sock->sk->sk_scm_pidfd)
-		scm_pidfd_recv(msg, scm);
+	if (sk_scm_pidfd_wanted(sock->sk))
+		scm_pidfd_recv(msg, scm, PIDTYPE_TGID, SCM_PIDFD);
+
+	if (sk_scm_pidfd_thread_wanted(sock->sk))
+		scm_pidfd_recv(msg, scm, PIDTYPE_PID, SCM_PIDFD_THREAD);
 
 	scm_destroy_cred(scm);
 }
diff --git a/net/core/sock.c b/net/core/sock.c
index d23333bb4f3fa..c970f8beae3ba 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -1578,6 +1578,13 @@ int sk_setsockopt(struct sock *sk, int level, int optname,
 			ret = -EOPNOTSUPP;
 		break;
 
+	case SO_PASSPIDFD_THREAD:
+		if (sk_is_unix(sk))
+			sk->sk_scm_pidfd_thread = valbool;
+		else
+			ret = -EOPNOTSUPP;
+		break;
+
 	case SO_PASSRIGHTS:
 		if (sk_is_unix(sk))
 			sk->sk_scm_rights = valbool;
@@ -1729,6 +1736,50 @@ static int groups_to_user(sockptr_t dst, const struct group_info *src)
 	return 0;
 }
 
+/* Hand out a pidfd for @type of the socket's peer via SO_PEERPIDFD*. */
+static int sk_getsockopt_peerpidfd(struct sock *sk, enum pid_type type,
+				   sockptr_t optval, sockptr_t optlen, int len)
+{
+	struct file *pidfd_file = NULL;
+	unsigned int flags = 0;
+	struct pid *peer_pid;
+	int pidfd;
+
+	if (len > sizeof(pidfd))
+		len = sizeof(pidfd);
+
+	spin_lock(&sk->sk_peer_lock);
+	peer_pid = get_pid(sk->sk_peer_pid[type]);
+	spin_unlock(&sk->sk_peer_lock);
+
+	if (!peer_pid)
+		return -ENODATA;
+
+	/* The use of PIDFD_STALE requires stashing of struct pid on pidfs
+	 * with pidfs_register_pid() and only AF_UNIX is prepared for this.
+	 */
+	if (sk_is_unix(sk))
+		flags |= PIDFD_STALE;
+	if (type == PIDTYPE_PID)
+		flags |= PIDFD_THREAD;
+
+	pidfd = pidfd_prepare(peer_pid, flags, &pidfd_file);
+	put_pid(peer_pid);
+	if (pidfd < 0)
+		return pidfd;
+
+	if (copy_to_sockptr(optval, &pidfd, len) ||
+	    copy_to_sockptr(optlen, &len, sizeof(int))) {
+		put_unused_fd(pidfd);
+		fput(pidfd_file);
+
+		return -EFAULT;
+	}
+
+	fd_install(pidfd, pidfd_file);
+	return 0;
+}
+
 int sk_getsockopt(struct sock *sk, int level, int optname,
 		  sockptr_t optval, sockptr_t optlen)
 {
@@ -1893,6 +1944,13 @@ int sk_getsockopt(struct sock *sk, int level, int optname,
 		v.val = sk->sk_scm_pidfd;
 		break;
 
+	case SO_PASSPIDFD_THREAD:
+		if (!sk_is_unix(sk))
+			return -EOPNOTSUPP;
+
+		v.val = sk->sk_scm_pidfd_thread;
+		break;
+
 	case SO_PASSRIGHTS:
 		if (!sk_is_unix(sk))
 			return -EOPNOTSUPP;
@@ -1907,7 +1965,8 @@ int sk_getsockopt(struct sock *sk, int level, int optname,
 			len = sizeof(peercred);
 
 		spin_lock(&sk->sk_peer_lock);
-		cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
+		cred_to_ucred(sk->sk_peer_pid[PIDTYPE_TGID], sk->sk_peer_cred,
+			      &peercred);
 		spin_unlock(&sk->sk_peer_lock);
 
 		if (copy_to_sockptr(optval, &peercred, len))
@@ -1916,45 +1975,14 @@ int sk_getsockopt(struct sock *sk, int level, int optname,
 	}
 
 	case SO_PEERPIDFD:
-	{
-		struct pid *peer_pid;
-		struct file *pidfd_file = NULL;
-		unsigned int flags = 0;
-		int pidfd;
-
-		if (len > sizeof(pidfd))
-			len = sizeof(pidfd);
-
-		spin_lock(&sk->sk_peer_lock);
-		peer_pid = get_pid(sk->sk_peer_pid);
-		spin_unlock(&sk->sk_peer_lock);
-
-		if (!peer_pid)
-			return -ENODATA;
-
-		/* The use of PIDFD_STALE requires stashing of struct pid
-		 * on pidfs with pidfs_register_pid() and only AF_UNIX
-		 * were prepared for this.
-		 */
-		if (sk->sk_family == AF_UNIX)
-			flags = PIDFD_STALE;
+		return sk_getsockopt_peerpidfd(sk, PIDTYPE_TGID, optval, optlen, len);
 
-		pidfd = pidfd_prepare(peer_pid, flags, &pidfd_file);
-		put_pid(peer_pid);
-		if (pidfd < 0)
-			return pidfd;
-
-		if (copy_to_sockptr(optval, &pidfd, len) ||
-		    copy_to_sockptr(optlen, &len, sizeof(int))) {
-			put_unused_fd(pidfd);
-			fput(pidfd_file);
-
-			return -EFAULT;
-		}
+	case SO_PEERPIDFD_THREAD:
+		/* Only AF_UNIX records the peer's connecting thread. */
+		if (!sk_is_unix(sk))
+			return -EOPNOTSUPP;
 
-		fd_install(pidfd, pidfd_file);
-		return 0;
-	}
+		return sk_getsockopt_peerpidfd(sk, PIDTYPE_PID, optval, optlen, len);
 
 	case SO_PEERGROUPS:
 	{
@@ -2380,7 +2408,7 @@ static void __sk_destruct(struct rcu_head *head)
 
 	/* We do not need to acquire sk->sk_peer_lock, we are the last user. */
 	put_cred(sk->sk_peer_cred);
-	put_pid(sk->sk_peer_pid);
+	put_pids(sk->sk_peer_pid);
 
 	if (likely(sk->sk_net_refcnt)) {
 		put_net_track(net, &sk->ns_tracker);
@@ -3785,7 +3813,7 @@ void sock_init_data_uid(struct socket *sock, struct sock *sk, kuid_t uid)
 	sk->sk_frag.offset	=	0;
 	sk->sk_peek_off		=	-1;
 
-	sk->sk_peer_pid 	=	NULL;
+	memset(sk->sk_peer_pid, 0, sizeof(sk->sk_peer_pid));
 	sk->sk_peer_cred	=	NULL;
 	spin_lock_init(&sk->sk_peer_lock);
 
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 42cffeafc8c14..54f122952979a 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -737,57 +737,53 @@ static void unix_release_sock(struct sock *sk, int embrion)
 }
 
 struct unix_peercred {
-	struct pid *peer_pid;
+	DECLARE_PIDS(peer_pid, PIDTYPE_TGID);
 	const struct cred *peer_cred;
 };
 
 static inline int prepare_peercred(struct unix_peercred *peercred)
 {
-	struct pid *pid;
 	int err;
 
-	pid = task_tgid(current);
-	err = pidfs_register_pid(pid);
-	if (likely(!err)) {
-		peercred->peer_pid = get_pid(pid);
-		peercred->peer_cred = get_current_cred();
+	get_task_pids(peercred->peer_pid, current);
+	err = pidfs_register_pids(peercred->peer_pid);
+	if (unlikely(err)) {
+		put_pids(peercred->peer_pid);
+		return err;
 	}
-	return err;
+
+	peercred->peer_cred = get_current_cred();
+	return 0;
 }
 
 static void drop_peercred(struct unix_peercred *peercred)
 {
 	const struct cred *cred = NULL;
-	struct pid *pid = NULL;
 
 	might_sleep();
 
-	swap(peercred->peer_pid, pid);
+	put_pids(peercred->peer_pid);
 	swap(peercred->peer_cred, cred);
-
-	put_pid(pid);
 	put_cred(cred);
 }
 
 static inline void init_peercred(struct sock *sk,
 				 const struct unix_peercred *peercred)
 {
-	sk->sk_peer_pid = peercred->peer_pid;
+	memcpy(sk->sk_peer_pid, peercred->peer_pid, sizeof(sk->sk_peer_pid));
 	sk->sk_peer_cred = peercred->peer_cred;
 }
 
 static void update_peercred(struct sock *sk, struct unix_peercred *peercred)
 {
 	const struct cred *old_cred;
-	struct pid *old_pid;
 
 	spin_lock(&sk->sk_peer_lock);
-	old_pid = sk->sk_peer_pid;
+	swap_pids(sk->sk_peer_pid, peercred->peer_pid);
 	old_cred = sk->sk_peer_cred;
-	init_peercred(sk, peercred);
+	sk->sk_peer_cred = peercred->peer_cred;
 	spin_unlock(&sk->sk_peer_lock);
 
-	peercred->peer_pid = old_pid;
 	peercred->peer_cred = old_cred;
 }
 
@@ -796,14 +792,15 @@ static void copy_peercred(struct sock *sk, struct sock *peersk)
 	lockdep_assert_held(&unix_sk(peersk)->lock);
 
 	spin_lock(&sk->sk_peer_lock);
-	sk->sk_peer_pid = get_pid(peersk->sk_peer_pid);
+	get_pids(sk->sk_peer_pid, peersk->sk_peer_pid);
 	sk->sk_peer_cred = get_cred(peersk->sk_peer_cred);
 	spin_unlock(&sk->sk_peer_lock);
 }
 
 static bool unix_may_passcred(const struct sock *sk)
 {
-	return sk->sk_scm_credentials || sk->sk_scm_pidfd;
+	return sk->sk_scm_credentials || sk_scm_pidfd_wanted(sk) ||
+		sk_scm_pidfd_thread_wanted(sk);
 }
 
 static int unix_listen(struct socket *sock, int backlog)
@@ -1060,6 +1057,7 @@ static bool unix_bpf_bypass_getsockopt(int level, int optname)
 	if (level == SOL_SOCKET) {
 		switch (optname) {
 		case SO_PEERPIDFD:
+		case SO_PEERPIDFD_THREAD:
 			return true;
 		default:
 			return false;
@@ -1973,7 +1971,7 @@ static void unix_destruct_scm(struct sk_buff *skb)
 {
 	struct scm_cookie scm = {};
 
-	swap(scm.pid, UNIXCB(skb).pid);
+	swap_pids(scm.pid, UNIXCB(skb).pid);
 
 	if (UNIXCB(skb).fp)
 		unix_detach_fds(&scm, skb);
@@ -1991,7 +1989,7 @@ static int unix_scm_to_skb(struct scm_cookie *scm, struct sk_buff *skb, bool sen
 {
 	int err = 0;
 
-	UNIXCB(skb).pid = get_pid(scm->pid);
+	get_pids(UNIXCB(skb).pid, scm->pid);
 	UNIXCB(skb).uid = scm->creds.uid;
 	UNIXCB(skb).gid = scm->creds.gid;
 	UNIXCB(skb).fp = NULL;
@@ -2005,7 +2003,10 @@ static int unix_scm_to_skb(struct scm_cookie *scm, struct sk_buff *skb, bool sen
 
 static void unix_skb_to_scm(struct sk_buff *skb, struct scm_cookie *scm)
 {
-	scm_set_cred(scm, UNIXCB(skb).pid, UNIXCB(skb).uid, UNIXCB(skb).gid);
+	get_pids(scm->pid, UNIXCB(skb).pid);
+	scm->creds.pid = pid_vnr(scm->pid[PIDTYPE_TGID]);
+	scm->creds.uid = UNIXCB(skb).uid;
+	scm->creds.gid = UNIXCB(skb).gid;
 	unix_set_secdata(scm, skb);
 }
 
@@ -2025,30 +2026,35 @@ static void unix_skb_to_scm(struct sk_buff *skb, struct scm_cookie *scm)
 static int unix_maybe_add_creds(struct sk_buff *skb, const struct sock *sk,
 				const struct sock *other)
 {
-	if (UNIXCB(skb).pid)
+	if (UNIXCB(skb).pid[PIDTYPE_TGID])
 		return 0;
 
 	if (unix_may_passcred(sk) || unix_may_passcred(other) ||
 	    !other->sk_socket) {
-		struct pid *pid;
 		int err;
 
-		pid = task_tgid(current);
-		err = pidfs_register_pid(pid);
-		if (unlikely(err))
+		get_task_pids(UNIXCB(skb).pid, current);
+		err = pidfs_register_pids(UNIXCB(skb).pid);
+		if (unlikely(err)) {
+			put_pids(UNIXCB(skb).pid);
 			return err;
+		}
 
-		UNIXCB(skb).pid = get_pid(pid);
 		current_uid_gid(&UNIXCB(skb).uid, &UNIXCB(skb).gid);
 	}
 
 	return 0;
 }
 
-static bool unix_skb_scm_eq(struct sk_buff *skb,
+static bool unix_skb_scm_eq(const struct sock *sk, struct sk_buff *skb,
 			    struct scm_cookie *scm)
 {
-	return UNIXCB(skb).pid == scm->pid &&
+	/* Only a thread pidfd receiver can tell threads of one process apart. */
+	if (sk->sk_scm_pidfd_thread &&
+	    UNIXCB(skb).pid[PIDTYPE_PID] != scm->pid[PIDTYPE_PID])
+		return false;
+
+	return UNIXCB(skb).pid[PIDTYPE_TGID] == scm->pid[PIDTYPE_TGID] &&
 	       uid_eq(UNIXCB(skb).uid, scm->creds.uid) &&
 	       gid_eq(UNIXCB(skb).gid, scm->creds.gid) &&
 	       unix_secdata_eq(scm, skb);
@@ -3030,7 +3036,7 @@ static int unix_stream_read_generic(struct unix_stream_read_state *state,
 
 		if (check_creds) {
 			/* Never glue messages from different writers */
-			if (!unix_skb_scm_eq(skb, &scm))
+			if (!unix_skb_scm_eq(sk, skb, &scm))
 				break;
 		} else if (unix_may_passcred(sk)) {
 			/* Copy credentials */
diff --git a/net/unix/af_unix.h b/net/unix/af_unix.h
index 8119dbeef3a3c..402742895acca 100644
--- a/net/unix/af_unix.h
+++ b/net/unix/af_unix.h
@@ -2,6 +2,7 @@
 #ifndef __AF_UNIX_H
 #define __AF_UNIX_H
 
+#include <linux/pid_types.h>
 #include <linux/uidgid.h>
 
 #define UNIX_HASH_MOD	(256 - 1)
@@ -11,7 +12,7 @@
 struct sock *unix_peer_get(struct sock *sk);
 
 struct unix_skb_parms {
-	struct pid		*pid;		/* skb credentials	*/
+	DECLARE_PIDS(pid, PIDTYPE_TGID);	/* skb credentials by pid type */
 	kuid_t			uid;
 	kgid_t			gid;
 	struct scm_fp_list	*fp;		/* Passed files		*/
diff --git a/tools/lib/python/kdoc/xforms_lists.py b/tools/lib/python/kdoc/xforms_lists.py
index e3dda2fe8a537..e792785a15ec6 100644
--- a/tools/lib/python/kdoc/xforms_lists.py
+++ b/tools/lib/python/kdoc/xforms_lists.py
@@ -45,6 +45,7 @@ class CTransforms:
         (CMatch("DECLARE_HASHTABLE"), r"unsigned long \1[1 << ((\2) - 1)]"),
         (CMatch("DECLARE_KFIFO"), r"\2 *\1"),
         (CMatch("DECLARE_KFIFO_PTR"), r"\2 *\1"),
+        (CMatch("DECLARE_PIDS"), r"struct pid *\1[(\2) + 1]"),
         (CMatch("(?:__)?DECLARE_FLEX_ARRAY"), r"\1 \2[]"),
         (CMatch("DEFINE_DMA_UNMAP_ADDR"), r"dma_addr_t \1"),
         (CMatch("DEFINE_DMA_UNMAP_LEN"), r"__u32 \1"),
diff --git a/tools/testing/selftests/coredump/coredump_socket_test.c b/tools/testing/selftests/coredump/coredump_socket_test.c
index 422728f632ca6..ec73bb690bbcb 100644
--- a/tools/testing/selftests/coredump/coredump_socket_test.c
+++ b/tools/testing/selftests/coredump/coredump_socket_test.c
@@ -592,6 +592,181 @@ TEST_F(coredump, socket_coredump_signal_sigsegv)
 	wait_and_check_coredump_server(pid_coredump_server, _metadata, self);
 }
 
+static bool check_coredump_info(const struct pidfd_info *info, const char *what)
+{
+	if (!(info->mask & PIDFD_INFO_COREDUMP)) {
+		fprintf(stderr, "%s: PIDFD_INFO_COREDUMP not set in mask\n", what);
+		return false;
+	}
+
+	if (!(info->coredump_mask & PIDFD_COREDUMPED)) {
+		fprintf(stderr, "%s: PIDFD_COREDUMPED not set in coredump_mask\n", what);
+		return false;
+	}
+
+	if (!(info->mask & PIDFD_INFO_COREDUMP_SIGNAL) || info->coredump_signal != SIGSEGV) {
+		fprintf(stderr, "%s: coredump_signal=%d, expected SIGSEGV=%d\n",
+			what, info->coredump_signal, SIGSEGV);
+		return false;
+	}
+
+	if (!(info->mask & PIDFD_INFO_COREDUMP_CODE) || info->coredump_code != SEGV_MAPERR) {
+		fprintf(stderr, "%s: coredump_code=%d, expected SEGV_MAPERR=%d\n",
+			what, info->coredump_code, SEGV_MAPERR);
+		return false;
+	}
+
+	return true;
+}
+
+/*
+ * Test: PIDFD_INFO_COREDUMP on the dumping thread's pidfd
+ *
+ * Crash from a non-leader thread and verify that the pidfd from
+ * SO_PEERPIDFD_THREAD refers to that thread and reports the coredump
+ * like the thread-group leader's pidfd from SO_PEERPIDFD does.
+ */
+TEST_F(coredump, socket_coredump_thread)
+{
+	int pidfd, ret, status;
+	pid_t pid, pid_coredump_server;
+	struct pidfd_info info = {};
+	int ipc_sockets[2];
+	char c;
+
+	ASSERT_TRUE(set_core_pattern("@/tmp/coredump.socket"));
+
+	ret = socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, ipc_sockets);
+	ASSERT_EQ(ret, 0);
+
+	pid_coredump_server = fork();
+	ASSERT_GE(pid_coredump_server, 0);
+	if (pid_coredump_server == 0) {
+		int fd_server = -1, fd_coredump = -1, fd_peer_pidfd = -1;
+		int fd_thread_pidfd = -1, fd_core_file = -1;
+		struct pidfd_info thread_info = {};
+		int exit_code = EXIT_FAILURE;
+
+		close(ipc_sockets[0]);
+
+		fd_server = create_and_listen_unix_socket("/tmp/coredump.socket");
+		if (fd_server < 0) {
+			fprintf(stderr, "socket_coredump_thread: listen socket failed: %m\n");
+			goto out;
+		}
+
+		if (write_nointr(ipc_sockets[1], "1", 1) < 0) {
+			fprintf(stderr, "socket_coredump_thread: ipc write failed: %m\n");
+			goto out;
+		}
+
+		close(ipc_sockets[1]);
+
+		fd_coredump = accept4(fd_server, NULL, NULL, SOCK_CLOEXEC);
+		if (fd_coredump < 0) {
+			fprintf(stderr, "socket_coredump_thread: accept4 failed: %m\n");
+			goto out;
+		}
+
+		fd_peer_pidfd = get_peer_pidfd(fd_coredump);
+		if (fd_peer_pidfd < 0) {
+			fprintf(stderr, "socket_coredump_thread: get_peer_pidfd failed\n");
+			goto out;
+		}
+
+		fd_thread_pidfd = get_peer_pidfd_thread(fd_coredump);
+		if (fd_thread_pidfd < 0) {
+			fprintf(stderr, "socket_coredump_thread: get_peer_pidfd_thread failed\n");
+			goto out;
+		}
+
+		if (!get_pidfd_info(fd_peer_pidfd, &info) ||
+		    !get_pidfd_info(fd_thread_pidfd, &thread_info)) {
+			fprintf(stderr, "socket_coredump_thread: get_pidfd_info failed\n");
+			goto out;
+		}
+
+		/* The peer is the thread-group leader, the dumping thread is not. */
+		if (info.pid != info.tgid || thread_info.tgid != info.tgid ||
+		    thread_info.pid == thread_info.tgid) {
+			fprintf(stderr, "socket_coredump_thread: unexpected ids %d/%d and %d/%d\n",
+				info.pid, info.tgid, thread_info.pid, thread_info.tgid);
+			goto out;
+		}
+
+		if (!check_coredump_info(&info, "SO_PEERPIDFD") ||
+		    !check_coredump_info(&thread_info, "SO_PEERPIDFD_THREAD"))
+			goto out;
+
+		fd_core_file = open_coredump_tmpfile(self->fd_tmpfs_detached);
+		if (fd_core_file < 0) {
+			fprintf(stderr, "socket_coredump_thread: core tmpfile failed: %m\n");
+			goto out;
+		}
+
+		for (;;) {
+			char buffer[4096];
+			ssize_t bytes_read, bytes_write;
+
+			bytes_read = read(fd_coredump, buffer, sizeof(buffer));
+			if (bytes_read < 0) {
+				fprintf(stderr, "socket_coredump_thread: core read failed: %m\n");
+				goto out;
+			}
+
+			if (bytes_read == 0)
+				break;
+
+			bytes_write = write(fd_core_file, buffer, bytes_read);
+			if (bytes_read != bytes_write) {
+				fprintf(stderr, "socket_coredump_thread: core write %zd/%zd: %m\n",
+					bytes_read, bytes_write);
+				goto out;
+			}
+		}
+
+		exit_code = EXIT_SUCCESS;
+		fprintf(stderr, "socket_coredump_thread: completed successfully\n");
+out:
+		if (fd_core_file >= 0)
+			close(fd_core_file);
+		if (fd_thread_pidfd >= 0)
+			close(fd_thread_pidfd);
+		if (fd_peer_pidfd >= 0)
+			close(fd_peer_pidfd);
+		if (fd_coredump >= 0)
+			close(fd_coredump);
+		if (fd_server >= 0)
+			close(fd_server);
+		_exit(exit_code);
+	}
+	self->pid_coredump_server = pid_coredump_server;
+
+	EXPECT_EQ(close(ipc_sockets[1]), 0);
+	ASSERT_EQ(read_nointr(ipc_sockets[0], &c, 1), 1);
+	EXPECT_EQ(close(ipc_sockets[0]), 0);
+
+	pid = fork();
+	ASSERT_GE(pid, 0);
+	if (pid == 0)
+		crashing_child_thread();
+
+	pidfd = sys_pidfd_open(pid, 0);
+	ASSERT_GE(pidfd, 0);
+
+	waitpid(pid, &status, 0);
+	ASSERT_TRUE(WIFSIGNALED(status));
+	ASSERT_EQ(WTERMSIG(status), SIGSEGV);
+	ASSERT_TRUE(WCOREDUMP(status));
+
+	ASSERT_TRUE(get_pidfd_info(pidfd, &info));
+	ASSERT_TRUE(!!(info.mask & PIDFD_INFO_COREDUMP));
+	ASSERT_TRUE(!!(info.coredump_mask & PIDFD_COREDUMPED));
+	ASSERT_EQ(info.coredump_signal, SIGSEGV);
+
+	wait_and_check_coredump_server(pid_coredump_server, _metadata, self);
+}
+
 /*
  * Test: PIDFD_INFO_COREDUMP_SIGNAL via simple socket coredump with SIGABRT
  *
diff --git a/tools/testing/selftests/coredump/coredump_test.h b/tools/testing/selftests/coredump/coredump_test.h
index ed47f01fa53c5..4212656e31f01 100644
--- a/tools/testing/selftests/coredump/coredump_test.h
+++ b/tools/testing/selftests/coredump/coredump_test.h
@@ -27,10 +27,12 @@ FIXTURE(coredump)
 /* Shared helper function declarations */
 void *do_nothing(void *arg);
 void crashing_child(void);
+void crashing_child_thread(void);
 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);
 
 /* Inline helper that uses harness types */
diff --git a/tools/testing/selftests/coredump/coredump_test_helpers.c b/tools/testing/selftests/coredump/coredump_test_helpers.c
index 2a20faf9cb0ad..36306069f62e5 100644
--- a/tools/testing/selftests/coredump/coredump_test_helpers.c
+++ b/tools/testing/selftests/coredump/coredump_test_helpers.c
@@ -13,6 +13,7 @@
 #include <string.h>
 #include <sys/epoll.h>
 #include <sys/ioctl.h>
+#include <sys/mman.h>
 #include <sys/socket.h>
 #include <sys/types.h>
 #include <sys/un.h>
@@ -38,6 +39,10 @@ struct _fixture_coredump_data {
 
 #define NUM_THREAD_SPAWN 128
 
+#ifndef SO_PEERPIDFD_THREAD
+#define SO_PEERPIDFD_THREAD 87
+#endif
+
 void *do_nothing(void *arg)
 {
 	(void)arg;
@@ -59,6 +64,36 @@ void crashing_child(void)
 	i = *(volatile int *)NULL;
 }
 
+static void *crashing_thread(void *arg)
+{
+	int *p;
+
+	(void)arg;
+
+	/* crash on purpose with SEGV_MAPERR */
+	p = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE,
+		 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+	if (p == MAP_FAILED)
+		return NULL;
+	munmap(p, PAGE_SIZE);
+	*p = 0;
+
+	return NULL;
+}
+
+void crashing_child_thread(void)
+{
+	pthread_t thread;
+	int i;
+
+	for (i = 0; i < NUM_THREAD_SPAWN; ++i)
+		pthread_create(&thread, NULL, do_nothing, NULL);
+
+	/* crash from a non-leader thread */
+	pthread_create(&thread, NULL, crashing_thread, NULL);
+	pause();
+}
+
 int create_detached_tmpfs(void)
 {
 	int fd_context, fd_tmpfs;
@@ -138,6 +173,20 @@ int get_peer_pidfd(int fd)
 	return fd_peer_pidfd;
 }
 
+int get_peer_pidfd_thread(int fd)
+{
+	int fd_peer_pidfd;
+	socklen_t fd_peer_pidfd_len = sizeof(fd_peer_pidfd);
+	int ret = getsockopt(fd, SOL_SOCKET, SO_PEERPIDFD_THREAD, &fd_peer_pidfd,
+			     &fd_peer_pidfd_len);
+	if (ret < 0) {
+		fprintf(stderr, "%s: getsockopt(SO_PEERPIDFD_THREAD) failed: %m\n", __func__);
+		return -1;
+	}
+	fprintf(stderr, "%s: successfully retrieved pidfd %d\n", __func__, fd_peer_pidfd);
+	return fd_peer_pidfd;
+}
+
 bool get_pidfd_info(int fd_peer_pidfd, struct pidfd_info *info)
 {
 	int ret;
diff --git a/tools/testing/selftests/net/af_unix/Makefile b/tools/testing/selftests/net/af_unix/Makefile
index a66f10fb0c231..45b841758f1bf 100644
--- a/tools/testing/selftests/net/af_unix/Makefile
+++ b/tools/testing/selftests/net/af_unix/Makefile
@@ -23,6 +23,8 @@ TEST_GEN_FILES := scm_rights_denial_lsm.bpf.o
 include ../../lib.mk
 include ../bpf.mk
 
+$(OUTPUT)/scm_pidfd: CFLAGS += -pthread
+
 $(OUTPUT)/scm_rights_denial_lsm: $(BPFOBJ)
 $(OUTPUT)/scm_rights_denial_lsm: CFLAGS += -I$(SCRATCH_DIR)/include
 $(OUTPUT)/scm_rights_denial_lsm: LDLIBS += -lelf -lz
diff --git a/tools/testing/selftests/net/af_unix/scm_pidfd.c b/tools/testing/selftests/net/af_unix/scm_pidfd.c
index 2c18b92a26035..cbe53fab44fc5 100644
--- a/tools/testing/selftests/net/af_unix/scm_pidfd.c
+++ b/tools/testing/selftests/net/af_unix/scm_pidfd.c
@@ -10,6 +10,7 @@
 #include <unistd.h>
 #include <string.h>
 #include <errno.h>
+#include <pthread.h>
 #include <sys/un.h>
 #include <sys/signal.h>
 #include <sys/types.h>
@@ -27,6 +28,18 @@
 #define SCM_PIDFD 0x04
 #endif
 
+#ifndef SCM_PIDFD_THREAD
+#define SCM_PIDFD_THREAD 0x05
+#endif
+
+#ifndef SO_PASSPIDFD_THREAD
+#define SO_PASSPIDFD_THREAD 86
+#endif
+
+#ifndef SO_PEERPIDFD_THREAD
+#define SO_PEERPIDFD_THREAD 87
+#endif
+
 #define CHILD_EXIT_CODE_OK 123
 
 static void child_die()
@@ -553,4 +566,593 @@ TEST_F(scm_pidfd, test)
 	close(pfd);
 }
 
+struct thread_ids {
+	pid_t pid;
+	pid_t tid;
+};
+
+#define MAX_WRITERS 2
+
+/* Used by writers to signal they've written, so we can sequence multiple writers */
+static int seq_pipe[2];
+
+static void *send_ids_thread(void *arg)
+{
+	int fd = *(int *)arg;
+	struct thread_ids ids = {
+		.pid = getpid(),
+		.tid = gettid(),
+	};
+	char sync;
+
+	if (send(fd, &ids, sizeof(ids), 0) != sizeof(ids))
+		return (void *)1;
+
+	/* let the client start the next writer, so the queue order is known */
+	if (write(seq_pipe[1], "1", 1) != 1)
+		return (void *)1;
+
+	/* stay alive until the receiver has looked at our pidfd */
+	if (read(fd, &sync, 1) != 1)
+		return (void *)1;
+
+	return NULL;
+}
+
+static void *send_ids_creds_thread(void *arg)
+{
+	int fd = *(int *)arg;
+	struct thread_ids ids = {
+		.pid = getpid(),
+		.tid = gettid(),
+	};
+	struct ucred ucred = {
+		.pid = getpid(),
+		.uid = getuid(),
+		.gid = getgid(),
+	};
+	char control[CMSG_SPACE(sizeof(ucred))] = { 0 };
+	struct iovec iov;
+	struct msghdr msg = { 0 };
+	struct cmsghdr *cmsg;
+	char sync;
+
+	iov.iov_base = &ids;
+	iov.iov_len = sizeof(ids);
+
+	msg.msg_iov = &iov;
+	msg.msg_iovlen = 1;
+	msg.msg_control = control;
+	msg.msg_controllen = sizeof(control);
+
+	cmsg = CMSG_FIRSTHDR(&msg);
+	cmsg->cmsg_level = SOL_SOCKET;
+	cmsg->cmsg_type = SCM_CREDENTIALS;
+	cmsg->cmsg_len = CMSG_LEN(sizeof(ucred));
+	memcpy(CMSG_DATA(cmsg), &ucred, sizeof(ucred));
+
+	if (sendmsg(fd, &msg, 0) != sizeof(ids))
+		return (void *)1;
+
+	/* signal we've written our info */
+	if (write(seq_pipe[1], "1", 1) != 1)
+		return (void *)1;
+
+	/* stay alive until the receiver has looked at our pidfd */
+	if (read(fd, &sync, 1) != 1)
+		return (void *)1;
+
+	return NULL;
+}
+
+/*
+ * Runs @nwriters copies of @sender, each in its own non-leader thread, one
+ * at a time so the queue order is known, then tells the parent on @ackfd
+ * that everything is queued.
+ */
+static void thread_client(int fd, int syncfd, int ackfd,
+			  void *(*sender)(void *), int nwriters)
+{
+	pthread_t writers[MAX_WRITERS];
+	void *ret;
+	char sync;
+	int i;
+
+	/* wait until the receiver enabled the options it wants */
+	if (read(syncfd, &sync, 1) != 1)
+		child_die();
+
+	for (i = 0; i < nwriters; i++) {
+		if (pthread_create(&writers[i], NULL, sender, &fd))
+			child_die();
+
+		if (read(seq_pipe[0], &sync, 1) != 1)
+			child_die();
+	}
+
+	if (write(ackfd, "1", 1) != 1)
+		child_die();
+
+	for (i = 0; i < nwriters; i++)
+		if (pthread_join(writers[i], &ret) || ret)
+			child_die();
+
+	exit(0);
+}
+
+struct pidfd_msg {
+	ssize_t len;
+	struct thread_ids ids;
+	struct pidfd_info tgid_info;
+	struct pidfd_info thread_info;
+	int tgid_flags;
+	int thread_flags;
+	bool have_tgid;
+	bool have_thread;
+};
+
+static int get_pidfd_info(int pidfd, struct pidfd_info *info)
+{
+	info->mask = PIDFD_INFO_PID;
+	if (ioctl(pidfd, PIDFD_GET_INFO, info)) {
+		log_err("ioctl(PIDFD_GET_INFO)");
+		return -1;
+	}
+
+	return 0;
+}
+
+/* One recvmsg(), reporting how many bytes came back and what the pidfd
+ * cmsgs that came with them say.
+ */
+static int read_pidfd_msg(int fd, struct pidfd_msg *out)
+{
+	char control[CMSG_SPACE(sizeof(int)) * 2] = { 0 };
+	int tgid_pidfd = -1, thread_pidfd = -1;
+	struct thread_ids buf[2] = { 0 };
+	struct msghdr msg = { 0 };
+	struct cmsghdr *cmsg;
+	struct iovec iov;
+
+	iov.iov_base = buf;
+	iov.iov_len = sizeof(buf);
+	msg.msg_iov = &iov;
+	msg.msg_iovlen = 1;
+	msg.msg_control = control;
+	msg.msg_controllen = sizeof(control);
+
+	out->len = recvmsg(fd, &msg, 0);
+	if (out->len < 0) {
+		log_err("recvmsg");
+		return -1;
+	}
+
+	if (msg.msg_flags & MSG_CTRUNC) {
+		log_err("recvmsg: control truncated");
+		return -1;
+	}
+
+	out->ids = buf[0];
+
+	for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL;
+	     cmsg = CMSG_NXTHDR(&msg, cmsg)) {
+		if (cmsg->cmsg_level != SOL_SOCKET)
+			continue;
+
+		if (cmsg->cmsg_type == SCM_PIDFD)
+			memcpy(&tgid_pidfd, CMSG_DATA(cmsg), sizeof(tgid_pidfd));
+		else if (cmsg->cmsg_type == SCM_PIDFD_THREAD)
+			memcpy(&thread_pidfd, CMSG_DATA(cmsg), sizeof(thread_pidfd));
+	}
+
+	out->have_tgid = tgid_pidfd >= 0;
+	out->have_thread = thread_pidfd >= 0;
+
+	if (out->have_tgid) {
+		if (get_pidfd_info(tgid_pidfd, &out->tgid_info))
+			return -1;
+		out->tgid_flags = fcntl(tgid_pidfd, F_GETFL);
+		close(tgid_pidfd);
+	}
+
+	if (out->have_thread) {
+		if (get_pidfd_info(thread_pidfd, &out->thread_info))
+			return -1;
+		out->thread_flags = fcntl(thread_pidfd, F_GETFL);
+		close(thread_pidfd);
+	}
+
+	return 0;
+}
+
+/*
+ * Runs @nwriters threads of one child process against a SOCK_STREAM pair,
+ * all of them queued before the parent reads. SO_PASSPIDFD is set when
+ * @want_tgid is given, SO_PASSPIDFD_THREAD when @want_thread is. @nread
+ * reads are returned in @out.
+ */
+static int pidfd_flow(void *(*sender)(void *), int nwriters, bool want_tgid,
+		      bool want_thread, struct pidfd_msg *out, int nread)
+{
+	int child_status = 0;
+	int syncpipe[2];
+	int ackpipe[2];
+	int sk[2];
+	int on = 1;
+	char sync;
+	pid_t child;
+	int i;
+
+	if (nwriters > MAX_WRITERS)
+		return -1;
+
+	if (socketpair(AF_UNIX, SOCK_STREAM, 0, sk))
+		return -1;
+	if (pipe(syncpipe) || pipe(ackpipe) || pipe(seq_pipe))
+		return -1;
+
+	child = fork();
+	if (child < 0)
+		return -1;
+
+	if (child == 0) {
+		close(sk[0]);
+		close(syncpipe[1]);
+		close(ackpipe[0]);
+		thread_client(sk[1], syncpipe[0], ackpipe[1], sender, nwriters);
+	}
+	close(sk[1]);
+	close(syncpipe[0]);
+	close(ackpipe[1]);
+	close(seq_pipe[0]);
+	close(seq_pipe[1]);
+
+	if (want_tgid &&
+	    setsockopt(sk[0], SOL_SOCKET, SO_PASSPIDFD, &on, sizeof(on))) {
+		log_err("Failed to set SO_PASSPIDFD");
+		return -1;
+	}
+
+	if (want_thread &&
+	    setsockopt(sk[0], SOL_SOCKET, SO_PASSPIDFD_THREAD, &on, sizeof(on))) {
+		log_err("Failed to set SO_PASSPIDFD_THREAD");
+		return -1;
+	}
+
+	/* let the child know the options are set, it can write now */
+	if (write(syncpipe[1], "1", 1) != 1)
+		return -1;
+	close(syncpipe[1]);
+
+	/* wait until every writer has queued its message */
+	if (read(ackpipe[0], &sync, 1) != 1)
+		return -1;
+	close(ackpipe[0]);
+
+	for (i = 0; i < nread; i++)
+		if (read_pidfd_msg(sk[0], &out[i]))
+			return -1;
+
+	/* release the writers */
+	for (i = 0; i < nwriters; i++)
+		if (write(sk[0], "x", 1) != 1)
+			return -1;
+	close(sk[0]);
+
+	waitpid(child, &child_status, 0);
+	if (!WIFEXITED(child_status) || WEXITSTATUS(child_status))
+		return -1;
+
+	return 0;
+}
+
+static int sockopt_set(int fd, int optname, int val)
+{
+	return setsockopt(fd, SOL_SOCKET, optname, &val, sizeof(val));
+}
+
+static int sockopt_get(int fd, int optname)
+{
+	socklen_t len = sizeof(int);
+	int val = -1;
+
+	if (getsockopt(fd, SOL_SOCKET, optname, &val, &len))
+		return -1;
+
+	return val;
+}
+
+TEST(scm_pidfd_setsockopt_values)
+{
+	int sk[2];
+
+	ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_STREAM, 0, sk));
+
+	/* Verify that the options are truly set independently */
+	ASSERT_EQ(0, sockopt_set(sk[0], SO_PASSPIDFD_THREAD, 1));
+	ASSERT_EQ(1, sockopt_get(sk[0], SO_PASSPIDFD_THREAD));
+	ASSERT_EQ(0, sockopt_get(sk[0], SO_PASSPIDFD));
+
+	ASSERT_EQ(0, sockopt_set(sk[0], SO_PASSPIDFD, 1));
+	ASSERT_EQ(1, sockopt_get(sk[0], SO_PASSPIDFD));
+	ASSERT_EQ(1, sockopt_get(sk[0], SO_PASSPIDFD_THREAD));
+
+	/* Verify that the options are truly cleared independently */
+	ASSERT_EQ(0, sockopt_set(sk[0], SO_PASSPIDFD, 0));
+	ASSERT_EQ(0, sockopt_get(sk[0], SO_PASSPIDFD));
+	ASSERT_EQ(1, sockopt_get(sk[0], SO_PASSPIDFD_THREAD));
+
+	ASSERT_EQ(0, sockopt_set(sk[0], SO_PASSPIDFD_THREAD, 0));
+	ASSERT_EQ(0, sockopt_get(sk[0], SO_PASSPIDFD_THREAD));
+	ASSERT_EQ(0, sockopt_get(sk[0], SO_PASSPIDFD));
+
+	close(sk[0]);
+	close(sk[1]);
+}
+
+/* A receiver that only asked about the process cannot tell the two
+ * threads apart, so their writes are glued into one read.
+ */
+TEST(scm_pidfd_stream_glues_threads)
+{
+	struct pidfd_msg msg[1] = { 0 };
+
+	ASSERT_EQ(0, pidfd_flow(send_ids_thread, 2, true, false, msg, 1));
+	EXPECT_EQ(sizeof(struct thread_ids) * 2, msg[0].len);
+
+	EXPECT_TRUE(msg[0].have_tgid);
+	EXPECT_FALSE(msg[0].have_thread);
+	EXPECT_EQ(msg[0].ids.pid, msg[0].tgid_info.pid);
+	EXPECT_EQ(msg[0].ids.pid, msg[0].tgid_info.tgid);
+}
+
+/* A receiver asking for both thread and process pidfd should get a unique
+ * msg for each thread writing
+ */
+TEST(scm_pidfd_thread_stream_splits_on_threads)
+{
+	struct pidfd_msg msg[2] = { 0 };
+	int i;
+
+	ASSERT_EQ(0, pidfd_flow(send_ids_thread, 2, true, true, msg, 2));
+
+	for (i = 0; i < 2; i++) {
+		EXPECT_EQ(sizeof(struct thread_ids), msg[i].len);
+		EXPECT_TRUE(msg[i].have_tgid);
+		EXPECT_TRUE(msg[i].have_thread);
+
+		/* Make sure the info makes sense for the pidfd type */
+		EXPECT_EQ(msg[i].ids.pid, msg[i].tgid_info.pid);
+		EXPECT_EQ(msg[i].ids.pid, msg[i].tgid_info.tgid);
+		EXPECT_EQ(msg[i].ids.tid, msg[i].thread_info.pid);
+		EXPECT_EQ(msg[i].ids.pid, msg[i].thread_info.tgid);
+		EXPECT_NE(msg[i].ids.pid, msg[i].ids.tid);
+	}
+
+	/* Make sure we really got unique threads per message */
+	EXPECT_NE(msg[0].ids.tid, msg[1].ids.tid);
+	EXPECT_EQ(msg[0].ids.pid, msg[1].ids.pid);
+	EXPECT_EQ(msg[0].tgid_info.pid, msg[1].tgid_info.pid);
+	EXPECT_NE(msg[0].thread_info.pid, msg[1].thread_info.pid);
+}
+
+/* Sends from the thread-group leader */
+static int leader_flow(bool want_thread, struct pidfd_msg *out)
+{
+	struct thread_ids ids = {
+		.pid = getpid(),
+		.tid = gettid(),
+	};
+	int sk[2];
+	int on = 1;
+	int ret;
+
+	if (socketpair(AF_UNIX, SOCK_STREAM, 0, sk))
+		return -1;
+
+	if (setsockopt(sk[0], SOL_SOCKET, SO_PASSPIDFD, &on, sizeof(on))) {
+		log_err("Failed to set SO_PASSPIDFD");
+		return -1;
+	}
+
+	if (want_thread &&
+	    setsockopt(sk[0], SOL_SOCKET, SO_PASSPIDFD_THREAD, &on, sizeof(on))) {
+		log_err("Failed to set SO_PASSPIDFD_THREAD");
+		return -1;
+	}
+
+	if (send(sk[1], &ids, sizeof(ids), 0) != sizeof(ids)) {
+		log_err("send");
+		return -1;
+	}
+
+	ret = read_pidfd_msg(sk[0], out);
+
+	close(sk[0]);
+	close(sk[1]);
+
+	return ret;
+}
+
+TEST(scm_pidfd_leader_sender)
+{
+	struct pidfd_msg msg = { 0 };
+
+	ASSERT_EQ(getpid(), gettid());
+
+	ASSERT_EQ(0, leader_flow(false, &msg));
+	ASSERT_TRUE(msg.have_tgid);
+	EXPECT_FALSE(msg.have_thread);
+
+	EXPECT_EQ(getpid(), msg.tgid_info.pid);
+	EXPECT_EQ(getpid(), msg.tgid_info.tgid);
+	EXPECT_FALSE(msg.tgid_flags & O_EXCL);
+}
+
+TEST(scm_pidfd_thread_leader_sender)
+{
+	struct pidfd_msg msg = { 0 };
+
+	ASSERT_EQ(getpid(), gettid());
+
+	ASSERT_EQ(0, leader_flow(true, &msg));
+	ASSERT_TRUE(msg.have_tgid);
+	ASSERT_TRUE(msg.have_thread);
+
+	EXPECT_EQ(getpid(), msg.tgid_info.pid);
+	EXPECT_EQ(getpid(), msg.tgid_info.tgid);
+	EXPECT_EQ(getpid(), msg.thread_info.pid);
+	EXPECT_EQ(getpid(), msg.thread_info.tgid);
+
+	EXPECT_FALSE(msg.tgid_flags & O_EXCL);
+	EXPECT_TRUE(msg.thread_flags & O_EXCL);
+}
+
+TEST(scm_pidfd_thread_and_group)
+{
+	struct pidfd_msg msg = { 0 };
+
+	ASSERT_EQ(0, pidfd_flow(send_ids_thread, 1, true, true, &msg, 1));
+	ASSERT_NE(msg.ids.pid, msg.ids.tid);
+	ASSERT_TRUE(msg.have_tgid);
+	ASSERT_TRUE(msg.have_thread);
+
+	EXPECT_EQ(msg.ids.pid, msg.tgid_info.pid);
+	EXPECT_EQ(msg.ids.pid, msg.tgid_info.tgid);
+
+	EXPECT_EQ(msg.ids.tid, msg.thread_info.pid);
+	EXPECT_EQ(msg.ids.pid, msg.thread_info.tgid);
+}
+
+TEST(scm_pidfd_thread)
+{
+	struct pidfd_msg msg = { 0 };
+
+	ASSERT_EQ(0, pidfd_flow(send_ids_thread, 1, false, true, &msg, 1));
+	ASSERT_NE(msg.ids.pid, msg.ids.tid);
+	ASSERT_TRUE(msg.have_thread);
+	EXPECT_FALSE(msg.have_tgid);
+	EXPECT_EQ(msg.ids.tid, msg.thread_info.pid);
+	EXPECT_EQ(msg.ids.pid, msg.thread_info.tgid);
+}
+
+TEST(scm_pidfd_thread_group)
+{
+	struct pidfd_msg msg = { 0 };
+
+	ASSERT_EQ(0, pidfd_flow(send_ids_thread, 1, true, false, &msg, 1));
+	ASSERT_NE(msg.ids.pid, msg.ids.tid);
+	ASSERT_TRUE(msg.have_tgid);
+	EXPECT_FALSE(msg.have_thread);
+	EXPECT_EQ(msg.ids.pid, msg.tgid_info.pid);
+	EXPECT_EQ(msg.ids.pid, msg.tgid_info.tgid);
+}
+
+TEST(scm_pidfd_thread_creds)
+{
+	struct pidfd_msg msg = { 0 };
+
+	ASSERT_EQ(0, pidfd_flow(send_ids_creds_thread, 1, true, true, &msg, 1));
+	ASSERT_NE(msg.ids.pid, msg.ids.tid);
+	ASSERT_TRUE(msg.have_tgid);
+	ASSERT_TRUE(msg.have_thread);
+	EXPECT_EQ(msg.ids.pid, msg.tgid_info.pid);
+	EXPECT_EQ(msg.ids.pid, msg.tgid_info.tgid);
+	EXPECT_EQ(msg.ids.tid, msg.thread_info.pid);
+	EXPECT_EQ(msg.ids.pid, msg.thread_info.tgid);
+}
+
+static void *peer_connect_thread(void *arg)
+{
+	struct sock_addr *sa = arg;
+	struct thread_ids ids = {
+		.pid = getpid(),
+		.tid = gettid(),
+	};
+	int fd;
+	char sync;
+
+	fd = socket(AF_UNIX, SOCK_STREAM, 0);
+	if (fd < 0)
+		return (void *)1;
+
+	if (connect(fd, (struct sockaddr *)&sa->listen_addr, sa->addrlen))
+		return (void *)1;
+
+	if (send(fd, &ids, sizeof(ids), 0) != sizeof(ids))
+		return (void *)1;
+
+	/* stay alive until the server has looked at our pidfd */
+	if (read(fd, &sync, 1) != 1)
+		return (void *)1;
+
+	close(fd);
+	return NULL;
+}
+
+static int peer_pidfd_info(int fd, int optname, struct pidfd_info *info)
+{
+	int pidfd;
+	socklen_t len = sizeof(pidfd);
+
+	if (getsockopt(fd, SOL_SOCKET, optname, &pidfd, &len)) {
+		log_err("getsockopt(SO_PEERPIDFD*)");
+		return -1;
+	}
+
+	info->mask = PIDFD_INFO_PID;
+	if (ioctl(pidfd, PIDFD_GET_INFO, info)) {
+		log_err("ioctl(PIDFD_GET_INFO)");
+		close(pidfd);
+		return -1;
+	}
+
+	close(pidfd);
+	return 0;
+}
+
+/* SO_PEERPIDFD_THREAD returns a pidfd for the peer's connecting thread. */
+TEST(so_peerpidfd_thread)
+{
+	struct sock_addr sa;
+	struct thread_ids ids;
+	struct pidfd_info info;
+	pthread_t thread;
+	void *tret;
+	int server, cfd;
+
+	server = socket(AF_UNIX, SOCK_STREAM, 0);
+	ASSERT_LE(0, server);
+
+	fill_sockaddr(&sa, true);
+	ASSERT_EQ(0, bind(server, (struct sockaddr *)&sa.listen_addr, sa.addrlen));
+	ASSERT_EQ(0, listen(server, 1));
+
+	ASSERT_EQ(0, pthread_create(&thread, NULL, peer_connect_thread, &sa));
+
+	cfd = accept(server, NULL, NULL);
+	ASSERT_LE(0, cfd);
+
+	ASSERT_EQ(sizeof(ids), recv(cfd, &ids, sizeof(ids), MSG_WAITALL));
+	ASSERT_NE(ids.pid, ids.tid);
+
+	/* SO_PEERPIDFD refers to the peer's thread-group. */
+	ASSERT_EQ(0, peer_pidfd_info(cfd, SO_PEERPIDFD, &info));
+	EXPECT_EQ(ids.pid, info.pid);
+	EXPECT_EQ(ids.pid, info.tgid);
+
+	/* SO_PEERPIDFD_THREAD refers to the connecting thread. */
+	ASSERT_EQ(0, peer_pidfd_info(cfd, SO_PEERPIDFD_THREAD, &info));
+	EXPECT_EQ(ids.tid, info.pid);
+	EXPECT_EQ(ids.pid, info.tgid);
+
+	/* release the connecting thread */
+	ASSERT_EQ(1, write(cfd, "x", 1));
+	ASSERT_EQ(0, pthread_join(thread, &tret));
+	ASSERT_EQ(NULL, tret);
+
+	close(cfd);
+	close(server);
+}
+
 TEST_HARNESS_MAIN

35/3 2026/09/29 11:04 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 26700
							output: 30
							thoughts: 721
						

Thoughts:
**Analyzing the PIDFD Patch**

Okay, so this patch is introducing new features related to PIDFD handling within the kernel, specifically targeting thread IDs. It seems we're adding support for `SO_PASSPIDFD_THREAD`, `SO_PEERPIDFD_THREAD`, and `SCM_PIDFD_THREAD` for AF_UNIX sockets, and also extending the handling for pidfs and coredump generation. My primary concern, as always, is around potential security vulnerabilities—specifically, uninitialized memory reads, leaks to userspace, or exploitation in control flow. Let's dig in.

The initial changes are pretty straightforward: the `socket.h` headers are getting the new constants, and `linux/socket.h` is getting `SCM_PIDFD_THREAD`. No red flags there. The `pid_types.h` and `pid.h` changes look like standard infrastructure additions, defining and adding functions for managing `struct pid` arrays. The introduction of `DECLARE_PIDS` is important, defining the size of the PID array as 2 for `PIDTYPE_TGID`. The added helper functions for PID manipulation seem reasonable.

Now, things get more interesting with the `sched/signal.h` changes. We've got `task_pids` and `get_task_pids` which look to be populating PID arrays based on task information, and importantly, taking references on the `pid` with `get_pid`. This is normal.

The coredump changes in `coredump.h` and `fs/coredump.c` are what really pique my interest. We're seeing `cprm->pid` becoming a `DECLARE_PIDS` array, and functions like `task_pids` are being used to populate it. We see `cprm->pid` being used in several places, including in `coredump_parse`, `umh_coredump_setup`, and `coredump_sock_connect`. There's also a call to `pidfs_register_pids` and a check using `pids_equal`.

But hold on a second… a critical question is how `cprm` (which I assume is some kind of coredump parameter structure) is initialized *before* `coredump_parse` or `coredump_sock_connect` are called. This is the crux. If `cprm` isn't properly initialized before these functions touch its `pid` member, we could be looking at an uninitialized read or, even worse, a use-after-free scenario. This needs immediate investigation. I'll need to use `grepper` (or just read the file, of course) to trace the initialization of `cprm` within `fs/coredump.c` to see if that initialization is safe. That's the key: if the initialization is secure, the patch likely is too, in this area. If not, this is a serious vulnerability.



36/3 2026/09/29 11:04 tool grepper
0m Args:
{
  "Expression": "coredump_params",
  "PathPrefix": "fs/coredump.c"
}

Results:
{
  "Output": "fs/coredump.c-68-\nfs/coredump.c:69:static bool dump_vma_snapshot(struct coredump_params *cprm);\nfs/coredump.c:70:static void free_vma_snapshot(struct coredump_params *cprm);\nfs/coredump.c-71-\n--\nfs/coredump.c=198=static int cn_print_exe_file(struct core_name *cn, bool name_only)\n--\nfs/coredump.c-238- */\nfs/coredump.c:239:static bool coredump_parse(struct core_name *cn, struct coredump_params *cprm,\nfs/coredump.c-240-\t\t\t   size_t **argv, int *argc)\n--\nfs/coredump.c=623=static int umh_coredump_setup(struct subprocess_info *info, struct cred *new)\n--\nfs/coredump.c-625-\tstruct file *files[2];\nfs/coredump.c:626:\tstruct coredump_params *cp = (struct coredump_params *)info-\u003edata;\nfs/coredump.c-627-\tint err;\n--\nfs/coredump.c-671-#ifdef CONFIG_UNIX\nfs/coredump.c:672:static bool coredump_sock_connect(struct core_name *cn, struct coredump_params *cprm)\nfs/coredump.c-673-{\n--\nfs/coredump.c=787=static inline void coredump_sock_shutdown(struct file *file)\n--\nfs/coredump.c-798-\nfs/coredump.c:799:static bool coredump_sock_request(struct core_name *cn, struct coredump_params *cprm)\nfs/coredump.c-800-{\n--\nfs/coredump.c-861-\nfs/coredump.c:862:static bool coredump_socket(struct core_name *cn, struct coredump_params *cprm)\nfs/coredump.c-863-{\n--\nfs/coredump.c=871=static inline void coredump_sock_shutdown(struct file *file) { }\nfs/coredump.c:872:static inline bool coredump_socket(struct core_name *cn, struct coredump_params *cprm) { return false; }\nfs/coredump.c-873-#endif\n--\nfs/coredump.c-875-/* cprm-\u003edumpable is the snapshot of task dumpability at dump start. */\nfs/coredump.c:876:static inline bool coredump_force_suid_safe(const struct coredump_params *cprm)\nfs/coredump.c-877-{\n--\nfs/coredump.c-881-\nfs/coredump.c:882:static bool coredump_file(struct core_name *cn, struct coredump_params *cprm,\nfs/coredump.c-883-\t\t\t  const struct linux_binfmt *binfmt)\n--\nfs/coredump.c-972-\nfs/coredump.c:973:static bool coredump_pipe(struct core_name *cn, struct coredump_params *cprm,\nfs/coredump.c-974-\t\t\t  size_t *argv, int argc)\n--\nfs/coredump.c=1039=static bool coredump_write(struct core_name *cn,\nfs/coredump.c:1040:\t\t\t  struct coredump_params *cprm,\nfs/coredump.c-1041-\t\t\t  const struct linux_binfmt *binfmt)\n--\nfs/coredump.c-1066-\nfs/coredump.c:1067:static void coredump_cleanup(struct core_name *cn, struct coredump_params *cprm)\nfs/coredump.c-1068-{\n--\nfs/coredump.c-1078-\nfs/coredump.c:1079:static inline bool coredump_skip(const struct coredump_params *cprm,\nfs/coredump.c-1080-\t\t\t\t const struct linux_binfmt *binfmt)\n--\nfs/coredump.c-1090-\nfs/coredump.c:1091:static void do_coredump(struct core_name *cn, struct coredump_params *cprm,\nfs/coredump.c-1092-\t\t\tsize_t **argv, int *argc, const struct linux_binfmt *binfmt)\n--\nfs/coredump.c=1160=void vfs_coredump(const kernel_siginfo_t *siginfo)\n--\nfs/coredump.c-1167-\tint argc = 0;\nfs/coredump.c:1168:\tstruct coredump_params cprm = {\nfs/coredump.c-1169-\t\t.siginfo = siginfo,\n--\nfs/coredump.c-1208- */\nfs/coredump.c:1209:static int __dump_emit(struct coredump_params *cprm, const void *addr, int nr)\nfs/coredump.c-1210-{\n--\nfs/coredump.c-1228-\nfs/coredump.c:1229:static int __dump_skip(struct coredump_params *cprm, size_t nr)\nfs/coredump.c-1230-{\n--\nfs/coredump.c-1249-\nfs/coredump.c:1250:int dump_emit(struct coredump_params *cprm, const void *addr, int nr)\nfs/coredump.c-1251-{\n--\nfs/coredump.c=1259=EXPORT_SYMBOL(dump_emit);\nfs/coredump.c-1260-\nfs/coredump.c:1261:void dump_skip_to(struct coredump_params *cprm, unsigned long pos)\nfs/coredump.c-1262-{\n--\nfs/coredump.c=1265=EXPORT_SYMBOL(dump_skip_to);\nfs/coredump.c-1266-\nfs/coredump.c:1267:void dump_skip(struct coredump_params *cprm, size_t nr)\nfs/coredump.c-1268-{\n--\nfs/coredump.c=1271=EXPORT_SYMBOL(dump_skip);\n--\nfs/coredump.c-1273-#ifdef CONFIG_ELF_CORE\nfs/coredump.c:1274:static int dump_emit_page(struct coredump_params *cprm, struct page *page)\nfs/coredump.c-1275-{\n--\nfs/coredump.c=1330=static inline struct page *dump_page_copy(struct page *src, struct page *dst)\n--\nfs/coredump.c-1335-\nfs/coredump.c:1336:int dump_user_range(struct coredump_params *cprm, unsigned long start,\nfs/coredump.c-1337-\t\t    unsigned long len)\n--\nfs/coredump.c-1399-\nfs/coredump.c:1400:int dump_align(struct coredump_params *cprm, int align)\nfs/coredump.c-1401-{\n--\nfs/coredump.c=1676=static struct vm_area_struct *coredump_next_vma(struct vma_iterator *vmi,\n--\nfs/coredump.c-1688-\nfs/coredump.c:1689:static void free_vma_snapshot(struct coredump_params *cprm)\nfs/coredump.c-1690-{\n--\nfs/coredump.c=1703=static int cmp_vma_size(const void *vma_meta_lhs_ptr, const void *vma_meta_rhs_ptr)\n--\nfs/coredump.c-1718- */\nfs/coredump.c:1719:static bool dump_vma_snapshot(struct coredump_params *cprm)\nfs/coredump.c-1720-{\n"
}

37/3 2026/09/29 11:04 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 30170
							output: 36
							thoughts: 1021
						

Thoughts:
**Analyzing Potential Data Leakage in `SO_PEERPIDFD` Implementation**

Okay, let's dive into this. My initial thought is to examine how a `coredump_params` struct is initialized, specifically looking at line 1168 in `fs/coredump.c`. Ah, right, designated initializers ensure that unspecified fields, like `cprm.pid`, are zeroed out initially. Good.

Now, I'm shifting gears to `net/core/sock.c` and specifically the `sk_getsockopt_peerpidfd` function. I'm focusing on how `SO_PEERPIDFD` and the related `SO_PEERPIDFD_THREAD` options are implemented. The code's structure catches my attention: the original logic, which directly handled `SO_PEERPIDFD`, has been refactored into `sk_getsockopt_peerpidfd`, which is then called with different `PIDTYPE` values. Smart, keeps things clean.

I'm zeroing in on this function and its use of `copy_to_sockptr`. The critical point here is the `copy_to_sockptr(optlen, &len, sizeof(int))` call. This is where a potential vulnerability might exist. I need to understand how the length of the data being copied (represented by `len` and `optlen`) is handled within the `sk_getsockopt` framework. Specifically, I need to know if the `len` value is being properly validated or truncated before it is used to copy user-provided data back to userspace.

To get a complete picture, I need to look at the `sk_getsockopt` function itself, specifically around lines 1740-1800. This is where the length and option-value handling is done. I'm going to read through this section carefully to see how `optlen` and `len` are handled, and whether there are any potential buffer overflows or information leaks related to the copying of the `pidfd` value.



38/3 2026/09/29 11:04 tool read-file
0m Args:
{
  "File": "net/core/sock.c",
  "FirstLine": 1780,
  "LineCount": 50
}

Results:
{
  "Contents": "1780:\t\treturn 0;\n1781:\t}\n1782:\t\n1783:\tint sk_getsockopt(struct sock *sk, int level, int optname,\n1784:\t\t\t  sockptr_t optval, sockptr_t optlen)\n1785:\t{\n1786:\t\tstruct socket *sock = sk-\u003esk_socket;\n1787:\t\n1788:\t\tunion {\n1789:\t\t\tint val;\n1790:\t\t\tu64 val64;\n1791:\t\t\tunsigned long ulval;\n1792:\t\t\tstruct linger ling;\n1793:\t\t\tstruct old_timeval32 tm32;\n1794:\t\t\tstruct __kernel_old_timeval tm;\n1795:\t\t\tstruct  __kernel_sock_timeval stm;\n1796:\t\t\tstruct sock_txtime txtime;\n1797:\t\t\tstruct so_timestamping timestamping;\n1798:\t\t} v;\n1799:\t\n1800:\t\tint lv = sizeof(int);\n1801:\t\tint len;\n1802:\t\n1803:\t\tif (copy_from_sockptr(\u0026len, optlen, sizeof(int)))\n1804:\t\t\treturn -EFAULT;\n1805:\t\tif (len \u003c 0)\n1806:\t\t\treturn -EINVAL;\n1807:\t\n1808:\t\tmemset(\u0026v, 0, sizeof(v));\n1809:\t\n1810:\t\tswitch (optname) {\n1811:\t\tcase SO_DEBUG:\n1812:\t\t\tv.val = sock_flag(sk, SOCK_DBG);\n1813:\t\t\tbreak;\n1814:\t\n1815:\t\tcase SO_DONTROUTE:\n1816:\t\t\tv.val = sock_flag(sk, SOCK_LOCALROUTE);\n1817:\t\t\tbreak;\n1818:\t\n1819:\t\tcase SO_BROADCAST:\n1820:\t\t\tv.val = sock_flag(sk, SOCK_BROADCAST);\n1821:\t\t\tbreak;\n1822:\t\n1823:\t\tcase SO_SNDBUF:\n1824:\t\t\tv.val = READ_ONCE(sk-\u003esk_sndbuf);\n1825:\t\t\tbreak;\n1826:\t\n1827:\t\tcase SO_RCVBUF:\n1828:\t\t\tv.val = READ_ONCE(sk-\u003esk_rcvbuf);\n1829:\t\t\tbreak;\n"
}

39/3 2026/09/29 11:04 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 32334
							output: 35
							thoughts: 200
						

Thoughts:
**Analyzing the `sk_getsockopt` Flow**

Alright, let's break this down. First, `len` is being initialized from `optlen` at the beginning of the `sk_getsockopt` function. Then, that value for `len` is passed to `sk_getsockopt_peerpidfd`. Inside of `sk_getsockopt_peerpidfd`, the crucial bit is that `len` is capped to the size of `pidfd`. Specifically, there's that if-statement:

```c
	if (len > sizeof(pidfd))
		len = sizeof(pidfd);
```

Makes sense, we can't write beyond the bounds of the destination buffer, so this is a crucial check. After that, we're copying this potentially-truncated `len` value, along with the contents of `pidfd`, back to user space using `copy_to_sockptr`. Seems straightforward so far. We are setting the `pidfd` value. Oh, it is an `int`, and it is initialized using the `pidfd_prepare(...)` function.

However, I'm now thinking about `scm_replace_pid` in `net/core/scm.c`. I have a feeling that we might be missing something from the full picture. Let's delve into that function, and see what the implications are in `net/core/scm.c`.



40/3 2026/09/29 11:05 tool read-file
0m Args:
{
  "File": "net/core/scm.c",
  "FirstLine": 140,
  "LineCount": 50
}

Results:
{
  "Contents": " 140:\t\tif (fpl) {\n 141:\t\t\tscm-\u003efp = NULL;\n 142:\t\t\tfor (i=fpl-\u003ecount-1; i\u003e=0; i--)\n 143:\t\t\t\tfput(fpl-\u003efp[i]);\n 144:\t\t\tfree_uid(fpl-\u003euser);\n 145:\t\t\tkfree(fpl);\n 146:\t\t}\n 147:\t}\n 148:\tEXPORT_SYMBOL(__scm_destroy);\n 149:\t\n 150:\tstatic inline int scm_replace_pid(struct scm_cookie *scm, struct pid *pid)\n 151:\t{\n 152:\t\tstruct pid *thread_pid;\n 153:\t\tint err;\n 154:\t\n 155:\t\t/* drop all previous references */\n 156:\t\tscm_destroy_cred(scm);\n 157:\t\n 158:\t\terr = pidfs_register_pid(pid);\n 159:\t\tif (unlikely(err))\n 160:\t\t\treturn err;\n 161:\t\n 162:\t\t/* A sender naming its own thread-group sends from the current thread. */\n 163:\t\tif (pid == task_tgid(current))\n 164:\t\t\tthread_pid = task_pid(current);\n 165:\t\telse\n 166:\t\t\tthread_pid = pid;\n 167:\t\n 168:\t\terr = pidfs_register_pid(thread_pid);\n 169:\t\tif (unlikely(err))\n 170:\t\t\treturn err;\n 171:\t\n 172:\t\tscm-\u003epid[PIDTYPE_TGID] = pid;\n 173:\t\tscm-\u003epid[PIDTYPE_PID] = get_pid(thread_pid);\n 174:\t\tscm-\u003ecreds.pid = pid_vnr(pid);\n 175:\t\treturn 0;\n 176:\t}\n 177:\t\n 178:\tint __scm_send(struct socket *sock, struct msghdr *msg, struct scm_cookie *p)\n 179:\t{\n 180:\t\tconst struct proto_ops *ops = READ_ONCE(sock-\u003eops);\n 181:\t\tstruct cmsghdr *cmsg;\n 182:\t\tint err;\n 183:\t\n 184:\t\tfor_each_cmsghdr(cmsg, msg) {\n 185:\t\t\terr = -EINVAL;\n 186:\t\n 187:\t\t\t/* Verify that cmsg_len is at least sizeof(struct cmsghdr) */\n 188:\t\t\t/* The first check was omitted in \u003c= 2.2.5. The reasoning was\n 189:\t\t\t   that parser checks cmsg_len in any case, so that\n"
}

41/3 2026/09/29 11:05 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 33610
							output: 19
							thoughts: 381
						

Thoughts:
**Analyzing `scm_replace_pid` and Error Handling**

Okay, let's break down this `scm_replace_pid` function. My initial thought is to understand its purpose and how it handles potential errors, as that's often where the subtle bugs hide in these low-level systems. I see it's responsible for replacing the PID associated with an `scm_cookie`, likely related to some form of inter-process communication or security context.

The first thing that jumps out is the call to `scm_destroy_cred(scm)`.  It's critical to understand what that does *before* any registration occurs. Okay, `scm_destroy_cred` calls `put_pids(scm->pid);`, which appears to null out entries in the `scm->pid` array. Good, that indicates a clean slate before any potentially new PID is set.

The code then calls `pidfs_register_pid`.  Interesting, I know that function, and it seems like some kind of registration within the pid namespace subsystem. The critical question here becomes: what if `pidfs_register_pid` *fails* after the credentials have been destroyed?

Looking closely, it looks like `err = pidfs_register_pid(thread_pid)` is called after the first `pidfs_register_pid` call. If there's an error in *this* call, the function returns.  I have to ask, what's the state of `scm->pid`? Since `scm_destroy_cred` has already been called and the code returns on error, the values for `scm->pid` are now `NULL` at the indices that get populated.  That's a point of vulnerability that I will check thoroughly.  A failure there likely means that `scm->pid` is left in an inconsistent state, possibly leading to resource leaks or even security issues down the line.

Now, to fully understand the impact, I need to see *where* this function is called. What's the surrounding context? What's the broader flow of execution? What kind of data is passed in and what is assumed about the initial state of the `scm_cookie`? Let's trace the call sites of `scm_replace_pid`. That's where I can get a more complete picture.



42/3 2026/09/29 11:05 tool grepper
0m Args:
{
  "Expression": "scm_replace_pid"
}

Results:
{
  "Output": "net/core/scm.c=148=EXPORT_SYMBOL(__scm_destroy);\nnet/core/scm.c-149-\nnet/core/scm.c:150:static inline int scm_replace_pid(struct scm_cookie *scm, struct pid *pid)\nnet/core/scm.c-151-{\n--\nnet/core/scm.c=178=int __scm_send(struct socket *sock, struct msghdr *msg, struct scm_cookie *p)\n--\nnet/core/scm.c-230-\t\t\t\t/* pass a struct pid reference from\nnet/core/scm.c:231:\t\t\t\t * find_get_pid() to scm_replace_pid().\nnet/core/scm.c-232-\t\t\t\t */\nnet/core/scm.c:233:\t\t\t\terr = scm_replace_pid(p, pid);\nnet/core/scm.c-234-\t\t\t\tif (err) {\n"
}

43/3 2026/09/29 11:05 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 34747
							output: 35
							thoughts: 23
						

Thoughts:
Okay, let's dive into this. Here's my thought process on this:

**Analyzing `net/core/scm.c` - Lines 220-245**

Right, so the task at hand is to understand the code within lines 220-245 of `net/core/scm.c`. Based on what I know about this area, this likely concerns Socket Control Messages (SCMs) and their handling within the kernel's networking stack. Given the file and context, it's almost certain this section deals with either the reception, processing, or possibly the transmission of control messages associated with a socket.

My initial assumption is that this region of code is probably involved in either:

*   **Data Structure Manipulation:** Likely, the code is dealing with the manipulation of data structures (like `struct msghdr`, `struct scm_cookie`, or similar kernel representations) to extract or package control information. Are we receiving SCM data with a `recvmsg` call? Is the code parsing or constructing the SCM data here?
*   **Permission Checks or Parameter Validation:** It's also possible that this chunk deals with security checks. We might be verifying user permissions, or validating data integrity before passing SCM information further into the networking stack. Perhaps this section handles the setting/getting of socket options.
*   **Error Handling:** Given the critical nature of networking code, I wouldn't be surprised to find some error-handling logic within this block. Are there checks for resource allocation failures, invalid SCM flags, or related issues? This part might handle some edge cases or unusual setups.

I need to quickly analyze the code and look for key indicators to refine my thinking. I'll look for:

*   Function calls related to SCM handling (`scm_send`, `scm_recv`, `sock_setsockopt`, `sock_getsockopt`, etc.)
*   Data structure access and manipulation, specifically related to `struct msghdr` members (e.g., `msg_control`, `msg_controllen`, `msg_iov`, etc.)
*   Conditional statements and error codes.
*   Any calls to memory allocation/deallocation functions.

Armed with those specific details, I'll be in a better place to accurately deduce exactly what this code is doing. Let's get to the code.



44/3 2026/09/29 11:05 tool read-file
0m Args:
{
  "File": "net/core/scm.c",
  "FirstLine": 215,
  "LineCount": 40
}

Results:
{
  "Contents": " 215:\t\t\t\tif (cmsg-\u003ecmsg_len != CMSG_LEN(sizeof(struct ucred)))\n 216:\t\t\t\t\tgoto error;\n 217:\t\t\t\tmemcpy(\u0026creds, CMSG_DATA(cmsg), sizeof(struct ucred));\n 218:\t\t\t\terr = scm_check_creds(\u0026creds);\n 219:\t\t\t\tif (err)\n 220:\t\t\t\t\tgoto error;\n 221:\t\n 222:\t\t\t\tif (!p-\u003epid[PIDTYPE_TGID] ||\n 223:\t\t\t\t    pid_vnr(p-\u003epid[PIDTYPE_TGID]) != creds.pid) {\n 224:\t\t\t\t\tstruct pid *pid;\n 225:\t\t\t\t\terr = -ESRCH;\n 226:\t\t\t\t\tpid = find_get_pid(creds.pid);\n 227:\t\t\t\t\tif (!pid)\n 228:\t\t\t\t\t\tgoto error;\n 229:\t\n 230:\t\t\t\t\t/* pass a struct pid reference from\n 231:\t\t\t\t\t * find_get_pid() to scm_replace_pid().\n 232:\t\t\t\t\t */\n 233:\t\t\t\t\terr = scm_replace_pid(p, pid);\n 234:\t\t\t\t\tif (err) {\n 235:\t\t\t\t\t\tput_pid(pid);\n 236:\t\t\t\t\t\tgoto error;\n 237:\t\t\t\t\t}\n 238:\t\t\t\t}\n 239:\t\n 240:\t\t\t\terr = -EINVAL;\n 241:\t\t\t\tuid = make_kuid(current_user_ns(), creds.uid);\n 242:\t\t\t\tgid = make_kgid(current_user_ns(), creds.gid);\n 243:\t\t\t\tif (!uid_valid(uid) || !gid_valid(gid))\n 244:\t\t\t\t\tgoto error;\n 245:\t\n 246:\t\t\t\tp-\u003ecreds.uid = uid;\n 247:\t\t\t\tp-\u003ecreds.gid = gid;\n 248:\t\t\t\tbreak;\n 249:\t\t\t}\n 250:\t\t\tdefault:\n 251:\t\t\t\tgoto error;\n 252:\t\t\t}\n 253:\t\t}\n 254:\t\n"
}

45/3 2026/09/29 11:05 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 35871
							output: 19
							thoughts: 469
						

Thoughts:
**Analyzing `scm_set_cred` in the Kernel**

Okay, let's dive into this `scm_set_cred` function. First, I need to remind myself where it's defined: `include/net/scm.h`. Right, here it is:

```c
static __inline__ void scm_set_cred(struct scm_cookie *scm,
				    struct pid *pid, kuid_t uid, kgid_t gid)
{
	scm->pid[PIDTYPE_TGID] = get_pid(pid);
	scm->creds.pid = pid_vnr(pid);
	scm->creds.uid = uid;
	scm->creds.gid = gid;
}
```

Wait a second...I'm a little puzzled. What exactly is this function doing with the `scm->pid` field? It sets `scm->pid[PIDTYPE_TGID]`, which is fine, but it doesn't appear to touch `scm->pid[PIDTYPE_PID]`. Hmm, that seems odd. Let me just confirm my understanding. Back to the same include file to find the definition of the structure, specifically `scm_cookie`.

```c
struct scm_cookie {
	DECLARE_PIDS(pid, PIDTYPE_TGID);	/* Skb credentials by pid type */
	struct scm_fp_list	*fp;		/* Passed files		*/
	struct scm_creds	creds;		/* Skb credentials	*/
...
```

Right, `DECLARE_PIDS(pid, PIDTYPE_TGID)` expands to: `struct pid *pid[PIDTYPE_TGID + 1]`.  Given that `PIDTYPE_TGID` is likely 1, it means `pid` is an array of size 2: `pid[0]` (likely `PIDTYPE_PID`) and `pid[1]` (the `PIDTYPE_TGID` we already saw being set in the function).

So, now I have to know *why* that other element isn't being set. Either it's initialized elsewhere, or its value is unimportant in the context of what `scm_set_cred` is designed to accomplish. Given my experience, I'd say the former is more likely.

To understand the implications, I need to know *who* calls `scm_set_cred` and in *what* context.  Time to fire up grep and scan the entire kernel source to find all calls to `scm_set_cred`. That will give me the necessary clues to see if there is a gap or intentional design.



46/3 2026/09/29 11:05 tool grepper
0m Args:
{
  "Expression": "scm_set_cred"
}

Results:
{
  "Output": "include/net/scm.h=65=static __inline__ void unix_get_peersec_dgram(struct socket *sock, struct scm_cookie *scm)\n--\ninclude/net/scm.h-68-\ninclude/net/scm.h:69:static __inline__ void scm_set_cred(struct scm_cookie *scm,\ninclude/net/scm.h-70-\t\t\t\t    struct pid *pid, kuid_t uid, kgid_t gid)\n--\ninclude/net/scm.h=90=static __inline__ int scm_send(struct socket *sock, struct msghdr *msg,\n--\ninclude/net/scm.h-96-\tif (forcecreds)\ninclude/net/scm.h:97:\t\tscm_set_cred(scm, task_tgid(current), current_uid(), current_gid());\ninclude/net/scm.h-98-\tunix_get_peersec_dgram(sock, scm);\n"
}

47/3 2026/09/29 11:05 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 37181
							output: 34
							thoughts: 32
						

Thoughts:
Here's my take on the thought process, tailored for an expert audience:

**Diving into SCM and Socket Credentials**

Right, hold on a second. Something about this just doesn't sit right. Let's zoom in on this `scm_send` function call. My gut tells me there's something to investigate further there. Specifically, my mind keeps coming back to the intricacies of socket credential passing. Okay, let's pull up the source for `include/net/scm.h` and focus on those lines – let's see, lines 80 through 115. That area should contain the key definitions, structures, or macros related to how control messages are constructed and processed when sending credentials. I want to see how the kernel structures and how the metadata are handled. That's where the magic – or potential pitfalls – often lie. Time to dissect those lines!



48/3 2026/09/29 11:05 tool read-file
0m Args:
{
  "File": "include/net/scm.h",
  "FirstLine": 80,
  "LineCount": 40
}

Results:
{
  "Contents": "  80:\t\tput_pids(scm-\u003epid);\n  81:\t}\n  82:\t\n  83:\tstatic __inline__ void scm_destroy(struct scm_cookie *scm)\n  84:\t{\n  85:\t\tscm_destroy_cred(scm);\n  86:\t\tif (scm-\u003efp)\n  87:\t\t\t__scm_destroy(scm);\n  88:\t}\n  89:\t\n  90:\tstatic __inline__ int scm_send(struct socket *sock, struct msghdr *msg,\n  91:\t\t\t\t       struct scm_cookie *scm, bool forcecreds)\n  92:\t{\n  93:\t\tmemset(scm, 0, sizeof(*scm));\n  94:\t\tscm-\u003ecreds.uid = INVALID_UID;\n  95:\t\tscm-\u003ecreds.gid = INVALID_GID;\n  96:\t\tif (forcecreds)\n  97:\t\t\tscm_set_cred(scm, task_tgid(current), current_uid(), current_gid());\n  98:\t\tunix_get_peersec_dgram(sock, scm);\n  99:\t\tif (msg-\u003emsg_controllen \u003c= 0)\n 100:\t\t\treturn 0;\n 101:\t\treturn __scm_send(sock, msg, scm);\n 102:\t}\n 103:\t\n 104:\tvoid scm_recv(struct socket *sock, struct msghdr *msg,\n 105:\t\t      struct scm_cookie *scm, int flags);\n 106:\tvoid scm_recv_unix(struct socket *sock, struct msghdr *msg,\n 107:\t\t\t   struct scm_cookie *scm, int flags);\n 108:\t\n 109:\tint scm_recv_one_fd(struct file *f, int __user *ufd, unsigned int flags,\n 110:\t\t\t    bool notrunc);\n 111:\t\n 112:\t#endif /* __LINUX_NET_SCM_H */\n 113:\t\n"
}

49/3 2026/09/29 11:05 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 37970
							output: 19
							thoughts: 69
						

Thoughts:
Here's my summary, as the expert:

**Investigating a Potential `scm_cookie` Initialization Issue**

Okay, so I'm digging into this `scm_send` function, and the first thing that jumps out at me is this `memset(scm, 0, sizeof(*scm));` call. I immediately think, "Wait a minute, isn't that a bit *too* aggressive?" That's effectively zeroing out the entire `struct scm_cookie`. Specifically, I'm concerned that `scm->pid` gets wiped clean with this call. Is this intentional, or could this lead to unexpected behavior later on if some other code expects this value to be pre-populated?

This raises a red flag in my mind.  This `memset` could be a bug. The current zeroing action is questionable and I'm not familiar with the code in detail.  I need to understand if there is an intended design, or an error.

To fully grasp the implications, I need a broader understanding of how `struct scm_cookie` is used.  Therefore, I'm going to launch a full-tree search for every instance of `struct scm_cookie`. I want to see *every* declaration, usage, and manipulation of this structure throughout the project to understand the context and purpose. Only then can I determine if this initialization strategy is correct or potentially problematic.  I suspect I'll find some clues to the design.



50/3 2026/09/29 11:06 tool grepper
0m Args:
{
  "Expression": "struct scm_cookie"
}

Results:
{
  "Output": "Documentation/security/lsm.rst=91=network device security information, security fields were added to\nDocumentation/security/lsm.rst-92-:c:type:`struct sk_buff \u003csk_buff\u003e` and\nDocumentation/security/lsm.rst:93::c:type:`struct scm_cookie \u003cscm_cookie\u003e`.\nDocumentation/security/lsm.rst-94-Unlike the other security module data, the data used here is a\n--\nDocumentation/translations/zh_CN/security/lsm.rst=68=struct shmid_kernel的定义被移动到头文件中( ``include/linux/msg.h`` 和\n--\nDocumentation/translations/zh_CN/security/lsm.rst-71-对于数据包和网络设备的安全信息,安全域被添加到 :c:type:\nDocumentation/translations/zh_CN/security/lsm.rst:72:`struct sk_buff \u003csk_buff\u003e` 和 :c:type: `struct scm_cookie \u003cscm_cookie\u003e` 中。\nDocumentation/translations/zh_CN/security/lsm.rst-73-与其他安全模块数据不同,这里使用的数据是一个32位整数。安全模块需要将这些值\n--\ninclude/net/scm.h=30=struct scm_fp_list {\n--\ninclude/net/scm.h-43-\ninclude/net/scm.h:44:struct scm_cookie {\ninclude/net/scm.h-45-\tDECLARE_PIDS(pid, PIDTYPE_TGID);\t/* Skb credentials by pid type */\n--\ninclude/net/scm.h-52-\ninclude/net/scm.h:53:void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm, bool notrunc);\ninclude/net/scm.h:54:void scm_detach_fds_compat(struct msghdr *msg, struct scm_cookie *scm, bool notrunc);\ninclude/net/scm.h:55:int __scm_send(struct socket *sock, struct msghdr *msg, struct scm_cookie *scm);\ninclude/net/scm.h:56:void __scm_destroy(struct scm_cookie *scm);\ninclude/net/scm.h-57-struct scm_fp_list *scm_fp_dup(struct scm_fp_list *fpl);\n--\ninclude/net/scm.h-59-#ifdef CONFIG_SECURITY_NETWORK\ninclude/net/scm.h:60:static __inline__ void unix_get_peersec_dgram(struct socket *sock, struct scm_cookie *scm)\ninclude/net/scm.h-61-{\n--\ninclude/net/scm.h-64-#else\ninclude/net/scm.h:65:static __inline__ void unix_get_peersec_dgram(struct socket *sock, struct scm_cookie *scm)\ninclude/net/scm.h-66-{ }\n--\ninclude/net/scm.h-68-\ninclude/net/scm.h:69:static __inline__ void scm_set_cred(struct scm_cookie *scm,\ninclude/net/scm.h-70-\t\t\t\t    struct pid *pid, kuid_t uid, kgid_t gid)\n--\ninclude/net/scm.h-77-\ninclude/net/scm.h:78:static __inline__ void scm_destroy_cred(struct scm_cookie *scm)\ninclude/net/scm.h-79-{\n--\ninclude/net/scm.h-82-\ninclude/net/scm.h:83:static __inline__ void scm_destroy(struct scm_cookie *scm)\ninclude/net/scm.h-84-{\n--\ninclude/net/scm.h=90=static __inline__ int scm_send(struct socket *sock, struct msghdr *msg,\ninclude/net/scm.h:91:\t\t\t       struct scm_cookie *scm, bool forcecreds)\ninclude/net/scm.h-92-{\n--\ninclude/net/scm.h=104=void scm_recv(struct socket *sock, struct msghdr *msg,\ninclude/net/scm.h:105:\t      struct scm_cookie *scm, int flags);\ninclude/net/scm.h-106-void scm_recv_unix(struct socket *sock, struct msghdr *msg,\ninclude/net/scm.h:107:\t\t   struct scm_cookie *scm, int flags);\ninclude/net/scm.h-108-\n--\nnet/bluetooth/hci_sock.c=1567=static int hci_sock_recvmsg(struct socket *sock, struct msghdr *msg,\n--\nnet/bluetooth/hci_sock.c-1569-{\nnet/bluetooth/hci_sock.c:1570:\tstruct scm_cookie scm;\nnet/bluetooth/hci_sock.c-1571-\tstruct sock *sk = sock-\u003esk;\n--\nnet/compat.c=282=static int scm_max_fds_compat(struct msghdr *msg)\n--\nnet/compat.c-288-\nnet/compat.c:289:void scm_detach_fds_compat(struct msghdr *msg, struct scm_cookie *scm, bool notrunc)\nnet/compat.c-290-{\n--\nnet/core/scm.c=69=static int scm_fp_copy(struct cmsghdr *cmsg, struct scm_fp_list **fplp)\n--\nnet/core/scm.c-134-\nnet/core/scm.c:135:void __scm_destroy(struct scm_cookie *scm)\nnet/core/scm.c-136-{\n--\nnet/core/scm.c=148=EXPORT_SYMBOL(__scm_destroy);\nnet/core/scm.c-149-\nnet/core/scm.c:150:static inline int scm_replace_pid(struct scm_cookie *scm, struct pid *pid)\nnet/core/scm.c-151-{\n--\nnet/core/scm.c-177-\nnet/core/scm.c:178:int __scm_send(struct socket *sock, struct msghdr *msg, struct scm_cookie *p)\nnet/core/scm.c-179-{\n--\nnet/core/scm.c=367=int scm_recv_one_fd(struct file *f, int __user *ufd, unsigned int flags,\n--\nnet/core/scm.c-390-\nnet/core/scm.c:391:void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm, bool notrunc)\nnet/core/scm.c-392-{\n--\nnet/core/scm.c=467=EXPORT_SYMBOL(scm_fp_dup);\n--\nnet/core/scm.c-469-#ifdef CONFIG_SECURITY_NETWORK\nnet/core/scm.c:470:static void scm_passec(struct sock *sk, struct msghdr *msg, struct scm_cookie *scm)\nnet/core/scm.c-471-{\n--\nnet/core/scm.c=487=static bool scm_has_secdata(struct sock *sk)\n--\nnet/core/scm.c-491-#else\nnet/core/scm.c:492:static void scm_passec(struct sock *sk, struct msghdr *msg, struct scm_cookie *scm)\nnet/core/scm.c-493-{\n--\nnet/core/scm.c=496=static bool scm_has_secdata(struct sock *sk)\n--\nnet/core/scm.c-501-\nnet/core/scm.c:502:static void scm_pidfd_recv(struct msghdr *msg, struct scm_cookie *scm,\nnet/core/scm.c-503-\t\t\t   enum pid_type type, int cmsg_type)\n--\nnet/core/scm.c=546=static bool __scm_recv_common(struct sock *sk, struct msghdr *msg,\nnet/core/scm.c:547:\t\t\t      struct scm_cookie *scm, int flags)\nnet/core/scm.c-548-{\n--\nnet/core/scm.c=574=void scm_recv(struct socket *sock, struct msghdr *msg,\nnet/core/scm.c:575:\t      struct scm_cookie *scm, int flags)\nnet/core/scm.c-576-{\n--\nnet/core/scm.c=584=void scm_recv_unix(struct socket *sock, struct msghdr *msg,\nnet/core/scm.c:585:\t\t   struct scm_cookie *scm, int flags)\nnet/core/scm.c-586-{\n--\nnet/netlink/af_netlink.c=1837=static int netlink_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)\n--\nnet/netlink/af_netlink.c-1845-\tint err;\nnet/netlink/af_netlink.c:1846:\tstruct scm_cookie scm;\nnet/netlink/af_netlink.c-1847-\tu32 netlink_skb_flags = 0;\n--\nnet/netlink/af_netlink.c=1926=static int netlink_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,\n--\nnet/netlink/af_netlink.c-1928-{\nnet/netlink/af_netlink.c:1929:\tstruct scm_cookie scm;\nnet/netlink/af_netlink.c-1930-\tstruct sock *sk = sock-\u003esk;\n--\nnet/unix/af_unix.c=243=static void unix_table_double_unlock(struct net *net,\n--\nnet/unix/af_unix.c-255-#ifdef CONFIG_SECURITY_NETWORK\nnet/unix/af_unix.c:256:static void unix_get_secdata(struct scm_cookie *scm, struct sk_buff *skb)\nnet/unix/af_unix.c-257-{\n--\nnet/unix/af_unix.c-260-\nnet/unix/af_unix.c:261:static inline void unix_set_secdata(struct scm_cookie *scm, struct sk_buff *skb)\nnet/unix/af_unix.c-262-{\n--\nnet/unix/af_unix.c-265-\nnet/unix/af_unix.c:266:static inline bool unix_secdata_eq(struct scm_cookie *scm, struct sk_buff *skb)\nnet/unix/af_unix.c-267-{\n--\nnet/unix/af_unix.c-270-#else\nnet/unix/af_unix.c:271:static inline void unix_get_secdata(struct scm_cookie *scm, struct sk_buff *skb)\nnet/unix/af_unix.c-272-{ }\nnet/unix/af_unix.c-273-\nnet/unix/af_unix.c:274:static inline void unix_set_secdata(struct scm_cookie *scm, struct sk_buff *skb)\nnet/unix/af_unix.c-275-{ }\nnet/unix/af_unix.c-276-\nnet/unix/af_unix.c:277:static inline bool unix_secdata_eq(struct scm_cookie *scm, struct sk_buff *skb)\nnet/unix/af_unix.c-278-{\n--\nnet/unix/af_unix.c=1932=static inline bool too_many_unix_fds(struct task_struct *p)\n--\nnet/unix/af_unix.c-1940-\nnet/unix/af_unix.c:1941:static int unix_attach_fds(struct scm_cookie *scm, struct sk_buff *skb)\nnet/unix/af_unix.c-1942-{\n--\nnet/unix/af_unix.c-1954-\nnet/unix/af_unix.c:1955:static void unix_detach_fds(struct scm_cookie *scm, struct sk_buff *skb)\nnet/unix/af_unix.c-1956-{\n--\nnet/unix/af_unix.c-1962-\nnet/unix/af_unix.c:1963:static void unix_peek_fds(struct scm_cookie *scm, struct sk_buff *skb)\nnet/unix/af_unix.c-1964-{\n--\nnet/unix/af_unix.c=1970=static void unix_destruct_scm(struct sk_buff *skb)\nnet/unix/af_unix.c-1971-{\nnet/unix/af_unix.c:1972:\tstruct scm_cookie scm = {};\nnet/unix/af_unix.c-1973-\n--\nnet/unix/af_unix.c=1982=static void unix_wfree(struct sk_buff *skb)\n--\nnet/unix/af_unix.c-1987-\nnet/unix/af_unix.c:1988:static int unix_scm_to_skb(struct scm_cookie *scm, struct sk_buff *skb, bool send_fds)\nnet/unix/af_unix.c-1989-{\n--\nnet/unix/af_unix.c-2003-\nnet/unix/af_unix.c:2004:static void unix_skb_to_scm(struct sk_buff *skb, struct scm_cookie *scm)\nnet/unix/af_unix.c-2005-{\n--\nnet/unix/af_unix.c=2049=static bool unix_skb_scm_eq(const struct sock *sk, struct sk_buff *skb,\nnet/unix/af_unix.c:2050:\t\t\t    struct scm_cookie *scm)\nnet/unix/af_unix.c-2051-{\n--\nnet/unix/af_unix.c=2096=static int unix_dgram_sendmsg(struct socket *sock, struct msghdr *msg,\n--\nnet/unix/af_unix.c-2100-\tstruct unix_sock *u = unix_sk(sk);\nnet/unix/af_unix.c:2101:\tstruct scm_cookie scm;\nnet/unix/af_unix.c-2102-\tstruct sk_buff *skb;\n--\nnet/unix/af_unix.c=2330=static int queue_oob(struct sock *sk, struct msghdr *msg, struct sock *other,\nnet/unix/af_unix.c:2331:\t\t     struct scm_cookie *scm, bool fds_sent)\nnet/unix/af_unix.c-2332-{\n--\nnet/unix/af_unix.c=2390=static int unix_stream_sendmsg(struct socket *sock, struct msghdr *msg,\n--\nnet/unix/af_unix.c-2396-\tstruct unix_sock *otheru;\nnet/unix/af_unix.c:2397:\tstruct scm_cookie scm;\nnet/unix/af_unix.c-2398-\tbool fds_sent = false;\n--\nnet/unix/af_unix.c=2575=int __unix_dgram_recvmsg(struct sock *sk, struct msghdr *msg, size_t size,\n--\nnet/unix/af_unix.c-2577-{\nnet/unix/af_unix.c:2578:\tstruct scm_cookie scm;\nnet/unix/af_unix.c-2579-\tstruct socket *sock = sk-\u003esk_socket;\n--\nnet/unix/af_unix.c=2924=static int unix_stream_read_generic(struct unix_stream_read_state *state,\n--\nnet/unix/af_unix.c-2933-\tbool check_creds = false;\nnet/unix/af_unix.c:2934:\tstruct scm_cookie scm;\nnet/unix/af_unix.c-2935-\tstruct unix_sock *u;\n"
}

51/3 2026/09/29 11:06 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 42478
							output: 38
							thoughts: 52
						

Thoughts:
Okay, let's dive into this.

**Investigating the HCI Socket Receive Path**

My immediate instinct is to pinpoint the socket receive mechanism. I'm thinking the logical entry point is likely `net/bluetooth/hci_sock.c`. Given that, the `hci_sock_recvmsg` function is probably the key area to examine. Now, I'll go directly to lines 1565-1610 of that file. That should give me a solid view of the data handling and any potential bottlenecks or areas for deeper analysis within the receive process. Let's see what's happening in there.



52/3 2026/09/29 11:06 tool read-file
0m Args:
{
  "File": "net/bluetooth/hci_sock.c",
  "FirstLine": 1565,
  "LineCount": 45
}

Results:
{
  "Contents": "1565:\t}\n1566:\t\n1567:\tstatic int hci_sock_recvmsg(struct socket *sock, struct msghdr *msg,\n1568:\t\t\t\t    size_t len, int flags)\n1569:\t{\n1570:\t\tstruct scm_cookie scm;\n1571:\t\tstruct sock *sk = sock-\u003esk;\n1572:\t\tstruct sk_buff *skb;\n1573:\t\tint copied, err;\n1574:\t\tunsigned int skblen;\n1575:\t\n1576:\t\tBT_DBG(\"sock %p, sk %p\", sock, sk);\n1577:\t\n1578:\t\tif (flags \u0026 MSG_OOB)\n1579:\t\t\treturn -EOPNOTSUPP;\n1580:\t\n1581:\t\tif (hci_pi(sk)-\u003echannel == HCI_CHANNEL_LOGGING)\n1582:\t\t\treturn -EOPNOTSUPP;\n1583:\t\n1584:\t\tif (sk-\u003esk_state == BT_CLOSED)\n1585:\t\t\treturn 0;\n1586:\t\n1587:\t\tskb = skb_recv_datagram(sk, flags, \u0026err);\n1588:\t\tif (!skb)\n1589:\t\t\treturn err;\n1590:\t\n1591:\t\tskblen = skb-\u003elen;\n1592:\t\tcopied = skb-\u003elen;\n1593:\t\tif (len \u003c copied) {\n1594:\t\t\tmsg-\u003emsg_flags |= MSG_TRUNC;\n1595:\t\t\tcopied = len;\n1596:\t\t}\n1597:\t\n1598:\t\tskb_reset_transport_header(skb);\n1599:\t\terr = skb_copy_datagram_msg(skb, 0, msg, copied);\n1600:\t\n1601:\t\tswitch (hci_pi(sk)-\u003echannel) {\n1602:\t\tcase HCI_CHANNEL_RAW:\n1603:\t\t\thci_sock_cmsg(sk, msg, skb);\n1604:\t\t\tbreak;\n1605:\t\tcase HCI_CHANNEL_USER:\n1606:\t\tcase HCI_CHANNEL_MONITOR:\n1607:\t\t\tsock_recv_timestamp(msg, sk, skb);\n1608:\t\t\tbreak;\n1609:\t\tdefault:\n"
}

53/3 2026/09/29 11:06 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 43336
							output: 38
							thoughts: 27
						

Thoughts:
Okay, here's my attempt at summarizing the thought process, as requested, targeting an expert audience and using the first person:

**Diving into hci_sock.c: Specific Lines**

Alright, time to dig in. Let's see... the issue seems related to Bluetooth, so I'll start by focusing on the HCI socket layer. I need to refresh my memory on the specific logic, so I'm going to jump straight to the code. Let me check lines 1610 through 1630 of `net/bluetooth/hci_sock.c`. These lines are often where the critical error handling occurs. Hopefully, the problem is obvious to me once I read the relevant code. I am hoping to get a quick grasp of the issue, and understand its root cause.



54/3 2026/09/29 11:06 tool read-file
0m Args:
{
  "File": "net/bluetooth/hci_sock.c",
  "FirstLine": 1610,
  "LineCount": 25
}

Results:
{
  "Contents": "1610:\t\t\tif (hci_mgmt_chan_find(hci_pi(sk)-\u003echannel))\n1611:\t\t\t\tsock_recv_timestamp(msg, sk, skb);\n1612:\t\t\tbreak;\n1613:\t\t}\n1614:\t\n1615:\t\tmemset(\u0026scm, 0, sizeof(scm));\n1616:\t\tscm.creds = bt_cb(skb)-\u003ecreds;\n1617:\t\n1618:\t\tskb_free_datagram(sk, skb);\n1619:\t\n1620:\t\tif (flags \u0026 MSG_TRUNC)\n1621:\t\t\tcopied = skblen;\n1622:\t\n1623:\t\tscm_recv(sock, msg, \u0026scm, flags);\n1624:\t\n1625:\t\treturn err ? : copied;\n1626:\t}\n1627:\t\n1628:\tstatic int hci_mgmt_cmd(struct hci_mgmt_chan *chan, struct sock *sk,\n1629:\t\t\t\tstruct sk_buff *skb)\n1630:\t{\n1631:\t\tu8 *cp;\n1632:\t\tstruct mgmt_hdr *hdr;\n1633:\t\tu16 opcode, index, len;\n1634:\t\tstruct hci_dev *hdev = NULL;\n"
}

55/3 2026/09/29 11:06 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 43928
							output: 40
							thoughts: 58
						

Thoughts:
Okay, here's my take on those thoughts, framed as an expert's internal monologue:

**Investigating Potential Data Corruption in HCI Socket Reception**

Right, so I'm digging into `hci_sock_recvmsg` and I see that `memset(&scm, 0, sizeof(scm));` call. Hmm, that's standard practice to initialize the ancillary data structure. But my mind immediately jumps to a potential area for subtle issues. Where else might similar logic, or *related* logic, be lurking that could contribute to a corruption scenario or vulnerability? Let's not just focus on *this* code in isolation.

Okay, let's pivot to the broader network context. The use of ancillary data rings a bell, and I know that the netlink subsystem is a prominent user of this mechanism. So, where's the potential for something to slip through the cracks, or to be exploited? My first instinct is to dive into `net/netlink/af_netlink.c`. I need to compare how netlink handles ancillary data. Specifically, I should be looking closely at the `netlink_sendmsg` and `netlink_recvmsg` functions. Any discrepancies or potential gotchas in their data handling could shed light on the initial problem, maybe a systemic error, not just a local one.



56/3 2026/09/29 11:06 tool read-file
0m Args:
{
  "File": "net/netlink/af_netlink.c",
  "FirstLine": 1840,
  "LineCount": 40
}

Results:
{
  "Contents": "1840:\t\tstruct netlink_sock *nlk = nlk_sk(sk);\n1841:\t\tDECLARE_SOCKADDR(struct sockaddr_nl *, addr, msg-\u003emsg_name);\n1842:\t\tu32 dst_portid;\n1843:\t\tu32 dst_group;\n1844:\t\tstruct sk_buff *skb;\n1845:\t\tint err;\n1846:\t\tstruct scm_cookie scm;\n1847:\t\tu32 netlink_skb_flags = 0;\n1848:\t\n1849:\t\tif (msg-\u003emsg_flags \u0026 MSG_OOB)\n1850:\t\t\treturn -EOPNOTSUPP;\n1851:\t\n1852:\t\tif (len == 0) {\n1853:\t\t\tpr_warn_once(\"Zero length message leads to an empty skb\\n\");\n1854:\t\t\treturn -ENODATA;\n1855:\t\t}\n1856:\t\n1857:\t\terr = scm_send(sock, msg, \u0026scm, true);\n1858:\t\tif (err \u003c 0)\n1859:\t\t\treturn err;\n1860:\t\n1861:\t\tif (msg-\u003emsg_namelen) {\n1862:\t\t\terr = -EINVAL;\n1863:\t\t\tif (msg-\u003emsg_namelen \u003c sizeof(struct sockaddr_nl))\n1864:\t\t\t\tgoto out;\n1865:\t\t\tif (addr-\u003enl_family != AF_NETLINK)\n1866:\t\t\t\tgoto out;\n1867:\t\t\tdst_portid = addr-\u003enl_pid;\n1868:\t\t\tdst_group = ffs(addr-\u003enl_groups);\n1869:\t\t\terr =  -EPERM;\n1870:\t\t\tif ((dst_group || dst_portid) \u0026\u0026\n1871:\t\t\t    !netlink_allowed(sock, NL_CFG_F_NONROOT_SEND))\n1872:\t\t\t\tgoto out;\n1873:\t\t\tnetlink_skb_flags |= NETLINK_SKB_DST;\n1874:\t\t} else {\n1875:\t\t\t/* Paired with WRITE_ONCE() in netlink_connect() */\n1876:\t\t\tdst_portid = READ_ONCE(nlk-\u003edst_portid);\n1877:\t\t\tdst_group = READ_ONCE(nlk-\u003edst_group);\n1878:\t\t}\n1879:\t\n"
}

57/3 2026/09/29 11:06 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 44948
							output: 40
							thoughts: 49
						

Thoughts:
Okay, here's my take on those thoughts, framed as my own:

**Investigating Netlink Message Handling**

Alright, so I'm digging into this `netlink_sendmsg` function. It looks like it's calling `scm_send` internally, and that seems to handle some crucial socket control message (SCM) sending. Specifically, it's passing in a `msg` and a pointer to an `scm` structure, with a boolean flag set to `true`. The interesting detail here is the `memset(&scm, 0, sizeof(*scm))` call. It's initializing the SCM struct to zero before use. That makes sense, ensuring a clean slate before populating it with relevant control data, preventing any stale or random data from being sent. I'm noting this is good hygiene.

Now, my mind immediately jumps to the other side of the conversation. I wonder what's happening during the `netlink_recvmsg` process? Is there a corresponding similar initialization, or some other mechanism to handle the SCM on the receiving end? This could be a potential area for subtle vulnerabilities if the receive side isn't handled carefully and properly initializes SCM structures as well, as might be missed data or leftover information on the other end, potentially leading to security issues. I need to look into `netlink_recvmsg` next. I want to see if the zeroing out of the SCM structure has a symmetrical behavior. It's important to understand the full lifecycle of these control messages for secure netlink usage.



58/3 2026/09/29 11:06 tool read-file
0m Args:
{
  "File": "net/netlink/af_netlink.c",
  "FirstLine": 1925,
  "LineCount": 40
}

Results:
{
  "Contents": "1925:\t\n1926:\tstatic int netlink_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,\n1927:\t\t\t\t   int flags)\n1928:\t{\n1929:\t\tstruct scm_cookie scm;\n1930:\t\tstruct sock *sk = sock-\u003esk;\n1931:\t\tstruct netlink_sock *nlk = nlk_sk(sk);\n1932:\t\tsize_t copied, max_recvmsg_len;\n1933:\t\tstruct sk_buff *skb, *data_skb;\n1934:\t\tint err, ret;\n1935:\t\n1936:\t\tif (flags \u0026 MSG_OOB)\n1937:\t\t\treturn -EOPNOTSUPP;\n1938:\t\n1939:\t\tcopied = 0;\n1940:\t\n1941:\t\tskb = skb_recv_datagram(sk, flags, \u0026err);\n1942:\t\tif (skb == NULL)\n1943:\t\t\tgoto out;\n1944:\t\n1945:\t\tdata_skb = skb;\n1946:\t\n1947:\t#ifdef CONFIG_COMPAT_NETLINK_MESSAGES\n1948:\t\tif (unlikely(skb_shinfo(skb)-\u003efrag_list)) {\n1949:\t\t\t/*\n1950:\t\t\t * If this skb has a frag_list, then here that means that we\n1951:\t\t\t * will have to use the frag_list skb's data for compat tasks\n1952:\t\t\t * and the regular skb's data for normal (non-compat) tasks.\n1953:\t\t\t *\n1954:\t\t\t * If we need to send the compat skb, assign it to the\n1955:\t\t\t * 'data_skb' variable so that it will be used below for data\n1956:\t\t\t * copying. We keep 'skb' for everything else, including\n1957:\t\t\t * freeing both later.\n1958:\t\t\t */\n1959:\t\t\tif (flags \u0026 MSG_CMSG_COMPAT)\n1960:\t\t\t\tdata_skb = skb_shinfo(skb)-\u003efrag_list;\n1961:\t\t}\n1962:\t#endif\n1963:\t\n1964:\t\t/* Record the max length of recvmsg() calls for future allocations */\n"
}

59/3 2026/09/29 11:06 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 45992
							output: 40
							thoughts: 13
						

Thoughts:
Okay, here's my summarized thought process, assuming I'm an expert and this is part of a deep dive into networking code:

**Diving Deeper into `netlink_recvmsg`**

Alright, I'm thinking we need to drill down into `netlink_recvmsg`. That's where the rubber meets the road, where the incoming Netlink messages are actually handled. My gut feeling is that any issues we're seeing, especially if they're intermittent or race-condition related, are likely exposed *somewhere* within that function or its immediate callers/callees. It's the central point for receiving and processing these crucial network communications, so it's the natural first stop for deeper investigation. Let's see what we can find.



60/3 2026/09/29 11:06 tool read-file
0m Args:
{
  "File": "net/netlink/af_netlink.c",
  "FirstLine": 1980,
  "LineCount": 35
}

Results:
{
  "Contents": "1980:\t\t\taddr-\u003enl_family = AF_NETLINK;\n1981:\t\t\taddr-\u003enl_pad    = 0;\n1982:\t\t\taddr-\u003enl_pid\t= NETLINK_CB(skb).portid;\n1983:\t\t\taddr-\u003enl_groups\t= netlink_group_mask(NETLINK_CB(skb).dst_group);\n1984:\t\t\tmsg-\u003emsg_namelen = sizeof(*addr);\n1985:\t\t}\n1986:\t\n1987:\t\tif (nlk_test_bit(RECV_PKTINFO, sk))\n1988:\t\t\tnetlink_cmsg_recv_pktinfo(msg, skb);\n1989:\t\tif (nlk_test_bit(LISTEN_ALL_NSID, sk))\n1990:\t\t\tnetlink_cmsg_listen_all_nsid(sk, msg, skb);\n1991:\t\n1992:\t\tmemset(\u0026scm, 0, sizeof(scm));\n1993:\t\tscm.creds = *NETLINK_CREDS(skb);\n1994:\t\tif (flags \u0026 MSG_TRUNC)\n1995:\t\t\tcopied = data_skb-\u003elen;\n1996:\t\n1997:\t\tskb_free_datagram(sk, skb);\n1998:\t\n1999:\t\tif (READ_ONCE(nlk-\u003ecb_running) \u0026\u0026\n2000:\t\t    atomic_read(\u0026sk-\u003esk_rmem_alloc) \u003c= sk-\u003esk_rcvbuf / 2) {\n2001:\t\t\tret = netlink_dump(sk, false);\n2002:\t\t\tif (ret) {\n2003:\t\t\t\tWRITE_ONCE(sk-\u003esk_err, -ret);\n2004:\t\t\t\tsk_error_report(sk);\n2005:\t\t\t}\n2006:\t\t}\n2007:\t\n2008:\t\tscm_recv(sock, msg, \u0026scm, flags);\n2009:\tout:\n2010:\t\tnetlink_rcv_wake(sk);\n2011:\t\treturn err ? : copied;\n2012:\t}\n2013:\t\n2014:\tstatic void netlink_data_ready(struct sock *sk)\n"
}

61/3 2026/09/29 11:06 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 46799
							output: 38
							thoughts: 148
						

Thoughts:
**Analyzing the Netlink and Unix Domain Socket Interaction**

Okay, so I'm looking into this `netlink_recvmsg` function, and the first thing that jumps out is the `memset(&scm, 0, sizeof(scm));` call. I need to understand how the Socket Control Message (`scm`) is being used, especially in relation to Unix domain sockets. This signals that there's a connection between Netlink and Unix sockets in this context.

Now, my focus shifts to `net/unix/af_unix.c`. Specifically, I need to trace the usage of `struct scm_cookie`, `UNIXCB(skb)`, and `sk_peer_pid` within this file. These are the key data structures and macros that are usually associated with the exchange of control information between Unix domain sockets, and I suspect they are critical to the Netlink interaction.

Let's begin by checking each instance, methodically. Ah, here's one: `unix_dgram_sendmsg`. Line 2101: `struct scm_cookie scm;` is the relevant line. Okay, looks like I need to inspect the surrounding code, especially lines 2095 through 2140 in `net/unix/af_unix.c`, to get a complete picture. This gives me a starting point for figuring out how the `scm_cookie` is being used here in the Unix domain socket sending process. This will probably hold the key to understanding the control message flow between these two domain types.



62/3 2026/09/29 11:06 tool read-file
0m Args:
{
  "File": "net/unix/af_unix.c",
  "FirstLine": 2095,
  "LineCount": 45
}

Results:
{
  "Contents": "2095:\t\n2096:\tstatic int unix_dgram_sendmsg(struct socket *sock, struct msghdr *msg,\n2097:\t\t\t\t      size_t len)\n2098:\t{\n2099:\t\tstruct sock *sk = sock-\u003esk, *other = NULL;\n2100:\t\tstruct unix_sock *u = unix_sk(sk);\n2101:\t\tstruct scm_cookie scm;\n2102:\t\tstruct sk_buff *skb;\n2103:\t\tint data_len = 0;\n2104:\t\tint sk_locked;\n2105:\t\tlong timeo;\n2106:\t\tint err;\n2107:\t\n2108:\t\terr = scm_send(sock, msg, \u0026scm, false);\n2109:\t\tif (err \u003c 0)\n2110:\t\t\treturn err;\n2111:\t\n2112:\t\tif (msg-\u003emsg_flags \u0026 MSG_OOB) {\n2113:\t\t\terr = -EOPNOTSUPP;\n2114:\t\t\tgoto out;\n2115:\t\t}\n2116:\t\n2117:\t\tif (msg-\u003emsg_namelen) {\n2118:\t\t\terr = unix_validate_addr(msg-\u003emsg_name, msg-\u003emsg_namelen);\n2119:\t\t\tif (err)\n2120:\t\t\t\tgoto out;\n2121:\t\n2122:\t\t\terr = BPF_CGROUP_RUN_PROG_UNIX_SENDMSG_LOCK(sk,\n2123:\t\t\t\t\t\t\t\t    msg-\u003emsg_name,\n2124:\t\t\t\t\t\t\t\t    \u0026msg-\u003emsg_namelen,\n2125:\t\t\t\t\t\t\t\t    NULL);\n2126:\t\t\tif (err)\n2127:\t\t\t\tgoto out;\n2128:\t\t}\n2129:\t\n2130:\t\tif (unix_may_passcred(sk) \u0026\u0026 !READ_ONCE(u-\u003eaddr)) {\n2131:\t\t\terr = unix_autobind(sk);\n2132:\t\t\tif (err)\n2133:\t\t\t\tgoto out;\n2134:\t\t}\n2135:\t\n2136:\t\tif (len \u003e READ_ONCE(sk-\u003esk_sndbuf) - 32) {\n2137:\t\t\terr = -EMSGSIZE;\n2138:\t\t\tgoto out;\n2139:\t\t}\n"
}

63/3 2026/09/29 11:06 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 47947
							output: 38
							thoughts: 66
						

Thoughts:
Here's my analysis of what's going on, based on the code snippet and my expertise:

**Unix Domain Socket Sendmsg Analysis**

Okay, so I see this `scm_send(sock, msg, &scm, false);` call. The important thing here is that `scm` gets zeroed out right away. That's a key detail to start with. The immediate question burning in my mind is: what happens to this zeroed `scm` structure later when we get to `unix_dgram_sendmsg`? That's where the magic really happens, or perhaps, where a problem might rear its head.

Time to dive into the source. I'll need to check the relevant section within `net/unix/af_unix.c`. Specifically, lines 2180 to 2240 should hold the answers to my questions. I expect to find the actual socket message processing logic there. I'll be looking for any uses of `scm` within that function, any copying of data into it, and any uses of any information from it. I need to understand if the initial zeroing has any impact on the ultimate sending behavior, or if the system is populating it with meaningful data later. The core of this investigation is whether the function has the chance to set the values of the fields in scm that are zeroed earlier. I want to see how the system handles control messages (or lack thereof) from the context of this function. That will reveal the purpose of this initial zeroing. I'll be checking carefully for any potential for unexpected behavior or subtle bugs arising from this initial zeroing.



64/3 2026/09/29 11:06 tool read-file
0m Args:
{
  "File": "net/unix/af_unix.c",
  "FirstLine": 2180,
  "LineCount": 45
}

Results:
{
  "Contents": "2180:\t\t\t\terr = -ENOTCONN;\n2181:\t\t\t\tgoto out_free;\n2182:\t\t\t}\n2183:\t\t}\n2184:\t\n2185:\t\tif (sk_filter(other, skb) \u003c 0) {\n2186:\t\t\t/* Toss the packet but do not return any error to the sender */\n2187:\t\t\terr = len;\n2188:\t\t\tgoto out_sock_put;\n2189:\t\t}\n2190:\t\n2191:\t\terr = unix_maybe_add_creds(skb, sk, other);\n2192:\t\tif (err)\n2193:\t\t\tgoto out_sock_put;\n2194:\t\n2195:\trestart:\n2196:\t\tsk_locked = 0;\n2197:\t\tunix_state_lock(other);\n2198:\trestart_locked:\n2199:\t\n2200:\t\tif (!unix_may_send(sk, other)) {\n2201:\t\t\terr = -EPERM;\n2202:\t\t\tgoto out_unlock;\n2203:\t\t}\n2204:\t\n2205:\t\tif (unlikely(sock_flag(other, SOCK_DEAD))) {\n2206:\t\t\t/* Check with 1003.1g - what should datagram error */\n2207:\t\n2208:\t\t\tunix_state_unlock(other);\n2209:\t\n2210:\t\t\tif (sk-\u003esk_type == SOCK_SEQPACKET) {\n2211:\t\t\t\t/* We are here only when racing with unix_release_sock()\n2212:\t\t\t\t * is clearing @other. Never change state to TCP_CLOSE\n2213:\t\t\t\t * unlike SOCK_DGRAM wants.\n2214:\t\t\t\t */\n2215:\t\t\t\terr = -EPIPE;\n2216:\t\t\t\tgoto out_sock_put;\n2217:\t\t\t}\n2218:\t\n2219:\t\t\tif (!sk_locked)\n2220:\t\t\t\tunix_state_lock(sk);\n2221:\t\n2222:\t\t\tif (unix_peer(sk) == other) {\n2223:\t\t\t\tunix_peer(sk) = NULL;\n2224:\t\t\t\tunix_dgram_peer_wake_disconnect_wakeup(sk, other);\n"
}

65/3 2026/09/29 11:06 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 49015
							output: 38
							thoughts: 46
						

Thoughts:
Here's my thought process, summarized as you requested:

**Debugging a Network Socket Memory Leak**

Okay, hold on a second. Before I delve deeper into line 2180, I need to understand the full context of what's happening with this `skb` (socket buffer) and `unix_scm_to_skb`. Something feels off, so I need to trace this memory allocation and transfer. Specifically, I need to know where this socket buffer is actually created, because `unix_scm_to_skb` likely assumes it exists already! The logic between lines 2140 and 2180 is the obvious place to start digging. Let me confirm my suspicion and review the code in that region. I need to make sure that the `skb` is properly initialized before this function even attempts to use it. That's the first place to start.



66/3 2026/09/29 11:06 tool read-file
0m Args:
{
  "File": "net/unix/af_unix.c",
  "FirstLine": 2140,
  "LineCount": 40
}

Results:
{
  "Contents": "2140:\t\n2141:\t\tif (len \u003e SKB_MAX_ALLOC) {\n2142:\t\t\tdata_len = min_t(size_t,\n2143:\t\t\t\t\t len - SKB_MAX_ALLOC,\n2144:\t\t\t\t\t MAX_SKB_FRAGS * PAGE_SIZE);\n2145:\t\t\tdata_len = PAGE_ALIGN(data_len);\n2146:\t\n2147:\t\t\tBUILD_BUG_ON(SKB_MAX_ALLOC \u003c PAGE_SIZE);\n2148:\t\t}\n2149:\t\n2150:\t\tskb = sock_alloc_send_pskb(sk, len - data_len, data_len,\n2151:\t\t\t\t\t   msg-\u003emsg_flags \u0026 MSG_DONTWAIT, \u0026err,\n2152:\t\t\t\t\t   PAGE_ALLOC_COSTLY_ORDER);\n2153:\t\tif (!skb)\n2154:\t\t\tgoto out;\n2155:\t\n2156:\t\terr = unix_scm_to_skb(\u0026scm, skb, true);\n2157:\t\tif (err \u003c 0)\n2158:\t\t\tgoto out_free;\n2159:\t\n2160:\t\tskb_put(skb, len - data_len);\n2161:\t\tskb-\u003edata_len = data_len;\n2162:\t\tskb-\u003elen = len;\n2163:\t\terr = skb_copy_datagram_from_iter(skb, 0, \u0026msg-\u003emsg_iter, len);\n2164:\t\tif (err)\n2165:\t\t\tgoto out_free;\n2166:\t\n2167:\t\ttimeo = sock_sndtimeo(sk, msg-\u003emsg_flags \u0026 MSG_DONTWAIT);\n2168:\t\n2169:\t\tif (msg-\u003emsg_namelen) {\n2170:\tlookup:\n2171:\t\t\tother = unix_find_other(sock_net(sk), msg-\u003emsg_name,\n2172:\t\t\t\t\t\tmsg-\u003emsg_namelen, sk-\u003esk_type, 0);\n2173:\t\t\tif (IS_ERR(other)) {\n2174:\t\t\t\terr = PTR_ERR(other);\n2175:\t\t\t\tgoto out_free;\n2176:\t\t\t}\n2177:\t\t} else {\n2178:\t\t\tother = unix_peer_get(sk);\n2179:\t\t\tif (!other) {\n"
}

67/3 2026/09/29 11:06 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 49925
							output: 38
							thoughts: 1061
						

Thoughts:
**Analyzing UNIX Domain Socket Credential Passing**

Okay, let's break this down. My initial focus is on how credentials are handled within the UNIX domain socket code, specifically how they're propagated between processes. I started with `unix_scm_to_skb`, and immediately, the `UNIXCB(skb)` macro caught my attention. I need to understand what that is, and if it is initialized. It seems to be the crucial piece of metadata associated with the socket buffer (`skb`). I'll need to confirm if this `skb->cb` is zeroed or initialized.

I looked at the code and wondered, what would happen if `scm->pid` was `NULL` within `unix_scm_to_skb`? That's when I dug into `get_pids`.  The macro expansion in `__get_pids` is interesting. The call to `get_pid(NULL)` returns `NULL`, which means those PID fields are explicitly set to `NULL`. Good to know; that explains what to expect with a NULL `scm->pid`.

Now, I moved on to `unix_maybe_add_creds`. This is where it gets interesting, as it checks if credentials should be passed. Here the `UNIXCB(skb).pid` is checked. If it isn't set, then credentials are copied from the current task using `get_task_pids`. However, if the `if` statement is false, `UNIXCB(skb).pid` remains `NULL`, because `unix_scm_to_skb` sets them to `NULL` previously. This implies that credential passing is conditional, and the absence of credentials is a valid state.

Finally, I checked `unix_skb_to_scm`, and I need to understand the reverse process. `get_pids(scm->pid, UNIXCB(skb).pid);`. Here, if `UNIXCB(skb).pid[PIDTYPE_TGID]` is `NULL`, then `scm->pid[PIDTYPE_TGID]` ends up being `NULL` too, and the associated PID value gets set to 0.

So, the key seems to be that `UNIXCB(skb).pid` can be either a valid `pid` array or `NULL`. If it's `NULL`, it implies that either the credentials weren't explicitly passed, or were removed in a later step. This NULL state is then propagated through the various functions. Now I will inspect the code in `net/unix/af_unix.c` to see how the credential data is handled.



68/3 2026/09/29 11:06 tool read-file
0m Args:
{
  "File": "net/unix/af_unix.c",
  "FirstLine": 2575,
  "LineCount": 45
}

Results:
{
  "Contents": "2575:\tint __unix_dgram_recvmsg(struct sock *sk, struct msghdr *msg, size_t size,\n2576:\t\t\t\t int flags)\n2577:\t{\n2578:\t\tstruct scm_cookie scm;\n2579:\t\tstruct socket *sock = sk-\u003esk_socket;\n2580:\t\tstruct unix_sock *u = unix_sk(sk);\n2581:\t\tstruct sk_buff *skb, *last;\n2582:\t\tlong timeo;\n2583:\t\tint skip;\n2584:\t\tint err;\n2585:\t\n2586:\t\terr = -EOPNOTSUPP;\n2587:\t\tif (flags\u0026MSG_OOB)\n2588:\t\t\tgoto out;\n2589:\t\n2590:\t\ttimeo = sock_rcvtimeo(sk, flags \u0026 MSG_DONTWAIT);\n2591:\t\n2592:\t\tdo {\n2593:\t\t\tmutex_lock(\u0026u-\u003eiolock);\n2594:\t\n2595:\t\t\tskip = sk_peek_offset(sk, flags);\n2596:\t\t\tskb = __skb_try_recv_datagram(sk, \u0026sk-\u003esk_receive_queue, flags,\n2597:\t\t\t\t\t\t      \u0026skip, \u0026err, \u0026last);\n2598:\t\t\tif (skb) {\n2599:\t\t\t\tif (!(flags \u0026 MSG_PEEK))\n2600:\t\t\t\t\tscm_stat_del(sk, skb);\n2601:\t\t\t\tbreak;\n2602:\t\t\t}\n2603:\t\n2604:\t\t\tmutex_unlock(\u0026u-\u003eiolock);\n2605:\t\n2606:\t\t\tif (err != -EAGAIN)\n2607:\t\t\t\tbreak;\n2608:\t\t} while (timeo \u0026\u0026\n2609:\t\t\t !__skb_wait_for_more_packets(sk, \u0026sk-\u003esk_receive_queue,\n2610:\t\t\t\t\t\t      \u0026err, \u0026timeo, last));\n2611:\t\n2612:\t\tif (!skb) { /* implies iolock unlocked */\n2613:\t\t\t/* Signal EOF on disconnected non-blocking SEQPACKET socket. */\n2614:\t\t\tif (sk-\u003esk_type == SOCK_SEQPACKET \u0026\u0026 err == -EAGAIN \u0026\u0026\n2615:\t\t\t    (READ_ONCE(sk-\u003esk_shutdown) \u0026 RCV_SHUTDOWN))\n2616:\t\t\t\terr = 0;\n2617:\t\t\tgoto out;\n2618:\t\t}\n2619:\t\n"
}

69/3 2026/09/29 11:06 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 52265
							output: 38
							thoughts: 28
						

Thoughts:
Okay, let's dive into this. I'm focusing on `__unix_dgram_recvmsg`, specifically lines 2620 to 2670. I need to understand the data flow and any potential edge cases within this function, particularly within this critical segment. I'll be looking for nuances around data handling, buffer management, error checking, and anything that might impact performance or security in the datagram socket reception process. I'll pay close attention to the interactions with the underlying kernel structures and any synchronization primitives employed. My goal is a solid understanding of this code path.



70/3 2026/09/29 11:07 tool read-file
0m Args:
{
  "File": "net/unix/af_unix.c",
  "FirstLine": 2620,
  "LineCount": 50
}

Results:
{
  "Contents": "2620:\t\tif (wq_has_sleeper(\u0026u-\u003epeer_wait))\n2621:\t\t\twake_up_interruptible_sync_poll(\u0026u-\u003epeer_wait,\n2622:\t\t\t\t\t\t\tEPOLLOUT | EPOLLWRNORM |\n2623:\t\t\t\t\t\t\tEPOLLWRBAND);\n2624:\t\n2625:\t\tif (msg-\u003emsg_name) {\n2626:\t\t\tunix_copy_addr(msg, skb-\u003esk);\n2627:\t\n2628:\t\t\tBPF_CGROUP_RUN_PROG_UNIX_RECVMSG_LOCK(sk,\n2629:\t\t\t\t\t\t\t      msg-\u003emsg_name,\n2630:\t\t\t\t\t\t\t      \u0026msg-\u003emsg_namelen);\n2631:\t\t}\n2632:\t\n2633:\t\tif (size \u003e skb-\u003elen - skip)\n2634:\t\t\tsize = skb-\u003elen - skip;\n2635:\t\telse if (size \u003c skb-\u003elen - skip)\n2636:\t\t\tmsg-\u003emsg_flags |= MSG_TRUNC;\n2637:\t\n2638:\t\terr = skb_copy_datagram_msg(skb, skip, msg, size);\n2639:\t\tif (err)\n2640:\t\t\tgoto out_free;\n2641:\t\n2642:\t\tif (sock_flag(sk, SOCK_RCVTSTAMP))\n2643:\t\t\t__sock_recv_timestamp(msg, sk, skb);\n2644:\t\n2645:\t\tmemset(\u0026scm, 0, sizeof(scm));\n2646:\t\n2647:\t\tunix_skb_to_scm(skb, \u0026scm);\n2648:\t\n2649:\t\tif (!(flags \u0026 MSG_PEEK)) {\n2650:\t\t\tif (UNIXCB(skb).fp)\n2651:\t\t\t\tunix_detach_fds(\u0026scm, skb);\n2652:\t\n2653:\t\t\tsk_peek_offset_bwd(sk, skb-\u003elen);\n2654:\t\t} else {\n2655:\t\t\t/* It is questionable: on PEEK we could:\n2656:\t\t\t   - do not return fds - good, but too simple 8)\n2657:\t\t\t   - return fds, and do not return them on read (old strategy,\n2658:\t\t\t     apparently wrong)\n2659:\t\t\t   - clone fds (I chose it for now, it is the most universal\n2660:\t\t\t     solution)\n2661:\t\n2662:\t\t\t   POSIX 1003.1g does not actually define this clearly\n2663:\t\t\t   at all. POSIX 1003.1g doesn't define a lot of things\n2664:\t\t\t   clearly however!\n2665:\t\n2666:\t\t\t*/\n2667:\t\n2668:\t\t\tsk_peek_offset_fwd(sk, size);\n2669:\t\n"
}

71/3 2026/09/29 11:07 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 53230
							output: 38
							thoughts: 107
						

Thoughts:
**Analyzing the Unix Socket Data Flow**

Okay, so I'm diving into this Unix socket code, and I'm tracing the data flow. Right now, my focus is on how data is received and processed. I see this `memset` call on line 2645, initializing the `scm` structure to zero. That makes sense; we want a clean slate for the control message data. Then, `unix_skb_to_scm` at line 2647, which looks like it's extracting the data from the socket buffer (`skb`) and populating the `scm` structure. That’s probably the important step! Following that, it looks like `scm_recv_unix` gets involved, along with the `sock`, the `msg` struct, the `scm` struct, and the `flags`. That's where the actual reception and possibly processing of the control message happens.

I should also check how `unix_stream_read_generic` plays into this. It's likely involved in the data reception as well, so I need to understand its role. Lines 2925 through 2960 and 3030 through 3060 seem like a good place to start dissecting that function, since they are likely the main data processing functions. I need to understand the interaction between `scm_recv_unix` and the generic read function. I'll focus on these parts to clarify the bigger picture.



72/3 2026/09/29 11:07 tool read-file
0m Args:
{
  "File": "net/unix/af_unix.c",
  "FirstLine": 2925,
  "LineCount": 45
}

Results:
{
  "Contents": "2925:\t\t\t\t\t    bool freezable)\n2926:\t{\n2927:\t\tint noblock = state-\u003eflags \u0026 MSG_DONTWAIT;\n2928:\t\tstruct socket *sock = state-\u003esocket;\n2929:\t\tstruct msghdr *msg = state-\u003emsg;\n2930:\t\tstruct sock *sk = sock-\u003esk;\n2931:\t\tsize_t size = state-\u003esize;\n2932:\t\tint flags = state-\u003eflags;\n2933:\t\tbool check_creds = false;\n2934:\t\tstruct scm_cookie scm;\n2935:\t\tstruct unix_sock *u;\n2936:\t\tint copied = 0;\n2937:\t\tint err = 0;\n2938:\t\tlong timeo;\n2939:\t\tint target;\n2940:\t\tint skip;\n2941:\t\n2942:\t\tif (unlikely(READ_ONCE(sk-\u003esk_state) != TCP_ESTABLISHED)) {\n2943:\t\t\terr = -EINVAL;\n2944:\t\t\tgoto out;\n2945:\t\t}\n2946:\t\n2947:\t\tif (unlikely(flags \u0026 MSG_OOB)) {\n2948:\t\t\terr = -EOPNOTSUPP;\n2949:\t#if IS_ENABLED(CONFIG_AF_UNIX_OOB)\n2950:\t\t\terr = unix_stream_recv_urg(state);\n2951:\t#endif\n2952:\t\t\tgoto out;\n2953:\t\t}\n2954:\t\n2955:\t\ttarget = sock_rcvlowat(sk, flags \u0026 MSG_WAITALL, size);\n2956:\t\ttimeo = sock_rcvtimeo(sk, noblock);\n2957:\t\n2958:\t\tmemset(\u0026scm, 0, sizeof(scm));\n2959:\t\n2960:\t\tu = unix_sk(sk);\n2961:\t\n2962:\tredo:\n2963:\t\t/* Lock the socket to prevent queue disordering\n2964:\t\t * while sleeps in memcpy_tomsg\n2965:\t\t */\n2966:\t\tmutex_lock(\u0026u-\u003eiolock);\n2967:\t\n2968:\t\tskip = max(sk_peek_offset(sk, flags), 0);\n2969:\t\n"
}

73/3 2026/09/29 11:07 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 54315
							output: 38
							thoughts: 49
						

Thoughts:
Okay, here's my interpretation of that thought process, tailored for an expert audience:

**Examining Socket Control Message Initialization and Potential AF_UNIX Vulnerabilities**

Alright, so the first thing I'm seeing is a `memset` on the `scm` struct. Line 2958: `memset(&scm, 0, sizeof(scm));` This is standard, but always a good place to start. It means we're initializing the socket control message struct to all zeros. Ensures we're starting from a known state. Prevents any potential garbage values from interfering. Good practice, but it doesn't give me any immediate red flags, assuming this is done *before* any relevant data is populated into the `scm`.

Now, I need to dig deeper. I'm going to shift my focus to a critical section of the `net/unix/af_unix.c` file, specifically lines 3030-3070. That range is potentially where data is handled and where any vulnerabilities might emerge. That chunk likely involves the actual handling of socket control messages, so that's where I need to look for any unchecked size assumptions, off-by-one errors, or potential integer overflows that could be exploited. I'll need to look for potential vulnerabilities that might arise as a result of that zero-initialization or the subsequent values being set.



74/3 2026/09/29 11:07 tool read-file
0m Args:
{
  "File": "net/unix/af_unix.c",
  "FirstLine": 3030,
  "LineCount": 40
}

Results:
{
  "Contents": "3030:\t\t\t\tskb = skb_peek_next(skb, \u0026sk-\u003esk_receive_queue);\n3031:\t\t\t\tif (!skb)\n3032:\t\t\t\t\tgoto again;\n3033:\t\t\t}\n3034:\t\n3035:\t\t\tunix_state_unlock(sk);\n3036:\t\n3037:\t\t\tif (check_creds) {\n3038:\t\t\t\t/* Never glue messages from different writers */\n3039:\t\t\t\tif (!unix_skb_scm_eq(sk, skb, \u0026scm))\n3040:\t\t\t\t\tbreak;\n3041:\t\t\t} else if (unix_may_passcred(sk)) {\n3042:\t\t\t\t/* Copy credentials */\n3043:\t\t\t\tunix_skb_to_scm(skb, \u0026scm);\n3044:\t\t\t\tcheck_creds = true;\n3045:\t\t\t}\n3046:\t\n3047:\t\t\t/* Copy address just once */\n3048:\t\t\tif (msg \u0026\u0026 msg-\u003emsg_name) {\n3049:\t\t\t\tDECLARE_SOCKADDR(struct sockaddr_un *, sunaddr, msg-\u003emsg_name);\n3050:\t\n3051:\t\t\t\tunix_copy_addr(msg, skb-\u003esk);\n3052:\t\t\t\tBPF_CGROUP_RUN_PROG_UNIX_RECVMSG_LOCK(sk, msg-\u003emsg_name,\n3053:\t\t\t\t\t\t\t\t      \u0026msg-\u003emsg_namelen);\n3054:\t\n3055:\t\t\t\tsunaddr = NULL;\n3056:\t\t\t}\n3057:\t\n3058:\t\t\tchunk = min_t(unsigned int, unix_skb_len(skb) - skip, size);\n3059:\t\t\tchunk = state-\u003erecv_actor(skb, skip, chunk, state);\n3060:\t\t\tif (chunk \u003c 0) {\n3061:\t\t\t\tif (copied == 0)\n3062:\t\t\t\t\tcopied = -EFAULT;\n3063:\t\t\t\tbreak;\n3064:\t\t\t}\n3065:\t\t\tcopied += chunk;\n3066:\t\t\tsize -= chunk;\n3067:\t\n3068:\t\t\t/* Mark read part of skb as used */\n3069:\t\t\tif (!(flags \u0026 MSG_PEEK)) {\n"
}

75/3 2026/09/29 11:07 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 55290
							output: 38
							thoughts: 50
						

Thoughts:
Here's my take on those thoughts:

**Analyzing `unix_stream_sendmsg` and Control Messages**

Okay, so I'm digging into `unix_stream_sendmsg`. Specifically, I need to see how the code handles `scm` (Socket Control Messages) in that function. My initial thought is to jump straight into the kernel code; it's the most efficient way to get a clear picture of what's going on. Line numbers are a good start. I'm going to focus my attention on lines 2390 through 2440 within `net/unix/af_unix.c`. That chunk should give me the details I need on `scm` processing within this stream.



76/3 2026/09/29 11:07 tool read-file
0m Args:
{
  "File": "net/unix/af_unix.c",
  "FirstLine": 2390,
  "LineCount": 50
}

Results:
{
  "Contents": "2390:\tstatic int unix_stream_sendmsg(struct socket *sock, struct msghdr *msg,\n2391:\t\t\t\t       size_t len)\n2392:\t{\n2393:\t\tstruct sock *sk = sock-\u003esk;\n2394:\t\tstruct sk_buff *skb = NULL;\n2395:\t\tstruct sock *other = NULL;\n2396:\t\tstruct unix_sock *otheru;\n2397:\t\tstruct scm_cookie scm;\n2398:\t\tbool fds_sent = false;\n2399:\t\tint err, sent = 0;\n2400:\t\n2401:\t\terr = scm_send(sock, msg, \u0026scm, false);\n2402:\t\tif (err \u003c 0)\n2403:\t\t\treturn err;\n2404:\t\n2405:\t\tif (msg-\u003emsg_flags \u0026 MSG_OOB) {\n2406:\t\t\terr = -EOPNOTSUPP;\n2407:\t#if IS_ENABLED(CONFIG_AF_UNIX_OOB)\n2408:\t\t\tif (len)\n2409:\t\t\t\tlen--;\n2410:\t\t\telse\n2411:\t#endif\n2412:\t\t\t\tgoto out_err;\n2413:\t\t}\n2414:\t\n2415:\t\tif (msg-\u003emsg_namelen) {\n2416:\t\t\terr = READ_ONCE(sk-\u003esk_state) == TCP_ESTABLISHED ? -EISCONN : -EOPNOTSUPP;\n2417:\t\t\tgoto out_err;\n2418:\t\t}\n2419:\t\n2420:\t\tother = unix_peer(sk);\n2421:\t\tif (!other) {\n2422:\t\t\terr = -ENOTCONN;\n2423:\t\t\tgoto out_err;\n2424:\t\t}\n2425:\t\n2426:\t\totheru = unix_sk(other);\n2427:\t\n2428:\t\tif (READ_ONCE(sk-\u003esk_shutdown) \u0026 SEND_SHUTDOWN)\n2429:\t\t\tgoto out_pipe;\n2430:\t\n2431:\t\twhile (sent \u003c len) {\n2432:\t\t\tint size = len - sent;\n2433:\t\t\tint data_len;\n2434:\t\n2435:\t\t\tif (unlikely(msg-\u003emsg_flags \u0026 MSG_SPLICE_PAGES)) {\n2436:\t\t\t\tskb = sock_alloc_send_pskb(sk, 0, 0,\n2437:\t\t\t\t\t\t\t   msg-\u003emsg_flags \u0026 MSG_DONTWAIT,\n2438:\t\t\t\t\t\t\t   \u0026err, 0);\n2439:\t\t\t} else {\n"
}

77/3 2026/09/29 11:07 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 56247
							output: 38
							thoughts: 34
						

Thoughts:
Okay, here's my interpretation of that thought process, from an expert's perspective:

**Diving into `unix_stream_sendmsg` and `scm`**

Right, so I'm digging into `unix_stream_sendmsg`, specifically trying to understand its interaction with `scm` – that's the Security Credentials Message. A crucial part of this function, I know, but I need to refresh my memory on the specific implementation. Let's get to the heart of the matter. I'm going to jump straight into the code, and lines 2440 through 2490 is where I'll start. It is likely the area where the magic happens, specifically related to the credentials. Let's see what interesting things those lines contain.



78/3 2026/09/29 11:07 tool read-file
0m Args:
{
  "File": "net/unix/af_unix.c",
  "FirstLine": 2440,
  "LineCount": 50
}

Results:
{
  "Contents": "2440:\t\t\t\t/* Keep two messages in the pipe so it schedules better */\n2441:\t\t\t\tsize = min_t(int, size, (READ_ONCE(sk-\u003esk_sndbuf) \u003e\u003e 1) - 64);\n2442:\t\n2443:\t\t\t\t/* allow fallback to order-0 allocations */\n2444:\t\t\t\tsize = min_t(int, size, SKB_MAX_HEAD(0) + UNIX_SKB_FRAGS_SZ);\n2445:\t\n2446:\t\t\t\tdata_len = max_t(int, 0, size - SKB_MAX_HEAD(0));\n2447:\t\n2448:\t\t\t\tdata_len = min_t(size_t, size, PAGE_ALIGN(data_len));\n2449:\t\n2450:\t\t\t\tskb = sock_alloc_send_pskb(sk, size - data_len, data_len,\n2451:\t\t\t\t\t\t\t   msg-\u003emsg_flags \u0026 MSG_DONTWAIT, \u0026err,\n2452:\t\t\t\t\t\t\t   get_order(UNIX_SKB_FRAGS_SZ));\n2453:\t\t\t}\n2454:\t\t\tif (!skb)\n2455:\t\t\t\tgoto out_err;\n2456:\t\n2457:\t\t\t/* Only send the fds in the first buffer */\n2458:\t\t\terr = unix_scm_to_skb(\u0026scm, skb, !fds_sent);\n2459:\t\t\tif (err \u003c 0)\n2460:\t\t\t\tgoto out_free;\n2461:\t\n2462:\t\t\tfds_sent = true;\n2463:\t\n2464:\t\t\terr = unix_maybe_add_creds(skb, sk, other);\n2465:\t\t\tif (err)\n2466:\t\t\t\tgoto out_free;\n2467:\t\n2468:\t\t\tif (unlikely(msg-\u003emsg_flags \u0026 MSG_SPLICE_PAGES)) {\n2469:\t\t\t\tskb-\u003eip_summed = CHECKSUM_UNNECESSARY;\n2470:\t\t\t\terr = skb_splice_from_iter(skb, \u0026msg-\u003emsg_iter, size);\n2471:\t\t\t\tif (err \u003c 0)\n2472:\t\t\t\t\tgoto out_free;\n2473:\t\n2474:\t\t\t\tsize = err;\n2475:\t\t\t\trefcount_add(size, \u0026sk-\u003esk_wmem_alloc);\n2476:\t\t\t} else {\n2477:\t\t\t\tskb_put(skb, size - data_len);\n2478:\t\t\t\tskb-\u003edata_len = data_len;\n2479:\t\t\t\tskb-\u003elen = size;\n2480:\t\t\t\terr = skb_copy_datagram_from_iter(skb, 0, \u0026msg-\u003emsg_iter, size);\n2481:\t\t\t\tif (err)\n2482:\t\t\t\t\tgoto out_free;\n2483:\t\t\t}\n2484:\t\n2485:\t\t\tunix_state_lock(other);\n2486:\t\n2487:\t\t\tif (sock_flag(other, SOCK_DEAD) ||\n2488:\t\t\t    (other-\u003esk_shutdown \u0026 RCV_SHUTDOWN))\n2489:\t\t\t\tgoto out_pipe_unlock;\n"
}

79/3 2026/09/29 11:07 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 57332
							output: 38
							thoughts: 63
						

Thoughts:
Here's my take on those thoughts:

**Analyzing `unix_scm_to_skb` and `queue_oob`**

Alright, so `unix_scm_to_skb` is responsible for setting the `UNIXCB(skb).pid`. That seems straightforward enough, but I want to be certain about the flow and any potential side effects. My attention is now drawn to how this PID is used within the overall system.

My next step is to examine the `queue_oob` function, specifically focusing on lines 2330-2360 in `net/unix/af_unix.c`. This section likely handles out-of-band data queuing, so I need to see how the PID set earlier in `unix_scm_to_skb` is used during this process. Understanding how the PID influences OOB data handling is crucial. I need to understand if the PID is being used for security checks, routing decisions, or possibly for signaling purposes. The context of these specific lines will be key to understanding the interplay between the PID and OOB data. I'm looking for any flags or conditions that use that PID, in that area of code.



80/3 2026/09/29 11:07 tool read-file
0m Args:
{
  "File": "net/unix/af_unix.c",
  "FirstLine": 2330,
  "LineCount": 35
}

Results:
{
  "Contents": "2330:\tstatic int queue_oob(struct sock *sk, struct msghdr *msg, struct sock *other,\n2331:\t\t\t     struct scm_cookie *scm, bool fds_sent)\n2332:\t{\n2333:\t\tstruct unix_sock *ousk = unix_sk(other);\n2334:\t\tstruct sk_buff *skb;\n2335:\t\tint err;\n2336:\t\n2337:\t\tskb = sock_alloc_send_skb(sk, 1, msg-\u003emsg_flags \u0026 MSG_DONTWAIT, \u0026err);\n2338:\t\n2339:\t\tif (!skb)\n2340:\t\t\treturn err;\n2341:\t\n2342:\t\terr = unix_scm_to_skb(scm, skb, !fds_sent);\n2343:\t\tif (err \u003c 0)\n2344:\t\t\tgoto out;\n2345:\t\n2346:\t\terr = unix_maybe_add_creds(skb, sk, other);\n2347:\t\tif (err)\n2348:\t\t\tgoto out;\n2349:\t\n2350:\t\tskb_put(skb, 1);\n2351:\t\terr = skb_copy_datagram_from_iter(skb, 0, \u0026msg-\u003emsg_iter, 1);\n2352:\t\n2353:\t\tif (err)\n2354:\t\t\tgoto out;\n2355:\t\n2356:\t\tunix_state_lock(other);\n2357:\t\n2358:\t\tif (sock_flag(other, SOCK_DEAD) ||\n2359:\t\t    (other-\u003esk_shutdown \u0026 RCV_SHUTDOWN)) {\n2360:\t\t\terr = -EPIPE;\n2361:\t\t\tgoto out_unlock;\n2362:\t\t}\n2363:\t\n2364:\t\tif (UNIXCB(skb).fp \u0026\u0026 !other-\u003esk_scm_rights) {\n"
}

81/3 2026/09/29 11:07 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 58222
							output: 19
							thoughts: 624
						

Thoughts:
**Analyzing `scm_pidfd_recv` and Potential Error Handling**

Okay, so I'm looking at this `scm_pidfd_recv` function, specifically how it handles PIDFDs being sent over a socket. My immediate thought is to dissect the logic flow here. The code retrieves a PID, checks the control message length for the basic structure, and then calls `pidfd_prepare`. The goal is clearly to create a PIDFD (process ID file descriptor) for a given PID to send over a socket.

Hold on a second... I see the line that calls `pidfd_prepare`. What if `pidfd_prepare` fails? It seems like it is assumed to succeed, which is a common oversight. In general, `pidfd_prepare` returns an integer. What is `pidfd` if there's an error? I don't see any explicit check *after* the call. The value from `pidfd_prepare` is being directly used in `put_cmsg`. Let me examine this more closely and see what exactly `put_cmsg` does in this situation. It's supposed to handle potential errors in the message setup, but I need to be certain.

Let's go back and consider what the *old* code did for this, and see if there was a difference in how it's handled. Maybe the original version of this function handled errors differently. Aha, that's interesting! The old code *also* didn't explicitly check for a negative return from `pidfd_prepare`. So, the error handling is still missing.

Now, if `pidfd_prepare` returns a negative value indicating an error, that value will be used as a file descriptor. What if the error value is used directly in `fd_install`?

I need to understand *what* `pidfd_prepare` returns in case of a failure so I can understand the impact of this oversight. I need to track down the definition of `pidfd_prepare` now to understand its return value and what kind of errors it handles.



82/3 2026/09/29 11:08 tool grepper
0m Args:
{
  "Expression": "pidfd_prepare\\("
}

Results:
{
  "Output": "fs/notify/fanotify/fanotify_user.c=836=static ssize_t copy_event_to_user(struct fsnotify_group *group,\n--\nfs/notify/fanotify/fanotify_user.c-914-\t\tif (metadata.pid)\nfs/notify/fanotify/fanotify_user.c:915:\t\t\tpidfd = pidfd_prepare(event-\u003epid, pidfd_flags, \u0026pidfd_file);\nfs/notify/fanotify/fanotify_user.c-916-\n--\ninclude/linux/pid.h=86=struct task_struct *pidfd_get_task(int pidfd, unsigned int *flags);\ninclude/linux/pid.h:87:int pidfd_prepare(struct pid *pid, unsigned int flags, struct file **ret_file);\ninclude/linux/pid.h-88-void do_notify_pidfd(struct task_struct *task);\n--\nkernel/fork.c=1863=static inline void rcu_copy_process(struct task_struct *p)\n--\nkernel/fork.c-1908- */\nkernel/fork.c:1909:int pidfd_prepare(struct pid *pid, unsigned int flags, struct file **ret_file)\nkernel/fork.c-1910-{\n--\nkernel/fork.c=2013=__latent_entropy struct task_struct *copy_process(\n--\nkernel/fork.c-2351-\t\t */\nkernel/fork.c:2352:\t\tretval = pidfd_prepare(pid, flags, \u0026pidfile);\nkernel/fork.c-2353-\t\tif (retval \u003c 0)\n--\nkernel/pid.c=671=static int pidfd_create(struct pid *pid, unsigned int flags)\n--\nkernel/pid.c-675-\nkernel/pid.c:676:\tpidfd = pidfd_prepare(pid, flags, \u0026pidfd_file);\nkernel/pid.c-677-\tif (pidfd \u003c 0)\n--\nnet/core/scm.c=502=static void scm_pidfd_recv(struct msghdr *msg, struct scm_cookie *scm,\n--\nnet/core/scm.c-530-\nnet/core/scm.c:531:\tpidfd = pidfd_prepare(pid, flags, \u0026pidfd_file);\nnet/core/scm.c-532-\n--\nnet/core/sock.c=1740=static int sk_getsockopt_peerpidfd(struct sock *sk, enum pid_type type,\n--\nnet/core/sock.c-1765-\nnet/core/sock.c:1766:\tpidfd = pidfd_prepare(peer_pid, flags, \u0026pidfd_file);\nnet/core/sock.c-1767-\tput_pid(peer_pid);\n"
}

83/3 2026/09/29 11:08 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 60034
							output: 34
							thoughts: 23
						

Thoughts:
Okay, let's dive into this. Here's my take on those lines of code, presented as if they were my own internal thought process:

**Diving Deep into `kernel/fork.c` - Lines 1908-1940**

Alright, time to get into the nitty-gritty. Let's see... the code specifies `kernel/fork.c`, lines 1908 to 1940. I know this file pretty well; it's the heart of how processes are duplicated, the crux of the `fork()` system call. So, what's going on in this section? I'm betting we're in the critical path, likely dealing with resource allocation or the final steps of setting up the new child process.

*   I'll quickly scan for any familiar function calls or data structures. I'm looking for the use of `struct task_struct`, memory allocation calls (`kmalloc`, `vm_area_struct`), or anything related to copying page tables and process context.
*   I expect there to be a check and maybe allocation of the PID. That's a critical part of the fork process.
*   The lines very likely deal with some of the more complex parts. I wouldn't be surprised if there were some security checks, or some of the more complicated initialization.

I'm mentally stepping through this code, I'm already anticipating the typical challenges:

*   **Race conditions:** I have to be particularly vigilant for race conditions, especially if there's any shared resource access during this critical section.
*   **Error handling:** Robust error handling is crucial. The `fork()` system call can fail for a variety of reasons (e.g., resource exhaustion, permissions issues), so I'm watching for how the code handles these failures and cleans up accordingly.
*   **Memory management:** This is a resource-intensive operation, and careful memory management is vital to avoid leaks or other problems. I'll be looking at how memory is copied, potentially shared (if using copy-on-write), and ultimately released.
*   **Context switching:** Since we're dealing with creating a new process, the code will likely touch on the process context.

Overall, I'm expecting this section to be a core part of the process duplication sequence. I'm keen to see if any interesting optimizations or techniques are used, especially in this performance-critical part of the kernel. Let's go line by line to confirm.



84/3 2026/09/29 11:08 tool read-file
0m Args:
{
  "File": "kernel/fork.c",
  "FirstLine": 1908,
  "LineCount": 40
}

Results:
{
  "Contents": "1908:\t */\n1909:\tint pidfd_prepare(struct pid *pid, unsigned int flags, struct file **ret_file)\n1910:\t{\n1911:\t\tstruct file *pidfs_file;\n1912:\t\n1913:\t\t/*\n1914:\t\t * PIDFD_STALE is only allowed to be passed if the caller knows\n1915:\t\t * that @pid is already registered in pidfs and thus\n1916:\t\t * PIDFD_INFO_EXIT information is guaranteed to be available.\n1917:\t\t */\n1918:\t\tif (!(flags \u0026 PIDFD_STALE)) {\n1919:\t\t\t/*\n1920:\t\t\t * While holding the pidfd waitqueue lock removing the\n1921:\t\t\t * task linkage for the thread-group leader pid\n1922:\t\t\t * (PIDTYPE_TGID) isn't possible. Thus, if there's still\n1923:\t\t\t * task linkage for PIDTYPE_PID not having thread-group\n1924:\t\t\t * leader linkage for the pid means it wasn't a\n1925:\t\t\t * thread-group leader in the first place.\n1926:\t\t\t */\n1927:\t\t\tguard(spinlock_irq)(\u0026pid-\u003ewait_pidfd.lock);\n1928:\t\n1929:\t\t\t/* Task has already been reaped. */\n1930:\t\t\tif (!pid_has_task(pid, PIDTYPE_PID))\n1931:\t\t\t\treturn -ESRCH;\n1932:\t\t\t/*\n1933:\t\t\t * If this struct pid isn't used as a thread-group\n1934:\t\t\t * leader but the caller requested to create a\n1935:\t\t\t * thread-group leader pidfd then report ENOENT.\n1936:\t\t\t */\n1937:\t\t\tif (!(flags \u0026 PIDFD_THREAD) \u0026\u0026 !pid_has_task(pid, PIDTYPE_TGID))\n1938:\t\t\t\treturn -ENOENT;\n1939:\t\t}\n1940:\t\n1941:\t\tCLASS(get_unused_fd, pidfd)(O_CLOEXEC);\n1942:\t\tif (pidfd \u003c 0)\n1943:\t\t\treturn pidfd;\n1944:\t\n1945:\t\tpidfs_file = pidfs_alloc_file(pid, flags | O_RDWR);\n1946:\t\tif (IS_ERR(pidfs_file))\n1947:\t\t\treturn PTR_ERR(pidfs_file);\n"
}

85/3 2026/09/29 11:08 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 61265
							output: 35
							thoughts: 436
						

Thoughts:
**Analyzing the `pidfd_prepare` Error Handling**

Okay, let's break this down. If `pidfd_prepare` fails, the returned `pidfd` is negative, and `*ret_file` remains NULL, which is the expected behavior. Now, the next step is `put_cmsg(msg, SOL_SOCKET, cmsg_type, sizeof(int), &pidfd)`. I need to be sure; if `pidfd_prepare` errors, does `scm_pidfd_recv` correctly package the negative error code into the control message? I have to double-check `net/core/scm.c`.

Aha! `pidfd` is initialized with the return of `pidfd_prepare`, and then `if (put_cmsg(...))` is called. So, if `pidfd` is negative, we're putting that negative errno (like `-ESRCH` or `-EMFILE`) directly into the message. That's the key.

Wait, is this how the *original* code worked? Let's refresh our memory. Ah yes! The original code looks like:

```c
-	pidfd = pidfd_prepare(scm->pid, PIDFD_STALE, &pidfd_file);
-	if (put_cmsg(msg, SOL_SOCKET, SCM_PIDFD, sizeof(int), &pidfd)) {
-		if (pidfd_file) {
-			put_unused_fd(pidfd);
-			fput(pidfd_file);
-		}
-		return;
-	}
-	fd_install(pidfd, pidfd_file);
```

Okay, I see the call to `fd_install(pidfd, pidfd_file)` now. It's clear that this code could crash if `pidfd` is negative, and `pidfd_file` is NULL, which is what we would expect in the error case. That's bad. That means `fd_install` could be called with an invalid file descriptor.

Hold on... can `fd_install` *actually* be called with `pidfd < 0`? The key question is whether or not that error path is actually taken, or if the `put_cmsg` error handling prevents it. Time to dive back into `net/core/scm.c`, lines 525-545 in the original tree to be sure. It will be obvious when I look at the code.



86/3 2026/09/29 11:08 tool read-file
0m Args:
{
  "File": "net/core/scm.c",
  "FirstLine": 520,
  "LineCount": 30
}

Results:
{
  "Contents": " 520:\t\tif (msg-\u003emsg_controllen \u003c len) {\n 521:\t\t\tmsg-\u003emsg_flags |= MSG_CTRUNC;\n 522:\t\t\treturn;\n 523:\t\t}\n 524:\t\n 525:\t\tif (!pid)\n 526:\t\t\treturn;\n 527:\t\n 528:\t\tif (type == PIDTYPE_PID)\n 529:\t\t\tflags |= PIDFD_THREAD;\n 530:\t\n 531:\t\tpidfd = pidfd_prepare(pid, flags, \u0026pidfd_file);\n 532:\t\n 533:\t\tif (put_cmsg(msg, SOL_SOCKET, cmsg_type, sizeof(int), \u0026pidfd)) {\n 534:\t\t\tif (pidfd_file) {\n 535:\t\t\t\tput_unused_fd(pidfd);\n 536:\t\t\t\tfput(pidfd_file);\n 537:\t\t\t}\n 538:\t\n 539:\t\t\treturn;\n 540:\t\t}\n 541:\t\n 542:\t\tif (pidfd_file)\n 543:\t\t\tfd_install(pidfd, pidfd_file);\n 544:\t}\n 545:\t\n 546:\tstatic bool __scm_recv_common(struct sock *sk, struct msghdr *msg,\n 547:\t\t\t\t      struct scm_cookie *scm, int flags)\n 548:\t{\n 549:\t\tif (!msg-\u003emsg_control) {\n"
}

87/3 2026/09/29 11:08 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 62687
							output: 37
							thoughts: 322
						

Thoughts:
**Analyzing Potential PID Leak in Bluetooth Socket Allocation**

Okay, here we go. Line 542 has caught my eye: `if (pidfd_file) fd_install(pidfd, pidfd_file);`. Seems straightforward, but let's dig a little deeper. My initial concern stems from potentially related fields, specifically around process identifiers. I need to understand how these PID's are handled, especially since we're dealing with socket creation.

Let's start with `sock_init_data_uid`. I see `sk->sk_peer_pid` is being zeroed out using `memset`. That's good defensive programming – ensuring no stale data leaks into this field. But what about the *rest* of the code?

Now, the `bt_sock_alloc` function. The code has been updated: instead of simply assigning `sk->sk_peer_pid`, it is now assigning the TGID to `sk->sk_peer_pid[PIDTYPE_TGID]`. But what about `sk->sk_peer_pid[PIDTYPE_PID]`? Is that initialized properly or is there a vulnerability? And doesn't `bt_sock_alloc` call `sk_alloc` which allocates with kzalloc or zeroes fields?

I'm starting to get a picture, but to be sure I must check the allocation flow. Specifically, I need to see if `bt_sock_alloc` calls `sock_init_data`, as that would be crucial for understanding how the entire structure is initialized. This is a critical area, potentially related to a PID leak. I need to fully understand how the `sk->sk_peer_pid` array is populated throughout the socket lifecycle. I'll head over to `net/bluetooth/af_bluetooth.c` and start reviewing lines 140-180 to see how it works.



88/3 2026/09/29 11:08 tool read-file
0m Args:
{
  "File": "net/bluetooth/af_bluetooth.c",
  "FirstLine": 140,
  "LineCount": 45
}

Results:
{
  "Contents": " 140:\t\treturn err;\n 141:\t}\n 142:\t\n 143:\tstruct sock *bt_sock_alloc(struct net *net, struct socket *sock,\n 144:\t\t\t\t   struct proto *prot, int proto, gfp_t prio, int kern)\n 145:\t{\n 146:\t\tstruct sock *sk;\n 147:\t\n 148:\t\tsk = sk_alloc(net, PF_BLUETOOTH, prio, prot, kern);\n 149:\t\tif (!sk)\n 150:\t\t\treturn NULL;\n 151:\t\n 152:\t\tsock_init_data(sock, sk);\n 153:\t\tINIT_LIST_HEAD(\u0026bt_sk(sk)-\u003eaccept_q);\n 154:\t\tspin_lock_init(\u0026bt_sk(sk)-\u003eaccept_q_lock);\n 155:\t\n 156:\t\tsock_reset_flag(sk, SOCK_ZAPPED);\n 157:\t\n 158:\t\tsk-\u003esk_protocol = proto;\n 159:\t\tsk-\u003esk_state    = BT_OPEN;\n 160:\t\n 161:\t\t/* Init peer information so it can be properly monitored */\n 162:\t\tif (!kern) {\n 163:\t\t\tspin_lock(\u0026sk-\u003esk_peer_lock);\n 164:\t\t\tsk-\u003esk_peer_pid[PIDTYPE_TGID]  = get_pid(task_tgid(current));\n 165:\t\t\tsk-\u003esk_peer_cred = get_current_cred();\n 166:\t\t\tspin_unlock(\u0026sk-\u003esk_peer_lock);\n 167:\t\t}\n 168:\t\n 169:\t\treturn sk;\n 170:\t}\n 171:\tEXPORT_SYMBOL(bt_sock_alloc);\n 172:\t\n 173:\tvoid bt_sock_link(struct bt_sock_list *l, struct sock *sk)\n 174:\t{\n 175:\t\twrite_lock(\u0026l-\u003elock);\n 176:\t\tsk_add_node(sk, \u0026l-\u003ehead);\n 177:\t\twrite_unlock(\u0026l-\u003elock);\n 178:\t}\n 179:\tEXPORT_SYMBOL(bt_sock_link);\n 180:\t\n 181:\tvoid bt_sock_unlink(struct bt_sock_list *l, struct sock *sk)\n 182:\t{\n 183:\t\twrite_lock(\u0026l-\u003elock);\n 184:\t\tsk_del_node_init(sk);\n"
}

89/3 2026/09/29 11:08 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 64123
							output: 18
							thoughts: 665
						

Thoughts:
**Bluetooth Socket Peer PID/TGID Handling**

Okay, so I'm looking at how peer PIDs are handled in Bluetooth sockets, and I've traced the initialization and use of `sk->sk_peer_pid`. It seems like `bt_sock_alloc` sets up the initial socket data by calling a chain of functions, leading to `memset(sk->sk_peer_pid, 0, sizeof(sk->sk_peer_pid))`. This zeros out both `PIDTYPE_PID` and `PIDTYPE_TGID` within `sk->sk_peer_pid`. Then, later, `sk->sk_peer_pid[PIDTYPE_TGID]` gets populated with the TGID, leaving the PID entry as NULL.

When a connection is accepted in `bt_accept_enqueue`, the TGID PID is copied from the parent socket, but the original PID entry remains untouched as NULL.

Now, here's where it gets interesting. I thought about the `getsockopt` calls, specifically when dealing with `SO_PEERPIDFD_THREAD`. If you try to use `SO_PEERPIDFD_THREAD` for a non-AF_UNIX socket (like Bluetooth), it returns `-EOPNOTSUPP`. That's expected.

However, the more relevant case is `SO_PEERPIDFD`. For Bluetooth, this uses `sk_getsockopt_peerpidfd` and specifies `PIDTYPE_TGID`. This function retrieves the peer PID by doing a `get_pid(sk->sk_peer_pid[type])` where the type is `PIDTYPE_TGID`. So far, so good – we are retrieving the TGID, which was previously populated. But, importantly, if `peer_pid` is NULL, it returns `-ENODATA`. That makes sense given that it was initially set to NULL.

I also looked at how `unix_peercred` is used in `net/unix/af_unix.c`. This structure uses a `DECLARE_PIDS(peer_pid, PIDTYPE_TGID)`. So I'm seeing a pattern, the TGID is the primary identifier. The PID is never populated for Bluetooth sockets.

This explains the behavior: the PID is always NULL on Bluetooth sockets, while the TGID contains the process group. Attempting to get the PID will correctly yield `-ENODATA` because, by design, the PID entry is never populated in this specific context. The code reflects this explicitly, preventing access to a non-existent PID, and focusing on the TGID for peer identification.



90/3 2026/09/29 11:08 tool grepper
0m Args:
{
  "Expression": "unix_peercred"
}

Results:
{
  "Output": "net/unix/af_unix.c=665=static void unix_release_sock(struct sock *sk, int embrion)\n--\nnet/unix/af_unix.c-738-\nnet/unix/af_unix.c:739:struct unix_peercred {\nnet/unix/af_unix.c-740-\tDECLARE_PIDS(peer_pid, PIDTYPE_TGID);\n--\nnet/unix/af_unix.c-743-\nnet/unix/af_unix.c:744:static inline int prepare_peercred(struct unix_peercred *peercred)\nnet/unix/af_unix.c-745-{\n--\nnet/unix/af_unix.c-758-\nnet/unix/af_unix.c:759:static void drop_peercred(struct unix_peercred *peercred)\nnet/unix/af_unix.c-760-{\n--\nnet/unix/af_unix.c=770=static inline void init_peercred(struct sock *sk,\nnet/unix/af_unix.c:771:\t\t\t\t const struct unix_peercred *peercred)\nnet/unix/af_unix.c-772-{\n--\nnet/unix/af_unix.c-776-\nnet/unix/af_unix.c:777:static void update_peercred(struct sock *sk, struct unix_peercred *peercred)\nnet/unix/af_unix.c-778-{\n--\nnet/unix/af_unix.c=806=static int unix_listen(struct socket *sock, int backlog)\n--\nnet/unix/af_unix.c-810-\tstruct unix_sock *u = unix_sk(sk);\nnet/unix/af_unix.c:811:\tstruct unix_peercred peercred = {};\nnet/unix/af_unix.c-812-\n--\nnet/unix/af_unix.c=1632=static int unix_stream_connect(struct socket *sock, struct sockaddr_unsized *uaddr,\n--\nnet/unix/af_unix.c-1637-\tstruct unix_sock *u = unix_sk(sk), *newu, *otheru;\nnet/unix/af_unix.c:1638:\tstruct unix_peercred peercred = {};\nnet/unix/af_unix.c-1639-\tstruct net *net = sock_net(sk);\n--\nnet/unix/af_unix.c=1812=static int unix_socketpair(struct socket *socka, struct socket *sockb)\nnet/unix/af_unix.c-1813-{\nnet/unix/af_unix.c:1814:\tstruct unix_peercred ska_peercred = {}, skb_peercred = {};\nnet/unix/af_unix.c-1815-\tstruct sock *ska = socka-\u003esk, *skb = sockb-\u003esk;\n"
}

91/3 2026/09/29 11:08 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 66096
							output: 20
							thoughts: 2863
						

Thoughts:
**Analysis of Potential Uninitialized Memory in Peer Credential Handling and PIDFD Operations**

Okay, let's break this down. The initial focus is on `struct unix_peercred` instances, and how they're initialized with `= {}`. The `prepare_peercred` function, after obtaining the PIDs, retrieves the current credential. This seems straightforward. The subsequent dive into `pidfs.c` and `pidfs_coredump` is where things get interesting. The core concern is about the potential for `cprm->pid[type]` to be NULL.

The call chain of `pidfs_coredump` reveals that it's called from `fs/coredump.c` only when the core pattern includes `%P`, and `task_pids(cprm->pid, current)` sets the PIDs for both `PIDTYPE_PID` and `PIDTYPE_TGID`. If `%P` isn't present, the TGID is NULL, and `pidfs_coredump` is skipped. This is good. Then the check `if (cp->pid[PIDTYPE_TGID])` would be false. So, unless `%P` is present, it's not called, and thus, `cprm->pid` (which is an array of `struct pid *`) are initialized, so there is no dereference of NULL. Also, if there was a dereference of NULL, KASAN would detect this, not KMSAN.

The `Landlock` check clarifies that the code now reads from `peer->sk_peer_pid[PIDTYPE_TGID]`, which is more specific.

The investigation into `SCM_PIDFD` and `SCM_PIDFD_THREAD` control messages, through `scm_pidfd_recv` and `sk_getsockopt_peerpidfd`, focuses on the `pidfd` variable. In both functions, `pidfd` is initialized with the return value of `pidfd_prepare`, and its value is then copied. `put_cmsg` copies `sizeof(int)` bytes, and `copy_to_sockptr` copies up to `len` bytes, so no uninitialized values should be exposed. There is a check of length in both cases, which means we can avoid overflows. The `SO_PASSPIDFD_THREAD` path in `sk_getsockopt` directly assigns a bitfield value (0 or 1) and then copies the value.

The analysis concludes by examining the `struct sock` definition to verify the bitfield arrangement. Finally, the bitfield variables `sk_scm_*` are initialized in all relevant places, so there should be no uninitialized memory accessed.



92/3 2026/09/29 11:09 tool grepper
0m Args:
{
  "Expression": "sk_scm_pidfd"
}

Results:
{
  "Output": "include/net/sock.h=242=struct sk_filter;\n--\ninclude/net/sock.h-356-  *\t@sk_scm_security: flagged by SO_PASSSEC to recv SCM_SECURITY\ninclude/net/sock.h:357:  *\t@sk_scm_pidfd: flagged by SO_PASSPIDFD to recv SCM_PIDFD\ninclude/net/sock.h-358-  *\t@sk_scm_rights: flagged by SO_PASSRIGHTS to recv SCM_RIGHTS\ninclude/net/sock.h:359:  *\t@sk_scm_pidfd_thread: flagged by SO_PASSPIDFD_THREAD to recv a thread SCM_PIDFD\ninclude/net/sock.h-360-  *\t@sk_scm_unused: unused flags for scm_recv()\n--\ninclude/net/sock.h=366=struct sock {\n--\ninclude/net/sock.h-563-\t\t\t\tsk_scm_security : 1,\ninclude/net/sock.h:564:\t\t\t\tsk_scm_pidfd : 1,\ninclude/net/sock.h-565-\t\t\t\tsk_scm_rights : 1,\ninclude/net/sock.h:566:\t\t\t\tsk_scm_pidfd_thread : 1,\ninclude/net/sock.h-567-\t\t\t\tsk_scm_unused : 3;\n--\ninclude/net/sock.h=2988=static inline bool sk_is_stream_unix(const struct sock *sk)\n--\ninclude/net/sock.h-2992-\ninclude/net/sock.h:2993:static inline bool sk_scm_pidfd_wanted(const struct sock *sk)\ninclude/net/sock.h-2994-{\ninclude/net/sock.h:2995:\treturn sk-\u003esk_scm_pidfd;\ninclude/net/sock.h-2996-}\ninclude/net/sock.h-2997-\ninclude/net/sock.h:2998:static inline bool sk_scm_pidfd_thread_wanted(const struct sock *sk)\ninclude/net/sock.h-2999-{\ninclude/net/sock.h:3000:\treturn sk-\u003esk_scm_pidfd_thread;\ninclude/net/sock.h-3001-}\n--\nnet/core/scm.c=546=static bool __scm_recv_common(struct sock *sk, struct msghdr *msg,\n--\nnet/core/scm.c-549-\tif (!msg-\u003emsg_control) {\nnet/core/scm.c:550:\t\tif (sk-\u003esk_scm_credentials || sk_scm_pidfd_wanted(sk) ||\nnet/core/scm.c:551:\t\t    sk_scm_pidfd_thread_wanted(sk) || scm-\u003efp || scm_has_secdata(sk))\nnet/core/scm.c-552-\t\t\tmsg-\u003emsg_flags |= MSG_CTRUNC;\n--\nnet/core/scm.c=584=void scm_recv_unix(struct socket *sock, struct msghdr *msg,\n--\nnet/core/scm.c-596-\nnet/core/scm.c:597:\tif (sk_scm_pidfd_wanted(sock-\u003esk))\nnet/core/scm.c-598-\t\tscm_pidfd_recv(msg, scm, PIDTYPE_TGID, SCM_PIDFD);\nnet/core/scm.c-599-\nnet/core/scm.c:600:\tif (sk_scm_pidfd_thread_wanted(sock-\u003esk))\nnet/core/scm.c-601-\t\tscm_pidfd_recv(msg, scm, PIDTYPE_PID, SCM_PIDFD_THREAD);\n--\nnet/core/sock.c=1195=int sk_setsockopt(struct sock *sk, int level, int optname,\n--\nnet/core/sock.c-1575-\t\tif (sk_is_unix(sk))\nnet/core/sock.c:1576:\t\t\tsk-\u003esk_scm_pidfd = valbool;\nnet/core/sock.c-1577-\t\telse\n--\nnet/core/sock.c-1582-\t\tif (sk_is_unix(sk))\nnet/core/sock.c:1583:\t\t\tsk-\u003esk_scm_pidfd_thread = valbool;\nnet/core/sock.c-1584-\t\telse\n--\nnet/core/sock.c=1783=int sk_getsockopt(struct sock *sk, int level, int optname,\n--\nnet/core/sock.c-1943-\nnet/core/sock.c:1944:\t\tv.val = sk-\u003esk_scm_pidfd;\nnet/core/sock.c-1945-\t\tbreak;\n--\nnet/core/sock.c-1950-\nnet/core/sock.c:1951:\t\tv.val = sk-\u003esk_scm_pidfd_thread;\nnet/core/sock.c-1952-\t\tbreak;\n--\nnet/unix/af_unix.c=800=static bool unix_may_passcred(const struct sock *sk)\nnet/unix/af_unix.c-801-{\nnet/unix/af_unix.c:802:\treturn sk-\u003esk_scm_credentials || sk_scm_pidfd_wanted(sk) ||\nnet/unix/af_unix.c:803:\t\tsk_scm_pidfd_thread_wanted(sk);\nnet/unix/af_unix.c-804-}\n--\nnet/unix/af_unix.c=2049=static bool unix_skb_scm_eq(const struct sock *sk, struct sk_buff *skb,\n--\nnet/unix/af_unix.c-2052-\t/* Only a thread pidfd receiver can tell threads of one process apart. */\nnet/unix/af_unix.c:2053:\tif (sk-\u003esk_scm_pidfd_thread \u0026\u0026\nnet/unix/af_unix.c-2054-\t    UNIXCB(skb).pid[PIDTYPE_PID] != scm-\u003epid[PIDTYPE_PID])\n"
}

93/3 2026/09/29 11:09 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 71126
							output: 36
							thoughts: 52
						

Thoughts:
Here's my analysis of the provided snippet, tailored for an expert like yourself:

**Diving into `sock_init_data_uid` in net/core/sock.c**

Alright, let's break this down. The code indicates we're focusing on the `sock_init_data_uid` function. Given the naming convention and its context within `net/core/sock.c`, my initial assumption is that this routine handles the initialization or configuration of user ID related data structures within the socket data. I'll need to confirm, though, by looking at its implementation.

My instinct is to check around lines 3780-3840 in `net/core/sock.c` - a quick grep would likely confirm that. This range probably contains the core logic for setting up UID-specific socket attributes. I'm expecting to see how user identity, perhaps effective UID or the security credentials, are handled during socket creation or initialization. It could be mapping the socket to a specific user context or setting permissions. I'll need to look for calls to security modules as well as references to `cred` or `uid` to confirm that it's dealing with user-related data.



94/3 2026/09/29 11:09 tool read-file
0m Args:
{
  "File": "net/core/sock.c",
  "FirstLine": 3780,
  "LineCount": 50
}

Results:
{
  "Contents": "3780:\t\n3781:\tvoid sock_init_data_uid(struct socket *sock, struct sock *sk, kuid_t uid)\n3782:\t{\n3783:\t\tsk_init_common(sk);\n3784:\t\tsk-\u003esk_send_head\t=\tNULL;\n3785:\t\n3786:\t\ttimer_setup(\u0026sk-\u003esk_timer, NULL, 0);\n3787:\t\n3788:\t\tsk-\u003esk_allocation\t=\tGFP_KERNEL;\n3789:\t\tsk-\u003esk_rcvbuf\t\t=\tREAD_ONCE(sysctl_rmem_default);\n3790:\t\tsk-\u003esk_sndbuf\t\t=\tREAD_ONCE(sysctl_wmem_default);\n3791:\t\tsk-\u003esk_state\t\t=\tTCP_CLOSE;\n3792:\t\tsk-\u003esk_use_task_frag\t=\ttrue;\n3793:\t\tsk_set_socket(sk, sock);\n3794:\t\n3795:\t\tsock_set_flag(sk, SOCK_ZAPPED);\n3796:\t\n3797:\t\tif (sock) {\n3798:\t\t\tsk-\u003esk_type\t=\tsock-\u003etype;\n3799:\t\t\tRCU_INIT_POINTER(sk-\u003esk_wq, \u0026sock-\u003ewq);\n3800:\t\t\tsock-\u003esk\t=\tsk;\n3801:\t\t} else {\n3802:\t\t\tRCU_INIT_POINTER(sk-\u003esk_wq, NULL);\n3803:\t\t}\n3804:\t\tsk-\u003esk_uid\t=\tuid;\n3805:\t\n3806:\t\tsk-\u003esk_state_change\t=\tsock_def_wakeup;\n3807:\t\tsk-\u003esk_data_ready\t=\tsock_def_readable;\n3808:\t\tsk-\u003esk_write_space\t=\tsock_def_write_space;\n3809:\t\tsk-\u003esk_error_report\t=\tsock_def_error_report;\n3810:\t\tsk-\u003esk_destruct\t\t=\tsock_def_destruct;\n3811:\t\n3812:\t\tsk-\u003esk_frag.page\t=\tNULL;\n3813:\t\tsk-\u003esk_frag.offset\t=\t0;\n3814:\t\tsk-\u003esk_peek_off\t\t=\t-1;\n3815:\t\n3816:\t\tmemset(sk-\u003esk_peer_pid, 0, sizeof(sk-\u003esk_peer_pid));\n3817:\t\tsk-\u003esk_peer_cred\t=\tNULL;\n3818:\t\tspin_lock_init(\u0026sk-\u003esk_peer_lock);\n3819:\t\n3820:\t\tsk-\u003esk_write_pending\t=\t0;\n3821:\t\tsk-\u003esk_rcvlowat\t\t=\t1;\n3822:\t\tsk-\u003esk_rcvtimeo\t\t=\tMAX_SCHEDULE_TIMEOUT;\n3823:\t\tsk-\u003esk_sndtimeo\t\t=\tMAX_SCHEDULE_TIMEOUT;\n3824:\t\n3825:\t\tsk-\u003esk_stamp = SK_DEFAULT_STAMP;\n3826:\t#if BITS_PER_LONG==32\n3827:\t\tseqlock_init(\u0026sk-\u003esk_stamp_seq);\n3828:\t#endif\n3829:\t\tatomic_set(\u0026sk-\u003esk_zckey, 0);\n"
}

95/3 2026/09/29 11:09 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 72356
							output: 31
							thoughts: 41
						

Thoughts:
Okay, here's my take on those thoughts, framed as a first-person expert summary:

**Digging into Socket Allocation**

Alright, so I need to understand this socket allocation process. The text mentions `sk_alloc` and how it's implemented using either `kmem_cache_alloc` with zeroing, or a `memset`. That's a key detail – it tells me about the fundamental memory allocation strategy used for new sockets, and whether we're seeing initialization through zeroing the memory or if something else is going on. I immediately want to confirm this by taking a look at `net/core/sock.c`. I need to verify how `sk_alloc` is truly being used, and which mechanism is being used for initialization and zeroing, to understand its potential performance impact. I want to see if this affects the initialization of various members within the `sock` structure, which could have performance implications if it occurs in a hot path. And that file, `net/core/sock.c`, is the logical place to start. Let's see what's really happening.



96/3 2026/09/29 11:09 tool grepper
0m Args:
{
  "Expression": "sk_alloc\\(",
  "PathPrefix": "net/core/sock.c"
}

Results:
{
  "Output": "net/core/sock.c=2266=static struct sock *sk_prot_alloc(struct proto *prot, gfp_t priority,\n--\nnet/core/sock.c-2282-\tif (sk != NULL) {\nnet/core/sock.c:2283:\t\tif (security_sk_alloc(sk, family, priority))\nnet/core/sock.c-2284-\t\t\tgoto out_free;\n--\nnet/core/sock.c=2302=static void sk_prot_free(struct proto *prot, struct sock *sk)\n--\nnet/core/sock.c-2330- */\nnet/core/sock.c:2331:struct sock *sk_alloc(struct net *net, int family, gfp_t priority,\nnet/core/sock.c-2332-\t\t      struct proto *prot, int kern)\n--\nnet/core/sock.c-2363-\nnet/core/sock.c:2364:\t\tmem_cgroup_sk_alloc(sk);\nnet/core/sock.c:2365:\t\tcgroup_sk_alloc(\u0026sk-\u003esk_cgrp_data);\nnet/core/sock.c-2366-\t\tsock_update_classid(\u0026sk-\u003esk_cgrp_data);\n"
}

97/3 2026/09/29 11:09 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 72994
							output: 36
							thoughts: 11
						

Thoughts:
Okay, here's my take on those thoughts, tailored for an expert audience, and written as if they were my own:

**Initial Check on sk_prot_alloc**

Alright, time to get to it. Let's see... the `sk_prot_alloc` function. *That's* where we're allocating the socket protocol control block. Crucial function, obviously. Gotta make sure it's behaving as expected. Need to confirm a few key aspects, like the allocation size, the appropriate flags being passed, memory alignment, and that the return value is non-NULL under normal operation. Then let's consider the unusual cases, what sort of errors might arise and whether those have been handled. I want to quickly refresh my memory on the edge cases, and confirm whether any recent changes in the codebase have impacted this vital piece of code. I really do need to make sure we don't have some subtle memory corruption issue waiting to bite us later. This function is the foundation for subsequent operations.



98/3 2026/09/29 11:09 tool read-file
0m Args:
{
  "File": "net/core/sock.c",
  "FirstLine": 2266,
  "LineCount": 25
}

Results:
{
  "Contents": "2266:\tstatic struct sock *sk_prot_alloc(struct proto *prot, gfp_t priority,\n2267:\t\t\tint family)\n2268:\t{\n2269:\t\tstruct sock *sk;\n2270:\t\tstruct kmem_cache *slab;\n2271:\t\n2272:\t\tslab = prot-\u003eslab;\n2273:\t\tif (slab != NULL) {\n2274:\t\t\tsk = kmem_cache_alloc(slab, priority \u0026 ~__GFP_ZERO);\n2275:\t\t\tif (!sk)\n2276:\t\t\t\treturn sk;\n2277:\t\t\tif (want_init_on_alloc(priority))\n2278:\t\t\t\tsk_prot_clear_nulls(sk, prot-\u003eobj_size);\n2279:\t\t} else\n2280:\t\t\tsk = kmalloc(prot-\u003eobj_size, priority);\n2281:\t\n2282:\t\tif (sk != NULL) {\n2283:\t\t\tif (security_sk_alloc(sk, family, priority))\n2284:\t\t\t\tgoto out_free;\n2285:\t\n2286:\t\t\tif (!try_module_get(prot-\u003eowner))\n2287:\t\t\t\tgoto out_free_sec;\n2288:\t\t}\n2289:\t\n2290:\t\treturn sk;\n"
}

99/3 2026/09/29 11:09 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 73611
							output: 19
							thoughts: 33
						

Thoughts:
Okay, let's see. My mind's immediately drawn to the initialization sequence here. **Tracking Down the Initialization Point.** My first thought is: I need to pinpoint where, precisely, the struct in question is being initialized. Specifically, I'm thinking about the connection between `sk_init_common` and `prot_slab`. Are *either* of those the responsible party? It's a fundamental question. Right, so the logical next step is to dive into the code for `sk_init_common`. That function's behavior holds the key. Let's see what we can find. I'm going to start there and see what it tells us.



100/3 2026/09/29 11:09 tool grepper
0m Args:
{
  "Expression": "sk_init_common"
}

Results:
{
  "Output": "net/core/sock.c=2471=EXPORT_SYMBOL(sk_free);\nnet/core/sock.c-2472-\nnet/core/sock.c:2473:static void sk_init_common(struct sock *sk)\nnet/core/sock.c-2474-{\n--\nnet/core/sock.c=2508=struct sock *sk_clone(const struct sock *sk, const gfp_t priority,\n--\nnet/core/sock.c-2558-\tatomic_set(\u0026newsk-\u003esk_omem_alloc, 0);\nnet/core/sock.c:2559:\tsk_init_common(newsk);\nnet/core/sock.c-2560-\n--\nnet/core/sock.c=3781=void sock_init_data_uid(struct socket *sock, struct sock *sk, kuid_t uid)\nnet/core/sock.c-3782-{\nnet/core/sock.c:3783:\tsk_init_common(sk);\nnet/core/sock.c-3784-\tsk-\u003esk_send_head\t=\tNULL;\n"
}

101/3 2026/09/29 11:09 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 74105
							output: 36
							thoughts: 32
						

Thoughts:
Here's my take on those lines of `net/core/sock.c`, given my expertise:

**Diving into `sk_init_common` in `net/core/sock.c`**

Alright, let's zero in on those critical initialization routines within the kernel's socket core. My mind automatically jumps to `net/core/sock.c`, and specifically lines 2470-2500, focusing on `sk_init_common`. I know this is where the *really* foundational stuff happens for a new socket. I'm expecting to see the setting of core data structures, initial flags, and perhaps some essential checks or allocations. I want to pay attention to how they handle the common initialization of the `sock` structure, ensuring all the necessary fields are set to a sane initial state before more specific protocol initialization kicks in. We'll examine how the sock structure gets linked into various lists and what locking primitives are used to protect concurrent access. I'll be looking for any potential race conditions or areas where a design choice might impact scalability or performance under high load. I'm also curious about what optimizations or potential future-proofing considerations are made here. This is the bedrock; if this isn't solid, everything built on it is suspect.



102/3 2026/09/29 11:09 tool read-file
0m Args:
{
  "File": "net/core/sock.c",
  "FirstLine": 2470,
  "LineCount": 35
}

Results:
{
  "Contents": "2470:\t}\n2471:\tEXPORT_SYMBOL(sk_free);\n2472:\t\n2473:\tstatic void sk_init_common(struct sock *sk)\n2474:\t{\n2475:\t\tskb_queue_head_init(\u0026sk-\u003esk_receive_queue);\n2476:\t\tskb_queue_head_init(\u0026sk-\u003esk_write_queue);\n2477:\t\tskb_queue_head_init(\u0026sk-\u003esk_error_queue);\n2478:\t\n2479:\t\trwlock_init(\u0026sk-\u003esk_callback_lock);\n2480:\t\tlockdep_set_class_and_name(\u0026sk-\u003esk_receive_queue.lock,\n2481:\t\t\t\taf_rlock_keys + sk-\u003esk_family,\n2482:\t\t\t\taf_family_rlock_key_strings[sk-\u003esk_family]);\n2483:\t\tlockdep_set_class_and_name(\u0026sk-\u003esk_write_queue.lock,\n2484:\t\t\t\taf_wlock_keys + sk-\u003esk_family,\n2485:\t\t\t\taf_family_wlock_key_strings[sk-\u003esk_family]);\n2486:\t\tlockdep_set_class_and_name(\u0026sk-\u003esk_error_queue.lock,\n2487:\t\t\t\taf_elock_keys + sk-\u003esk_family,\n2488:\t\t\t\taf_family_elock_key_strings[sk-\u003esk_family]);\n2489:\t\tif (sk-\u003esk_kern_sock)\n2490:\t\t\tlockdep_set_class_and_name(\u0026sk-\u003esk_callback_lock,\n2491:\t\t\t\taf_kern_callback_keys + sk-\u003esk_family,\n2492:\t\t\t\taf_family_kern_clock_key_strings[sk-\u003esk_family]);\n2493:\t\telse\n2494:\t\t\tlockdep_set_class_and_name(\u0026sk-\u003esk_callback_lock,\n2495:\t\t\t\taf_callback_keys + sk-\u003esk_family,\n2496:\t\t\t\taf_family_clock_key_strings[sk-\u003esk_family]);\n2497:\t}\n2498:\t\n2499:\t/**\n2500:\t * sk_clone - clone a socket\n2501:\t * @sk: the socket to clone\n2502:\t * @priority: for allocation (%GFP_KERNEL, %GFP_ATOMIC, etc)\n2503:\t * @lock: if true, lock the cloned sk\n2504:\t *\n"
}

103/3 2026/09/29 11:09 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 75099
							output: 19
							thoughts: 48
						

Thoughts:
Okay, let me quickly summarize this train of thought for you.

**Tracking Down a Socket Control Message Initialization**

Alright, I'm trying to figure out where the `sk_scm_*` variables are initialized, probably in the context of some socket handling. My initial thought is to check `net/core/sock.c` since that's where a lot of the fundamental socket-level structures and operations reside. Specifically, I'm going to search for either `sk_scm_rights` or `sk_scm_unused` within that file. Those seem like good starting points to understand how those particular SCM (Socket Control Message) related members of the `sock` structure are handled at boot. That should give me the initial call stack.



104/3 2026/09/29 11:09 tool grepper
0m Args:
{
  "Expression": "sk_scm_rights"
}

Results:
{
  "Output": "include/net/sock.h=242=struct sk_filter;\n--\ninclude/net/sock.h-357-  *\t@sk_scm_pidfd: flagged by SO_PASSPIDFD to recv SCM_PIDFD\ninclude/net/sock.h:358:  *\t@sk_scm_rights: flagged by SO_PASSRIGHTS to recv SCM_RIGHTS\ninclude/net/sock.h-359-  *\t@sk_scm_pidfd_thread: flagged by SO_PASSPIDFD_THREAD to recv a thread SCM_PIDFD\n--\ninclude/net/sock.h=366=struct sock {\n--\ninclude/net/sock.h-564-\t\t\t\tsk_scm_pidfd : 1,\ninclude/net/sock.h:565:\t\t\t\tsk_scm_rights : 1,\ninclude/net/sock.h-566-\t\t\t\tsk_scm_pidfd_thread : 1,\n--\nnet/core/sock.c=1195=int sk_setsockopt(struct sock *sk, int level, int optname,\n--\nnet/core/sock.c-1589-\t\tif (sk_is_unix(sk))\nnet/core/sock.c:1590:\t\t\tsk-\u003esk_scm_rights = valbool;\nnet/core/sock.c-1591-\t\telse\n--\nnet/core/sock.c=1783=int sk_getsockopt(struct sock *sk, int level, int optname,\n--\nnet/core/sock.c-1957-\nnet/core/sock.c:1958:\t\tv.val = sk-\u003esk_scm_rights;\nnet/core/sock.c-1959-\t\tbreak;\n--\nnet/unix/af_unix.c=1092=static struct sock *unix_create1(struct net *net, struct socket *sock, int kern, int type)\n--\nnet/unix/af_unix.c-1115-\nnet/unix/af_unix.c:1116:\tsk-\u003esk_scm_rights\t= 1;\nnet/unix/af_unix.c-1117-\tsk-\u003esk_hash\t\t= unix_unbound_hash(sk);\n--\nnet/unix/af_unix.c=2096=static int unix_dgram_sendmsg(struct socket *sock, struct msghdr *msg,\n--\nnet/unix/af_unix.c-2250-\nnet/unix/af_unix.c:2251:\tif (UNIXCB(skb).fp \u0026\u0026 !other-\u003esk_scm_rights) {\nnet/unix/af_unix.c-2252-\t\terr = -EPERM;\n--\nnet/unix/af_unix.c=2330=static int queue_oob(struct sock *sk, struct msghdr *msg, struct sock *other,\n--\nnet/unix/af_unix.c-2363-\nnet/unix/af_unix.c:2364:\tif (UNIXCB(skb).fp \u0026\u0026 !other-\u003esk_scm_rights) {\nnet/unix/af_unix.c-2365-\t\terr = -EPERM;\n--\nnet/unix/af_unix.c=2390=static int unix_stream_sendmsg(struct socket *sock, struct msghdr *msg,\n--\nnet/unix/af_unix.c-2490-\nnet/unix/af_unix.c:2491:\t\tif (UNIXCB(skb).fp \u0026\u0026 !other-\u003esk_scm_rights) {\nnet/unix/af_unix.c-2492-\t\t\tunix_state_unlock(other);\n"
}

105/3 2026/09/29 11:09 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 76254
							output: 33
							thoughts: 102
						

Thoughts:
Okay, here's my thought process as I'm analyzing this code snippet:

**Investigating Potential Uninitialized Memory in Socket Creation**

Hold on a second... I'm looking at `sk_create` or `sk_alloc`, and something's bugging me. Where, exactly, is this `sk` structure *guaranteed* to be zeroed? I need to be absolutely certain. My mind immediately jumps to `sk_prot_alloc`. Let's dig in. Okay, here we are: `sk = kmem_cache_alloc(slab, priority & ~__GFP_ZERO);`. Ah, *kmem_cache_alloc*. This is the key. But wait a minute... that `& ~__GFP_ZERO` bit... that means it *might not* be zeroed!

Okay, new question. Is this `slab` itself created such that it is zeroed, or does it have the `SLAB_TYPESAFE_BY_RCU` flag? If it's typesafe, zeroing might be avoided. The function `kmem_cache_create` is called as part of registration, so I need to find out *how* this `slab` is being created. Time to check `proto_register`... let's see how `prot->slab` is initialized! I'll see where `kmem_cache_create` is called with that `slab` and what flags are passed to determine if this socket's memory is properly initialized or not.



106/3 2026/09/29 11:09 tool grepper
0m Args:
{
  "Expression": "kmem_cache_create",
  "PathPrefix": "net/core/sock.c"
}

Results:
{
  "Output": "net/core/sock.c=4227=static int tw_prot_init(const struct proto *prot)\n--\nnet/core/sock.c-4239-\ttwsk_prot-\u003etwsk_slab =\nnet/core/sock.c:4240:\t\tkmem_cache_create(twsk_prot-\u003etwsk_slab_name,\nnet/core/sock.c-4241-\t\t\t\t  twsk_prot-\u003etwsk_obj_size, 0,\n--\nnet/core/sock.c=4263=static int req_prot_init(const struct proto *prot)\n--\nnet/core/sock.c-4274-\nnet/core/sock.c:4275:\trsk_prot-\u003eslab = kmem_cache_create(rsk_prot-\u003eslab_name,\nnet/core/sock.c-4276-\t\t\t\t\t   rsk_prot-\u003eobj_size, 0,\n--\nnet/core/sock.c=4288=int proto_register(struct proto *prot, int alloc_slab)\n--\nnet/core/sock.c-4307-\nnet/core/sock.c:4308:\t\tprot-\u003eslab = kmem_cache_create(prot-\u003ename, prot-\u003eobj_size,\nnet/core/sock.c-4309-\t\t\t\t\t\u0026args,\n"
}

107/3 2026/09/29 11:09 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 77055
							output: 38
							thoughts: 32
						

Thoughts:
Okay, let's dive in.

**Unix Socket Allocation: Let's Trace it Back**

Right, so I need to understand how these Unix sockets are allocated internally. My first instinct, as always, is to head directly into the heart of the matter. Let's see... the `net/unix/af_unix.c` file feels like the logical starting point. I want to see how the kernel handles the creation and management of these sockets, specifically the allocation process. I'm expecting some kind of `alloc` or `create` function, something central to the socket's lifecycle. Let's get right down to it and see if `unix_create1` is the magic function I'm looking for... I'm pretty sure that this is where the action starts.



108/3 2026/09/29 11:09 tool read-file
0m Args:
{
  "File": "net/unix/af_unix.c",
  "FirstLine": 1090,
  "LineCount": 40
}

Results:
{
  "Contents": "1090:\t};\n1091:\t\n1092:\tstatic struct sock *unix_create1(struct net *net, struct socket *sock, int kern, int type)\n1093:\t{\n1094:\t\tstruct unix_sock *u;\n1095:\t\tstruct sock *sk;\n1096:\t\tint err;\n1097:\t\n1098:\t\tatomic_long_inc(\u0026unix_nr_socks);\n1099:\t\tif (atomic_long_read(\u0026unix_nr_socks) \u003e 2 * get_max_files()) {\n1100:\t\t\terr = -ENFILE;\n1101:\t\t\tgoto err;\n1102:\t\t}\n1103:\t\n1104:\t\tif (type == SOCK_STREAM)\n1105:\t\t\tsk = sk_alloc(net, PF_UNIX, GFP_KERNEL, \u0026unix_stream_proto, kern);\n1106:\t\telse /*dgram and  seqpacket */\n1107:\t\t\tsk = sk_alloc(net, PF_UNIX, GFP_KERNEL, \u0026unix_dgram_proto, kern);\n1108:\t\n1109:\t\tif (!sk) {\n1110:\t\t\terr = -ENOMEM;\n1111:\t\t\tgoto err;\n1112:\t\t}\n1113:\t\n1114:\t\tsock_init_data(sock, sk);\n1115:\t\n1116:\t\tsk-\u003esk_scm_rights\t= 1;\n1117:\t\tsk-\u003esk_hash\t\t= unix_unbound_hash(sk);\n1118:\t\tsk-\u003esk_allocation\t= GFP_KERNEL_ACCOUNT;\n1119:\t\tsk-\u003esk_write_space\t= unix_write_space;\n1120:\t\tsk-\u003esk_max_ack_backlog\t= READ_ONCE(net-\u003eunx.sysctl_max_dgram_qlen);\n1121:\t\tsk-\u003esk_destruct\t\t= unix_sock_destructor;\n1122:\t\tlock_set_cmp_fn(\u0026sk-\u003esk_receive_queue.lock, unix_recvq_lock_cmp_fn, NULL);\n1123:\t\n1124:\t\tu = unix_sk(sk);\n1125:\t\tu-\u003elistener = NULL;\n1126:\t\tu-\u003evertex = NULL;\n1127:\t\tu-\u003epath.dentry = NULL;\n1128:\t\tu-\u003epath.mnt = NULL;\n1129:\t\tspin_lock_init(\u0026u-\u003elock);\n"
}

109/3 2026/09/29 11:09 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 77952
							output: 36
							thoughts: 34
						

Thoughts:
Okay, let's dive into this. Here's my thought process on this snippet:

**Diving into `sk_alloc` at Line 2340**

Alright, I'm going to pinpoint the `sk_alloc` function around line 2340. The most critical aspect here is to understand how this function initializes the socket structure, the `sk`. I need to zero in on what steps are taken within `sk_alloc` to set up the foundational elements of this socket, the initial state. This is crucial for tracing how the socket is actually formed. I need to understand, in precise detail, how the memory is allocated and, more importantly, how the fundamental socket structure is initialized.



110/3 2026/09/29 11:09 tool read-file
0m Args:
{
  "File": "net/core/sock.c",
  "FirstLine": 2330,
  "LineCount": 40
}

Results:
{
  "Contents": "2330:\t */\n2331:\tstruct sock *sk_alloc(struct net *net, int family, gfp_t priority,\n2332:\t\t\t      struct proto *prot, int kern)\n2333:\t{\n2334:\t\tstruct sock *sk;\n2335:\t\n2336:\t\tsk = sk_prot_alloc(prot, priority | __GFP_ZERO, family);\n2337:\t\tif (sk) {\n2338:\t\t\tsk-\u003esk_family = family;\n2339:\t\t\t/*\n2340:\t\t\t * See comment in struct sock definition to understand\n2341:\t\t\t * why we need sk_prot_creator -acme\n2342:\t\t\t */\n2343:\t\t\tsk-\u003esk_prot = sk-\u003esk_prot_creator = prot;\n2344:\t\n2345:\t\t\tif (READ_ONCE(net-\u003ecore.sysctl_bypass_prot_mem))\n2346:\t\t\t\tsk-\u003esk_bypass_prot_mem = 1;\n2347:\t\n2348:\t\t\tsk-\u003esk_kern_sock = kern;\n2349:\t\t\tsock_lock_init(sk);\n2350:\t\n2351:\t\t\tsk-\u003esk_net_refcnt = kern ? 0 : 1;\n2352:\t\t\tif (likely(sk-\u003esk_net_refcnt)) {\n2353:\t\t\t\tget_net_track(net, \u0026sk-\u003ens_tracker, priority);\n2354:\t\t\t\tsock_inuse_add(net, 1);\n2355:\t\t\t} else {\n2356:\t\t\t\tnet_passive_inc(net);\n2357:\t\t\t\t__netns_tracker_alloc(net, \u0026sk-\u003ens_tracker,\n2358:\t\t\t\t\t\t      false, priority);\n2359:\t\t\t}\n2360:\t\n2361:\t\t\tsock_net_set(sk, net);\n2362:\t\t\trefcount_set(\u0026sk-\u003esk_wmem_alloc, SK_WMEM_ALLOC_BIAS);\n2363:\t\n2364:\t\t\tmem_cgroup_sk_alloc(sk);\n2365:\t\t\tcgroup_sk_alloc(\u0026sk-\u003esk_cgrp_data);\n2366:\t\t\tsock_update_classid(\u0026sk-\u003esk_cgrp_data);\n2367:\t\t\tsock_update_netprioidx(\u0026sk-\u003esk_cgrp_data);\n2368:\t\t\tsk_tx_queue_clear(sk);\n2369:\t\t}\n"
}

111/3 2026/09/29 11:09 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 78825
							output: 35
							thoughts: 157
						

Thoughts:
**Analyzing Socket Initialization and Unix Control Blocks**

Okay, here's what I'm thinking as I dive into this code. Line 2336, specifically: `sk = sk_prot_alloc(prot, priority | __GFP_ZERO, family);` That `priority | __GFP_ZERO` bit really jumps out at me. It means that any socket allocated using `sk_alloc` (and, by extension, likely any socket allocated via this path) is *always* zero-initialized. Nice, clean, and predictable – a good practice. I see that `want_init_on_alloc` is also in play, so there's an explicit clearing happening as well. That confirms it. Then `sock_init_data_uid` also seems to explicitly zero the `sk->sk_peer_pid` buffer via a `memset`. Again, good. This consistent zeroing reduces potential security issues related to uninitialized memory.

Now, let's switch gears and investigate `UNIXCB(skb)`. I need to figure out where that's defined and what its size is. So, I'll go straight to `net/unix/af_unix.h`. This is where the core definitions for the Unix domain socket family should be located. I need to understand how the Unix Control Block relates to the socket buffers. I expect `UNIXCB` to provide structure related to local peer, connection status, and other Unix-specific metadata associated with a socket buffer. Understanding this is crucial to assessing how these sockets function and how the data is managed. Let's see what `af_unix.h` reveals.



112/3 2026/09/29 11:09 tool read-file
0m Args:
{
  "File": "net/unix/af_unix.h",
  "FirstLine": 1,
  "LineCount": 45
}

Results:
{
  "Contents": "   1:\t/* SPDX-License-Identifier: GPL-2.0 */\n   2:\t#ifndef __AF_UNIX_H\n   3:\t#define __AF_UNIX_H\n   4:\t\n   5:\t#include \u003clinux/pid_types.h\u003e\n   6:\t#include \u003clinux/uidgid.h\u003e\n   7:\t\n   8:\t#define UNIX_HASH_MOD\t(256 - 1)\n   9:\t#define UNIX_HASH_SIZE\t(256 * 2)\n  10:\t#define UNIX_HASH_BITS\t8\n  11:\t\n  12:\tstruct sock *unix_peer_get(struct sock *sk);\n  13:\t\n  14:\tstruct unix_skb_parms {\n  15:\t\tDECLARE_PIDS(pid, PIDTYPE_TGID);\t/* skb credentials by pid type */\n  16:\t\tkuid_t\t\t\tuid;\n  17:\t\tkgid_t\t\t\tgid;\n  18:\t\tstruct scm_fp_list\t*fp;\t\t/* Passed files\t\t*/\n  19:\t#ifdef CONFIG_SECURITY_NETWORK\n  20:\t\tu32\t\t\tsecid;\t\t/* Security ID\t\t*/\n  21:\t#endif\n  22:\t\tu32\t\t\tconsumed;\n  23:\t} __randomize_layout;\n  24:\t\n  25:\t#define UNIXCB(skb)\t(*(struct unix_skb_parms *)\u0026((skb)-\u003ecb))\n  26:\t\n  27:\t/* GC for SCM_RIGHTS */\n  28:\tvoid unix_add_edges(struct scm_fp_list *fpl, struct unix_sock *receiver);\n  29:\tvoid unix_del_edges(struct scm_fp_list *fpl);\n  30:\tvoid unix_update_edges(struct unix_sock *receiver);\n  31:\tint unix_prepare_fpl(struct scm_fp_list *fpl);\n  32:\tvoid unix_destroy_fpl(struct scm_fp_list *fpl);\n  33:\tvoid unix_peek_fpl(struct scm_fp_list *fpl);\n  34:\tvoid unix_schedule_gc(struct user_struct *user);\n  35:\t\n  36:\t/* SOCK_DIAG */\n  37:\tlong unix_inq_len(struct sock *sk);\n  38:\tlong unix_outq_len(struct sock *sk);\n  39:\t\n  40:\t/* sysctl */\n  41:\t#ifdef CONFIG_SYSCTL\n  42:\tint unix_sysctl_register(struct net *net);\n  43:\tvoid unix_sysctl_unregister(struct net *net);\n  44:\t#else\n  45:\tstatic inline int unix_sysctl_register(struct net *net)\n"
}

113/3 2026/09/29 11:09 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 80088
							output: 31
							thoughts: 238
						

Thoughts:
**Analyzing the Size and Content of `unix_skb_parms`**

Okay, let's take a look at this `unix_skb_parms` structure. I need to make sure its size fits within the allocated control buffer of the `sk_buff`. So, first, I'll confirm that `sizeof(skb->cb)` is indeed 48 bytes on this 64-bit system, with that `char cb[48] __aligned(8)` definition.

Now, let's dissect the contents of `unix_skb_parms` itself.  I see:

*   `DECLARE_PIDS(pid, PIDTYPE_TGID)` which should translate to two pointers, totaling 16 bytes.
*   A `kuid_t uid`, which is 4 bytes.
*   A `kgid_t gid`, also 4 bytes.
*   A `struct scm_fp_list *fp`, pointing to a `scm_fp_list` struct, that will be 8 bytes
*   A `u32 secid`, 4 bytes.
*   A `u32 consumed`, also 4 bytes.

Adding all of that up, 16 + 4 + 4 + 8 + 4 + 4 gives me a total of 40 bytes. That's within the 48-byte limit of `skb->cb`, so we're good there. It's a tighter fit than I'd like, but it works.

Finally, I need to double-check that there isn't a `BUILD_BUG_ON` statement that would prevent the structure being larger than `skb->cb`. I'll have to go look at `af_unix.c` to be certain.



114/3 2026/09/29 11:10 tool grepper
0m Args:
{
  "Expression": "BUILD_BUG_ON.*cb",
  "PathPrefix": "net/unix/"
}

Results:
{
  "Output": "net/unix/af_unix.c=3951=static int __init af_unix_init(void)\n--\nnet/unix/af_unix.c-3954-\nnet/unix/af_unix.c:3955:\tBUILD_BUG_ON(sizeof(struct unix_skb_parms) \u003e sizeof_field(struct sk_buff, cb));\nnet/unix/af_unix.c-3956-\n"
}

115/3 2026/09/29 11:10 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 80868
							output: 32
							thoughts: 107
						

Thoughts:
**Analyzing the `af_unix` Socket Buffer Allocation**

Okay, so line 3955 contains a crucial check: `BUILD_BUG_ON(sizeof(struct unix_skb_parms) > sizeof_field(struct sk_buff, cb));`. This is the core of the issue. I know this code, so I'm thinking, this means `struct unix_skb_parms` *must* fit within the `sk_buff`'s control block (`cb`). We're preventing it from overflowing.

Now the question is how `cb` and `UNIXCB(skb)` are initialized. Given the assertion, I need to understand when and how the `af_unix` code handles the allocation and population of this `cb` area. The kernel is highly sensitive about these control block structures. So, I need to know the allocation strategy.

To get the full picture, I'm going to carefully review the `net/unix/af_unix.c` file. I need to track down all instances where either `skb->cb` or, more importantly, the macro `UNIXCB(skb)` is used. That should give me the initialization path and reveal any potential problems with memory access or size assumptions. I will need to look at socket buffer creation, management, and use within the `af_unix` context. I need to make sure the size constraints in line 3955 are strictly enforced throughout.



116/3 2026/09/29 11:10 tool grepper
0m Args:
{
  "Expression": "UNIXCB",
  "PathPrefix": "net/unix/af_unix.c"
}

Results:
{
  "Output": "net/unix/af_unix.c=256=static void unix_get_secdata(struct scm_cookie *scm, struct sk_buff *skb)\nnet/unix/af_unix.c-257-{\nnet/unix/af_unix.c:258:\tUNIXCB(skb).secid = scm-\u003esecid;\nnet/unix/af_unix.c-259-}\n--\nnet/unix/af_unix.c=261=static inline void unix_set_secdata(struct scm_cookie *scm, struct sk_buff *skb)\nnet/unix/af_unix.c-262-{\nnet/unix/af_unix.c:263:\tscm-\u003esecid = UNIXCB(skb).secid;\nnet/unix/af_unix.c-264-}\n--\nnet/unix/af_unix.c=266=static inline bool unix_secdata_eq(struct scm_cookie *scm, struct sk_buff *skb)\nnet/unix/af_unix.c-267-{\nnet/unix/af_unix.c:268:\treturn (scm-\u003esecid == UNIXCB(skb).secid);\nnet/unix/af_unix.c-269-}\n--\nnet/unix/af_unix.c=660=static unsigned int unix_skb_len(const struct sk_buff *skb)\nnet/unix/af_unix.c-661-{\nnet/unix/af_unix.c:662:\treturn skb-\u003elen - UNIXCB(skb).consumed;\nnet/unix/af_unix.c-663-}\n--\nnet/unix/af_unix.c=1941=static int unix_attach_fds(struct scm_cookie *scm, struct sk_buff *skb)\n--\nnet/unix/af_unix.c-1945-\nnet/unix/af_unix.c:1946:\tUNIXCB(skb).fp = scm-\u003efp;\nnet/unix/af_unix.c-1947-\tscm-\u003efp = NULL;\nnet/unix/af_unix.c-1948-\nnet/unix/af_unix.c:1949:\tif (unix_prepare_fpl(UNIXCB(skb).fp))\nnet/unix/af_unix.c-1950-\t\treturn -ENOMEM;\n--\nnet/unix/af_unix.c=1955=static void unix_detach_fds(struct scm_cookie *scm, struct sk_buff *skb)\nnet/unix/af_unix.c-1956-{\nnet/unix/af_unix.c:1957:\tscm-\u003efp = UNIXCB(skb).fp;\nnet/unix/af_unix.c:1958:\tUNIXCB(skb).fp = NULL;\nnet/unix/af_unix.c-1959-\n--\nnet/unix/af_unix.c=1963=static void unix_peek_fds(struct scm_cookie *scm, struct sk_buff *skb)\nnet/unix/af_unix.c-1964-{\nnet/unix/af_unix.c:1965:\tscm-\u003efp = scm_fp_dup(UNIXCB(skb).fp);\nnet/unix/af_unix.c-1966-\n--\nnet/unix/af_unix.c=1970=static void unix_destruct_scm(struct sk_buff *skb)\n--\nnet/unix/af_unix.c-1973-\nnet/unix/af_unix.c:1974:\tswap_pids(scm.pid, UNIXCB(skb).pid);\nnet/unix/af_unix.c-1975-\nnet/unix/af_unix.c:1976:\tif (UNIXCB(skb).fp)\nnet/unix/af_unix.c-1977-\t\tunix_detach_fds(\u0026scm, skb);\n--\nnet/unix/af_unix.c=1988=static int unix_scm_to_skb(struct scm_cookie *scm, struct sk_buff *skb, bool send_fds)\n--\nnet/unix/af_unix.c-1991-\nnet/unix/af_unix.c:1992:\tget_pids(UNIXCB(skb).pid, scm-\u003epid);\nnet/unix/af_unix.c:1993:\tUNIXCB(skb).uid = scm-\u003ecreds.uid;\nnet/unix/af_unix.c:1994:\tUNIXCB(skb).gid = scm-\u003ecreds.gid;\nnet/unix/af_unix.c:1995:\tUNIXCB(skb).fp = NULL;\nnet/unix/af_unix.c-1996-\tunix_get_secdata(scm, skb);\n--\nnet/unix/af_unix.c=2004=static void unix_skb_to_scm(struct sk_buff *skb, struct scm_cookie *scm)\nnet/unix/af_unix.c-2005-{\nnet/unix/af_unix.c:2006:\tget_pids(scm-\u003epid, UNIXCB(skb).pid);\nnet/unix/af_unix.c-2007-\tscm-\u003ecreds.pid = pid_vnr(scm-\u003epid[PIDTYPE_TGID]);\nnet/unix/af_unix.c:2008:\tscm-\u003ecreds.uid = UNIXCB(skb).uid;\nnet/unix/af_unix.c:2009:\tscm-\u003ecreds.gid = UNIXCB(skb).gid;\nnet/unix/af_unix.c-2010-\tunix_set_secdata(scm, skb);\n--\nnet/unix/af_unix.c=2026=static int unix_maybe_add_creds(struct sk_buff *skb, const struct sock *sk,\n--\nnet/unix/af_unix.c-2028-{\nnet/unix/af_unix.c:2029:\tif (UNIXCB(skb).pid[PIDTYPE_TGID])\nnet/unix/af_unix.c-2030-\t\treturn 0;\n--\nnet/unix/af_unix.c-2035-\nnet/unix/af_unix.c:2036:\t\tget_task_pids(UNIXCB(skb).pid, current);\nnet/unix/af_unix.c:2037:\t\terr = pidfs_register_pids(UNIXCB(skb).pid);\nnet/unix/af_unix.c-2038-\t\tif (unlikely(err)) {\nnet/unix/af_unix.c:2039:\t\t\tput_pids(UNIXCB(skb).pid);\nnet/unix/af_unix.c-2040-\t\t\treturn err;\n--\nnet/unix/af_unix.c-2042-\nnet/unix/af_unix.c:2043:\t\tcurrent_uid_gid(\u0026UNIXCB(skb).uid, \u0026UNIXCB(skb).gid);\nnet/unix/af_unix.c-2044-\t}\n--\nnet/unix/af_unix.c=2049=static bool unix_skb_scm_eq(const struct sock *sk, struct sk_buff *skb,\n--\nnet/unix/af_unix.c-2053-\tif (sk-\u003esk_scm_pidfd_thread \u0026\u0026\nnet/unix/af_unix.c:2054:\t    UNIXCB(skb).pid[PIDTYPE_PID] != scm-\u003epid[PIDTYPE_PID])\nnet/unix/af_unix.c-2055-\t\treturn false;\nnet/unix/af_unix.c-2056-\nnet/unix/af_unix.c:2057:\treturn UNIXCB(skb).pid[PIDTYPE_TGID] == scm-\u003epid[PIDTYPE_TGID] \u0026\u0026\nnet/unix/af_unix.c:2058:\t       uid_eq(UNIXCB(skb).uid, scm-\u003ecreds.uid) \u0026\u0026\nnet/unix/af_unix.c:2059:\t       gid_eq(UNIXCB(skb).gid, scm-\u003ecreds.gid) \u0026\u0026\nnet/unix/af_unix.c-2060-\t       unix_secdata_eq(scm, skb);\n--\nnet/unix/af_unix.c=2063=static void scm_stat_add(struct sock *sk, struct sk_buff *skb)\nnet/unix/af_unix.c-2064-{\nnet/unix/af_unix.c:2065:\tstruct scm_fp_list *fp = UNIXCB(skb).fp;\nnet/unix/af_unix.c-2066-\tstruct unix_sock *u = unix_sk(sk);\n--\nnet/unix/af_unix.c=2074=static void scm_stat_del(struct sock *sk, struct sk_buff *skb)\nnet/unix/af_unix.c-2075-{\nnet/unix/af_unix.c:2076:\tstruct scm_fp_list *fp = UNIXCB(skb).fp;\nnet/unix/af_unix.c-2077-\tstruct unix_sock *u = unix_sk(sk);\n--\nnet/unix/af_unix.c=2096=static int unix_dgram_sendmsg(struct socket *sock, struct msghdr *msg,\n--\nnet/unix/af_unix.c-2250-\nnet/unix/af_unix.c:2251:\tif (UNIXCB(skb).fp \u0026\u0026 !other-\u003esk_scm_rights) {\nnet/unix/af_unix.c-2252-\t\terr = -EPERM;\n--\nnet/unix/af_unix.c=2330=static int queue_oob(struct sock *sk, struct msghdr *msg, struct sock *other,\n--\nnet/unix/af_unix.c-2363-\nnet/unix/af_unix.c:2364:\tif (UNIXCB(skb).fp \u0026\u0026 !other-\u003esk_scm_rights) {\nnet/unix/af_unix.c-2365-\t\terr = -EPERM;\n--\nnet/unix/af_unix.c=2390=static int unix_stream_sendmsg(struct socket *sock, struct msghdr *msg,\n--\nnet/unix/af_unix.c-2490-\nnet/unix/af_unix.c:2491:\t\tif (UNIXCB(skb).fp \u0026\u0026 !other-\u003esk_scm_rights) {\nnet/unix/af_unix.c-2492-\t\t\tunix_state_unlock(other);\n--\nnet/unix/af_unix.c=2575=int __unix_dgram_recvmsg(struct sock *sk, struct msghdr *msg, size_t size,\n--\nnet/unix/af_unix.c-2649-\tif (!(flags \u0026 MSG_PEEK)) {\nnet/unix/af_unix.c:2650:\t\tif (UNIXCB(skb).fp)\nnet/unix/af_unix.c-2651-\t\t\tunix_detach_fds(\u0026scm, skb);\n--\nnet/unix/af_unix.c-2669-\nnet/unix/af_unix.c:2670:\t\tif (UNIXCB(skb).fp)\nnet/unix/af_unix.c-2671-\t\t\tunix_peek_fds(\u0026scm, skb);\n--\nnet/unix/af_unix.c=2770=static int unix_stream_recv_urg(struct unix_stream_read_state *state)\n--\nnet/unix/af_unix.c-2807-\tif (!(state-\u003eflags \u0026 MSG_PEEK))\nnet/unix/af_unix.c:2808:\t\tUNIXCB(oob_skb).consumed += 1;\nnet/unix/af_unix.c-2809-\n--\nnet/unix/af_unix.c=2924=static int unix_stream_read_generic(struct unix_stream_read_state *state,\n--\nnet/unix/af_unix.c-3069-\t\tif (!(flags \u0026 MSG_PEEK)) {\nnet/unix/af_unix.c:3070:\t\t\tUNIXCB(skb).consumed += chunk;\nnet/unix/af_unix.c-3071-\n--\nnet/unix/af_unix.c-3073-\nnet/unix/af_unix.c:3074:\t\t\tif (UNIXCB(skb).fp) {\nnet/unix/af_unix.c-3075-\t\t\t\tscm_stat_del(sk, skb);\n--\nnet/unix/af_unix.c-3094-\t\t\t */\nnet/unix/af_unix.c:3095:\t\t\tif (UNIXCB(skb).fp)\nnet/unix/af_unix.c-3096-\t\t\t\tunix_peek_fds(\u0026scm, skb);\n--\nnet/unix/af_unix.c-3099-\nnet/unix/af_unix.c:3100:\t\t\tif (UNIXCB(skb).fp)\nnet/unix/af_unix.c-3101-\t\t\t\tbreak;\n--\nnet/unix/af_unix.c=3133=static int unix_stream_read_actor(struct sk_buff *skb,\n--\nnet/unix/af_unix.c-3138-\nnet/unix/af_unix.c:3139:\tret = skb_copy_datagram_msg(skb, UNIXCB(skb).consumed + skip,\nnet/unix/af_unix.c-3140-\t\t\t\t    state-\u003emsg, chunk);\n--\nnet/unix/af_unix.c=3179=static int unix_stream_splice_actor(struct sk_buff *skb,\n--\nnet/unix/af_unix.c-3183-\treturn skb_splice_bits(skb, state-\u003esocket-\u003esk,\nnet/unix/af_unix.c:3184:\t\t\t       UNIXCB(skb).consumed + skip,\nnet/unix/af_unix.c-3185-\t\t\t       state-\u003epipe, chunk, state-\u003esplice_flags);\n"
}

117/3 2026/09/29 11:10 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 84953
							output: 22
							thoughts: 57
						

Thoughts:
Here's my thought process, as if I were considering this code:

**Diving into `sock_alloc_send_pskb`**

Okay, so I'm looking at `af_unix.c`, specifically `sock_alloc_send_pskb`. I need to be absolutely certain about how this function behaves, especially concerning the `skb->cb` field. Does `sock_alloc_send_pskb` initialize, clear, or leave `skb->cb` untouched? This is critical for understanding the subsequent data flow and potential for memory corruption or unintended side effects in my area of expertise. I can't afford any assumptions here. The only way to know with confidence is to directly examine the code of `sock_alloc_send_pskb` itself and verify its behavior. Let's get to the function definition and confirm.



118/3 2026/09/29 11:10 tool grepper
0m Args:
{
  "Expression": "sock_alloc_send_pskb"
}

Results:
{
  "Output": "drivers/net/ovpn/tcp.c=404=static int ovpn_tcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)\n--\ndrivers/net/ovpn/tcp.c-434-\ndrivers/net/ovpn/tcp.c:435:\tskb = sock_alloc_send_pskb(sk, linear, size - linear,\ndrivers/net/ovpn/tcp.c-436-\t\t\t\t   msg-\u003emsg_flags \u0026 MSG_DONTWAIT, \u0026ret, 0);\n--\ndrivers/net/tap.c=543=static inline struct sk_buff *tap_alloc_skb(struct sock *sk, size_t prepad,\n--\ndrivers/net/tap.c-554-\t\tlinear = len - MAX_SKB_FRAGS * (PAGE_SIZE \u003c\u003c PAGE_ALLOC_COSTLY_ORDER);\ndrivers/net/tap.c:555:\tskb = sock_alloc_send_pskb(sk, prepad + linear, len - linear, noblock,\ndrivers/net/tap.c-556-\t\t\t\t   err, PAGE_ALLOC_COSTLY_ORDER);\n--\ndrivers/net/tun.c=1533=static struct sk_buff *tun_alloc_skb(struct tun_file *tfile,\n--\ndrivers/net/tun.c-1546-\t\tlinear = len - MAX_SKB_FRAGS * (PAGE_SIZE \u003c\u003c PAGE_ALLOC_COSTLY_ORDER);\ndrivers/net/tun.c:1547:\tskb = sock_alloc_send_pskb(sk, prepad + linear, len - linear, noblock,\ndrivers/net/tun.c-1548-\t\t\t\t   \u0026err, PAGE_ALLOC_COSTLY_ORDER);\n--\ninclude/net/sock.h=1899=int sock_gettstamp(struct socket *sock, void __user *userstamp,\ninclude/net/sock.h-1900-\t\t   bool timeval, bool time32);\ninclude/net/sock.h:1901:struct sk_buff *sock_alloc_send_pskb(struct sock *sk, unsigned long header_len,\ninclude/net/sock.h-1902-\t\t\t\t     unsigned long data_len, int noblock,\n--\ninclude/net/sock.h=1905=static inline struct sk_buff *sock_alloc_send_skb(struct sock *sk,\n--\ninclude/net/sock.h-1908-{\ninclude/net/sock.h:1909:\treturn sock_alloc_send_pskb(sk, size, 0, noblock, errcode, 0);\ninclude/net/sock.h-1910-}\n--\nnet/core/sock.c=2991=static long sock_wait_for_wmem(struct sock *sk, long timeo)\n--\nnet/core/sock.c-3019-\nnet/core/sock.c:3020:struct sk_buff *sock_alloc_send_pskb(struct sock *sk, unsigned long header_len,\nnet/core/sock.c-3021-\t\t\t\t     unsigned long data_len, int noblock,\n--\nnet/core/sock.c-3061-}\nnet/core/sock.c:3062:EXPORT_SYMBOL(sock_alloc_send_pskb);\nnet/core/sock.c-3063-\n--\nnet/ipv6/ndisc.c=414=static struct sk_buff *ndisc_alloc_skb(struct net_device *dev,\n--\nnet/ipv6/ndisc.c-431-\t/* Manually assign socket ownership as we avoid calling\nnet/ipv6/ndisc.c:432:\t * sock_alloc_send_pskb() to bypass wmem buffer limits\nnet/ipv6/ndisc.c-433-\t */\n--\nnet/iucv/af_iucv.c=919=static int iucv_sock_sendmsg(struct socket *sock, struct msghdr *msg,\n--\nnet/iucv/af_iucv.c-1017-\t}\nnet/iucv/af_iucv.c:1018:\tskb = sock_alloc_send_pskb(sk, headroom + linear, len - linear,\nnet/iucv/af_iucv.c-1019-\t\t\t\t   noblock, \u0026err, 0);\n--\nnet/packet/af_packet.c=2976=static struct sk_buff *packet_alloc_skb(struct sock *sk, size_t prepad,\n--\nnet/packet/af_packet.c-2988-\t\tlinear = len - MAX_SKB_FRAGS * (PAGE_SIZE \u003c\u003c PAGE_ALLOC_COSTLY_ORDER);\nnet/packet/af_packet.c:2989:\tskb = sock_alloc_send_pskb(sk, prepad + linear, len - linear, noblock,\nnet/packet/af_packet.c-2990-\t\t\t\t   err, PAGE_ALLOC_COSTLY_ORDER);\n--\nnet/unix/af_unix.c=2096=static int unix_dgram_sendmsg(struct socket *sock, struct msghdr *msg,\n--\nnet/unix/af_unix.c-2149-\nnet/unix/af_unix.c:2150:\tskb = sock_alloc_send_pskb(sk, len - data_len, data_len,\nnet/unix/af_unix.c-2151-\t\t\t\t   msg-\u003emsg_flags \u0026 MSG_DONTWAIT, \u0026err,\n--\nnet/unix/af_unix.c=2390=static int unix_stream_sendmsg(struct socket *sock, struct msghdr *msg,\n--\nnet/unix/af_unix.c-2435-\t\tif (unlikely(msg-\u003emsg_flags \u0026 MSG_SPLICE_PAGES)) {\nnet/unix/af_unix.c:2436:\t\t\tskb = sock_alloc_send_pskb(sk, 0, 0,\nnet/unix/af_unix.c-2437-\t\t\t\t\t\t   msg-\u003emsg_flags \u0026 MSG_DONTWAIT,\n--\nnet/unix/af_unix.c-2449-\nnet/unix/af_unix.c:2450:\t\t\tskb = sock_alloc_send_pskb(sk, size - data_len, data_len,\nnet/unix/af_unix.c-2451-\t\t\t\t\t\t   msg-\u003emsg_flags \u0026 MSG_DONTWAIT, \u0026err,\n"
}

119/3 2026/09/29 11:10 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 86846
							output: 31
							thoughts: 65
						

Thoughts:
Here's my thought process, as it stands:

**Diving into SKB Allocation Details**

Okay, so I'm looking at the `alloc_skb` function again, as this is a core building block for packet handling, and I need to understand its behaviour in detail, particularly in the context of recent performance tweaks. My first instinct is always to trace its calls, and so I see that `alloc_skb` ultimately calls `__alloc_skb`. A critical point I need to verify: does `__alloc_skb` perform the necessary initializations for the control buffer, `skb->cb`? This is frequently a source of subtle issues and optimization opportunities. I need to make sure this isn't a performance bottleneck and that the buffer is properly initialized to prevent potential out-of-bounds access.

Therefore, the next logical step is to dive right into the source code. I need to get the definitive answer, so I'll open up `net/core/skbuff.c` and specifically examine the `__alloc_skb` implementation to confirm the initialization of `skb->cb`. I'm looking for the exact details of how `skb->cb` is set up.



120/3 2026/09/29 11:10 tool grepper
0m Error:
no matches

Args:
{
  "Expression": "memset.*cb",
  "PathPrefix": "net/core/skbuff.c"
}

Results:
{
  "error": "no matches"
}

121/3 2026/09/29 11:10 llm kmsan-evaluator-compressor
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Reply:
### 1. Approaches Tried and Results

- **Diff and Subsystem Analysis**:
  - Examined the patch diff modifying core networking, socket options, Unix domain sockets (`AF_UNIX`), Bluetooth sockets (`AF_BLUETOOTH`), pidfs, coredumping, and related architecture headers (`SO_PASSPIDFD_THREAD`, `SO_PEERPIDFD_THREAD`, `SCM_PIDFD_THREAD`).
  - Checked introduction of `DECLARE_PIDS(name, last)` and helper functions in `include/linux/pid.h` (`__get_pids`, `__put_pids`, `__swap_pids`, `__pids_equal`, `task_pids`, `get_task_pids`).
  
- **Coredump Handling (`fs/coredump.c` & `include/linux/coredump.h`)**:
  - Investigated `cprm.pid` declaration (`DECLARE_PIDS(pid, PIDTYPE_TGID)`).
  - Traced `cprm` initialization in `vfs_coredump()`: initialized using designated initializer `struct coredump_params cprm = { .siginfo = siginfo, ... }`, which guarantees all unmentioned fields (including `cprm.pid` array of pointers) are zero-initialized.
  - Checked `umh_coredump_setup`, `coredump_sock_connect`, and `pidfs_coredump()`: properly guarded by `if (cp->pid[PIDTYPE_TGID])`. No reads of uninitialized stack memory.

- **Socket Options & Data Copied to User Space (`net/core/sock.c`)**:
  - Examined `sk_getsockopt_peerpidfd()` for `SO_PEERPIDFD` and `SO_PEERPIDFD_THREAD`.
  - Checked whether uninitialized memory or padding could leak:
    - `pidfd` is a local `int`, initialized with `pidfd_prepare(peer_pid, flags, &pidfd_file)`.
    - `len` is bounded by `sizeof(pidfd)` (i.e. `sizeof(int)`).
    - `copy_to_sockptr(optval, &pidfd, len)` and `copy_to_sockptr(optlen, &len, sizeof(int))` copy strictly initialized bytes.
  - In `sk_getsockopt()`:
    - Handled `SO_PASSPIDFD_THREAD`: returns `v.val = sk->sk_scm_pidfd_thread`. `union { int val; ... } v` is fully zeroed by `memset(&v, 0, sizeof(v))` beforehand.
    - Handled `SO_PEERCRED`: `cred_to_ucred()` copies into `struct ucred peercred`, which is fully populated.

- **SCM Processing and Datagram/Stream Lifecycle (`net/core/scm.c`, `net/unix/af_unix.c`)**:
  - Examined `scm_replace_pid()`: calls `scm_destroy_cred(scm)` which invokes `put_pids(scm->pid)` (clearing pointers to NULL) before populating `scm->pid[PIDTYPE_TGID]` and `scm->pid[PIDTYPE_PID]`.
  - Examined `scm_send()`: explicitly calls `memset(scm, 0, sizeof(*scm))`.
  - Examined `unix_dgram_sendmsg()` and `unix_stream_sendmsg()`: `struct scm_cookie scm` initialized via `scm_send()` with `memset`.
  - Examined `unix_scm_to_skb()`: assigns `UNIXCB(skb).pid` using `get_pids()`, handling NULL safely.
  - Examined `unix_skb_to_scm()`: copies `UNIXCB(skb).pid` via `get_pids()`, safely copying pointers.
  - Examined `scm_pidfd_recv()`:
    - Checks `if (!pid) return;`.
    - Passes `&pidfd` to `put_cmsg(msg, SOL_SOCKET, cmsg_type, sizeof(int), &pidfd)`.
    - `pidfd` is fully initialized by `pidfd_prepare()`.
  - Examined consumers in other protocols (`net/bluetooth/hci_sock.c`, `net/netlink/af_netlink.c`):
    - Both zero-initialize `scm` via `memset(&scm, 0, sizeof(scm))` before calling `scm_recv()`.
    - `bt_sock_alloc()` invokes `sock_init_data()`, which executes `memset(sk->sk_peer_pid, 0, sizeof(sk->sk_peer_pid))`. Non-AF_UNIX sockets reject `SO_PEERPIDFD_THREAD` with `-EOPNOTSUPP`.

- **Bitfield Initialization in `struct sock` (`include/net/sock.h`)**:
  - `sk_scm_pidfd_thread : 1` added to existing bitfield union. `sock_init_data()` zeroes the socket structure (or kzalloc via `sk_alloc()`), ensuring no uninitialized bitfield reads.

### 2. Hypotheses and Active Lines of Investigation

- **Hypothesis**: The patch does NOT introduce uninitialized memory usage or info-leaks.
  - All structs/arrays (`cprm.pid`, `sk->sk_peer_pid`, `scm.pid`, `UNIXCB(skb).pid`, `peercred`) are either allocated with zeroing (`kzalloc`), cleared via `memset`, or initialized with C designated initializers (`= {}` or `.field = ...`).
  - Integer file descriptors (`pidfd`) and socket option lengths (`len`) are set explicitly before `copy_to_sockptr` / `put_cmsg`.
  - Uninitialized struct padding or uninitialized memory leakage to user space is absent.
  - Any potential bugs introduced (e.g. error handling in `pidfd_prepare` or refcount/lifecycle of `struct pid`) are memory safety / pointer / refcounting issues detectable by KASAN or standard checkers, not KMSAN-specific uninitialized memory reads.
- **Conclusion**: `NeedsKMSAN = false`.

### 3. Critical Code Snippets, Structs, and Files

- **`DECLARE_PIDS` definition (`include/linux/pid_types.h`)**:
  ```c
  #define DECLARE_PIDS(name, last) \
      struct pid *name[(last) + 1 + BUILD_BUG_ON_ZERO((last) >= PIDTYPE_MAX)]
  ```

- **Array Helper Macros (`include/linux/pid.h`)**:
  ```c
  #define pids_last(pids) \
      ((enum pid_type)(ARRAY_SIZE(pids) - 1 + BUILD_BUG_ON_ZERO(ARRAY_SIZE(pids) > PIDTYPE_MAX)))
  #define __pids_last2(a, b) \
      (pids_last(a) + BUILD_BUG_ON_ZERO(ARRAY_SIZE(a) != ARRAY_SIZE(b)))
  #define get_pids(dst, src)   __get_pids(dst, src, __pids_last2(dst, src))
  #define put_pids(pids)       __put_pids(pids, pids_last(pids))
  #define swap_pids(a, b)      __swap_pids(a, b, __pids_last2(a, b))
  #define pids_equal(a, b)     __pids_equal(a, b, __pids_last2(a, b))
  ```

- **Socket peer pidfd getsockopt (`net/core/sock.c`)**:
  ```c
  static int sk_getsockopt_peerpidfd(struct sock *sk, enum pid_type type,
                                     sockptr_t optval, sockptr_t optlen, int len)
  {
      struct file *pidfd_file = NULL;
      unsigned int flags = 0;
      struct pid *peer_pid;
      int pidfd;

      if (len > sizeof(pidfd))
          len = sizeof(pidfd);

      spin_lock(&sk->sk_peer_lock);
      peer_pid = get_pid(sk->sk_peer_pid[type]);
      spin_unlock(&sk->sk_peer_lock);

      if (!peer_pid)
          return -ENODATA;

      if (sk_is_unix(sk))
          flags |= PIDFD_STALE;
      if (type == PIDTYPE_PID)
          flags |= PIDFD_THREAD;

      pidfd = pidfd_prepare(peer_pid, flags, &pidfd_file);
      put_pid(peer_pid);
      if (pidfd < 0)
          return pidfd;

      if (copy_to_sockptr(optval, &pidfd, len) ||
          copy_to_sockptr(optlen, &len, sizeof(int))) {
          put_unused_fd(pidfd);
          fput(pidfd_file);
          return -EFAULT;
      }

      fd_install(pidfd, pidfd_file);
      return 0;
  }
  ```

- **Socket Control Message Receiving (`net/core/scm.c`)**:
  ```c
  static void scm_pidfd_recv(struct msghdr *msg, struct scm_cookie *scm,
                             enum pid_type type, int cmsg_type)
  {
      unsigned int flags = PIDFD_STALE;
      struct file *pidfd_file = NULL;
      struct pid *pid;
      int len, pidfd;

      pid = scm->pid[type];
      ...
      if (!pid)
          return;
      if (type == PIDTYPE_PID)
          flags |= PIDFD_THREAD;
      pidfd = pidfd_prepare(pid, flags, &pidfd_file);
      if (put_cmsg(msg, SOL_SOCKET, cmsg_type, sizeof(int), &pidfd)) {
          ...
      }
      if (pidfd_file)
          fd_install(pidfd, pidfd_file);
  }
  ```

### 4. Watch for Loops / Repetitive Patterns
- All key call sites (`coredump`, `sock_getsockopt`, `af_unix`, `af_bluetooth`, `af_netlink`, `scm_recv`) have been traced. No further tool invocations or reads are necessary. Ready for `set-results` execution and final response.

Tokens:
							input: 65469
							output: 2431
							thoughts: 0
						

122/3 2026/09/29 11:10 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 44222
							output: 33
							thoughts: 0
						

123/3 2026/09/29 11:10 tool grepper
0m Args:
{
  "Expression": "__alloc_skb",
  "PathPrefix": "net/core/skbuff.c"
}

Results:
{
  "Output": "net/core/skbuff.c=606=static void *kmalloc_reserve(unsigned int *size, gfp_t flags, int node,\n--\nnet/core/skbuff.c-657-/**\nnet/core/skbuff.c:658: *\t__alloc_skb\t-\tallocate a network buffer\nnet/core/skbuff.c-659- *\t@size: size to allocate\n--\nnet/core/skbuff.c-673- */\nnet/core/skbuff.c:674:struct sk_buff *__alloc_skb(unsigned int size, gfp_t gfp_mask,\nnet/core/skbuff.c-675-\t\t\t    int flags, int node)\n--\nnet/core/skbuff.c-745-}\nnet/core/skbuff.c:746:EXPORT_SYMBOL(__alloc_skb);\nnet/core/skbuff.c-747-\n--\nnet/core/skbuff.c=761=struct sk_buff *__netdev_alloc_skb(struct net_device *dev, unsigned int len,\n--\nnet/core/skbuff.c-776-\t    (gfp_mask \u0026 (__GFP_DIRECT_RECLAIM | GFP_DMA))) {\nnet/core/skbuff.c:777:\t\tskb = __alloc_skb(len, gfp_mask, SKB_ALLOC_RX, NUMA_NO_NODE);\nnet/core/skbuff.c-778-\t\tif (!skb)\n--\nnet/core/skbuff.c=838=struct sk_buff *napi_alloc_skb(struct napi_struct *napi, unsigned int len)\n--\nnet/core/skbuff.c-854-\t    (gfp_mask \u0026 (__GFP_DIRECT_RECLAIM | GFP_DMA))) {\nnet/core/skbuff.c:855:\t\tskb = __alloc_skb(len, gfp_mask, SKB_ALLOC_RX | SKB_ALLOC_NAPI,\nnet/core/skbuff.c-856-\t\t\t\t  NUMA_NO_NODE);\n--\nnet/core/skbuff.c=2180=struct sk_buff *skb_copy(const struct sk_buff *skb, gfp_t gfp_mask)\n--\nnet/core/skbuff.c-2193-\tsize = skb_end_offset(skb) + skb-\u003edata_len;\nnet/core/skbuff.c:2194:\tn = __alloc_skb(size, gfp_mask,\nnet/core/skbuff.c-2195-\t\t\tskb_alloc_rx_flag(skb), NUMA_NO_NODE);\n--\nnet/core/skbuff.c=2228=struct sk_buff *__pskb_copy_fclone(struct sk_buff *skb, int headroom,\n--\nnet/core/skbuff.c-2232-\tint flags = skb_alloc_rx_flag(skb) | (fclone ? SKB_ALLOC_FCLONE : 0);\nnet/core/skbuff.c:2233:\tstruct sk_buff *n = __alloc_skb(size, gfp_mask, flags, NUMA_NO_NODE);\nnet/core/skbuff.c-2234-\n--\nnet/core/skbuff.c=2505=struct sk_buff *skb_copy_expand(const struct sk_buff *skb,\n--\nnet/core/skbuff.c-2522-\toldheadroom = skb_headroom(skb);\nnet/core/skbuff.c:2523:\tn = __alloc_skb(newheadroom + skb-\u003elen + newtailroom,\nnet/core/skbuff.c-2524-\t\t\tgfp_mask, skb_alloc_rx_flag(skb),\n--\nnet/core/skbuff.c=4790=struct sk_buff *skb_segment(struct sk_buff *head_skb,\n--\nnet/core/skbuff.c-4958-\nnet/core/skbuff.c:4959:\t\t\tnskb = __alloc_skb(hsize + doffset + headroom,\nnet/core/skbuff.c-4960-\t\t\t\t\t   GFP_ATOMIC, skb_alloc_rx_flag(head_skb),\n"
}

124/3 2026/09/29 11:10 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 45354
							output: 36
							thoughts: 0
						

125/3 2026/09/29 11:10 tool read-file
0m Args:
{
  "File": "net/core/skbuff.c",
  "FirstLine": 460,
  "LineCount": 45
}

Results:
{
  "Contents": " 460:\t\n 461:\t\t/* frag_size == 0 is considered deprecated now. Callers\n 462:\t\t * using slab buffer should use slab_build_skb() instead.\n 463:\t\t */\n 464:\t\tif (WARN_ONCE(size == 0, \"Use slab_build_skb() instead\"))\n 465:\t\t\tdata = __slab_build_skb(data, \u0026size);\n 466:\t\n 467:\t\t__finalize_skb_around(skb, data, size);\n 468:\t}\n 469:\t\n 470:\t/**\n 471:\t * __build_skb - build a network buffer\n 472:\t * @data: data buffer provided by caller\n 473:\t * @frag_size: size of data (must not be 0)\n 474:\t *\n 475:\t * Allocate a new \u0026sk_buff. Caller provides space holding head and\n 476:\t * skb_shared_info. @data must have been allocated from the page\n 477:\t * allocator or vmalloc(). (A @frag_size of 0 to indicate a kmalloc()\n 478:\t * allocation is deprecated, and callers should use slab_build_skb()\n 479:\t * instead.)\n 480:\t * The return is the new skb buffer.\n 481:\t * On a failure the return is %NULL, and @data is not freed.\n 482:\t * Notes :\n 483:\t *  Before IO, driver allocates only data buffer where NIC put incoming frame\n 484:\t *  Driver should add room at head (NET_SKB_PAD) and\n 485:\t *  MUST add room at tail (SKB_DATA_ALIGN(skb_shared_info))\n 486:\t *  After IO, driver calls build_skb(), to allocate sk_buff and populate it\n 487:\t *  before giving packet to stack.\n 488:\t *  RX rings only contains data buffers, not full skbs.\n 489:\t */\n 490:\tstruct sk_buff *__build_skb(void *data, unsigned int frag_size)\n 491:\t{\n 492:\t\tstruct sk_buff *skb;\n 493:\t\n 494:\t\tskb = kmem_cache_alloc(net_hotdata.skbuff_cache,\n 495:\t\t\t\t       GFP_ATOMIC | __GFP_NOWARN);\n 496:\t\tif (unlikely(!skb))\n 497:\t\t\treturn NULL;\n 498:\t\n 499:\t\tskbuff_clear(skb);\n 500:\t\t__build_skb_around(skb, data, frag_size);\n 501:\t\n 502:\t\treturn skb;\n 503:\t}\n 504:\t\n"
}

126/3 2026/09/29 11:10 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 46142
							output: 18
							thoughts: 0
						

127/3 2026/09/29 11:10 tool grepper
0m Args:
{
  "Expression": "skbuff_clear"
}

Results:
{
  "Output": "net/core/skbuff.c=284=static inline struct sk_buff *napi_skb_cache_get(bool alloc)\n--\nnet/core/skbuff.c-315- */\nnet/core/skbuff.c:316:static inline void skbuff_clear(struct sk_buff *skb)\nnet/core/skbuff.c-317-{\n--\nnet/core/skbuff.c=344=u32 napi_skb_cache_get_bulk(void **skbs, u32 n)\n--\nnet/core/skbuff.c-379-\t\tkasan_mempool_unpoison_object(skbs[i], skbuff_cache_size);\nnet/core/skbuff.c:380:\t\tskbuff_clear(skbs[i]);\nnet/core/skbuff.c-381-\t}\n--\nnet/core/skbuff.c=437=struct sk_buff *slab_build_skb(void *data)\n--\nnet/core/skbuff.c-446-\nnet/core/skbuff.c:447:\tskbuff_clear(skb);\nnet/core/skbuff.c-448-\tdata = __slab_build_skb(data, \u0026size);\n--\nnet/core/skbuff.c=490=struct sk_buff *__build_skb(void *data, unsigned int frag_size)\n--\nnet/core/skbuff.c-498-\nnet/core/skbuff.c:499:\tskbuff_clear(skb);\nnet/core/skbuff.c-500-\t__build_skb_around(skb, data, frag_size);\n--\nnet/core/skbuff.c=552=static struct sk_buff *__napi_build_skb(void *data, unsigned int frag_size)\n--\nnet/core/skbuff.c-559-\nnet/core/skbuff.c:560:\tskbuff_clear(skb);\nnet/core/skbuff.c-561-\t__build_skb_around(skb, data, frag_size);\n--\nnet/core/skbuff.c=674=struct sk_buff *__alloc_skb(unsigned int size, gfp_t gfp_mask,\n--\nnet/core/skbuff.c-707-\t}\nnet/core/skbuff.c:708:\tskbuff_clear(skb);\nnet/core/skbuff.c-709-\n"
}

128/3 2026/09/29 11:10 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 46805
							output: 36
							thoughts: 10
						

Thoughts:
Okay, here's my attempt at summarizing that thought process, keeping in mind the user is an expert:

**Investigating `skbuff_clear`**

Alright, let's take a quick look at `skbuff_clear`. I'm going to start there because it seems like a potential point of interest. I'm probably thinking about memory management, buffer states, or maybe some specific corner case related to packet manipulation. I'm expecting this to be a quick check, likely because I need to understand its behaviour better in the context of a recent debugging session or an optimization I'm considering. I'm hoping I can refresh my memory on the function's internals.



129/3 2026/09/29 11:11 tool read-file
0m Args:
{
  "File": "net/core/skbuff.c",
  "FirstLine": 315,
  "LineCount": 25
}

Results:
{
  "Contents": " 315:\t */\n 316:\tstatic inline void skbuff_clear(struct sk_buff *skb)\n 317:\t{\n 318:\t\t/* Replace memset(skb, 0, offsetof(struct sk_buff, tail))\n 319:\t\t * with two smaller memset(), with a barrier() between them.\n 320:\t\t * This forces the compiler to inline both calls.\n 321:\t\t */\n 322:\t\tBUILD_BUG_ON(offsetof(struct sk_buff, tail) \u003c= 128);\n 323:\t\tmemset(skb, 0, 128);\n 324:\t\tbarrier();\n 325:\t\tmemset((void *)skb + 128, 0, offsetof(struct sk_buff, tail) - 128);\n 326:\t}\n 327:\t\n 328:\t/**\n 329:\t * napi_skb_cache_get_bulk - obtain a number of zeroed skb heads from the cache\n 330:\t * @skbs: pointer to an at least @n-sized array to fill with skb pointers\n 331:\t * @n: number of entries to provide\n 332:\t *\n 333:\t * Tries to obtain @n \u0026sk_buff entries from the NAPI percpu cache and writes\n 334:\t * the pointers into the provided array @skbs. If there are less entries\n 335:\t * available, tries to replenish the cache and bulk-allocates the diff from\n 336:\t * the MM layer if needed.\n 337:\t * The heads are being zeroed with either memset() or %__GFP_ZERO, so they are\n 338:\t * ready for {,__}build_skb_around() and don't have any data buffers attached.\n 339:\t * Must be called *only* from the BH context.\n"
}

130/3 2026/09/29 11:11 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 47484
							output: 33
							thoughts: 29
						

Thoughts:
Here's my attempt at summarizing that thought process, tailored for an expert audience:

**Investigating `sk_buff` Layout**

Okay, so I'm diving into the `sk_buff` structure again, specifically trying to understand the relationship between `tail` and the control block, or `cb`. I'm using `offsetof(struct sk_buff, tail)` as a starting point. That gives me the byte offset of `tail` within the `sk_buff` struct.  Now the question is, how does this relate to the custom data that `cb` is designed to hold? I need to quickly determine where `cb` lives relative to this `tail` pointer, within the overall structure. It's a fundamental part of analyzing packet handling, so I'm going to track down the answer.



131/3 2026/09/29 11:11 tool grepper
0m Args:
{
  "Expression": "cb\\[48\\]",
  "PathPrefix": "include/linux/skbuff.h"
}

Results:
{
  "Output": "include/linux/skbuff.h=886=struct sk_buff {\n--\ninclude/linux/skbuff.h-918-\t */\ninclude/linux/skbuff.h:919:\tchar\t\t\tcb[48] __aligned(8);\ninclude/linux/skbuff.h-920-\n"
}

132/3 2026/09/29 11:11 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 47808
							output: 36
							thoughts: 14
						

Thoughts:
Okay, here's my interpretation of those thoughts, tailored for an expert audience, and delivered as a first-person summary:

**Deconstructing the Relationship: Tail vs. cb**

Alright, I'm taking a moment to mentally map out the current state of affairs. My focus here is on understanding the relative positioning of `tail` in relation to `cb`. This isn't just a casual observation; I'm trying to pinpoint its contextual relevance. "Where is `tail` *relative* to `cb`" - that's the key question. I'm implicitly considering what information I may have regarding these variables and the relationships between them to determine which perspective would be the most efficient to analyze. This could be in a codebase, data structure, or some other system. Knowing this relationship is paramount to correctly interpreting whatever problem at hand is. It's the first step in formulating a plan to address the challenges this relationship introduces. I'm essentially building a mental model of their interaction before diving into specific operations.



133/3 2026/09/29 11:11 tool read-file
0m Args:
{
  "File": "include/linux/skbuff.h",
  "FirstLine": 910,
  "LineCount": 40
}

Results:
{
  "Contents": " 910:\t\t\tktime_t\t\ttstamp;\n 911:\t\t\tu64\t\tskb_mstamp_ns; /* earliest departure time */\n 912:\t\t};\n 913:\t\t/*\n 914:\t\t * This is the control buffer. It is free to use for every\n 915:\t\t * layer. Please put your private variables there. If you\n 916:\t\t * want to keep them across layers you have to do a skb_clone()\n 917:\t\t * first. This is owned by whoever has the skb queued ATM.\n 918:\t\t */\n 919:\t\tchar\t\t\tcb[48] __aligned(8);\n 920:\t\n 921:\t\tunion {\n 922:\t\t\tstruct {\n 923:\t\t\t\tunsigned long\t_skb_refdst;\n 924:\t\t\t\tvoid\t\t(*destructor)(struct sk_buff *skb);\n 925:\t\t\t};\n 926:\t\t\tstruct list_head\ttcp_tsorted_anchor;\n 927:\t#ifdef CONFIG_NET_SOCK_MSG\n 928:\t\t\tunsigned long\t\t_sk_redir;\n 929:\t#endif\n 930:\t\t};\n 931:\t\n 932:\t#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)\n 933:\t\tunsigned long\t\t _nfct;\n 934:\t#endif\n 935:\t\tunsigned int\t\tlen,\n 936:\t\t\t\t\tdata_len;\n 937:\t\t__u16\t\t\tmac_len,\n 938:\t\t\t\t\thdr_len;\n 939:\t\n 940:\t\t/* Following fields are _not_ copied in __copy_skb_header()\n 941:\t\t * Note that queue_mapping is here mostly to fill a hole.\n 942:\t\t */\n 943:\t\t__u16\t\t\tqueue_mapping;\n 944:\t\n 945:\t/* if you move cloned around you also must adapt those constants */\n 946:\t#ifdef __BIG_ENDIAN_BITFIELD\n 947:\t#define CLONED_MASK\t(1 \u003c\u003c 7)\n 948:\t#else\n 949:\t#define CLONED_MASK\t1\n"
}

134/3 2026/09/29 11:11 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 48665
							output: 490
							thoughts: 877
						

Thoughts:
**My Assessment of Potential Uninitialized Memory Issues**

Okay, let's break this down from a kernel security perspective. I'm looking at the initialization and usage of potentially sensitive data related to process IDs (PIDs), particularly where that data might be exposed to user space or used in security-sensitive contexts. The key area is the management of PIDs within `sk_buff` structures, Socket Control Messages (SCMs), and related structures.

First, I see that the `tail` member of `sk_buff` includes the `cb[48]` field within the allocated memory block, and everything up to `tail` gets `memset` to zero during `skb` allocation. This is a very important initial condition.

When an `skb` is allocated, like in `sock_alloc_send_pskb()`, the `UNIXCB(skb).pid[PIDTYPE_TGID]` field, part of the `cb` area, starts at zero, as you would expect. The crucial point is that if credentials are *then* added (e.g., via `unix_maybe_add_creds()`), the `get_task_pids()` function initializes *both* `PIDTYPE_PID` and `PIDTYPE_TGID` within the `UNIXCB(skb).pid` array. I confirm that a subsequent failure in `pidfs_register_pids()` results in `put_pids()` which correctly NULLs them out. That's good defensive programming.

For SCMs, I see a similar pattern. The `scm` struct itself is initialized with `memset(p, 0, sizeof(*p))` in `__scm_send()`. I also see that in `scm_replace_pid()`, `scm->pid[PIDTYPE_TGID]` and `scm->pid[PIDTYPE_PID]` are *both* explicitly written to. Furthermore, `DECLARE_PIDS(..., PIDTYPE_TGID)` means that the PID array explicitly reserves space for indices 0 and 1. This means, index 0 and 1 are always initialized.

Now, let's consider potential leaks to user space through socket options and `copy_to_user`. In `sk_getsockopt_peerpidfd()`, a local `int pidfd` is initialized before being copied. The length check with `min()` makes sure that we don't leak anything extra, and `copy_to_sockptr` is safe. Similarly, in `scm_pidfd_recv()`, the `pidfd` is prepared and only 4 bytes of an initialized `int` are copied via `put_cmsg`.

In the context of core dumps, `DECLARE_PIDS(pid, PIDTYPE_TGID)` is used within the `coredump_params` struct, which is zero-initialized. I see that `task_pids()` initializes both PIDs, and `pidfs_register_pids()` is responsible for registration. The fact that the struct is zero-initialized is important.

Lastly, in `af_bluetooth`, `sk->sk_peer_pid[PIDTYPE_TGID]` is initialized, and `memset` is used in `sock_init_data_uid()`, so the code consistently ensures these fields start initialized. The `SO_PEERPIDFD_THREAD` check for non-Unix sockets returning `-EOPNOTSUPP` is also a good control, preventing accidental disclosure through unsupported socket types.

Based on this analysis, I'm confident that all relevant data structures are properly zero-initialized, and all sensitive data is consistently initialized before use. The explicit writes, length checks, and the use of zero-initialization throughout the code, combined with the calls to `get_task_pids` and `put_pids` strongly suggest there aren't any uninitialized memory leaks or branches on uninitialized memory that KMSAN might catch. Standard KASAN, refcount, or locking tools would be the ones to find issues here, and they would be related to object lifetime and concurrency concerns, not uninitialized memory.

I'm ready to call this "set-results."



135/3 2026/09/29 11:11 tool set-results
0m Args:
{
  "KMSANReasoning": "The patch series introduces thread-specific pidfd support for Unix domain sockets and coredump socket connections (SO_PASSPIDFD_THREAD, SO_PEERPIDFD_THREAD, SCM_PIDFD_THREAD), converting single struct pid pointers to pid arrays via DECLARE_PIDS(..., PIDTYPE_TGID).\n\nAn inspection of the changes and surrounding code confirms that all touched data structures and memory buffers are fully initialized:\n1. struct sock: sk-\u003esk_peer_pid is zeroed in sock_init_data_uid() via memset(), and socket allocation zeroes the struct via sk_alloc(). The new sk_scm_pidfd_thread bitfield is part of the zero-initialized bitfield group.\n2. struct scm_cookie: Zero-initialized with memset() in __scm_send(), unix_destruct_scm(), and other caller wrappers. scm_replace_pid() and unix_skb_to_scm() explicitly initialize both PIDTYPE_TGID and PIDTYPE_PID entries.\n3. sk_buff: UNIXCB(skb) is embedded in skb-\u003ecb, which is zeroed upon allocation in skbuff_clear(). In unix_maybe_add_creds(), get_task_pids() populates both pid elements; on error, put_pids() clears them back to NULL.\n4. struct coredump_params: cprm is initialized in vfs_coredump() via designated initializers (ensuring all unmentioned fields, including cprm.pid, are zeroed).\n5. User copying: sk_getsockopt_peerpidfd() writes a local int pidfd and int len to optval/optlen after pidfd_prepare(); scm_pidfd_recv() writes pidfd via put_cmsg(). No uninitialized struct padding or uninitialized stack bytes are copied to user space.\n\nSince all structures are fully zeroed or initialized prior to use and no uninitialized memory risks or info-leaks are introduced, a dedicated KMSAN fuzzing session is not warranted. Any potential memory safety bugs (such as reference counting or socket locking) are covered by KASAN and standard debuggers.",
  "NeedsKMSAN": false
}

Results:
{
  "KMSANReasoning": "The patch series introduces thread-specific pidfd support for Unix domain sockets and coredump socket connections (SO_PASSPIDFD_THREAD, SO_PEERPIDFD_THREAD, SCM_PIDFD_THREAD), converting single struct pid pointers to pid arrays via DECLARE_PIDS(..., PIDTYPE_TGID).\n\nAn inspection of the changes and surrounding code confirms that all touched data structures and memory buffers are fully initialized:\n1. struct sock: sk-\u003esk_peer_pid is zeroed in sock_init_data_uid() via memset(), and socket allocation zeroes the struct via sk_alloc(). The new sk_scm_pidfd_thread bitfield is part of the zero-initialized bitfield group.\n2. struct scm_cookie: Zero-initialized with memset() in __scm_send(), unix_destruct_scm(), and other caller wrappers. scm_replace_pid() and unix_skb_to_scm() explicitly initialize both PIDTYPE_TGID and PIDTYPE_PID entries.\n3. sk_buff: UNIXCB(skb) is embedded in skb-\u003ecb, which is zeroed upon allocation in skbuff_clear(). In unix_maybe_add_creds(), get_task_pids() populates both pid elements; on error, put_pids() clears them back to NULL.\n4. struct coredump_params: cprm is initialized in vfs_coredump() via designated initializers (ensuring all unmentioned fields, including cprm.pid, are zeroed).\n5. User copying: sk_getsockopt_peerpidfd() writes a local int pidfd and int len to optval/optlen after pidfd_prepare(); scm_pidfd_recv() writes pidfd via put_cmsg(). No uninitialized struct padding or uninitialized stack bytes are copied to user space.\n\nSince all structures are fully zeroed or initialized prior to use and no uninitialized memory risks or info-leaks are introduced, a dedicated KMSAN fuzzing session is not warranted. Any potential memory safety bugs (such as reference counting or socket locking) are covered by KASAN and standard debuggers.",
  "NeedsKMSAN": false
}

LLM Calls Summary:
Total Calls Total Tokens Avg Tokens Total Duration (Seconds) Avg Duration (Seconds)
Tool Calls Summary:
Total Calls Total Duration (Seconds) Avg Duration (Seconds)