CVE-2021-47272: usb: dwc3: gadget: Bail from dwc3_gadget_exit() if dwc->gadget is NULL
In the Linux kernel, the following vulnerability has been resolved:
usb: dwc3: gadget: Bail from dwc3_gadget_exit() if dwc->gadget is NULL
There exists a possible scenario in which dwc3_gadget_init() can fail:
during during host -> peripheral mode switch in dwc3_set_mode(), and
a pending gadget driver fails to bind. Then, if the DRD undergoes
another mode switch from peripheral->host the resulting
dwc3_gadget_exit() will attempt to reference an invalid and dangling
dwc->gadget pointer as well as call dma_free_coherent() on unmapped
DMA pointers.
The exact scenario can be reproduced as follows:
- Start DWC3 in peripheral mode
- Configure ConfigFS gadget with FunctionFS instance (or use g_ffs)
- Run FunctionFS userspace application (open EPs, write descriptors, etc)
- Bind gadget driver to DWC3's UDC
- Switch DWC3 to host mode
=> dwc3_gadget_exit() is called. usb_del_gadget() will put the
ConfigFS driver instance on the gadget_driver_pending_list
- Stop FunctionFS application (closes the ep files)
- Switch DWC3 to peripheral mode
=> dwc3_gadget_init() fails as usb_add_gadget() calls
check_pending_gadget_drivers() and attempts to rebind the UDC
to the ConfigFS gadget but fails with -19 (-ENODEV) because the
FFS instance is not in FFS_ACTIVE state (userspace has not
re-opened and written the descriptors yet, i.e. desc_ready!=0).
- Switch DWC3 back to host mode
=> dwc3_gadget_exit() is called again, but this time dwc->gadget
is invalid.
Although it can be argued that userspace should take responsibility
for ensuring that the FunctionFS application be ready prior to
allowing the composite driver bind to the UDC, failure to do so
should not result in a panic from the kernel driver.
Fix this by setting dwc->gadget to NULL in the failure path of
dwc3_gadget_init() and add a check to dwc3_gadget_exit() to bail out
unless the gadget pointer is valid.
Security readout for executives and security teams
Plain-English summary
This Linux kernel issue can crash systems using the DWC3 USB dual-role controller when USB peripheral and host modes are switched after a gadget initialization failure. The likely business impact is device instability or denial of service, mainly for embedded, mobile, or appliance-style systems using USB gadget features.
Executive priority
Treat this as a targeted stability fix for products or infrastructure that use Linux USB gadget mode. It is not presented as internet-exploited, but affected devices could suffer kernel panics during specific USB role transitions, which matters for appliances, kiosks, mobile platforms, and embedded fleets.
Technical view
The DWC3 gadget driver could leave dwc->gadget dangling after dwc3_gadget_init() failed during a host-to-peripheral switch. A later peripheral-to-host switch could make dwc3_gadget_exit() dereference the invalid pointer and free unmapped DMA memory. The fix NULLs the pointer on failure and exits early when no valid gadget exists.
Likely exposure
Exposure appears limited to Linux systems with DWC3 dual-role USB hardware using gadget, ConfigFS, or FunctionFS workflows. General-purpose servers without this USB controller mode are less likely to be affected. The source bundle lists Linux kernel 5.10 and related stable ranges as affected, with fixes referenced in kernel stable commits.
Exploitation context
The provided sources do not show active exploitation, and the CVE is not marked in KEV. The described trigger requires a specific USB gadget and mode-switch sequence involving FunctionFS state, so this is more likely an operational denial-of-service risk than a broadly internet-exposed vulnerability.
Researcher notes
Evidence supports a DWC3 gadget failure-path bug causing invalid pointer use and bad DMA free during DRD role switching. The bundle does not provide CVSS, CWE, weaponized exploit evidence, or complete downstream vendor status. Validate by code provenance and vendor backport presence, not version strings alone.
Mitigation direction
Update to a vendor kernel containing the referenced stable fixes.
Check Linux distribution or device vendor advisories for patched kernel builds.
Prioritize embedded or appliance fleets using USB dual-role gadget mode.
Avoid risky host/peripheral mode switching on affected devices until patched.
Ensure FunctionFS userspace is ready before gadget binding where operationally feasible.
Validation and detection
Inventory devices running affected Linux kernels with DWC3 dual-role USB enabled.
Confirm the kernel includes one of the referenced stable commits or vendor backports.
Review crash logs for DWC3 gadget panics during USB role switching.
Regression-test USB gadget mode changes after applying the vendor fix.
Generated from the cited source records. This long-tail analysis has not been individually reviewed by a named human.
Potential ATT&CK relevance
Conservative CVE-to-ATT&CK context
These mappings and lookup hints may be relevant to the vulnerability behavior, CWE, affected product, or exposure path. Glexia-inferred context is not an official MITRE, ATT&CK, CWE, or CVE Program mapping.
ATT&CK lookup starting points
Use these exact CWE pages and searches to review the Glexia ATT&CK library from this CVE's weakness and description context.
cve · low confidence lookup
CVE-2021-47272 mapping review
Open the CVE-to-ATT&CK bridge for reviewed, inferred, or future official mappings tied to this CVE.
These fields come from the CVE record and ADP containers, not from Glexia's Take. They preserve time-varying source decisions such as CISA SSVC, KEV status, CVSS metrics, and provider references.