CVE-2021-46986
Severity CVSS v4.0:
Pending analysis
Type:
CWE-416
Use After Free
Publication date:
28/02/2024
Last modified:
31/12/2024
Description
In the Linux kernel, the following vulnerability has been resolved:<br />
<br />
usb: dwc3: gadget: Free gadget structure only after freeing endpoints<br />
<br />
As part of commit e81a7018d93a ("usb: dwc3: allocate gadget structure<br />
dynamically") the dwc3_gadget_release() was added which will free<br />
the dwc->gadget structure upon the device&#39;s removal when<br />
usb_del_gadget_udc() is called in dwc3_gadget_exit().<br />
<br />
However, simply freeing the gadget results a dangling pointer<br />
situation: the endpoints created in dwc3_gadget_init_endpoints()<br />
have their dep->endpoint.ep_list members chained off the list_head<br />
anchored at dwc->gadget->ep_list. Thus when dwc->gadget is freed,<br />
the first dwc3_ep in the list now has a dangling prev pointer and<br />
likewise for the next pointer of the dwc3_ep at the tail of the list.<br />
The dwc3_gadget_free_endpoints() that follows will result in a<br />
use-after-free when it calls list_del().<br />
<br />
This was caught by enabling KASAN and performing a driver unbind.<br />
The recent commit 568262bf5492 ("usb: dwc3: core: Add shutdown<br />
callback for dwc3") also exposes this as a panic during shutdown.<br />
<br />
There are a few possibilities to fix this. One could be to perform<br />
a list_del() of the gadget->ep_list itself which removes it from<br />
the rest of the dwc3_ep chain.<br />
<br />
Another approach is what this patch does, by splitting up the<br />
usb_del_gadget_udc() call into its separate "del" and "put"<br />
components. This allows dwc3_gadget_free_endpoints() to be<br />
called before the gadget is finally freed with usb_put_gadget().
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.38 (excluding) |
| cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* | 5.11 (including) | 5.11.22 (excluding) |
| cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* | 5.12 (including) | 5.12.5 (excluding) |
| cpe:2.3:o:linux:linux_kernel:5.13:rc1:*:*:*:*:*:* |
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/1ea775021282d90e1d08d696b7ab54aa75d688e5
- https://git.kernel.org/stable/c/b4b8e9601d7ee8806d2687f081a42485d27674a1
- https://git.kernel.org/stable/c/bb9c74a5bd1462499fe5ccb1e3c5ac40dcfa9139
- https://git.kernel.org/stable/c/bc0cdd72493236fb72b390ad38ce581e353c143c
- https://git.kernel.org/stable/c/1ea775021282d90e1d08d696b7ab54aa75d688e5
- https://git.kernel.org/stable/c/b4b8e9601d7ee8806d2687f081a42485d27674a1
- https://git.kernel.org/stable/c/bb9c74a5bd1462499fe5ccb1e3c5ac40dcfa9139
- https://git.kernel.org/stable/c/bc0cdd72493236fb72b390ad38ce581e353c143c



