Skip to content

Commit

Permalink
vdpa/mlx5: Fix is_index_valid() to refer to features
Browse files Browse the repository at this point in the history
Make sure the decision whether an index received through a callback is
valid or not consults the negotiated features.

The motivation for this was due to a case encountered where I shut down
the VM. After the reset operation was called features were already
clear, I got get_vq_state() call which caused out array bounds
access since is_index_valid() reported the index value.

So this is more of not hit a bug since the call shouldn't have been made
first place.

Signed-off-by: Eli Cohen <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Michael S. Tsirkin <[email protected]>
Reviewed-by: Si-Wei Liu<[email protected]>
Acked-by: Jason Wang <[email protected]>
  • Loading branch information
elic307i authored and mstsirkin committed Jan 14, 2022
1 parent 680ab9d commit f8ae3a4
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions drivers/vdpa/mlx5/net/mlx5_vnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,14 @@ struct mlx5_vdpa_virtqueue {

static bool is_index_valid(struct mlx5_vdpa_dev *mvdev, u16 idx)
{
if (unlikely(idx > mvdev->max_idx))
return false;
if (!(mvdev->actual_features & BIT_ULL(VIRTIO_NET_F_MQ))) {
if (!(mvdev->actual_features & BIT_ULL(VIRTIO_NET_F_CTRL_VQ)))
return idx < 2;
else
return idx < 3;
}

return true;
return idx <= mvdev->max_idx;
}

struct mlx5_vdpa_net {
Expand Down

0 comments on commit f8ae3a4

Please sign in to comment.