diff options
author | Sowmini Varadhan <sowmini.varadhan@oracle.com> | 2015-07-30 09:50:36 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-07-30 18:59:12 -0400 |
commit | 8a68173691f036613e3d4e6bf8dc129d4a7bf383 (patch) | |
tree | adc6484dea873eb45bb1ed01c4f63676a8bf40f7 /net/core/sock.c | |
parent | 28e6b67f0b292f557468c139085303b15f1a678f (diff) |
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.")
Acked-by: Eric Dumazet <edumazet@google.com>
Cc: Eric W. Biederman <ebiederm@xmission.com>
Signed-off-by: Sowmini Varadhan <sowmini.varadhan@oracle.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core/sock.c')
-rw-r--r-- | net/core/sock.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/net/core/sock.c b/net/core/sock.c index 8a14f1285fc4..193901d09757 100644 --- a/net/core/sock.c +++ b/net/core/sock.c | |||
@@ -1497,7 +1497,8 @@ struct sock *sk_clone_lock(const struct sock *sk, const gfp_t priority) | |||
1497 | sock_copy(newsk, sk); | 1497 | sock_copy(newsk, sk); |
1498 | 1498 | ||
1499 | /* SANITY */ | 1499 | /* SANITY */ |
1500 | get_net(sock_net(newsk)); | 1500 | if (likely(newsk->sk_net_refcnt)) |
1501 | get_net(sock_net(newsk)); | ||
1501 | sk_node_init(&newsk->sk_node); | 1502 | sk_node_init(&newsk->sk_node); |
1502 | sock_lock_init(newsk); | 1503 | sock_lock_init(newsk); |
1503 | bh_lock_sock(newsk); | 1504 | bh_lock_sock(newsk); |