kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] xen/grants: prevent integer overflow in gnttab_dma_alloc_pages()
@ 2022-09-01 15:35 Dan Carpenter
  2022-09-02  7:01 ` Juergen Gross
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2022-09-01 15:35 UTC (permalink / raw)
  To: Juergen Gross
  Cc: Stefano Stabellini, Oleksandr Tyshchenko, xen-devel, kernel-janitors

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>
---
 drivers/xen/grant-table.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c
index 738029de3c67..e1ec725c2819 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,
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] xen/grants: prevent integer overflow in gnttab_dma_alloc_pages()
  2022-09-01 15:35 [PATCH] xen/grants: prevent integer overflow in gnttab_dma_alloc_pages() Dan Carpenter
@ 2022-09-02  7:01 ` Juergen Gross
  0 siblings, 0 replies; 2+ messages in thread
From: Juergen Gross @ 2022-09-02  7:01 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Stefano Stabellini, Oleksandr Tyshchenko, xen-devel, kernel-janitors


[-- Attachment #1.1.1: Type: text/plain, Size: 415 bytes --]

On 01.09.22 17:35, Dan Carpenter wrote:
> 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>


Juergen

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3149 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-09-02  7:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-01 15:35 [PATCH] xen/grants: prevent integer overflow in gnttab_dma_alloc_pages() Dan Carpenter
2022-09-02  7:01 ` Juergen Gross

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).