History

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.

Dan Carpenter committed 4 years ago

Commit e9ea0b31 parent fe8f65b1 file · +3 −0Browse files

Unified · Split

drivers/xen/grant-table.c+3−0
@@ -1047,6 +1047,9 @@ int gnttab_dma_alloc_pages(struct gnttab_dma_alloc_args *args) · 1046 unmodified lines
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,