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 <dan.carpenter@oracle.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
Link: https://lore.kernel.org/r/YxDROJqu/RPvR0bi@kili
Signed-off-by: Juergen Gross <jgross@suse.com>

authored by

Dan Carpenter and committed by
Juergen Gross
e9ea0b30 fe8f65b0

+3
+3
drivers/xen/grant-table.c
··· 1047 1047 size_t size; 1048 1048 int i, ret; 1049 1049 1050 + if (args->nr_pages < 0 || args->nr_pages > (INT_MAX >> PAGE_SHIFT)) 1051 + return -ENOMEM; 1052 + 1050 1053 size = args->nr_pages << PAGE_SHIFT; 1051 1054 if (args->coherent) 1052 1055 args->vaddr = dma_alloc_coherent(args->dev, size,