cdc-acm: prevent infinite loop when parsing CDC headers.
cdc-acm: prevent infinite loop when parsing CDC headers.

Phil and I found out a problem with commit:

  7e860a6e7aa6 ("cdc-acm: add sanity checks")

It added some sanity checks to ignore potential garbage in CDC headers but
also introduced a potential infinite loop.  This can happen at the first
loop iteration (elength = 0 in that case) if the description isn't a
DT_CS_INTERFACE or later if 'buffer[0]' is zero.

It should also be noted that the wrong length was being added to 'buffer'
in case 'buffer[1]' was not a DT_CS_INTERFACE descriptor, since elength was
assigned after that check in the loop.

A specially crafted USB device could be used to trigger this infinite loop.

Fixes: 7e860a6e7aa6 ("cdc-acm: add sanity checks")
Signed-off-by: Phil Turnbull <636b3595fe7e430bd36214e65e82255c9006a0ec@oracle.com>
Signed-off-by: Quentin Casasnovas <3f2200175a6bbbfba43d52ba938bedf5f63cd8af@oracle.com>
CC: Sergei Shtylyov <d8c69075be49b0738b690ec4af0e9025b8c97c9e@cogentembedded.com>
CC: Oliver Neukum <bfee72d94d376f4e00f72b756466867d7f9eb24e@suse.de>
CC: Adam Lee <77a6eb4bd9fa0379ab5cc07bb09f3dcf71a7035d@gmail.com>
CC: <4fbacc2fa0ffdbb11bf1ad6925b886ebd08dd15f@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <4645f7897fd33786a2ee1264d590b3c400559d85@linuxfoundation.org>

KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs