# CVE-2021-46986: usb: dwc3: gadget: Free gadget structure only after freeing endpoints

> Archived entry. Full-text search covers entries since 2026-11-10; exact IDs work for all years.

- **Severity:** MEDIUM 5.5
- **CVSS:** 5.5 (v3.1, NVD) `CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H`
- **CVSS metrics:** Attack vector: Local; Attack complexity: Low; Privileges required: Low; User interaction: None; Scope: Unchanged; Confidentiality impact: None; Integrity impact: None; Availability impact: High
- **Exploited in the wild:** Not in CISA KEV
- **Public exploit / PoC:** None known
- **Remote exploitation:** Not remotely exploitable (local or adjacent access needed)
- **EPSS:** 0.23% (percentile 8, 2026-11-26)
- **CWE:** CWE-416
- **Published:** 2024-02-28T08:13:14.082Z
- **Modified:** 2026-06-17T04:16:05.083Z

## Who should check

- Anyone running Linux \>= e81a7018d93a7de31a3f121c9a7eecd0a5ec58b0, \< 1ea775021282d90e1d08d696b7ab54aa75d688e5; \>= e81a7018d93a7de31a3f121c9a7eecd0a5ec58b0, \< bc0cdd72493236fb72b390ad38ce581e353c143c; \>= e81a7018d93a7de31a3f121c9a7eecd0a5ec58b0, \< b4b8e9601d7ee8806d2687f081a42485d27674a1; \>= e81a7018d93a7de31a3f121c9a7eecd0a5ec58b0, \< bb9c74a5bd1462499fe5ccb1e3c5ac40dcfa9139
- Anyone running Linux 5.10

## Description

In the Linux kernel, the following vulnerability has been resolved:

usb: dwc3: gadget: Free gadget structure only after freeing endpoints

