From: Jerome Jutteau Date: Mon, 19 Oct 2015 09:44:27 +0000 (+0200) Subject: vhost: fix missing device checks X-Git-Tag: spdx-start~8375 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=6c6373c763748ca28805f215c3f646e127a7cf8a;p=dpdk.git 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 Acked-by: Yuanhan Liu --- diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.c b/lib/librte_vhost/vhost_user/virtio-net-user.c index 46899271d3..e0bc2a4ff4 100644 --- a/lib/librte_vhost/vhost_user/virtio-net-user.c +++ b/lib/librte_vhost/vhost_user/virtio-net-user.c @@ -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); diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c index 955a29d79b..a6ab2452b4 100644 --- a/lib/librte_vhost/virtio-net.c +++ b/lib/librte_vhost/virtio-net.c @@ -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; }