Skip to content

Commit 8e94936

Browse files
Aditya PakkiSaeed Mahameed
authored andcommitted
net: mlx5: Add a missing check on idr_find, free buf
idr_find() can return a NULL value to 'flow' which is used without a check. The patch adds a check to avoid potential NULL pointer dereference. In case of mlx5_fpga_sbu_conn_sendmsg() failure, free buf allocated using kzalloc. Fixes: ab412e1 ("net/mlx5: Accel, add TLS rx offload routines") Signed-off-by: Aditya Pakki <[email protected]> Reviewed-by: Yuval Shaia <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent 8998576 commit 8e94936

File tree

1 file changed

+11
-3
lines changed
  • drivers/net/ethernet/mellanox/mlx5/core/fpga

1 file changed

+11
-3
lines changed

drivers/net/ethernet/mellanox/mlx5/core/fpga/tls.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,21 @@ int mlx5_fpga_tls_resync_rx(struct mlx5_core_dev *mdev, u32 handle, u32 seq,
217217
void *cmd;
218218
int ret;
219219

220+
rcu_read_lock();
221+
flow = idr_find(&mdev->fpga->tls->rx_idr, ntohl(handle));
222+
rcu_read_unlock();
223+
224+
if (!flow) {
225+
WARN_ONCE(1, "Received NULL pointer for handle\n");
226+
return -EINVAL;
227+
}
228+
220229
buf = kzalloc(size, GFP_ATOMIC);
221230
if (!buf)
222231
return -ENOMEM;
223232

224233
cmd = (buf + 1);
225234

226-
rcu_read_lock();
227-
flow = idr_find(&mdev->fpga->tls->rx_idr, ntohl(handle));
228-
rcu_read_unlock();
229235
mlx5_fpga_tls_flow_to_cmd(flow, cmd);
230236

231237
MLX5_SET(tls_cmd, cmd, swid, ntohl(handle));
@@ -238,6 +244,8 @@ int mlx5_fpga_tls_resync_rx(struct mlx5_core_dev *mdev, u32 handle, u32 seq,
238244
buf->complete = mlx_tls_kfree_complete;
239245

240246
ret = mlx5_fpga_sbu_conn_sendmsg(mdev->fpga->tls->conn, buf);
247+
if (ret < 0)
248+
kfree(buf);
241249

242250
return ret;
243251
}

0 commit comments

Comments
 (0)