bug: usb: gadget: FSL_UDC_CORE Corrupted request list leads to unrecoverable loop.
Joakim Tjernlund
Joakim.Tjernlund at infinera.com
Sun Oct 31 01:20:12 AEDT 2021
On Fri, 2021-10-29 at 17:14 +0000, Eugene Bordenkircher wrote:
> Hello all,
>
> We've discovered a situation where the FSL udc driver (drivers/usb/gadget/udc/fsl_udc_core.c) will enter a loop iterating over the request queue, but the queue has been corrupted at some point so it loops infinitely. I believe we have narrowed into the offending code, but we are in need of assistance trying to find an appropriate fix for the problem. The identified code appears to be in all versions of the Linux kernel the driver exists in.
>
> The problem appears to be when handling a USB_REQ_GET_STATUS request. The driver gets this request and then calls the ch9getstatus() function. In this function, it starts a request by "borrowing" the per device status_req, filling it in, and then queuing it with a call to list_add_tail() to add the request to the endpoint queue. Right before it exits the function however, it's calling ep0_prime_status(), which is filling out that same status_req structure and then queuing it with another call to list_add_tail() to add the request to the endpoint queue. This adds two instances of the exact same LIST_HEAD to the endpoint queue, which breaks the list since the prev and next pointers end up pointing to the wrong things. This ends up causing a hard loop the next time nuke() gets called, which happens on the next setup IRQ.
>
> I'm not sure what the appropriate fix to this problem is, mostly due to my lack of expertise in USB and this driver stack. The code has been this way in the kernel for a very long time, which suggests that it has been working, unless USB_REQ_GET_STATUS requests are never made. This further suggests that there is something else going on that I don't understand. Deleting the call to ep0_prime_status() and the following ep0stall() call appears, on the surface, to get the device working again, but may have side effects that I'm not seeing.
>
> I'm hopeful someone in the community can help provide some information on what I may be missing or help come up with a solution to the problem. A big thank you to anyone who would like to help out.
>
> Eugene
Run into this to a while ago. Found the bug and a few more fixes.
This is against 4.19 so you may have to tweak them a bit.
Feel free to upstream them.
Jocke
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0005-fsl_udc_core-Init-max_pipes-for-reset_queues.patch
Type: text/x-patch
Size: 989 bytes
Desc: 0005-fsl_udc_core-Init-max_pipes-for-reset_queues.patch
URL: <http://lists.ozlabs.org/pipermail/linuxppc-dev/attachments/20211030/1d4d4e37/attachment-0005.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0004-fsl_udc_stop-Use-list_for_each_entry_safe-when-delet.patch
Type: text/x-patch
Size: 1422 bytes
Desc: 0004-fsl_udc_stop-Use-list_for_each_entry_safe-when-delet.patch
URL: <http://lists.ozlabs.org/pipermail/linuxppc-dev/attachments/20211030/1d4d4e37/attachment-0006.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0003-fsl_ep_dequeue.patch
Type: text/x-patch
Size: 1007 bytes
Desc: 0003-fsl_ep_dequeue.patch
URL: <http://lists.ozlabs.org/pipermail/linuxppc-dev/attachments/20211030/1d4d4e37/attachment-0007.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-fsl_udc-import-build_dtd-fixes.patch
Type: text/x-patch
Size: 2239 bytes
Desc: 0002-fsl_udc-import-build_dtd-fixes.patch
URL: <http://lists.ozlabs.org/pipermail/linuxppc-dev/attachments/20211030/1d4d4e37/attachment-0008.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-ch9getstatus-ep0_prime_status-fixes-RND-28770.patch
Type: text/x-patch
Size: 4367 bytes
Desc: 0001-ch9getstatus-ep0_prime_status-fixes-RND-28770.patch
URL: <http://lists.ozlabs.org/pipermail/linuxppc-dev/attachments/20211030/1d4d4e37/attachment-0009.bin>
More information about the Linuxppc-dev
mailing list