USB: core: fix out-of-bounds access bug in usb_get_bos_descriptor()
authorAlan Stern <stern@rowland.harvard.edu>
Wed, 18 Oct 2017 16:49:38 +0000 (12:49 -0400)
committerBen Hutchings <ben@decadent.org.uk>
Sat, 11 Nov 2017 13:34:40 +0000 (13:34 +0000)
commit7c27b82fad16d2804c7c8405316a636f57edeabd
tree0486c96323f4a78da37d673edbf7bb12285267e6
parent99de0781e0de7c866f762b931351c2a501c3074f
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>
drivers/usb/core/config.c