Skip to content

Commit e9ea0b3

Browse files
Dan Carpenterjgross1
authored andcommitted
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: b3f7931 ("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>
1 parent fe8f65b commit e9ea0b3

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

drivers/xen/grant-table.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,9 @@ int gnttab_dma_alloc_pages(struct gnttab_dma_alloc_args *args)
10471047
size_t size;
10481048
int i, ret;
10491049

1050+
if (args->nr_pages < 0 || args->nr_pages > (INT_MAX >> PAGE_SHIFT))
1051+
return -ENOMEM;
1052+
10501053
size = args->nr_pages << PAGE_SHIFT;
10511054
if (args->coherent)
10521055
args->vaddr = dma_alloc_coherent(args->dev, size,

0 commit comments

Comments
 (0)