Skip to content

Commit

Permalink
usb: usbtest: avoid integer overflow in alloc_sglist()
Browse files Browse the repository at this point in the history
A large `nents' from userspace could overflow the allocation size,
leading to memory corruption.

| alloc_sglist()
| usbtest_ioctl()

Use kmalloc_array() to avoid the overflow.

Signed-off-by: Xi Wang <xi.wang@gmail.com>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Xi Wang authored and Greg Kroah-Hartman committed Apr 17, 2012
1 parent e65cdfa commit 8bde9a6
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/usb/misc/usbtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ alloc_sglist(int nents, int max, int vary)
unsigned i;
unsigned size = max;

sg = kmalloc(nents * sizeof *sg, GFP_KERNEL);
sg = kmalloc_array(nents, sizeof *sg, GFP_KERNEL);
if (!sg)
return NULL;
sg_init_table(sg, nents);
Expand Down

0 comments on commit 8bde9a6

Please sign in to comment.