Skip to content

Commit c88b57e

Browse files
Guangguan WangNipaLocal
Guangguan Wang
authored and
NipaLocal
committed
net/smc: check smcd_v2_ext_offset when receiving proposal msg
When receiving proposal msg in server, the field smcd_v2_ext_offset in proposal msg is from the remote client and can not be fully trusted. Once the value of smcd_v2_ext_offset exceed the max value, there has the chance to access wrong address, and crash may happen. This patch checks the value of smcd_v2_ext_offset before using it. Fixes: 5c21c4c ("net/smc: determine accepted ISM devices") 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 390f9a1 commit c88b57e

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

net/smc/af_smc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2147,6 +2147,8 @@ static void smc_find_ism_v2_device_serv(struct smc_sock *new_smc,
21472147
pclc_smcd = smc_get_clc_msg_smcd(pclc);
21482148
smc_v2_ext = smc_get_clc_v2_ext(pclc);
21492149
smcd_v2_ext = smc_get_clc_smcd_v2_ext(smc_v2_ext);
2150+
if (!pclc_smcd || !smc_v2_ext || !smcd_v2_ext)
2151+
goto not_found;
21502152

21512153
mutex_lock(&smcd_dev_list.mutex);
21522154
if (pclc_smcd->ism.chid) {

net/smc/smc_clc.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,15 @@ smc_get_clc_v2_ext(struct smc_clc_msg_proposal *prop)
400400
static inline struct smc_clc_smcd_v2_extension *
401401
smc_get_clc_smcd_v2_ext(struct smc_clc_v2_extension *prop_v2ext)
402402
{
403+
u16 max_offset = offsetof(struct smc_clc_msg_proposal_area, pclc_smcd_v2_ext) -
404+
offsetof(struct smc_clc_msg_proposal_area, pclc_v2_ext) -
405+
offsetof(struct smc_clc_v2_extension, hdr) -
406+
offsetofend(struct smc_clnt_opts_area_hdr, smcd_v2_ext_offset);
407+
403408
if (!prop_v2ext)
404409
return NULL;
405-
if (!ntohs(prop_v2ext->hdr.smcd_v2_ext_offset))
410+
if (!ntohs(prop_v2ext->hdr.smcd_v2_ext_offset) ||
411+
ntohs(prop_v2ext->hdr.smcd_v2_ext_offset) > max_offset)
406412
return NULL;
407413

408414
return (struct smc_clc_smcd_v2_extension *)

0 commit comments

Comments
 (0)