From: Maxime Coquelin Date: Tue, 27 Nov 2018 09:54:51 +0000 (+0100) Subject: vhost: fix crash after mmap failure X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=cf14478d775cadbaed4f5aa96e3812b44a2383c1;p=dpdk.git vhost: fix crash after mmap failure If mmap() call fails in vhost_user_set_mem_table, dev->mem is set to NULL. If later, qva_to_vva() is called, a segfault occurs. Fixes: 8f972312b8f4 ("vhost: support vhost-user") Cc: stable@dpdk.org Reviewed-by: Tiwei Bie Signed-off-by: Maxime Coquelin Reviewed-by: Jens Freimann --- diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index 3ea64eba62..557213491e 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -489,6 +489,9 @@ qva_to_vva(struct virtio_net *dev, uint64_t qva, uint64_t *len) struct rte_vhost_mem_region *r; uint32_t i; + if (unlikely(!dev || !dev->mem)) + goto out_error; + /* Find the region where the address lives. */ for (i = 0; i < dev->mem->nregions; i++) { r = &dev->mem->regions[i]; @@ -503,6 +506,7 @@ qva_to_vva(struct virtio_net *dev, uint64_t qva, uint64_t *len) r->host_user_addr; } } +out_error: *len = 0; return 0;