vendor: a bulk OUT completion queued before SET_INTERFACE re-arms over vendord_set_alt's receive
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- c
- Domain
- embedded-iot
Research direction
Start with vendor_device.c at vendord_set_alt and vendord_xfer_cb, then trace queued endpoint completions through usbd.c and the nrf5x implementation in dcd_nrf5x.c. The report is a code trace and has not been reproduced; first verify the event ordering and failure on nrf5x with alternate settings enabled. Done means stale OUT completions cannot deliver data from the previous setting or cause the receive to be armed twice.
Written by the indexing model from the issue text.
Description
Greptile raised this in adafruit/Adafruit_TinyUSB_Arduino#615, the vendored sync of d543126c5. I checked it against
26adc208a; it is unchanged on current master.
Trigger
CFG_TUD_VENDOR_ALT_SETTINGS=1withCFG_TUD_VENDOR_RX_MANUAL_XFER=0, the default.- SET_INTERFACE to a setting that reuses the armed bulk OUT address: the same setting again, or two settings sharing
the endpoint. - An OUT completion on that endpoint queued after the SETUP event. On nrf5x this needs no host misbehaviour.
dcd_int_handlerqueues EP0SETUP before OUT END in the same ISR pass (dcd_nrf5x.c:988-993), and a bulk OUT
completes only after its EasyDMA run.
Causal path
vendord_control_xfer_cb→vendord_set_alt(vendor_device.c:885-888). The stall and clear-stall (:569-570,
:605-606) retire the old transfer in the DCD, but its completion is already queued.usbd_edpt_xferarms a new receive (:614-615). nrf5x setsstarted = true(dcd_nrf5x.c:576-577).- The stale completion is dispatched (
usbd.c:742-776). The endpoint is still bound to the vendor driver, so nothing
filters it; #4385 only drops completions on unbound endpoints. usbd clears BUSY and CLAIMED (:757-760). vendord_xfer_cb(vendor_device.c:956-961) delivers the old setting's data throughtud_vendor_rx_cband calls
usbd_edpt_xferagain. The usbd BUSY check passes (usbd.c:1730), and nrf5x failsTU_ASSERT(!xfer->started)
(dcd_nrf5x.c:557).
Consequence
- With a debugger attached, or
DHCSR.C_DEBUGENleft set, the assert runs BKPT, which escalates to a HardFault lockup. - Otherwise
usbd_edpt_xferreturns false while the DCD keeps the receive armed, and RX resumes on the next packet. - In both cases one packet from the old setting reaches the app as new-setting data.
rx_cbreads the buffer that the
still-armed receive may DMA into. - Ports without the
startedcheck re-program an armed endpoint; not analysed.
Related
- #4212 item 1: the same usbd mechanism, for nrf5x
data_received. - #3962:
dcd_edpt_abort_xfer. - #4385 and #4428.
Uncertain
- Not reproduced; this is a code trace only, and DCDs other than nrf5x were not checked.
RX_MANUAL_XFER=1can probably hit the same assert when an app thread arms the endpoint between the two events; not
traced. The only in-tree ALT_SETTINGS example,usbtest, usesRX_MANUAL_XFER=1.- A fix likely needs a per-endpoint transfer generation in usbd to drop completions of retired transfers.
- Dominant language
- C
- Stars
- 7.3k
- Forks
- 1.6k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 67
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from hathach/tinyusb
-
follow-up Port WCH USBFS Prio 📌
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
Maintainers usually reply within 1 day
-
follow-up Prio 📌
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
hil-contract: a background hil_remote.py launch is killed at the Bash default 10 min timeoutPossibly taken @hathach claimed this 16 days ago. Openfollow-up Prio 📌
Difficulty 1/5 Under an hour Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
ch32v30x: debug UART loses queued bytes when its TX ring fillsPossibly taken @hathach claimed this 16 days ago. Openfollow-up Prio 📌
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
Maintainers usually reply within 1 day
-
followup Prio 📌
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 69/100
-
Missing slice offset check in jvp_equal fast path corrupts slice comparison and aborts delpathsOpen
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 3 days
-
Difficulty 1/5 Under an hour Newbie friendliness 83/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
area9innovation/flow9#1805 ·
Maintainers usually reply within 3 days
-
AI:Robustness triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
open5gs/open5gs#5246 · 1 comment ·
Maintainers usually reply within 1 day