Subject: CVE-2021-47181: USB: gadget: bRequestType is a bitfield, not a enum

From: Greg Kroah-Hartman <[email-masked]>

Description
===========

USB: gadget: bRequestType is a bitfield, not a enum

Szymon rightly pointed out that the previous check for the endpoint
direction in bRequestType was not looking at only the bit involved, but
rather the whole value.  Normally this is ok, but for some request
types, bits other than bit 8 could be set and the check for the endpoint
length could not stall correctly.

Fix that up by only checking the single bit.

The Linux kernel CVE team has assigned CVE-2021-47181 to this issue.

Affected and fixed versions
===========================

	Issue introduced in 4.4.295 with commit 93cd7100fe47 and fixed in 4.4.296 with commit 2983866fc137
	Issue introduced in 4.9.293 with commit d2ca6859ea96 and fixed in 4.9.294 with commit 4dbf2224984f
	Issue introduced in 4.14.258 with commit e7c8afee1491 and fixed in 4.14.259 with commit 9b3a3a363591
	Issue introduced in 4.19.221 with commit 13e45e7a262d and fixed in 4.19.222 with commit 05da4194e81a
	Issue introduced in 5.4.165 with commit fd6de5a0cd42 and fixed in 5.4.168 with commit aae3448b78d9
	Issue introduced in 5.10.85 with commit 7193ad3e50e5 and fixed in 5.10.88 with commit 2b54f485f2c1
	Issue introduced in 5.15.8 with commit 36dfdf11af49 and fixed in 5.15.11 with commit abd3a33b3f2b

Please see https://www.kernel.org or a full list of currently supported
kernel versions by the kernel community.

Unaffected versions might change over time as fixes are backported to
older supported kernel versions.  The official CVE entry at
	https://cve.org/CVERecord/?id=CVE-2021-47181
will be updated if fixes are backported, please check that for the most
up to date information about this issue.

Affected files
==============

The file(s) affected by this issue are:
	drivers/usb/gadget/composite.c
	drivers/usb/gadget/legacy/dbgp.c
	drivers/usb/gadget/legacy/inode.c

Mitigation
==========

The Linux kernel CVE team recommends that you update to the latest
stable kernel version for this, and many other bugfixes.  Individual
changes are never tested alone, but rather are part of a larger kernel
release.  Cherry-picking individual commits is not recommended or
supported by the Linux kernel community at all.  If however, updating to
the latest release is impossible, the individual changes to resolve this
issue can be found at these commits:
	https://git.kernel.org/stable/c/2983866fc137
	https://git.kernel.org/stable/c/4dbf2224984f
	https://git.kernel.org/stable/c/9b3a3a363591
	https://git.kernel.org/stable/c/05da4194e81a
	https://git.kernel.org/stable/c/aae3448b78d9
	https://git.kernel.org/stable/c/2b54f485f2c1
	https://git.kernel.org/stable/c/abd3a33b3f2b