浏览代码

usb: usbtest: avoid integer overflow in alloc_sglist()

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>
Xi Wang 13 年之前
父节点
当前提交
8bde9a62ee
共有 1 个文件被更改,包括 1 次插入1 次删除
  1. 1 1
      drivers/usb/misc/usbtest.c

+ 1 - 1
drivers/usb/misc/usbtest.c

@@ -423,7 +423,7 @@ alloc_sglist(int nents, int max, int vary)
 	unsigned		i;
 	unsigned		i;
 	unsigned		size = max;
 	unsigned		size = max;
 
 
-	sg = kmalloc(nents * sizeof *sg, GFP_KERNEL);
+	sg = kmalloc_array(nents, sizeof *sg, GFP_KERNEL);
 	if (!sg)
 	if (!sg)
 		return NULL;
 		return NULL;
 	sg_init_table(sg, nents);
 	sg_init_table(sg, nents);