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.
Unified · Split
| @@ -745,9 +745,11 @@ static int vhost_vdpa_process_iotlb_msg(struct vhost_dev *dev, · 744 unmodified lines | ||
| 745 | 745 | const struct vdpa_config_ops *ops = vdpa->config; |
| 746 | 746 | int r = 0; |
| 747 | 747 | |
| 748 | + mutex_lock(&dev->mutex); | |
| 749 | + | |
| 748 | 750 | r = vhost_dev_check_owner(dev); |
| 749 | 751 | if (r) |
| 750 | − return r; | |
| 752 | + goto unlock; | |
| 751 | 753 | |
| 752 | 754 | switch (msg->type) { |
| 753 | 755 | case VHOST_IOTLB_UPDATE: |
| @@ -768,6 +770,8 @@ static int vhost_vdpa_process_iotlb_msg(struct vhost_dev *dev, · 14 unmodified lines | ||
| 768 | 770 | r = -EINVAL; |
| 769 | 771 | break; |
| 770 | 772 | } |
| 773 | +unlock: | |
| 774 | + mutex_unlock(&dev->mutex); | |
| 771 | 775 | |
| 772 | 776 | return r; |
| 773 | 777 | } |