Skip to content

Commit 13559c4

Browse files
Guangguan WangNipaLocal
Guangguan Wang
authored and
NipaLocal
committed
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 <[email protected]> Reviewed-by: Wen Gu <[email protected]> Reviewed-by: D. Wythe <[email protected]> Signed-off-by: NipaLocal <nipa@local>
1 parent 2057f18 commit 13559c4

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
@@ -2276,7 +2276,8 @@ static void smc_find_rdma_v2_device_serv(struct smc_sock *new_smc,
22762276
goto not_found;
22772277

22782278
smc_v2_ext = smc_get_clc_v2_ext(pclc);
2279-
if (!smc_clc_match_eid(ini->negotiated_eid, smc_v2_ext, NULL, NULL))
2279+
if (!smc_v2_ext ||
2280+
!smc_clc_match_eid(ini->negotiated_eid, smc_v2_ext, NULL, NULL))
22802281
goto not_found;
22812282

22822283
/* 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
@@ -380,8 +380,14 @@ static inline struct smc_clc_v2_extension *
380380
smc_get_clc_v2_ext(struct smc_clc_msg_proposal *prop)
381381
{
382382
struct smc_clc_msg_smcd *prop_smcd = smc_get_clc_msg_smcd(prop);
383+
u16 max_offset;
383384

384-
if (!prop_smcd || !ntohs(prop_smcd->v2_ext_offset))
385+
max_offset = offsetof(struct smc_clc_msg_proposal_area, pclc_v2_ext) -
386+
offsetof(struct smc_clc_msg_proposal_area, pclc_smcd) -
387+
offsetofend(struct smc_clc_msg_smcd, v2_ext_offset);
388+
389+
if (!prop_smcd || !ntohs(prop_smcd->v2_ext_offset) ||
390+
ntohs(prop_smcd->v2_ext_offset) > max_offset)
385391
return NULL;
386392

387393
return (struct smc_clc_v2_extension *)

0 commit comments

Comments
 (0)