Skip to content

Commit

Permalink
vhost-vdpa: protect concurrent access to vhost device iotlb
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
YongjiXie authored and mstsirkin committed Apr 22, 2021
1 parent bc04d93 commit a9d0645
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion drivers/vhost/vdpa.c
Original file line number Diff line number Diff line change
Expand Up @@ -745,9 +745,11 @@ static int vhost_vdpa_process_iotlb_msg(struct vhost_dev *dev,
const struct vdpa_config_ops *ops = vdpa->config;
int r = 0;

mutex_lock(&dev->mutex);

r = vhost_dev_check_owner(dev);
if (r)
return r;
goto unlock;

switch (msg->type) {
case VHOST_IOTLB_UPDATE:
Expand All @@ -768,6 +770,8 @@ static int vhost_vdpa_process_iotlb_msg(struct vhost_dev *dev,
r = -EINVAL;
break;
}
unlock:
mutex_unlock(&dev->mutex);

return r;
}
Expand Down

0 comments on commit a9d0645

Please sign in to comment.