USB: core: fix out-of-bounds access bug in usb_get_bos_descriptor() 91/179691/2
authorAlan Stern <stern@rowland.harvard.edu>
Wed, 18 Oct 2017 16:49:38 +0000 (12:49 -0400)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Thu, 24 May 2018 04:20:27 +0000 (13:20 +0900)
commit7769c0e21d84feed08b18df627432d8e541c242d
tree8b39651ab53066eea2a9130855bd1f99930b36ff
parenta176b12172d505995cf957c6487d1eaf88ff686b
USB: core: fix out-of-bounds access bug in usb_get_bos_descriptor()

commit 1c0edc3633b56000e18d82fc241e3995ca18a69e upstream.

Andrey used the syzkaller fuzzer to find an out-of-bounds memory
access in usb_get_bos_descriptor().  The code wasn't checking that the
next usb_dev_cap_header structure could fit into the remaining buffer
space.

This patch fixes the error and also reduces the bNumDeviceCaps field
in the header to match the actual number of capabilities found, in
cases where there are fewer than expected.

Reported-by: Andrey Konovalov <andreyknvl@google.com>
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Tested-by: Andrey Konovalov <andreyknvl@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
[sw0312.kim: cherry-pick from linux-3.16.y to fix usb issue related with CVE-2017-16531]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: I85edcdcda17564d1c2e92e6980d27b34eacb5d4b
drivers/usb/core/config.c