FAILED: patch "[PATCH] usb: cdns3: fix use-after-free in cdns3_gadget_exit()" failed to apply to 5.10-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 5.10-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.10.y
git checkout FETCH_HEAD
git cherry-pick -x ebe9b68c396792c15d0ac690d592e449e74ed804
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026100534-purging-uniquely-0db7@gregkh' --subject-prefix 'PATCH 5.10.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From ebe9b68c396792c15d0ac690d592e449e74ed804 Mon Sep 17 00:00:00 2001
From: Fan Wu <[email protected]>
Date: Wed, 9 Sep 2026 09:56:55 +0000
Subject: [PATCH] usb: cdns3: fix use-after-free in cdns3_gadget_exit()
cdns3_gadget_start() arms two works on system_freezable_wq:pending_status_wq for the deferred ep0 status stage and aligned_buf_wq for realigned request buffers. Both handlers use the cdns3_device the works are embedded in, and cdns3_pending_setup_status_handler() also calls the ep0 request completion.
cdns3_gadget_exit() does not wait for these works. It frees all endpoints and aligned buffers and drops the last reference to the gadget device, which frees priv_dev, so a work queued before the exit can run after the free.
Fix this by waiting for both works after the gadget driver is unbound and the IRQ is freed, when no new work can be queued, and before the endpoints and buffers are released.
This issue was found by an in-house static analysis tool.
drivers/usb/cdns3/cdns3-gadget.c +4 -0
@@ -3269,6 +3269,10 @@ static void cdns3_gadget_exit(struct cdns *cdns)usb_del_gadget (&priv_dev->gadget);devm_free_irq (cdns->dev, cdns->dev_irq, priv_dev); +/* The works can still be queued until the IRQ is freed. */ +cancel_work_sync (&priv_dev->pending_status_wq); +cancel_work_sync (&priv_dev->aligned_buf_wq); +cdns3_free_all_eps (priv_dev);while (!list_empty (&priv_dev->aligned_buf_list)) {
Sasha Levin
maintainerPATCH 1/1 usb: cdns3: fix use-after-free in cdns3_gadget_exit()
From: Fan Wu <[email protected]>
[ Upstream commit ebe9b68c396792c15d0ac690d592e449e74ed804 ]
cdns3_gadget_start() arms two works on system_freezable_wq:pending_status_wq for the deferred ep0 status stage and aligned_buf_wq for realigned request buffers. Both handlers use the cdns3_device the works are embedded in, and cdns3_pending_setup_status_handler() also calls the ep0 request completion.
cdns3_gadget_exit() does not wait for these works. It frees all endpoints and aligned buffers and drops the last reference to the gadget device, which frees priv_dev, so a work queued before the exit can run after the free.
Fix this by waiting for both works after the gadget driver is unbound and the IRQ is freed, when no new work can be queued, and before the endpoints and buffers are released.
This issue was found by an in-house static analysis tool.
--- drivers/usb/cdns3/gadget.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/usb/cdns3/gadget.c +4 -0
@@ -3254,6 +3254,10 @@ void cdns3_gadget_exit(struct cdns3 *cdns)usb_del_gadget (&priv_dev->gadget);devm_free_irq (cdns->dev, cdns->dev_irq, priv_dev); +/* The works can still be queued until the IRQ is freed. */ +cancel_work_sync (&priv_dev->pending_status_wq); +cancel_work_sync (&priv_dev->aligned_buf_wq); +cdns3_free_all_eps (priv_dev);while (!list_empty (&priv_dev->aligned_buf_list)) {
Signature · 1 line
2.53.0