]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.4/genwqe-prevent-an-integer-overflow-in-the-ioctl.patch
Linux 4.9.181
[thirdparty/kernel/stable-queue.git] / queue-4.4 / genwqe-prevent-an-integer-overflow-in-the-ioctl.patch
1 From 110080cea0d0e4dfdb0b536e7f8a5633ead6a781 Mon Sep 17 00:00:00 2001
2 From: Dan Carpenter <dan.carpenter@oracle.com>
3 Date: Tue, 7 May 2019 11:36:34 +0300
4 Subject: genwqe: Prevent an integer overflow in the ioctl
5
6 From: Dan Carpenter <dan.carpenter@oracle.com>
7
8 commit 110080cea0d0e4dfdb0b536e7f8a5633ead6a781 upstream.
9
10 There are a couple potential integer overflows here.
11
12 round_up(m->size + (m->addr & ~PAGE_MASK), PAGE_SIZE);
13
14 The first thing is that the "m->size + (...)" addition could overflow,
15 and the second is that round_up() overflows to zero if the result is
16 within PAGE_SIZE of the type max.
17
18 In this code, the "m->size" variable is an u64 but we're saving the
19 result in "map_size" which is an unsigned long and genwqe_user_vmap()
20 takes an unsigned long as well. So I have used ULONG_MAX as the upper
21 bound. From a practical perspective unsigned long is fine/better than
22 trying to change all the types to u64.
23
24 Fixes: eaf4722d4645 ("GenWQE Character device and DDCB queue")
25 Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
26 Cc: stable <stable@vger.kernel.org>
27 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
28
29 ---
30 drivers/misc/genwqe/card_dev.c | 2 ++
31 drivers/misc/genwqe/card_utils.c | 4 ++++
32 2 files changed, 6 insertions(+)
33
34 --- a/drivers/misc/genwqe/card_dev.c
35 +++ b/drivers/misc/genwqe/card_dev.c
36 @@ -782,6 +782,8 @@ static int genwqe_pin_mem(struct genwqe_
37
38 if ((m->addr == 0x0) || (m->size == 0))
39 return -EINVAL;
40 + if (m->size > ULONG_MAX - PAGE_SIZE - (m->addr & ~PAGE_MASK))
41 + return -EINVAL;
42
43 map_addr = (m->addr & PAGE_MASK);
44 map_size = round_up(m->size + (m->addr & ~PAGE_MASK), PAGE_SIZE);
45 --- a/drivers/misc/genwqe/card_utils.c
46 +++ b/drivers/misc/genwqe/card_utils.c
47 @@ -582,6 +582,10 @@ int genwqe_user_vmap(struct genwqe_dev *
48 /* determine space needed for page_list. */
49 data = (unsigned long)uaddr;
50 offs = offset_in_page(data);
51 + if (size > ULONG_MAX - PAGE_SIZE - offs) {
52 + m->size = 0; /* mark unused and not added */
53 + return -EINVAL;
54 + }
55 m->nr_pages = DIV_ROUND_UP(offs + size, PAGE_SIZE);
56
57 m->page_list = kcalloc(m->nr_pages,