Skip to contentSkip to conversation

net/smc: take sock lock in smc_ioctl()

PATCH Superseded Ursula Braun 2 participants 3 messages Jul 16, 2018

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 net/smc: take sock lock in smc_ioctl()

From: Ursula Braun <[email protected]>

SMC ioctl processing requires the sock lock to work properly in all thinkable scenarios.
Problem has been found with RaceFuzzer and fixes:

   KASAN: null-ptr-deref Read in smc_ioctl
---
 net/smc/af_smc.c | 3 +++
 1 file changed, 3 insertions(+)
net/smc/af_smc.c +3 -0
index 5334157f5065..a4381b38a521 100644
@@ -1524,6 +1524,7 @@ static int smc_ioctl(struct socket *sock, unsigned int cmd,
 			return -EBADF;
 		return smc->clcsock->ops->ioctl(smc->clcsock, cmd, arg);
 	}
+	lock_sock(&smc->sk);
 	switch (cmd) {
 	case SIOCINQ: /* same as FIONREAD */
 		if (smc->sk.sk_state == SMC_LISTEN)
@@ -1573,8 +1574,10 @@ static int smc_ioctl(struct socket *sock, unsigned int cmd,
 		}
 		break;
 	default:
+		release_sock(&smc->sk);
 		return -ENOIOCTLCMD;
 	}
+	release_sock(&smc->sk);
 
 	return put_user(answ, (int __user *)arg);
 }
Signature · 1 line
2.16.4
#1 lore raw
Quoted 19 lines · On Mon, 16 Jul 2018 12:01:01 +0200 Ursula Braun <[email protected]> wrote:

From: Ursula Braun <[email protected]>

SMC ioctl processing requires the sock lock to work properly in all thinkable scenarios.
Problem has been found with RaceFuzzer and fixes:

   KASAN: null-ptr-deref Read in smc_ioctl
---
 net/smc/af_smc.c | 3 +++
 1 file changed, 3 insertions(+)
net/smc/af_smc.c +0 -0
index 5334157f5065..a4381b38a521 100644

net/smc/af_smc.c static int smc_ioctl(struct socket *sock, unsigned int cmd, · line 1530

Quoted 7 lines
net/smc/af_smc.c +1 -0
@@ -1524,6 +1524,7 @@ static int smc_ioctl(struct socket *sock, unsigned int cmd,
 			return -EBADF;
 		return smc->clcsock->ops->ioctl(smc->clcsock, cmd, arg);
 	}
+	lock_sock(&smc->sk);
 	switch (cmd) {
 	case SIOCINQ: /* same as FIONREAD */
 		if (smc->sk.sk_state == SMC_LISTEN)
                        return -EINVAL;

you should also unlock here, and:

        case SIOCOUTQ:
                /* output queue size (not send + not acked) */
                if (smc->sk.sk_state == SMC_LISTEN)
                        return -EINVAL;

here, and:

        case SIOCOUTQNSD:
                /* output queue size (not send only) */
                if (smc->sk.sk_state == SMC_LISTEN)
                        return -EINVAL;

here, and:

        case SIOCATMARK:
                if (smc->sk.sk_state == SMC_LISTEN)
                        return -EINVAL;

here.

Signature · 1 line
Stefano
#2 lore raw
Quoted 46 lines · Stefano Brivio
Quoted 19 lines · On Mon, 16 Jul 2018 12:01:01 +0200 Ursula Braun <[email protected]> wrote:

From: Ursula Braun <[email protected]>

SMC ioctl processing requires the sock lock to work properly in all thinkable scenarios.
Problem has been found with RaceFuzzer and fixes:

   KASAN: null-ptr-deref Read in smc_ioctl
---
 net/smc/af_smc.c | 3 +++
 1 file changed, 3 insertions(+)
net/smc/af_smc.c +0 -0
index 5334157f5065..a4381b38a521 100644

net/smc/af_smc.c static int smc_ioctl(struct socket *sock, unsigned int cmd, · line 1530

Quoted 7 lines
net/smc/af_smc.c +1 -0
@@ -1524,6 +1524,7 @@ static int smc_ioctl(struct socket *sock, unsigned int cmd,
 			return -EBADF;
 		return smc->clcsock->ops->ioctl(smc->clcsock, cmd, arg);
 	}
+	lock_sock(&smc->sk);
 	switch (cmd) {
 	case SIOCINQ: /* same as FIONREAD */
 		if (smc->sk.sk_state == SMC_LISTEN)
                        return -EINVAL;

you should also unlock here, and:

        case SIOCOUTQ:
                /* output queue size (not send + not acked) */
                if (smc->sk.sk_state == SMC_LISTEN)
                        return -EINVAL;

here, and:

        case SIOCOUTQNSD:
                /* output queue size (not send only) */
                if (smc->sk.sk_state == SMC_LISTEN)
                        return -EINVAL;
Quoted 8 lines

here, and:

        case SIOCATMARK:
                if (smc->sk.sk_state == SMC_LISTEN)
                        return -EINVAL;

here.

sorry, my fault! V2 is on its way. Thanks for your hint.