net/sock: add WARN_ON(parent->sk) in sock_graft()
authorSowmini Varadhan <sowmini.varadhan@oracle.com>
Thu, 6 Jul 2017 15:15:07 +0000 (08:15 -0700)
committerDavid S. Miller <davem@davemloft.net>
Sat, 8 Jul 2017 10:16:16 +0000 (11:16 +0100)
sock_graft() unilaterally sets up parent->sk based on the
assumption that the existing parent->sk is null. If this
condition is not true, then the existing parent->sk would
be leaked, so add a WARN_ON() to alert callers who may fall
in this category.

Signed-off-by: Sowmini Varadhan <sowmini.varadhan@oracle.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/sock.h

index 48e4d5c38f855433c4e41af9b4ebac6eea8bb754..8c85791fc196c90d0ca52f8a6fadc65cf2faa479 100644 (file)
@@ -1697,6 +1697,7 @@ static inline void sock_orphan(struct sock *sk)
 
 static inline void sock_graft(struct sock *sk, struct socket *parent)
 {
+       WARN_ON(parent->sk);
        write_lock_bh(&sk->sk_callback_lock);
        sk->sk_wq = parent->wq;
        parent->sk = sk;