This patch is 2-part (in one). It reverts commit 3fc137386c46 ("usb: musb: Fix hardware lockup on first Rx endpoint request") and implements the second possible fix suggested in that commit. Reverting that commit alone would bring back CVE-2024-56687 which it addresses. However, the fix causes a regression in cases where the USB gadget device exposes itself as USB mass storage device. With that commit, musb_ep_restart() flushes the RX FIFO instead of reading it. As a consequence, a packet that came before the OUT request is lost. With the mass storage gadget the host loses commands (CBW), times out and resets the device; so, the PC never mounts the drive. We've found the issue in kernel 6.12.57. And we've identified the problem by reverting the driver to the 6.1.119 version (where this problem did not exist). The same commit also offers an alternative fix which works fine for the USB mass storage case. i.e. 2. Disable MUSB interrupts in musb_g_giveback() before calling the callback and re-enable them afterwars (by calling musb_{dis,en}able_interrupts(), for example). This would ensure that MUSB interrupts are not handled during the callback, even if IRQs are enabled. In fact, it would allow IRQs to be enabled when releasing the lock. However, this feels like an inelegant hack. This change also implements that fix. Fixes: 3fc137386c46 ("usb: musb: Fix hardware lockup on first Rx endpoint request") Signed-off-by: Alexandru Ardelean --- drivers/usb/musb/musb_gadget.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c index 016d3f3fc1e05..5cb7eb9c56de0 100644 --- a/drivers/usb/musb/musb_gadget.c +++ b/drivers/usb/musb/musb_gadget.c @@ -145,7 +145,10 @@ __acquires(ep->musb->lock) unmap_dma_buffer(req, musb); trace_musb_req_gb(req); + /* no MUSB interrupt during complete(), even if it enables IRQs */ + disable_irq_nosync(musb->nIrq); usb_gadget_giveback_request(&req->ep->end_point, &req->request); + enable_irq(musb->nIrq); spin_lock(&musb->lock); ep->busy = busy; } @@ -1162,19 +1165,12 @@ void musb_free_request(struct usb_ep *ep, struct usb_request *req) */ void musb_ep_restart(struct musb *musb, struct musb_request *req) { - u16 csr; - void __iomem *epio = req->ep->hw_ep->regs; - trace_musb_req_start(req); musb_ep_select(musb->mregs, req->epnum); - if (req->tx) { + if (req->tx) txstate(musb, req); - } else { - csr = musb_readw(epio, MUSB_RXCSR); - csr |= MUSB_RXCSR_FLUSHFIFO | MUSB_RXCSR_P_WZC_BITS; - musb_writew(epio, MUSB_RXCSR, csr); - musb_writew(epio, MUSB_RXCSR, csr); - } + else + rxstate(musb, req); } static int musb_ep_restart_resume_work(struct musb *musb, void *data) -- 2.43.0