[dpdk-dev] [PATCH v2 1/3] vhost: fix malloc in rte_vhost_get_mem_table

Jens Freimann jfreiman at redhat.com
Thu May 11 13:42:22 CEST 2017


On Thu, May 11, 2017 at 12:56:46PM +0200, Dariusz Stojaczyk wrote:
> Amount of allocated memory was too small, causing buffer overflow.
> 
> Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk at intel.com>
> ---
> Removed Gerrit Change-Id
>  lib/librte_vhost/vhost.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> 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);

Why not just add it to the line above where size is calculated?
With that changed,

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


regards,
Jens



More information about the dev mailing list