net/smc: bound v2 extension offsets and counts in CLC proposal
Subsystems (5)
cover net/smc: bound v2 extension offsets and counts in CLC proposal
5.10.y backport of the CVE-2024-49568 fix (patch 2), requested in the 6.1.y thread:
https://lore.kernel.org/r/[email protected]
5.10.y also lacks 9ab332deb671 (CVE-2024-47408) from the same upstream series; 5.15.y has it since v5.15.176. It goes first: the ism_gid_cnt limit in patch 2 bounds the gidchid[] walk only once smcd_v2_ext itself is inside the receive buffer. The diff is the same as the 5.15.y backport a36364d8d4fab.
Patch 2 has the same diff as the 5.15.y backport posted alongside.
Each commit builds net/smc on v5.10.270, x86_64, CONFIG_SMC=m, W=1 clean. Not runtime-tested.
Guangguan Wang (2):
net/smc: check smcd_v2_ext_offset when receiving proposal msg net/smc: check v2_ext_offset/eid_cnt/ism_gid_cnt when receiving
proposal msg
net/smc/smc_clc.c | 8 +++++++- net/smc/smc_clc.h | 17 +++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/2 net/smc: check smcd_v2_ext_offset when receiving proposal msg
From: Guangguan Wang <[email protected]>
commit 9ab332deb671d8f7e66d82a2ff2b3f715bc3a4ad upstream.
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.
[ jcao: drop the af_smc.c hunk, the !smcd_v2_ext test already there
covers it; result matches the 5.15.y backport a36364d8d4fab ]
--- net/smc/smc_clc.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
net/smc/smc_clc.h +7 -1
@@ -306,9 +306,15 @@ smc_get_clc_v2_ext(struct smc_clc_msg_proposal *prop)static inline struct smc_clc_smcd_v2_extension *smc_get_clc_smcd_v2_ext (struct smc_clc_v2_extension *prop_v2ext) { +u16 max_offset = offsetof(struct smc_clc_msg_proposal_area , pclc_smcd_v2_ext) - + offsetof(struct smc_clc_msg_proposal_area , pclc_v2_ext) - + offsetof(struct smc_clc_v2_extension , hdr) - + offsetofend(struct smc_clnt_opts_area_hdr, smcd_v2_ext_offset); +if (!prop_v2ext)return NULL ; -if (!ntohs (prop_v2ext->hdr.smcd_v2_ext_offset)) +if (!ntohs (prop_v2ext->hdr.smcd_v2_ext_offset) || +ntohs (prop_v2ext->hdr.smcd_v2_ext_offset) > max_offset)return NULL ; return (struct smc_clc_smcd_v2_extension *)
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH 5.10.y 1/2] net/smc: check smcd_v2_ext_offset when receiving proposal msg
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] net/smc: protocol regression in SMCv2 proposal parsing due to static max_offset --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] net/smc: protocol regression in SMCv2 proposal parsing due to static max_offset --
commit 32692cd08a75040e1005cf9b8d09a85a6a7acc74
Author: Guangguan Wang <[email protected]>
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.
net/smc/smc_clc.h smc_get_clc_v2_ext(struct smc_clc_msg_proposal *prop) · line 313
Quoted 13 lines
net/smc/smc_clc.h +5
-0@@ -306,9 +306,15 @@ smc_get_clc_v2_ext(struct smc_clc_msg_proposal *prop)static inline struct smc_clc_smcd_v2_extension *smc_get_clc_smcd_v2_ext (struct smc_clc_v2_extension *prop_v2ext) { +u16 max_offset = offsetof(struct smc_clc_msg_proposal_area , pclc_smcd_v2_ext) - + offsetof(struct smc_clc_msg_proposal_area , pclc_v2_ext) - + offsetof(struct smc_clc_v2_extension , hdr) - + offsetofend(struct smc_clnt_opts_area_hdr, smcd_v2_ext_offset); +
[Severity: High]
Does this static calculation ignore the dynamic size of the flexible user_eids array in struct smc_clc_v2_extension?
By not accounting for the user_eids array, max_offset appears strictly limited to the case where eid_cnt = 0.
net/smc/smc_clc.h smc_get_clc_v2_ext(struct smc_clc_msg_proposal *prop) · line 318
Quoted 6 lines
net/smc/smc_clc.h +2
-1if (!prop_v2ext)return NULL ; -if (!ntohs (prop_v2ext->hdr.smcd_v2_ext_offset)) +if (!ntohs (prop_v2ext->hdr.smcd_v2_ext_offset) || +ntohs (prop_v2ext->hdr.smcd_v2_ext_offset) > max_offset)return NULL ;
[Severity: High]
Will this falsely flag valid offsets as out-of-bounds when the proposal includes user EIDs?
When an untrusted remote peer initiates an SMC-D v2 connection proposing one or more user EIDs (up to SMC_CLC_MAX_UEID), the packet may be correctly sized and well-formed.
However, because max_offset ignores the flexible user_eids array, this check returns NULL and drops the capability, breaking protocol compliance and interoperability with SMCv2 peers that use Enterprise IDs.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH 2/2 net/smc: check v2_ext_offset/eid_cnt/ism_gid_cnt when receiving proposal msg
In reply to Junjie CaoFrom: Guangguan Wang <[email protected]>
commit 7863c9f3d24ba49dbead7e03dfbe40deb5888fdf upstream.
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.
[ jcao: drop the af_smc.c hunk, smc_find_rdma_v2_device_serv() came
with SMC-Rv2 in e49300a6bf62 (v5.16); take SMC_CLC_MAX_UEID from fa0866625543 (v5.16); SMC_MAX_ISM_DEVS is the pre-b40584d14570 name of SMCD_CLC_MAX_V2_GID_ENTRIES ]
--- net/smc/smc_clc.c | 8 +++++++- net/smc/smc_clc.h | 9 ++++++++- 2 files changed, 15 insertions(+), 2 deletions(-)
net/smc/smc_clc.c +7 -1
@@ -47,7 +47,6 @@ static bool smc_clc_msg_prop_valid(struct smc_clc_msg_proposal *pclc)struct smc_clc_msg_hdr *hdr = &pclc->hdr;struct smc_clc_v2_extension *v2_ext; - v2_ext =smc_get_clc_v2_ext (pclc); pclc_prfx =smc_clc_proposal_get_prefix (pclc);if (!pclc_prfx || pclc_prfx->ipv6_prefixes_cnt >SMC_CLC_MAX_V6_PREFIX )
@@ -64,6 +63,13 @@ static bool smc_clc_msg_prop_valid(struct smc_clc_msg_proposal *pclc) sizeof(struct smc_clc_msg_trail))return false; } else { + v2_ext =smc_get_clc_v2_ext (pclc); +if ((hdr->typev2 !=SMC_TYPE_N && + (!v2_ext || v2_ext->hdr.eid_cnt >SMC_CLC_MAX_UEID )) || + (smcd_indicated (hdr->typev2) && + v2_ext->hdr.ism_gid_cnt >SMC_MAX_ISM_DEVS )) +return false; + if (ntohs(hdr->length) != sizeof(*pclc) + sizeof(struct smc_clc_msg_smcd) +
net/smc/smc_clc.h +8 -1
@@ -153,6 +153,7 @@ struct smc_clc_msg_proposal { /* clc proposal message sent by Linux */ }__aligned(4) ;#define SMC_CLC_MAX_V6_PREFIX 8 +#define SMC_CLC_MAX_UEID 8struct smc_clc_msg_proposal_area {struct smc_clc_msg_proposal pclc_base;
@@ -292,8 +293,14 @@ static inline struct smc_clc_v2_extension * smc_get_clc_v2_ext(struct smc_clc_msg_proposal *prop) {struct smc_clc_msg_smcd *prop_smcd =smc_get_clc_msg_smcd (prop); +u16 max_offset; -if (!prop_smcd || !ntohs (prop_smcd->v2_ext_offset)) + max_offset = offsetof(struct smc_clc_msg_proposal_area , pclc_v2_ext) - + offsetof(struct smc_clc_msg_proposal_area , pclc_smcd) - + offsetofend(struct smc_clc_msg_smcd, v2_ext_offset); + +if (!prop_smcd || !ntohs (prop_smcd->v2_ext_offset) || +ntohs (prop_smcd->v2_ext_offset) > max_offset)return NULL ; return (struct smc_clc_v2_extension *)
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH 5.10.y 2/2] net/smc: check v2_ext_offset/eid_cnt/ism_gid_cnt when receiving proposal msg
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 18 lines
From: Guangguan Wang <[email protected]>
commit
7863c9f3d24ba49dbead7e03dfbe40deb5888fdfupstream.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 8c3dca341aea ("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 David S. Miller <[email protected]>
Quoted 5 lines
[ jcao: drop the
af_smc.chunk,smc_find_rdma_v2_device_serv()came
with SMC-Rv2 ine49300a6bf62(v5.16); takeSMC_CLC_MAX_UEIDfromfa0866625543(v5.16);SMC_MAX_ISM_DEVSis the pre-b40584d14570 name ofSMCD_CLC_MAX_V2_GID_ENTRIES]Signed-off-by Junjie Cao <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Quoted 4 lines
5.10.y also lacks
9ab332deb671(CVE-2024-47408) from the same upstream series; 5.15.y has it since v5.15.176. It goes first: theism_gid_cntlimit in patch 2 bounds the gidchid[] walk only oncesmcd_v2_extitself is inside the receive buffer.
Queued the series for 5.10, thanks. The 5.15 half went in alongside it, so the two trees are back in step.
Signature · 2 lines
Thanks, Sasha