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@vger.kernel.org Signed-off-by: Henry Martin Reviewed-by: Eric Dumazet --- v1 -> v2: - drop the inline comment, the changelog already explains it - use [PATCH net] in the subject, as requested net/core/sock.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/core/sock.c b/net/core/sock.c index ad414878dc5b..ebc83a466d91 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -2545,6 +2545,7 @@ struct sock *sk_clone(const struct sock *sk, const gfp_t priority, sk_node_init(&newsk->sk_node); sock_lock_init(newsk); + spin_lock_init(&newsk->sk_peer_lock); if (lock) bh_lock_sock(newsk); -- 2.43.7