linux_dsm_epyc7002/drivers/usb/gadget/legacy
Alan Stern faab50984f USB: gadgetfs: fix unbounded memory allocation bug
Andrey Konovalov reports that fuzz testing with syzkaller causes a
KASAN warning in gadgetfs:

BUG: KASAN: slab-out-of-bounds in dev_config+0x86f/0x1190 at addr ffff88003c47e160
Write of size 65537 by task syz-executor0/6356
CPU: 3 PID: 6356 Comm: syz-executor0 Not tainted 4.9.0-rc7+ #19
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
 ffff88003c107ad8 ffffffff81f96aba ffffffff3dc11ef0 1ffff10007820eee
 ffffed0007820ee6 ffff88003dc11f00 0000000041b58ab3 ffffffff8598b4c8
 ffffffff81f96828 ffffffff813fb4a0 ffff88003b6eadc0 ffff88003c107738
Call Trace:
 [<     inline     >] __dump_stack lib/dump_stack.c:15
 [<ffffffff81f96aba>] dump_stack+0x292/0x398 lib/dump_stack.c:51
 [<ffffffff817e4dec>] kasan_object_err+0x1c/0x70 mm/kasan/report.c:159
 [<     inline     >] print_address_description mm/kasan/report.c:197
 [<ffffffff817e5080>] kasan_report_error+0x1f0/0x4e0 mm/kasan/report.c:286
 [<ffffffff817e5705>] kasan_report+0x35/0x40 mm/kasan/report.c:306
 [<     inline     >] check_memory_region_inline mm/kasan/kasan.c:308
 [<ffffffff817e3fb9>] check_memory_region+0x139/0x190 mm/kasan/kasan.c:315
 [<ffffffff817e4044>] kasan_check_write+0x14/0x20 mm/kasan/kasan.c:326
 [<     inline     >] copy_from_user arch/x86/include/asm/uaccess.h:689
 [<     inline     >] ep0_write drivers/usb/gadget/legacy/inode.c:1135
 [<ffffffff83228caf>] dev_config+0x86f/0x1190 drivers/usb/gadget/legacy/inode.c:1759
 [<ffffffff817fdd55>] __vfs_write+0x5d5/0x760 fs/read_write.c:510
 [<ffffffff817ff650>] vfs_write+0x170/0x4e0 fs/read_write.c:560
 [<     inline     >] SYSC_write fs/read_write.c:607
 [<ffffffff81803a5b>] SyS_write+0xfb/0x230 fs/read_write.c:599
 [<ffffffff84f47ec1>] entry_SYSCALL_64_fastpath+0x1f/0xc2

Indeed, there is a comment saying that the value of len is restricted
to a 16-bit integer, but the code doesn't actually do this.

This patch fixes the warning.  It replaces the comment with a
computation that forces the amount of data copied from the user in
ep0_write() to be no larger than the wLength size for the control
transfer, which is a 16-bit quantity.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Reported-by: Andrey Konovalov <andreyknvl@google.com>
Tested-by: Andrey Konovalov <andreyknvl@google.com>
CC: <stable@vger.kernel.org>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2017-01-02 10:55:28 +02:00
..
acm_ms.c usb: f_mass_storage: test whether thread is running before starting another 2016-04-19 11:11:56 +03:00
audio.c usb: gadget: composite: remove redundant bcdUSB setting in legacy 2015-12-15 09:12:41 -06:00
cdc2.c usb: gadget: composite: remove redundant bcdUSB setting in legacy 2015-12-15 09:12:41 -06:00
dbgp.c usb: gadget: legacy: dbgp: eliminate abuse of ep->driver data 2015-09-27 10:54:31 -05:00
ether.c usb: gadget: composite: remove redundant bcdUSB setting in legacy 2015-12-15 09:12:41 -06:00
g_ffs.c usb: gadget: fix unused-but-set-variale warnings 2016-06-21 11:04:09 +03:00
gmidi.c usb: gadget: f_midi: defaults buflen sizes to 512 2016-08-25 12:13:15 +03:00
hid.c usb: gadget: composite: remove redundant bcdUSB setting in legacy 2015-12-15 09:12:41 -06:00
inode.c USB: gadgetfs: fix unbounded memory allocation bug 2017-01-02 10:55:28 +02:00
Kconfig Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/trivial 2016-03-17 21:38:27 -07:00
Makefile usb: gadget: webcam: convert webcam to new interface of f_uvc 2014-09-09 09:49:31 -05:00
mass_storage.c usb: f_mass_storage: test whether thread is running before starting another 2016-04-19 11:11:56 +03:00
multi.c usb: f_mass_storage: test whether thread is running before starting another 2016-04-19 11:11:56 +03:00
ncm.c usb: gadget: composite: remove redundant bcdUSB setting in legacy 2015-12-15 09:12:41 -06:00
nokia.c usb: f_mass_storage: test whether thread is running before starting another 2016-04-19 11:11:56 +03:00
printer.c usb: gadget: composite: remove redundant bcdUSB setting in legacy 2015-12-15 09:12:41 -06:00
serial.c usb: gadget: composite: remove redundant bcdUSB setting in legacy 2015-12-15 09:12:41 -06:00
tcm_usb_gadget.c Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending 2016-01-20 17:20:53 -08:00
webcam.c usb: gadget: composite: remove redundant bcdUSB setting in legacy 2015-12-15 09:12:41 -06:00
zero.c usb: gadget: composite: remove redundant bcdUSB setting in legacy 2015-12-15 09:12:41 -06:00