Skip to content

Commit a9d0645

Browse files
YongjiXiemstsirkin
authored andcommitted
vhost-vdpa: protect concurrent access to vhost device iotlb
Protect vhost device iotlb by vhost_dev->mutex. Otherwise, it might cause corruption of the list and interval tree in struct vhost_iotlb if userspace sends the VHOST_IOTLB_MSG_V2 message concurrently. Fixes: 4c8cf31("vhost: introduce vDPA-based backend") Cc: stable@vger.kernel.org Signed-off-by: Xie Yongji <xieyongji@bytedance.com> Acked-by: Jason Wang <jasowang@redhat.com> Reviewed-by: Stefano Garzarella <sgarzare@redhat.com> Link: https://lore.kernel.org/r/20210412095512.178-1-xieyongji@bytedance.com Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent bc04d93 commit a9d0645

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

drivers/vhost/vdpa.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,9 +745,11 @@ static int vhost_vdpa_process_iotlb_msg(struct vhost_dev *dev,
745745
const struct vdpa_config_ops *ops = vdpa->config;
746746
int r = 0;
747747

748+
mutex_lock(&dev->mutex);
749+
748750
r = vhost_dev_check_owner(dev);
749751
if (r)
750-
return r;
752+
goto unlock;
751753

752754
switch (msg->type) {
753755
case VHOST_IOTLB_UPDATE:
@@ -768,6 +770,8 @@ static int vhost_vdpa_process_iotlb_msg(struct vhost_dev *dev,
768770
r = -EINVAL;
769771
break;
770772
}
773+
unlock:
774+
mutex_unlock(&dev->mutex);
771775

772776
return r;
773777
}

0 commit comments

Comments
 (0)