From 4d490c7ce392d4307c9ad6009729a8279646cf6c Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Mon, 5 Feb 2018 13:16:00 +0100 Subject: [PATCH] vhost: validate untrusted memory regions number field Check if memory.nregions is valid right away. This eliminates the possibility of bugs when memory.nregions is used later on in vhost_user_set_mem_table(). Signed-off-by: Stefan Hajnoczi Reviewed-by: Maxime Coquelin --- lib/librte_vhost/vhost_user.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index 6db50affaf..baf58dd3a8 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -663,6 +663,12 @@ vhost_user_set_mem_table(struct virtio_net *dev, struct VhostUserMsg *pmsg) uint32_t i; int fd; + if (memory.nregions > VHOST_MEMORY_MAX_NREGIONS) { + RTE_LOG(ERR, VHOST_CONFIG, + "too many memory regions (%u)\n", memory.nregions); + return -1; + } + if (dev->mem && !vhost_memory_changed(&memory, dev->mem)) { RTE_LOG(INFO, VHOST_CONFIG, "(%d) memory regions not changed\n", dev->vid); -- 2.20.1