]> www.infradead.org Git - users/willy/pagecache.git/commitdiff
net/smc: check iparea_offset and ipv6_prefixes_cnt when receiving proposal msg
authorGuangguan Wang <guangguan.wang@linux.alibaba.com>
Wed, 11 Dec 2024 09:21:18 +0000 (17:21 +0800)
committerDavid S. Miller <davem@davemloft.net>
Sun, 15 Dec 2024 12:34:59 +0000 (12:34 +0000)
When receiving proposal msg in server, the field iparea_offset
and the field ipv6_prefixes_cnt in proposal msg are from the
remote client and can not be fully trusted. Especially the
field iparea_offset, once exceed the max value, there has the
chance to access wrong address, and crash may happen.

This patch checks iparea_offset and ipv6_prefixes_cnt before using them.

Fixes: e7b7a64a8493 ("smc: support variable CLC proposal messages")
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>
net/smc/af_smc.c
net/smc/smc_clc.c
net/smc/smc_clc.h

index 92448f2c362cb76ae1bb785c074bc2492d900f80..9a74c9693f09ef19a4086918781b8d1a91e21775 100644 (file)
@@ -2032,6 +2032,8 @@ static int smc_listen_prfx_check(struct smc_sock *new_smc,
        if (pclc->hdr.typev1 == SMC_TYPE_N)
                return 0;
        pclc_prfx = smc_clc_proposal_get_prefix(pclc);
+       if (!pclc_prfx)
+               return -EPROTO;
        if (smc_clc_prfx_match(newclcsock, pclc_prfx))
                return SMC_CLC_DECL_DIFFPREFIX;
 
@@ -2221,7 +2223,9 @@ static void smc_find_ism_v1_device_serv(struct smc_sock *new_smc,
        int rc = 0;
 
        /* check if ISM V1 is available */
-       if (!(ini->smcd_version & SMC_V1) || !smcd_indicated(ini->smc_type_v1))
+       if (!(ini->smcd_version & SMC_V1) ||
+           !smcd_indicated(ini->smc_type_v1) ||
+           !pclc_smcd)
                goto not_found;
        ini->is_smcd = true; /* prepare ISM check */
        ini->ism_peer_gid[0].gid = ntohll(pclc_smcd->ism.gid);
index 33fa787c28ebb2f63e4b9c163ff357e24dab9079..66a43b97eede025685e60e2e28e3534c07993942 100644 (file)
@@ -354,6 +354,10 @@ static bool smc_clc_msg_prop_valid(struct smc_clc_msg_proposal *pclc)
 
        v2_ext = smc_get_clc_v2_ext(pclc);
        pclc_prfx = smc_clc_proposal_get_prefix(pclc);
+       if (!pclc_prfx ||
+           pclc_prfx->ipv6_prefixes_cnt > SMC_CLC_MAX_V6_PREFIX)
+               return false;
+
        if (hdr->version == SMC_V1) {
                if (hdr->typev1 == SMC_TYPE_N)
                        return false;
index 5fd6f5b8ef034674a1b084f696b43d371530392b..ac8de6a177fac6660b24bce785a8a9fe34796aba 100644 (file)
@@ -336,8 +336,12 @@ struct smc_clc_msg_decline_v2 {    /* clc decline message */
 static inline struct smc_clc_msg_proposal_prefix *
 smc_clc_proposal_get_prefix(struct smc_clc_msg_proposal *pclc)
 {
+       u16 offset = ntohs(pclc->iparea_offset);
+
+       if (offset > sizeof(struct smc_clc_msg_smcd))
+               return NULL;
        return (struct smc_clc_msg_proposal_prefix *)
-              ((u8 *)pclc + sizeof(*pclc) + ntohs(pclc->iparea_offset));
+              ((u8 *)pclc + sizeof(*pclc) + offset);
 }
 
 static inline bool smcr_indicated(int smc_type)