[I][PATCH 6/6] net/smc: Ensure correct state of the socket in send path

frank.heimes at canonical.com frank.heimes at canonical.com
Mon Aug 16 07:05:07 UTC 2021


From: Guvenc Gulce <guvenc at linux.ibm.com>

BugLink: https://bugs.launchpad.net/bugs/1853290

When smc_sendmsg() is called before the SMC socket initialization has
completed, smc_tx_sendmsg() will access un-initialized fields of the
SMC socket which results in a null-pointer dereference.
Fix this by checking the socket state first in smc_tx_sendmsg().

Fixes: e0e4b8fa5338 ("net/smc: Add SMC statistics support")
Reported-by: syzbot+5dda108b672b54141857 at syzkaller.appspotmail.com
Reviewed-by: Karsten Graul <kgraul at linux.ibm.com>
Signed-off-by: Guvenc Gulce <guvenc at linux.ibm.com>
Signed-off-by: Karsten Graul <kgraul at linux.ibm.com>
Signed-off-by: David S. Miller <davem at davemloft.net>
(cherry picked from commit 17081633e22d83be928a779fd7acd04b247dec90)
Signed-off-by: Frank Heimes <frank.heimes at canonical.com>
---
 net/smc/smc_tx.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/net/smc/smc_tx.c b/net/smc/smc_tx.c
index 075c4f4b41cf..289025cd545a 100644
--- a/net/smc/smc_tx.c
+++ b/net/smc/smc_tx.c
@@ -154,6 +154,9 @@ int smc_tx_sendmsg(struct smc_sock *smc, struct msghdr *msg, size_t len)
 		goto out_err;
 	}
 
+	if (sk->sk_state == SMC_INIT)
+		return -ENOTCONN;
+
 	if (len > conn->sndbuf_desc->len)
 		SMC_STAT_RMB_TX_SIZE_SMALL(smc, !conn->lnk);
 
@@ -164,8 +167,6 @@ int smc_tx_sendmsg(struct smc_sock *smc, struct msghdr *msg, size_t len)
 		SMC_STAT_INC(smc, urg_data_cnt);
 
 	while (msg_data_left(msg)) {
-		if (sk->sk_state == SMC_INIT)
-			return -ENOTCONN;
 		if (smc->sk.sk_shutdown & SEND_SHUTDOWN ||
 		    (smc->sk.sk_err == ECONNABORTED) ||
 		    conn->killed)
-- 
2.25.1




More information about the kernel-team mailing list