As part of commit e81a7018d93a ("usb: dwc3: allocate gadget structure
dynamically") the dwc3\_gadget\_release() was added which will free
the dwc-\>gadget structure upon the device's removal when
usb\_del\_gadget\_udc() is called in dwc3\_gadget\_exit().

However, simply freeing the gadget results a dangling pointer
situation: the endpoints created in dwc3\_gadget\_init\_endpoints()
have their dep-\>endpoint.ep\_list members chained off the list\_head
anchored at dwc-\>gadget-\>ep\_list.  Thus when dwc-\>gadget is freed,
the first dwc3\_ep in the list now has a dangling prev pointer and
likewise for the next pointer of the dwc3\_ep at the tail of the list.
The dwc3\_gadget\_free\_endpoints() that follows will result in a
use-after-free when it calls list\_del().

This was caught by enabling KASAN and performing a driver unbind.
The recent commit 568262bf5492 ("usb: dwc3: core: Add shutdown
callback for dwc3") also exposes this as a panic during shutdown.

There are a few possibilities to fix this.  One could be to perform
a list\_del() of the gadget-\>ep\_list itself which removes it from
the rest of the dwc3\_ep chain.

Another approach is what this patch does, by splitting up the
usb\_del\_gadget\_udc() call into its separate "del" and "put"
components.  This allows dwc3\_gadget\_free\_endpoints() to be
called before the gadget is finally freed with usb\_put\_gadget().

## Affected and fixed versions

- Linux: \>= e81a7018d93a7de31a3f121c9a7eecd0a5ec58b0, \< 1ea775021282d90e1d08d696b7ab54aa75d688e5; \>= e81a7018d93a7de31a3f121c9a7eecd0a5ec58b0, \< bc0cdd72493236fb72b390ad38ce581e353c143c; \>= e81a7018d93a7de31a3f121c9a7eecd0a5ec58b0, \< b4b8e9601d7ee8806d2687f081a42485d27674a1; \>= e81a7018d93a7de31a3f121c9a7eecd0a5ec58b0, \< bb9c74a5bd1462499fe5ccb1e3c5ac40dcfa9139 (cvelist)
- Linux: 5.10 (cvelist)

## Mitigation

- No fix listed yet: follow the vendor advisory.

## Check your systems with an agent

Paste this into a coding agent:

```text
Check whether anything I run is affected by CVE-2021-46986. Work read-only: do not install, upgrade, delete or change anything.

Details: https://flawdb.com/CVE-2021-46986.md
Affected: Linux >= e81a7018d93a7de31a3f121c9a7eecd0a5ec58b0, < 1ea775021282d90e1d08d696b7ab54aa75d688e5; >= e81a7018d93a7de31a3f121c9a7eecd0a5ec58b0, < bc0cdd72493236fb72b390ad38ce581e353c143c; >= e81a7018d93a7de31a3f121c9a7eecd0a5ec58b0, < b4b8e9601d7ee8806d2687f081a42485d27674a1; >= e81a7018d93a7de31a3f121…
Fixed in: Linux 1ea775021282d90e1d08d696b7ab54aa75d688e5

Steps:
1. Search this machine and project for Linux: dependency manifests and lockfiles, installed packages, container images and running services.
2. For each match, note the installed version and whether it is inside the affected range.
3. Report a table: location, installed version, affected (yes / no / unsure), evidence. If affected, say which fixed version or mitigation from the details link applies, but don't apply it.
```

## FAQ

### Is CVE-2021-46986 being exploited?

There is no confirmed exploitation: CVE-2021-46986 is not in the CISA Known Exploited Vulnerabilities catalog. No public exploit code is known. EPSS estimates a 0.23% chance of exploitation in the next 30 days (as of 2026-11-26).

### How serious is CVE-2021-46986?

Medium: CVSS 5.5 (v3.1, scored by NVD). Not remotely exploitable (local or adjacent access needed).

### Which versions are affected by CVE-2021-46986?

Linux \>= e81a7018d93a7de31a3f121c9a7eecd0a5ec58b0, \< 1ea775021282d90e1d08d696b7ab54aa75d688e5; \>= e81a7018d93a7de31a3f121c9a7eecd0a5ec58b0, \< bc0cdd72493236fb72b390ad38ce581e353c143c; \>= e81a7018d93a7de31a3f121c9a7eecd0a5ec58b0, \< b4b8e9601d7ee8806d2687f081a42485d27674a1; \>= e81a7018d93a7de31a3f121c9a7eecd0a5ec58b0, \< bb9c74a5bd1462499fe5ccb1e3c5ac40dcfa9139; Linux 5.10.

### Is there a fix for CVE-2021-46986?

Yes. Fixed in Linux 1ea775021282d90e1d08d696b7ab54aa75d688e5. No fix listed yet: follow the vendor advisory.

### How do I check if I'm affected by CVE-2021-46986?

Find where you use the affected software (dependency lockfiles, installed packages, container images, servers) and compare the installed version with the affected range above. The agent prompt on this page does this read-only.

## References

- patch: <https://git.kernel.org/stable/c/1ea775021282d90e1d08d696b7ab54aa75d688e5>
- patch: <https://git.kernel.org/stable/c/bc0cdd72493236fb72b390ad38ce581e353c143c>
- patch: <https://git.kernel.org/stable/c/b4b8e9601d7ee8806d2687f081a42485d27674a1>
- patch: <https://git.kernel.org/stable/c/bb9c74a5bd1462499fe5ccb1e3c5ac40dcfa9139>

## Attribution

- CVE Program: CVE® is a registered trademark of The MITRE Corporation. CVE records © 1999–2026 The MITRE Corporation. <https://www.cve.org/Legal/TermsOfUse>
- NVD: This product uses data from the NVD API but is not endorsed or certified by the NVD. <https://nvd.nist.gov/vuln/detail/CVE-2021-46986>

HTML: <https://flawdb.com/CVE-2021-46986> · JSON: <https://flawdb.com/api/v1/entries/CVE-2021-46986>
