mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-26 16:41:25 +00:00
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. Link: http://lkml.kernel.org/r/20170322111950.GA11279@mwanda Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Cc: Jorgen Hansen <jhansen@vmware.com> Cc: Masahiro Yamada <yamada.masahiro@socionext.com> Cc: Michal Hocko <mhocko@suse.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
780cbcf287
commit
146180c052
1 changed files with 8 additions and 2 deletions
|
@ -298,8 +298,11 @@ static void *qp_alloc_queue(u64 size, u32 flags)
|
||||||
size_t pas_size;
|
size_t pas_size;
|
||||||
size_t vas_size;
|
size_t vas_size;
|
||||||
size_t queue_size = sizeof(*queue) + sizeof(*queue->kernel_if);
|
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 >
|
if (num_pages >
|
||||||
(SIZE_MAX - queue_size) /
|
(SIZE_MAX - queue_size) /
|
||||||
(sizeof(*queue->kernel_if->u.g.pas) +
|
(sizeof(*queue->kernel_if->u.g.pas) +
|
||||||
|
@ -624,9 +627,12 @@ static struct vmci_queue *qp_host_alloc_queue(u64 size)
|
||||||
{
|
{
|
||||||
struct vmci_queue *queue;
|
struct vmci_queue *queue;
|
||||||
size_t queue_page_size;
|
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));
|
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) /
|
if (num_pages > (SIZE_MAX - queue_size) /
|
||||||
sizeof(*queue->kernel_if->u.h.page))
|
sizeof(*queue->kernel_if->u.h.page))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue