Skip to content

Commit 1708163

Browse files
guvencdavem330
authored andcommitted
net/smc: Ensure correct state of the socket in send path
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: e0e4b8f ("net/smc: Add SMC statistics support") Reported-by: [email protected] Reviewed-by: Karsten Graul <[email protected]> Signed-off-by: Guvenc Gulce <[email protected]> Signed-off-by: Karsten Graul <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 4e3db44 commit 1708163

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

net/smc/smc_tx.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ int smc_tx_sendmsg(struct smc_sock *smc, struct msghdr *msg, size_t len)
154154
goto out_err;
155155
}
156156

157+
if (sk->sk_state == SMC_INIT)
158+
return -ENOTCONN;
159+
157160
if (len > conn->sndbuf_desc->len)
158161
SMC_STAT_RMB_TX_SIZE_SMALL(smc, !conn->lnk);
159162

@@ -164,8 +167,6 @@ int smc_tx_sendmsg(struct smc_sock *smc, struct msghdr *msg, size_t len)
164167
SMC_STAT_INC(smc, urg_data_cnt);
165168

166169
while (msg_data_left(msg)) {
167-
if (sk->sk_state == SMC_INIT)
168-
return -ENOTCONN;
169170
if (smc->sk.sk_shutdown & SEND_SHUTDOWN ||
170171
(smc->sk.sk_err == ECONNABORTED) ||
171172
conn->killed)

0 commit comments

Comments
 (0)