vhost: fix missing device checks
authorJerome Jutteau <jerome.jutteau@outscale.com>
Mon, 19 Oct 2015 09:44:27 +0000 (11:44 +0200)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Wed, 21 Oct 2015 10:21:18 +0000 (12:21 +0200)
virtio-net search for it's device in reset_owner.
The function don't check the return result of get_config_ll_entry.
Using get_config_ll_entry in reset_owner don't show any error when the
device is not found. This patch fix this by using get_device instead
instead of get_config_ll_entry.

In user_get_vring_base, get_device return is not checked and may cause
segfault when device is not found.

Signed-off-by: Jerome Jutteau <jerome.jutteau@outscale.com>
Acked-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
lib/librte_vhost/vhost_user/virtio-net-user.c
lib/librte_vhost/virtio-net.c

index 4689927..e0bc2a4 100644 (file)
@@ -276,6 +276,8 @@ user_get_vring_base(struct vhost_device_ctx ctx,
 {
        struct virtio_net *dev = get_device(ctx);
 
+       if (dev == NULL)
+               return -1;
        /* We have to stop the queue (virtio) if it is running. */
        if (dev->flags & VIRTIO_DEV_RUNNING)
                notify_ops->destroy_device(dev);
index 955a29d..a6ab245 100644 (file)
@@ -398,16 +398,17 @@ set_owner(struct vhost_device_ctx ctx)
 static int
 reset_owner(struct vhost_device_ctx ctx)
 {
-       struct virtio_net_config_ll *ll_dev;
+       struct virtio_net *dev;
        uint64_t device_fh;
 
-       ll_dev = get_config_ll_entry(ctx);
-       device_fh = ll_dev->dev.device_fh;
-
-       cleanup_device(&ll_dev->dev);
-       init_device(&ll_dev->dev);
-       ll_dev->dev.device_fh = device_fh;
+       dev = get_device(ctx);
+       if (dev == NULL)
+               return -1;
 
+       device_fh = dev->device_fh;
+       cleanup_device(dev);
+       init_device(dev);
+       dev->device_fh = device_fh;
        return 0;
 }