Skip to content

Commit 99d4eab

Browse files
author
Mete Durlu
committed
net/smc: check v2_ext_offset/eid_cnt/ism_gid_cnt when receiving proposal msg
JIRA: https://issues.redhat.com/browse/RHEL-73484 CVE: CVE-2024-57791 commit 7863c9f Author: Guangguan Wang <guangguan.wang@linux.alibaba.com> Date: Wed Dec 11 17:21:19 2024 +0800 net/smc: check v2_ext_offset/eid_cnt/ism_gid_cnt when receiving proposal msg When receiving proposal msg in server, the fields v2_ext_offset/ eid_cnt/ism_gid_cnt in proposal msg are from the remote client and can not be fully trusted. Especially the field v2_ext_offset, once exceed the max value, there has the chance to access wrong address, and crash may happen. This patch checks the fields v2_ext_offset/eid_cnt/ism_gid_cnt before using them. Fixes: 8c3dca3 ("net/smc: build and send V2 CLC proposal") 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 4836339 commit 99d4eab

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

net/smc/af_smc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2266,7 +2266,8 @@ static void smc_find_rdma_v2_device_serv(struct smc_sock *new_smc,
22662266
goto not_found;
22672267

22682268
smc_v2_ext = smc_get_clc_v2_ext(pclc);
2269-
if (!smc_clc_match_eid(ini->negotiated_eid, smc_v2_ext, NULL, NULL))
2269+
if (!smc_v2_ext ||
2270+
!smc_clc_match_eid(ini->negotiated_eid, smc_v2_ext, NULL, NULL))
22702271
goto not_found;
22712272

22722273
/* prepare RDMA check */

net/smc/smc_clc.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,6 @@ static bool smc_clc_msg_prop_valid(struct smc_clc_msg_proposal *pclc)
352352
struct smc_clc_msg_hdr *hdr = &pclc->hdr;
353353
struct smc_clc_v2_extension *v2_ext;
354354

355-
v2_ext = smc_get_clc_v2_ext(pclc);
356355
pclc_prfx = smc_clc_proposal_get_prefix(pclc);
357356
if (!pclc_prfx ||
358357
pclc_prfx->ipv6_prefixes_cnt > SMC_CLC_MAX_V6_PREFIX)
@@ -369,6 +368,13 @@ static bool smc_clc_msg_prop_valid(struct smc_clc_msg_proposal *pclc)
369368
sizeof(struct smc_clc_msg_trail))
370369
return false;
371370
} else {
371+
v2_ext = smc_get_clc_v2_ext(pclc);
372+
if ((hdr->typev2 != SMC_TYPE_N &&
373+
(!v2_ext || v2_ext->hdr.eid_cnt > SMC_CLC_MAX_UEID)) ||
374+
(smcd_indicated(hdr->typev2) &&
375+
v2_ext->hdr.ism_gid_cnt > SMCD_CLC_MAX_V2_GID_ENTRIES))
376+
return false;
377+
372378
if (ntohs(hdr->length) !=
373379
sizeof(*pclc) +
374380
sizeof(struct smc_clc_msg_smcd) +

net/smc/smc_clc.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,14 @@ static inline struct smc_clc_v2_extension *
376376
smc_get_clc_v2_ext(struct smc_clc_msg_proposal *prop)
377377
{
378378
struct smc_clc_msg_smcd *prop_smcd = smc_get_clc_msg_smcd(prop);
379+
u16 max_offset;
379380

380-
if (!prop_smcd || !ntohs(prop_smcd->v2_ext_offset))
381+
max_offset = offsetof(struct smc_clc_msg_proposal_area, pclc_v2_ext) -
382+
offsetof(struct smc_clc_msg_proposal_area, pclc_smcd) -
383+
offsetofend(struct smc_clc_msg_smcd, v2_ext_offset);
384+
385+
if (!prop_smcd || !ntohs(prop_smcd->v2_ext_offset) ||
386+
ntohs(prop_smcd->v2_ext_offset) > max_offset)
381387
return NULL;
382388

383389
return (struct smc_clc_v2_extension *)

0 commit comments

Comments
 (0)