zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.99k stars 6.69k forks source link

UDC events silently dropped on queue full lead to USB stack issues #74058

Open tmon-nordic opened 5 months ago

tmon-nordic commented 5 months ago

Describe the bug udc_submit_ep_event() events are queued to usbd_msgq inside usbd_event_carrier(). The problem is that the function can silently fail to queue the event because k_msgq_put() is called with K_NO_WAIT: https://github.com/zephyrproject-rtos/zephyr/blob/0781caf408459dfd6c91477cedb62a43912a8c51/subsys/usb/device_next/usbd_core.c#L34-L38

This can lead to all sort of issues, but two major issues have been notified so far:

To Reproduce

The following ways to fill the message queue were identified so far:

Expected behavior Queued endpoint events are never dropped, i.e. there is always a matching struct usbd_class_api request call for every successful usbd_ep_enqueue().

Impact If the issue trigger, the stack can cease to work until device reboot.

Logs and console output Console output irrelevant, the underlying issue is that things that must never be silently dropped can be dropped.

Environment (please complete the following information):

Additional context "Catching up" with not handled SOFs do not make much sense and can lead to avalanche effects if too many SOFs are queued for handling.

github-actions[bot] commented 1 month ago

This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.