xen/grants: prevent integer overflow in gnttab_dma_alloc_pages()
Subsystems (2)
PATCH 1/1 xen/grants: prevent integer overflow in gnttab_dma_alloc_pages()
The change from kcalloc() to kvmalloc() means that arg->nr_pages might now be large enough that the "args->nr_pages << PAGE_SHIFT" can result in an integer overflow.
Fixes b3f7931f5c61 ("xen/gntdev: switch from kcalloc() to kvcalloc()")
Signed-off-by Dan Carpenter <[email protected]>
--- drivers/xen/grant-table.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/xen/grant-table.c +3 -0
@@ -1047,6 +1047,9 @@ int gnttab_dma_alloc_pages(struct gnttab_dma_alloc_args *args)size_t size;int i, ret; +if (args->nr_pages <0 || args->nr_pages > (INT_MAX >>PAGE_SHIFT )) +return -ENOMEM ; + size = args->nr_pages <<PAGE_SHIFT ;if (args->coherent) args->vaddr = dma_alloc_coherent(args->dev, size,
Signature · 1 line
2.35.1
Quoted 6 lines · Dan Carpenter
The change from
kcalloc()tokvmalloc()means thatarg->nr_pagesmight now be large enough that the "args->nr_pages<<PAGE_SHIFT" can result in an integer overflow.Fixes b3f7931f5c61 ("xen/gntdev: switch from kcalloc() to kvcalloc()")Signed-off-by Dan Carpenter <[email protected]>
Reviewed-by Juergen Gross <[email protected]>
Juergen