CVE-2021-47272
Severity CVSS v4.0:
Pending analysis
Type:
Unavailable / Other
Publication date:
21/05/2024
Last modified:
30/04/2025
Description
In the Linux kernel, the following vulnerability has been resolved:<br />
<br />
usb: dwc3: gadget: Bail from dwc3_gadget_exit() if dwc->gadget is NULL<br />
<br />
There exists a possible scenario in which dwc3_gadget_init() can fail:<br />
during during host -> peripheral mode switch in dwc3_set_mode(), and<br />
a pending gadget driver fails to bind. Then, if the DRD undergoes<br />
another mode switch from peripheral->host the resulting<br />
dwc3_gadget_exit() will attempt to reference an invalid and dangling<br />
dwc->gadget pointer as well as call dma_free_coherent() on unmapped<br />
DMA pointers.<br />
<br />
The exact scenario can be reproduced as follows:<br />
- Start DWC3 in peripheral mode<br />
- Configure ConfigFS gadget with FunctionFS instance (or use g_ffs)<br />
- Run FunctionFS userspace application (open EPs, write descriptors, etc)<br />
- Bind gadget driver to DWC3&#39;s UDC<br />
- Switch DWC3 to host mode<br />
=> dwc3_gadget_exit() is called. usb_del_gadget() will put the<br />
ConfigFS driver instance on the gadget_driver_pending_list<br />
- Stop FunctionFS application (closes the ep files)<br />
- Switch DWC3 to peripheral mode<br />
=> dwc3_gadget_init() fails as usb_add_gadget() calls<br />
check_pending_gadget_drivers() and attempts to rebind the UDC<br />
to the ConfigFS gadget but fails with -19 (-ENODEV) because the<br />
FFS instance is not in FFS_ACTIVE state (userspace has not<br />
re-opened and written the descriptors yet, i.e. desc_ready!=0).<br />
- Switch DWC3 back to host mode<br />
=> dwc3_gadget_exit() is called again, but this time dwc->gadget<br />
is invalid.<br />
<br />
Although it can be argued that userspace should take responsibility<br />
for ensuring that the FunctionFS application be ready prior to<br />
allowing the composite driver bind to the UDC, failure to do so<br />
should not result in a panic from the kernel driver.<br />
<br />
Fix this by setting dwc->gadget to NULL in the failure path of<br />
dwc3_gadget_init() and add a check to dwc3_gadget_exit() to bail out<br />
unless the gadget pointer is valid.
Impact
Base Score 3.x
5.50
Severity 3.x
MEDIUM
Vulnerable products and versions
| CPE | From | Up to |
|---|---|---|
| cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* | 5.10 (including) | 5.10.44 (excluding) |
| cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* | 5.11 (including) | 5.12.11 (excluding) |
| cpe:2.3:o:linux:linux_kernel:5.13:rc1:*:*:*:*:*:* | ||
| cpe:2.3:o:linux:linux_kernel:5.13:rc2:*:*:*:*:*:* | ||
| cpe:2.3:o:linux:linux_kernel:5.13:rc3:*:*:*:*:*:* | ||
| cpe:2.3:o:linux:linux_kernel:5.13:rc4:*:*:*:*:*:* | ||
| cpe:2.3:o:linux:linux_kernel:5.13:rc5:*:*:*:*:*:* |
To consult the complete list of CPE names with products and versions, see this page
References to Advisories, Solutions, and Tools
- https://git.kernel.org/stable/c/03715ea2e3dbbc56947137ce3b4ac18a726b2f87
- https://git.kernel.org/stable/c/4aad390363d2b9b3e92428dd34d27bb7ea8f1ee8
- https://git.kernel.org/stable/c/851dee5a5da56564a70290713aee665403bb0b24
- https://git.kernel.org/stable/c/03715ea2e3dbbc56947137ce3b4ac18a726b2f87
- https://git.kernel.org/stable/c/4aad390363d2b9b3e92428dd34d27bb7ea8f1ee8
- https://git.kernel.org/stable/c/851dee5a5da56564a70290713aee665403bb0b24



