projects/linux·commit e9ea0b30

xen/grants: prevent integer overflow in gnttab_dma_alloc_pages()

e9ea0b30 · Dan Carpenter <[email protected]> · 2022-09-01 18:35:20 +03:00

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]>
Reviewed-by: Juergen Gross <[email protected]>
Link: https://lore.kernel.org/r/YxDROJqu/RPvR0bi@kili
Signed-off-by: Juergen Gross <[email protected]>
Commit
e9ea0b30ada008f4e65933f449db6894832cb242
Parents
fe8f65b0

Changes

1 files changed · +3 −0

FileStatusAddDelContent
drivers/xen/grant-table.cmodified+3−0View file

drivers/xen/grant-table.c

View file
diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c
index 738029d..e1ec725 100644
--- a/drivers/xen/grant-table.c
+++ b/drivers/xen/grant-table.c
@@ -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,