From: Sowmini Varadhan Date: Fri, 28 Aug 2015 00:57:24 +0000 (-0400) Subject: net: sk_clone_lock() should only do get_net() if the parent is not a kernel socket X-Git-Tag: v4.1.12-92~287^2~1 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=86e466b5f6ae62c950fa14c4d500fd50ae622f74;p=users%2Fjedix%2Flinux-maple.git 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: 26abe14379f8 ("net: Modify sk_alloc to not reference count the netns of kernel sockets.") Backport of upstream commit: 8a68173691f036613e3d4e6bf8dc129d4a7bf383 Orabug: 21437445 Acked-by: Eric Dumazet Cc: Eric W. Biederman Signed-off-by: Sowmini Varadhan Signed-off-by: David S. Miller --- diff --git a/net/core/sock.c b/net/core/sock.c index 9074c19dac1f7..60433563c9daa 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -1507,7 +1507,8 @@ struct sock *sk_clone_lock(const struct sock *sk, const gfp_t priority) sock_copy(newsk, sk); /* SANITY */ - get_net(sock_net(newsk)); + if (likely(newsk->sk_net_refcnt)) + get_net(sock_net(newsk)); sk_node_init(&newsk->sk_node); sock_lock_init(newsk); bh_lock_sock(newsk);