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-&gt;gadget structure upon the device&amp;#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-&gt;endpoint.ep_list members chained off the list_head<br /> anchored at dwc-&gt;gadget-&gt;ep_list. Thus when dwc-&gt;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-&gt;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().

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:*:*:*:*:*:*