]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net/smc: check return value of sock_recvmsg when draining clc data
authorGuangguan Wang <guangguan.wang@linux.alibaba.com>
Wed, 11 Dec 2024 09:21:21 +0000 (17:21 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 9 Jan 2025 12:28:31 +0000 (13:28 +0100)
[ Upstream commit c5b8ee5022a19464783058dc6042e8eefa34e8cd ]

When receiving clc msg, the field length in smc_clc_msg_hdr indicates the
length of msg should be received from network and the value should not be
fully trusted as it is from the network. Once the value of length exceeds
the value of buflen in function smc_clc_wait_msg it may run into deadloop
when trying to drain the remaining data exceeding buflen.

This patch checks the return value of sock_recvmsg when draining data in
case of deadloop in draining.

Fixes: fb4f79264c0f ("net/smc: tolerate future SMCD versions")
Signed-off-by: Guangguan Wang <guangguan.wang@linux.alibaba.com>
Reviewed-by: Wen Gu <guwen@linux.alibaba.com>
Reviewed-by: D. Wythe <alibuda@linux.alibaba.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/smc/smc_clc.c

index 035e8135ea49fd96abcd5419108d08686f22bc9b..52a0ba939c91c9c6169a52940eb4ff1838295fa0 100644 (file)
@@ -427,6 +427,11 @@ int smc_clc_wait_msg(struct smc_sock *smc, void *buf, int buflen,
                                                SMC_CLC_RECV_BUF_LEN : datlen;
                iov_iter_kvec(&msg.msg_iter, READ, &vec, 1, recvlen);
                len = sock_recvmsg(smc->clcsock, &msg, krflags);
+               if (len < recvlen) {
+                       smc->sk.sk_err = EPROTO;
+                       reason_code = -EPROTO;
+                       goto out;
+               }
                datlen -= len;
        }
        if (clcm->type == SMC_CLC_DECLINE) {