vhost: fix missing device checks

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>
This commit is contained in:
Jerome Jutteau 2015-10-19 11:44:27 +02:00 committed by Thomas Monjalon
parent 2c95f4de6a
commit 6c6373c763
2 changed files with 10 additions and 7 deletions

View 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);

View 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;
}