patch "genwqe: Prevent an integer overflow in the ioctl" added to char-misc-linus
This is a note to let you know that I've just added the patch titled
genwqe: Prevent an integer overflow in the ioctl
to my char-misc git tree which can be found at
git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git
in the char-misc-linus branch.
The patch will show up in the next release of the linux-next tree (usually sometime within the next 24 hours during the week.)
The patch will hopefully also be merged in Linus's tree for the next -rc kernel release.
If you have any questions about this process, please let me know.
From 110080cea0d0e4dfdb0b536e7f8a5633ead6a781 Mon Sep 17 00:00:00 2001
From: Dan Carpenter <[email protected]>
Date: Tue, 7 May 2019 11:36:34 +0300
Subject: genwqe: Prevent an integer overflow in the ioctl
There are a couple potential integer overflows here.
round_up(m->size + (m->addr & ~PAGE_MASK), PAGE_SIZE);
The first thing is that the "m->size + (...)" addition could overflow, and the second is that round_up() overflows to zero if the result is within PAGE_SIZE of the type max.
In this code, the "m->size" variable is an u64 but we're saving the result in "map_size" which is an unsigned long and genwqe_user_vmap() takes an unsigned long as well. So I have used ULONG_MAX as the upper bound. From a practical perspective unsigned long is fine/better than trying to change all the types to u64.
--- drivers/misc/genwqe/card_dev.c | 2 ++ drivers/misc/genwqe/card_utils.c | 4 ++++ 2 files changed, 6 insertions(+)
drivers/misc/genwqe/card_dev.c +2 -0
@@ -780,6 +780,8 @@ static int genwqe_pin_mem(struct genwqe_file *cfile, struct genwqe_mem *m)if ((m->addr ==0x0 ) || (m->size ==0 ))return -EINVAL ; +if (m->size >ULONG_MAX -PAGE_SIZE - (m->addr & ~PAGE_MASK )) +return -EINVAL ; map_addr = (m->addr &PAGE_MASK ); map_size =round_up (m->size + (m->addr & ~PAGE_MASK ),PAGE_SIZE );
drivers/misc/genwqe/card_utils.c +4 -0
@@ -586,6 +586,10 @@ int genwqe_user_vmap(struct genwqe_dev *cd, struct dma_mapping *m, void *uaddr,/* determine space needed for page_list. */ data = (unsigned long )uaddr; offs =offset_in_page (data); +if (size >ULONG_MAX -PAGE_SIZE - offs) { + m->size =0 ;/* mark unused and not added */ +return -EINVAL ; + } m->nr_pages =DIV_ROUND_UP (offs + size,PAGE_SIZE ); m->page_list = kcalloc(m->nr_pages,
Signature · 1 line
2.21.0