Skip to content

Commit f8ae3a4

Browse files
elic307imstsirkin
authored andcommitted
vdpa/mlx5: Fix is_index_valid() to refer to features
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 <elic@nvidia.com> Link: https://lore.kernel.org/r/20220111183400.38418-4-elic@nvidia.com Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Reviewed-by: Si-Wei Liu<si-wei.liu@oracle.com> Acked-by: Jason Wang <jasowang@redhat.com>
1 parent 680ab9d commit f8ae3a4

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

drivers/vdpa/mlx5/net/mlx5_vnet.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,14 @@ struct mlx5_vdpa_virtqueue {
133133

134134
static bool is_index_valid(struct mlx5_vdpa_dev *mvdev, u16 idx)
135135
{
136-
if (unlikely(idx > mvdev->max_idx))
137-
return false;
136+
if (!(mvdev->actual_features & BIT_ULL(VIRTIO_NET_F_MQ))) {
137+
if (!(mvdev->actual_features & BIT_ULL(VIRTIO_NET_F_CTRL_VQ)))
138+
return idx < 2;
139+
else
140+
return idx < 3;
141+
}
138142

139-
return true;
143+
return idx <= mvdev->max_idx;
140144
}
141145

142146
struct mlx5_vdpa_net {

0 commit comments

Comments
 (0)