l2tp: fix racy SOCK_ZAPPED flag check in l2tp_ip{,6}_bind()
[firefly-linux-kernel-4.4.55.git] / net / l2tp / l2tp_ip6.c
index 9ee4ddb6b3973899995e6e3f5766f7e210f90370..3c4f867d3633144f38c2ddc5783dd0fac23832f8 100644 (file)
@@ -266,8 +266,6 @@ static int l2tp_ip6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
        int addr_type;
        int err;
 
-       if (!sock_flag(sk, SOCK_ZAPPED))
-               return -EINVAL;
        if (addr->l2tp_family != AF_INET6)
                return -EINVAL;
        if (addr_len < sizeof(*addr))
@@ -293,6 +291,9 @@ static int l2tp_ip6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
        lock_sock(sk);
 
        err = -EINVAL;
+       if (!sock_flag(sk, SOCK_ZAPPED))
+               goto out_unlock;
+
        if (sk->sk_state != TCP_CLOSE)
                goto out_unlock;