Skip to content

Commit 556f93b

Browse files
qasim-ijazrleon
authored andcommitted
RDMA/mlx5: Handle errors returned from mlx5r_ib_rate()
In function create_ib_ah() the following line attempts to left shift the return value of mlx5r_ib_rate() by 4 and store it in the stat_rate_sl member of av: However the code overlooks the fact that mlx5r_ib_rate() may return -EINVAL if the rate passed to it is less than IB_RATE_2_5_GBPS or greater than IB_RATE_800_GBPS. Because of this, the code may invoke undefined behaviour when shifting a signed negative value when doing "-EINVAL << 4". To fix this check for errors before assigning stat_rate_sl and propagate any error value to the callers. Fixes: c534ffd ("RDMA/mlx5: Fix AH static rate parsing") Signed-off-by: Qasim Ijaz <qasdev00@gmail.com> Link: https://patch.msgid.link/20250304140246.205919-1-qasdev00@gmail.com Reviewed-by: Patrisious Haddad <phaddad@nvidia.com> Signed-off-by: Leon Romanovsky <leon@kernel.org>
1 parent e8e6087 commit 556f93b

File tree

1 file changed

+9
-5
lines changed
  • drivers/infiniband/hw/mlx5

1 file changed

+9
-5
lines changed

drivers/infiniband/hw/mlx5/ah.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,12 @@ static __be16 mlx5_ah_get_udp_sport(const struct mlx5_ib_dev *dev,
5050
return sport;
5151
}
5252

53-
static void create_ib_ah(struct mlx5_ib_dev *dev, struct mlx5_ib_ah *ah,
53+
static int create_ib_ah(struct mlx5_ib_dev *dev, struct mlx5_ib_ah *ah,
5454
struct rdma_ah_init_attr *init_attr)
5555
{
5656
struct rdma_ah_attr *ah_attr = init_attr->ah_attr;
5757
enum ib_gid_type gid_type;
58+
int rate_val;
5859

5960
if (rdma_ah_get_ah_flags(ah_attr) & IB_AH_GRH) {
6061
const struct ib_global_route *grh = rdma_ah_read_grh(ah_attr);
@@ -67,8 +68,10 @@ static void create_ib_ah(struct mlx5_ib_dev *dev, struct mlx5_ib_ah *ah,
6768
ah->av.tclass = grh->traffic_class;
6869
}
6970

70-
ah->av.stat_rate_sl =
71-
(mlx5r_ib_rate(dev, rdma_ah_get_static_rate(ah_attr)) << 4);
71+
rate_val = mlx5r_ib_rate(dev, rdma_ah_get_static_rate(ah_attr));
72+
if (rate_val < 0)
73+
return rate_val;
74+
ah->av.stat_rate_sl = rate_val << 4;
7275

7376
if (ah_attr->type == RDMA_AH_ATTR_TYPE_ROCE) {
7477
if (init_attr->xmit_slave)
@@ -89,6 +92,8 @@ static void create_ib_ah(struct mlx5_ib_dev *dev, struct mlx5_ib_ah *ah,
8992
ah->av.fl_mlid = rdma_ah_get_path_bits(ah_attr) & 0x7f;
9093
ah->av.stat_rate_sl |= (rdma_ah_get_sl(ah_attr) & 0xf);
9194
}
95+
96+
return 0;
9297
}
9398

9499
int mlx5_ib_create_ah(struct ib_ah *ibah, struct rdma_ah_init_attr *init_attr,
@@ -121,8 +126,7 @@ int mlx5_ib_create_ah(struct ib_ah *ibah, struct rdma_ah_init_attr *init_attr,
121126
return err;
122127
}
123128

124-
create_ib_ah(dev, ah, init_attr);
125-
return 0;
129+
return create_ib_ah(dev, ah, init_attr);
126130
}
127131

128132
int mlx5_ib_query_ah(struct ib_ah *ibah, struct rdma_ah_attr *ah_attr)

0 commit comments

Comments
 (0)