[net,2/2] vhost: do not try to access device IOTLB when not initialized
diff mbox series

Message ID 1516699646-7321-2-git-send-email-jasowang@redhat.com
State New, archived
Headers show
Series
  • [net,1/2] vhost: use mutex_lock_nested() in vhost_dev_lock_vqs()
Related show

Commit Message

Jason Wang Jan. 23, 2018, 9:27 a.m. UTC
The code will try to access dev->iotlb when processing
VHOST_IOTLB_INVALIDATE even if it was not initialized which may lead
to NULL pointer dereference. Fixes this by check dev->iotlb before.

Fixes: 6b1e6cc7855b0 ("vhost: new device IOTLB API")
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 drivers/vhost/vhost.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Michael S. Tsirkin Jan. 23, 2018, 3:58 p.m. UTC | #1
On Tue, Jan 23, 2018 at 05:27:26PM +0800, Jason Wang wrote:
> The code will try to access dev->iotlb when processing
> VHOST_IOTLB_INVALIDATE even if it was not initialized which may lead
> to NULL pointer dereference. Fixes this by check dev->iotlb before.
> 
> Fixes: 6b1e6cc7855b0 ("vhost: new device IOTLB API")
> Signed-off-by: Jason Wang <jasowang@redhat.com>

Acked-by: Michael S. Tsirkin <mst@redhat.com>

> ---
>  drivers/vhost/vhost.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
> index 549771a..5727b18 100644
> --- a/drivers/vhost/vhost.c
> +++ b/drivers/vhost/vhost.c
> @@ -1015,6 +1015,10 @@ static int vhost_process_iotlb_msg(struct vhost_dev *dev,
>  		vhost_iotlb_notify_vq(dev, msg);
>  		break;
>  	case VHOST_IOTLB_INVALIDATE:
> +		if (!dev->iotlb) {
> +			ret = -EFAULT;
> +			break;
> +		}
>  		vhost_vq_meta_reset(dev);
>  		vhost_del_umem_range(dev->iotlb, msg->iova,
>  				     msg->iova + msg->size - 1);
> -- 
> 2.7.4

Patch
diff mbox series

diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index 549771a..5727b18 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -1015,6 +1015,10 @@  static int vhost_process_iotlb_msg(struct vhost_dev *dev,
 		vhost_iotlb_notify_vq(dev, msg);
 		break;
 	case VHOST_IOTLB_INVALIDATE:
+		if (!dev->iotlb) {
+			ret = -EFAULT;
+			break;
+		}
 		vhost_vq_meta_reset(dev);
 		vhost_del_umem_range(dev->iotlb, msg->iova,
 				     msg->iova + msg->size - 1);