Skip to content

Commit

Permalink
RDMA/cma: Remove open coding of overflow checking for private_data_len
Browse files Browse the repository at this point in the history
The existing tests are a little hard to comprehend. Use
check_add_overflow() instead.

Fixes: 04ded16 ("RDMA/cma: Verify private data length")
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Håkon Bugge <[email protected]>
Reviewed-by: Leon Romanovsky <[email protected]>
Signed-off-by: Jason Gunthorpe <[email protected]>
  • Loading branch information
Hakon-Bugge authored and jgunthorpe committed Nov 25, 2021
1 parent 223b4d5 commit 8d0d2b0
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions drivers/infiniband/core/cma.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 8d0d2b0

Please sign in to comment.