Skip to content

Commit 4836339

Browse files
author
Mete Durlu
committed
net/smc: check iparea_offset and ipv6_prefixes_cnt when receiving proposal msg
JIRA: https://issues.redhat.com/browse/RHEL-73484 CVE: CVE-2024-57791 commit a29e220 Author: Guangguan Wang <guangguan.wang@linux.alibaba.com> Date: Wed Dec 11 17:21:18 2024 +0800 net/smc: check iparea_offset and ipv6_prefixes_cnt when receiving proposal msg 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: e7b7a64 ("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> Signed-off-by: Mete Durlu <mdurlu@redhat.com>
1 parent 1226e1a commit 4836339

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

net/smc/af_smc.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2022,6 +2022,8 @@ static int smc_listen_prfx_check(struct smc_sock *new_smc,
20222022
if (pclc->hdr.typev1 == SMC_TYPE_N)
20232023
return 0;
20242024
pclc_prfx = smc_clc_proposal_get_prefix(pclc);
2025+
if (!pclc_prfx)
2026+
return -EPROTO;
20252027
if (smc_clc_prfx_match(newclcsock, pclc_prfx))
20262028
return SMC_CLC_DECL_DIFFPREFIX;
20272029

@@ -2211,7 +2213,9 @@ static void smc_find_ism_v1_device_serv(struct smc_sock *new_smc,
22112213
int rc = 0;
22122214

22132215
/* check if ISM V1 is available */
2214-
if (!(ini->smcd_version & SMC_V1) || !smcd_indicated(ini->smc_type_v1))
2216+
if (!(ini->smcd_version & SMC_V1) ||
2217+
!smcd_indicated(ini->smc_type_v1) ||
2218+
!pclc_smcd)
22152219
goto not_found;
22162220
ini->is_smcd = true; /* prepare ISM check */
22172221
ini->ism_peer_gid[0].gid = ntohll(pclc_smcd->ism.gid);

net/smc/smc_clc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,10 @@ static bool smc_clc_msg_prop_valid(struct smc_clc_msg_proposal *pclc)
354354

355355
v2_ext = smc_get_clc_v2_ext(pclc);
356356
pclc_prfx = smc_clc_proposal_get_prefix(pclc);
357+
if (!pclc_prfx ||
358+
pclc_prfx->ipv6_prefixes_cnt > SMC_CLC_MAX_V6_PREFIX)
359+
return false;
360+
357361
if (hdr->version == SMC_V1) {
358362
if (hdr->typev1 == SMC_TYPE_N)
359363
return false;

net/smc/smc_clc.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,12 @@ struct smc_clc_msg_decline_v2 { /* clc decline message */
332332
static inline struct smc_clc_msg_proposal_prefix *
333333
smc_clc_proposal_get_prefix(struct smc_clc_msg_proposal *pclc)
334334
{
335+
u16 offset = ntohs(pclc->iparea_offset);
336+
337+
if (offset > sizeof(struct smc_clc_msg_smcd))
338+
return NULL;
335339
return (struct smc_clc_msg_proposal_prefix *)
336-
((u8 *)pclc + sizeof(*pclc) + ntohs(pclc->iparea_offset));
340+
((u8 *)pclc + sizeof(*pclc) + offset);
337341
}
338342

339343
static inline bool smcr_indicated(int smc_type)

0 commit comments

Comments
 (0)