Skip to contentSkip to conversation

RDMA/cma: Remove open coding of overflow checking for private_data_len

PATCH Applied Håkon Bugge 3 participants 3 messages Nov 23, 2021 – Nov 25, 2021 InfiniBand

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 RDMA/cma: Remove open coding of overflow checking for private_data_len

The existing tests are a little hard to comprehend. Use check_add_overflow() instead.

Fixes 04ded1672402 ("RDMA/cma: Verify private data length")

---

v1 -> v2:

* Also fixed same issue in cma_resolve_ib_udp() as pointed out by Leon

---
 drivers/infiniband/core/cma.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/infiniband/core/cma.c +2 -4
index 835ac54..8a98aa9 100644
@@ -4033,8 +4033,7 @@ static int cma_resolve_ib_udp(struct rdma_id_private *id_priv,
 
 	memset(&req, 0, sizeof req);
 	offset = cma_user_data_offset(id_priv);
-	req.private_data_len = offset + conn_param->private_data_len;
-	if (req.private_data_len < conn_param->private_data_len)
+	if (check_add_overflow(offset, conn_param->private_data_len, &req.private_data_len))
 		return -EINVAL;
 
 	if (req.private_data_len) {
@@ -4093,8 +4092,7 @@ static int cma_connect_ib(struct rdma_id_private *id_priv,
 
 	memset(&req, 0, sizeof req);
 	offset = cma_user_data_offset(id_priv);
-	req.private_data_len = offset + conn_param->private_data_len;
-	if (req.private_data_len < conn_param->private_data_len)
+	if (check_add_overflow(offset, conn_param->private_data_len, &req.private_data_len))
 		return -EINVAL;
 
 	if (req.private_data_len) {
Signature · 1 line
1.8.3.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 8 lines · Håkon Bugge

The existing tests are a little hard to comprehend. Use check_add_overflow() instead.

Fixes 04ded1672402 ("RDMA/cma: Verify private data length")

---

Quoted 8 lines

v1 -> v2:

* Also fixed same issue in cma_resolve_ib_udp() as pointed out by Leon

---
 drivers/infiniband/core/cma.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Thanks,

maintainer Applied
#2 lore raw
In reply to Håkon Bugge
Quoted 8 lines · Håkon Bugge

The existing tests are a little hard to comprehend. Use check_add_overflow() instead.

Fixes 04ded1672402 ("RDMA/cma: Verify private data length")

---

Quoted 7 lines

v1 -> v2:

* Also fixed same issue in cma_resolve_ib_udp() as pointed out by Leon

---
 drivers/infiniband/core/cma.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Applied to for-next, thanks

Jason