net/smc: move sock lock in smc_ioctl()
authorUrsula Braun <[email protected]>
Wed, 8 Aug 2018 12:13:21 +0000 (14:13 +0200)
committerDavid S. Miller <[email protected]>
Thu, 9 Aug 2018 02:14:22 +0000 (19:14 -0700)
When an SMC socket is connecting it is decided whether fallback to
TCP is needed. To avoid races between connect and ioctl move the
sock lock before the use_fallback check.

Reported-by: [email protected]
Reported-by: [email protected]
Fixes: 1992d99882af ("net/smc: take sock lock in smc_ioctl()")
Signed-off-by: Ursula Braun <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
net/smc/af_smc.c

index 0ee7721afbe58c6a803b536e28ed432e764a27cc..e7de5f282722d5dd41b77affc6bea0a490e3969d 100644 (file)
@@ -1522,12 +1522,16 @@ static int smc_ioctl(struct socket *sock, unsigned int cmd,
 
        smc = smc_sk(sock->sk);
        conn = &smc->conn;
+       lock_sock(&smc->sk);
        if (smc->use_fallback) {
-               if (!smc->clcsock)
+               if (!smc->clcsock) {
+                       release_sock(&smc->sk);
                        return -EBADF;
-               return smc->clcsock->ops->ioctl(smc->clcsock, cmd, arg);
+               }
+               answ = smc->clcsock->ops->ioctl(smc->clcsock, cmd, arg);
+               release_sock(&smc->sk);
+               return answ;
        }
-       lock_sock(&smc->sk);
        switch (cmd) {
        case SIOCINQ: /* same as FIONREAD */
                if (smc->sk.sk_state == SMC_LISTEN) {