Skip to contentSkip to conversation

net/smc: take sock lock in smc_ioctl()

PATCH In review Ursula Braun 3 participants 3 messages Jul 16, 2018

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 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 | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
net/smc/af_smc.c +15 -4
index 5334157f5065..c12a7fc18f56 100644
@@ -1524,10 +1524,13 @@ 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)
+		if (smc->sk.sk_state == SMC_LISTEN) {
+			release_sock(&smc->sk);
 			return -EINVAL;
+		}
 		if (smc->sk.sk_state == SMC_INIT ||
 		    smc->sk.sk_state == SMC_CLOSED)
 			answ = 0;
@@ -1536,8 +1539,10 @@ static int smc_ioctl(struct socket *sock, unsigned int cmd,
 		break;
 	case SIOCOUTQ:
 		/* output queue size (not send + not acked) */
-		if (smc->sk.sk_state == SMC_LISTEN)
+		if (smc->sk.sk_state == SMC_LISTEN) {
+			release_sock(&smc->sk);
 			return -EINVAL;
+		}
 		if (smc->sk.sk_state == SMC_INIT ||
 		    smc->sk.sk_state == SMC_CLOSED)
 			answ = 0;
@@ -1547,8 +1552,10 @@ static int smc_ioctl(struct socket *sock, unsigned int cmd,
 		break;
 	case SIOCOUTQNSD:
 		/* output queue size (not send only) */
-		if (smc->sk.sk_state == SMC_LISTEN)
+		if (smc->sk.sk_state == SMC_LISTEN) {
+			release_sock(&smc->sk);
 			return -EINVAL;
+		}
 		if (smc->sk.sk_state == SMC_INIT ||
 		    smc->sk.sk_state == SMC_CLOSED)
 			answ = 0;
@@ -1556,8 +1563,10 @@ static int smc_ioctl(struct socket *sock, unsigned int cmd,
 			answ = smc_tx_prepared_sends(&smc->conn);
 		break;
 	case SIOCATMARK:
-		if (smc->sk.sk_state == SMC_LISTEN)
+		if (smc->sk.sk_state == SMC_LISTEN) {
+			release_sock(&smc->sk);
 			return -EINVAL;
+		}
 		if (smc->sk.sk_state == SMC_INIT ||
 		    smc->sk.sk_state == SMC_CLOSED) {
 			answ = 0;
@@ -1573,8 +1582,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
Reviewed-by on v2 1/1
#1 lore raw
Quoted 10 lines · On Mon, 16 Jul 2018 13:56:52 +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
Signature · 1 line
Stefano
maintainer
#2 lore raw
In reply to Ursula Braun

From: Ursula Braun <[email protected]>
Date: Mon, 16 Jul 2018 13:56:52 +0200

Quoted 10 lines

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

Applied and queued up for -stable.