]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
usb: iowarrior: replace kmalloc with kmalloc_array
authorGustavo A. R. Silva <gustavo@embeddedor.com>
Thu, 23 Aug 2018 17:55:27 +0000 (12:55 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 10 Sep 2018 18:05:28 +0000 (20:05 +0200)
A common flaw in the kernel is integer overflow during memory allocation
size calculations. In an effort to reduce the frequency of these bugs,
kmalloc_array was implemented, which allocates memory for an array,
while at the same time detects integer overflow.

This patch replaces cases of:

kmalloc(a * b, gfp)

with:
kmalloc_array(a, b, gfp)

Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/misc/iowarrior.c

index c2991b8a65ce455b9e35c15fbb758108b1012071..ba05dd80a020fb553752ff2b80e04a20b862c26f 100644 (file)
@@ -808,8 +808,8 @@ static int iowarrior_probe(struct usb_interface *interface,
                         dev->int_in_endpoint->bInterval);
        /* create an internal buffer for interrupt data from the device */
        dev->read_queue =
-           kmalloc(((dev->report_size + 1) * MAX_INTERRUPT_BUFFER),
-                   GFP_KERNEL);
+           kmalloc_array(dev->report_size + 1, MAX_INTERRUPT_BUFFER,
+                         GFP_KERNEL);
        if (!dev->read_queue)
                goto error;
        /* Get the serial-number of the chip */