Skip to content

Commit 8a68173

Browse files
sowminivdavem330
authored andcommitted
net: sk_clone_lock() should only do get_net() if the parent is not a kernel socket
The newsk returned by sk_clone_lock should hold a get_net() reference if, and only if, the parent is not a kernel socket (making this similar to sk_alloc()). E.g,. for the SYN_RECV path, tcp_v4_syn_recv_sock->..inet_csk_clone_lock sets up the syn_recv newsk from sk_clone_lock. When the parent (listen) socket is a kernel socket (defined in sk_alloc() as having sk_net_refcnt == 0), then the newsk should also have a 0 sk_net_refcnt and should not hold a get_net() reference. Fixes: 26abe14 ("net: Modify sk_alloc to not reference count the netns of kernel sockets.") Acked-by: Eric Dumazet <[email protected]> Cc: Eric W. Biederman <[email protected]> Signed-off-by: Sowmini Varadhan <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 28e6b67 commit 8a68173

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

net/core/sock.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1497,7 +1497,8 @@ struct sock *sk_clone_lock(const struct sock *sk, const gfp_t priority)
14971497
sock_copy(newsk, sk);
14981498

14991499
/* SANITY */
1500-
get_net(sock_net(newsk));
1500+
if (likely(newsk->sk_net_refcnt))
1501+
get_net(sock_net(newsk));
15011502
sk_node_init(&newsk->sk_node);
15021503
sock_lock_init(newsk);
15031504
bh_lock_sock(newsk);

0 commit comments

Comments
 (0)