OSDN Git Service

USB: core: harden cdc_parse_cdc_header
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 21 Sep 2017 14:58:48 +0000 (16:58 +0200)
committerAjay Agarwal <ajaya@codeaurora.org>
Tue, 10 Jul 2018 09:40:09 +0000 (15:10 +0530)
Andrey Konovalov reported a possible out-of-bounds problem for the
cdc_parse_cdc_header function.  He writes:
It looks like cdc_parse_cdc_header() doesn't validate buflen
before accessing buffer[1], buffer[2] and so on. The only check
present is while (buflen > 0).

So fix this issue up by properly validating the buffer length matches
what the descriptor says it is.

Change-Id: I9c65dc98778aa357911e554c8d28deef2bf9a5b3
Reported-by: Andrey Konovalov <andreyknvl@google.com>
Tested-by: Andrey Konovalov <andreyknvl@google.com>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Git-commit: 2e1c42391ff2556387b3cb6308b24f6f65619feb
Git-repo: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Srinivasa Rao Kuppala <srkupp@codeaurora.org>
drivers/usb/core/message.c

index e7db646..7855b3e 100644 (file)
@@ -2074,6 +2074,10 @@ int cdc_parse_cdc_header(struct usb_cdc_parsed_header *hdr,
                        elength = 1;
                        goto next_desc;
                }
+               if ((buflen < elength) || (elength < 3)) {
+                       dev_err(&intf->dev, "invalid descriptor buffer length\n");
+                       break;
+               }
                if (buffer[1] != USB_DT_CS_INTERFACE) {
                        dev_err(&intf->dev, "skipping garbage\n");
                        goto next_desc;