drivers/misc/vmw_vmci/vmci_queue_pair.c: fix a couple integer overflow tests
Subsystems (2)
PATCH 15/114 drivers/misc/vmw_vmci/vmci_queue_pair.c: fix a couple integer overflow tests
From: Dan Carpenter <[email protected]>
Subject: drivers/misc/vmw_vmci/vmci_queue_pair.c: fix a couple integer overflow tests
The "DIV_ROUND_UP(size, PAGE_SIZE)" operation can overflow if "size" is more than ULLONG_MAX - PAGE_SIZE.
Signed-off-by Dan Carpenter <[email protected]>
Cc Jorgen Hansen <[email protected]>
Cc Masahiro Yamada <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Signed-off-by Andrew Morton <[email protected]>
---
drivers/misc/vmw_vmci/vmci_queue_pair.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/misc/vmw_vmci/vmci_queue_pair.c renamed from drivers/misc/vmw_vmci/vmci_queue_pair.c~vmci-fix-a-couple-integer-overflow-tests +8 -2
@@ -298,8 +298,11 @@ static void *qp_alloc_queue(u64 size, u3size_t pas_size;size_t vas_size;size_t queue_size =sizeof (*queue) +sizeof (*queue->kernel_if); -const u64 num_pages =DIV_ROUND_UP (size,PAGE_SIZE ) +1 ; +u64 num_pages; +if (size >SIZE_MAX -PAGE_SIZE ) +return NULL ; + num_pages =DIV_ROUND_UP (size,PAGE_SIZE ) +1 ;if (num_pages > (SIZE_MAX - queue_size) / (sizeof(*queue->kernel_if->u.g.pas) +
@@ -624,9 +627,12 @@ static struct vmci_queue *qp_host_alloc_ {struct vmci_queue *queue;size_t queue_page_size; -const u64 num_pages =DIV_ROUND_UP (size,PAGE_SIZE ) +1 ; +u64 num_pages;const size_t queue_size =sizeof (*queue) +sizeof (*(queue->kernel_if)); +if (size >SIZE_MAX -PAGE_SIZE ) +return NULL ; + num_pages =DIV_ROUND_UP (size,PAGE_SIZE ) +1 ;if (num_pages > (SIZE_MAX - queue_size) /sizeof (*queue->kernel_if->u.h.page))return NULL ;
_