OSDN Git Service

USB: devio: Prevent integer overflow in proc_do_submiturb()
authorDan Carpenter <dan.carpenter@oracle.com>
Fri, 22 Sep 2017 20:43:25 +0000 (23:43 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 9 Dec 2017 21:01:57 +0000 (22:01 +0100)
commit545c10375330c9212227a6a7efd84f49ccd6c9b2
tree068dfb5e58e75643258ab19552b1ea230fdb2428
parentd6ab871c432dbb30d8a186347f4d9ebd22041b6a
USB: devio: Prevent integer overflow in proc_do_submiturb()

commit 57999d1107c1e60c2ca7088f2ac0f819e2f554b3 upstream.

There used to be an integer overflow check in proc_do_submiturb() but
we removed it.  It turns out that it's still required.  The
uurb->buffer_length variable is a signed integer and it's controlled by
the user.  It can lead to an integer overflow when we do:

num_sgs = DIV_ROUND_UP(uurb->buffer_length, USB_SG_SIZE);

If we strip away the macro then that line looks like this:

num_sgs = (uurb->buffer_length + USB_SG_SIZE - 1) / USB_SG_SIZE;
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
It's the first addition which can overflow.

Fixes: 1129d270cbfb ("USB: Increase usbfs transfer limit")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/core/devio.c