Re: [PATCH net] net: initialize sk_peer_lock in cloned sockets

From: Kuniyuki Iwashima

Date: Sat Nov 21 2026 - 13:39:20 EST


On Wed, 18 Nov 2026 18:17:52 +0800, Henry Martin wrote:
> sock_copy() clones a struct sock with two memcpys that both include
> sk_peer_lock. sk_clone() re-initializes sk_lock, but nothing resets
> sk_peer_lock, so a clone created while the parent's sk_peer_lock is held
> inherits the lock in the locked state.
>
> The first getsockopt(SO_PEERCRED) on such a child spins forever in
> queued_spin_lock_slowpath(). spin_lock() disables preemption, so the
> task never schedules and its CPU stops reporting quiescent states; RCU
> grace periods then stop and callers of synchronize_rcu(), such as
> expand_files() from accept(), hang.
>
> Initialize sk_peer_lock explicitly for the clone.
>
> This issue was discovered by Tencent CodeBuddy Security.
>
> Fixes: 35306eb23814 ("af_unix: fix races in sk_peer_pid and sk_peer_cred accesses")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Henry Martin <bsdhenrymartin@xxxxxxxxx>
> Reviewed-by: Eric Dumazet <edumazet@xxxxxxxxxx>

Reviewed-by: Kuniyuki Iwashima <kuniyu@xxxxxxxxxx>

As Eric mentioned in v1, restricting SO_PEERCRED etc to AF_UNIX
and AF_BLUETOOTH makes more sense.