Skip to content

Commit 2057f18

Browse files
GuangguanWangNipaLocal
authored andcommitted
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 <[email protected]> Reviewed-by: Wen Gu <[email protected]> Reviewed-by: D. Wythe <[email protected]> Signed-off-by: NipaLocal <nipa@local>
1 parent c0b6ed1 commit 2057f18

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
@@ -2032,6 +2032,8 @@ static int smc_listen_prfx_check(struct smc_sock *new_smc,
20322032
if (pclc->hdr.typev1 == SMC_TYPE_N)
20332033
return 0;
20342034
pclc_prfx = smc_clc_proposal_get_prefix(pclc);
2035+
if (!pclc_prfx)
2036+
return -EPROTO;
20352037
if (smc_clc_prfx_match(newclcsock, pclc_prfx))
20362038
return SMC_CLC_DECL_DIFFPREFIX;
20372039

@@ -2221,7 +2223,9 @@ static void smc_find_ism_v1_device_serv(struct smc_sock *new_smc,
22212223
int rc = 0;
22222224

22232225
/* check if ISM V1 is available */
2224-
if (!(ini->smcd_version & SMC_V1) || !smcd_indicated(ini->smc_type_v1))
2226+
if (!(ini->smcd_version & SMC_V1) ||
2227+
!smcd_indicated(ini->smc_type_v1) ||
2228+
!pclc_smcd)
22252229
goto not_found;
22262230
ini->is_smcd = true; /* prepare ISM check */
22272231
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
@@ -336,8 +336,12 @@ struct smc_clc_msg_decline_v2 { /* clc decline message */
336336
static inline struct smc_clc_msg_proposal_prefix *
337337
smc_clc_proposal_get_prefix(struct smc_clc_msg_proposal *pclc)
338338
{
339+
u16 offset = ntohs(pclc->iparea_offset);
340+
341+
if (offset > sizeof(struct smc_clc_msg_smcd))
342+
return NULL;
339343
return (struct smc_clc_msg_proposal_prefix *)
340-
((u8 *)pclc + sizeof(*pclc) + ntohs(pclc->iparea_offset));
344+
((u8 *)pclc + sizeof(*pclc) + offset);
341345
}
342346

343347
static inline bool smcr_indicated(int smc_type)

0 commit comments

Comments
 (0)