Skip to content

Commit cd025c1

Browse files
eugpermarmstsirkin
authored andcommitted
vhost: move vdpa group bound check to vhost_vdpa
Remove duplication by consolidating these here. This reduces the posibility of a parent driver missing them. While we're at it, fix a bug in vdpa_sim where a valid ASID can be assigned to a group equal to ngroups, causing an out of bound write. Cc: stable@vger.kernel.org Fixes: bda324f ("vdpasim: control virtqueue support") Acked-by: Jason Wang <jasowang@redhat.com> Signed-off-by: Eugenio Pérez <eperezma@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Message-Id: <20260119143306.1818855-2-eperezma@redhat.com>
1 parent 74bc5f6 commit cd025c1

3 files changed

Lines changed: 1 addition & 10 deletions

File tree

drivers/vdpa/mlx5/net/mlx5_vnet.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3640,9 +3640,6 @@ static int mlx5_set_group_asid(struct vdpa_device *vdev, u32 group,
36403640
struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
36413641
int err = 0;
36423642

3643-
if (group >= MLX5_VDPA_NUMVQ_GROUPS)
3644-
return -EINVAL;
3645-
36463643
mvdev->mres.group2asid[group] = asid;
36473644

36483645
mutex_lock(&mvdev->mres.lock);

drivers/vdpa/vdpa_sim/vdpa_sim.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -606,12 +606,6 @@ static int vdpasim_set_group_asid(struct vdpa_device *vdpa, unsigned int group,
606606
struct vhost_iotlb *iommu;
607607
int i;
608608

609-
if (group > vdpasim->dev_attr.ngroups)
610-
return -EINVAL;
611-
612-
if (asid >= vdpasim->dev_attr.nas)
613-
return -EINVAL;
614-
615609
iommu = &vdpasim->iommu[asid];
616610

617611
mutex_lock(&vdpasim->mutex);

drivers/vhost/vdpa.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd,
680680
case VHOST_VDPA_SET_GROUP_ASID:
681681
if (copy_from_user(&s, argp, sizeof(s)))
682682
return -EFAULT;
683-
if (s.num >= vdpa->nas)
683+
if (idx >= vdpa->ngroups || s.num >= vdpa->nas)
684684
return -EINVAL;
685685
if (!ops->set_group_asid)
686686
return -EOPNOTSUPP;

0 commit comments

Comments
 (0)