[dpdk-dev,v3,1/3] vhost: fix malloc in rte_vhost_get_mem_table()

Message ID 1494513192-85863-2-git-send-email-dariuszx.stojaczyk@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Yuanhan Liu
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Stojaczyk, DariuszX May 11, 2017, 2:33 p.m. UTC
  Amount of allocated memory was too small, causing buffer overflow.

Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
---
 lib/librte_vhost/vhost.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Jens Freimann May 11, 2017, 1:56 p.m. UTC | #1
On Thu, May 11, 2017 at 04:33:10PM +0200, Dariusz Stojaczyk wrote:
> Amount of allocated memory was too small, causing buffer overflow.
> 
> Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
> ---
>  lib/librte_vhost/vhost.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 

Reviewed-by: Jens Freimann <jfreimann@redhat.com>
  

Patch

diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c
index 0b19d2e..1f565fb 100644
--- a/lib/librte_vhost/vhost.c
+++ b/lib/librte_vhost/vhost.c
@@ -369,7 +369,7 @@  rte_vhost_get_mem_table(int vid, struct rte_vhost_memory **mem)
 		return -1;
 
 	size = dev->mem->nregions * sizeof(struct rte_vhost_mem_region);
-	m = malloc(size);
+	m = malloc(sizeof(struct rte_vhost_memory) + size);
 	if (!m)
 		return -1;