net: initialize sk_peer_lock in cloned sockets
Subsystems (4)
PATCH 1/1 net: initialize sk_peer_lock in cloned sockets
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.
---
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(+)
net/core/sock.c +1 -0
@@ -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);
Signature · 1 line
2.43.7
[email protected]
AI reviewThis is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
Hi!
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
- Whether the issue was actually triggered, or is only theoretical (e.g. found by LLM and not proven at runtime). If it was triggered please include the symptoms, like the stack trace or kernel messages.
Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include the relevant info in the cover letter or commit messages.
Signature · 2 lines
The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.
Quoted 11 lines · Henry Martin
sock_copy()clones a struct sock with two memcpys that both includesk_peer_lock.sk_clone()re-initializessk_lock, but nothing resetssk_peer_lock, so a clone created while the parent'ssk_peer_lockis held inherits the lock in the locked state.The first
getsockopt(SO_PEERCRED)on such a child spins forever inqueued_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 ofsynchronize_rcu(), such asexpand_files()fromaccept(), hang.
Quoted 8 lines
Initialize
sk_peer_lockexplicitly 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")Signed-off-by Henry Martin <[email protected]>Reviewed-by Eric Dumazet <[email protected]>
As Eric mentioned in v1, restricting SO_PEERCRED etc to AF_UNIX and AF_BLUETOOTH makes more sense.
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 5 lines · On Wed, 18 Nov 2026 18:17:52 +0800 you wrote:
sock_copy()clones a struct sock with two memcpys that both includesk_peer_lock.sk_clone()re-initializessk_lock, but nothing resetssk_peer_lock, so a clone created while the parent'ssk_peer_lockis held inherits the lock in the locked state.
Quoted 7 lines
The first
getsockopt(SO_PEERCRED)on such a child spins forever inqueued_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 ofsynchronize_rcu(), such asexpand_files()fromaccept(), hang.[...]
Here is the summary with links:
- [net] net: initialize sk_peer_lock in cloned sockets
https://git.kernel.org/netdev/net/c/ff73a2bb558f
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html