usb: musb: fix use-after-free in musb_remove()
Subsystems (3)
PATCH 1/1 usb: musb: fix use-after-free in musb_remove()
Currently in musb_remove(), musb_platform_exit() drops the PHY refcount before usb_phy_shutdown() is called, causing a use-after-free bug.
Reorder the function so that usb_phy_shutdown() is called before musb_platform_exit(), the same way as musb_init_controller() does in the error path.
--- drivers/usb/musb/musb_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/musb/musb_core.c +1 -1
@@ -2642,6 +2642,7 @@ static void musb_remove(struct platform_device *pdev)musb_disable_interrupts (musb);musb_writeb (musb->mregs,MUSB_DEVCTL ,0 );spin_unlock_irqrestore (&musb->lock, flags); +usb_phy_shutdown (musb->xceiv);musb_platform_exit (musb);pm_runtime_dont_use_autosuspend (musb->controller);
@@ -2650,7 +2651,6 @@ static void musb_remove(struct platform_device *pdev) musb_phy_callback =NULL ;if (musb->dma_controller)musb_dma_controller_destroy (musb->dma_controller); -usb_phy_shutdown (musb->xceiv);musb_free (musb);device_init_wakeup (dev,0 ); }
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261107-usb-uaf-fix-bedcd9cd8f4b
Best regards,
Signature · 1 line
Joshua Crofts
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 7 lines
Currently in
musb_remove(),musb_platform_exit()drops the PHY refcount beforeusb_phy_shutdown()is called, causing a use-after-free bug.Reorder the function so that
usb_phy_shutdown()is called beforemusb_platform_exit(), the same way asmusb_init_controller()does in the error path.
Quoted 5 lines
Reported-by Sashiko <[email protected]>Fixes 39cee200c23e ("usb: musb: core: call init and shutdown for the usb phy")Signed-off-by Joshua Crofts <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Greg Kroah-Hartman
maintainerQuoted 41 lines · Joshua Crofts
Currently in
musb_remove(),musb_platform_exit()drops the PHY refcount beforeusb_phy_shutdown()is called, causing a use-after-free bug.Reorder the function so that
usb_phy_shutdown()is called beforemusb_platform_exit(), the same way asmusb_init_controller()does in the error path.Reported-by Sashiko <[email protected]>Fixes 39cee200c23e ("usb: musb: core: call init and shutdown for the usb phy")Signed-off-by Joshua Crofts <[email protected]>--- drivers/usb/musb/musb_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/usb/musb/musb_core.c +1
-2@@ -2642,6 +2642,7 @@ static void musb_remove(struct platform_device *pdev)musb_disable_interrupts (musb);musb_writeb (musb->mregs,MUSB_DEVCTL ,0 );spin_unlock_irqrestore (&musb->lock, flags); +usb_phy_shutdown (musb->xceiv);musb_platform_exit (musb);pm_runtime_dont_use_autosuspend (musb->controller);@@ -2650,7 +2651,6 @@ static void musb_remove(struct platform_device *pdev) musb_phy_callback =NULL ;if (musb->dma_controller)musb_dma_controller_destroy (musb->dma_controller); -usb_phy_shutdown (musb->xceiv);musb_free (musb);device_init_wakeup (dev,0 ); } ---base-commit:
6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261107-usb-uaf-fix-bedcd9cd8f4b
Quoted 4 lines
Best regards,
Signature · 1 line
Joshua Crofts
Does not apply to the usb-linus branch, please rebase and resend.
thanks,
greg k-h
Quoted 7 lines · Greg Kroah-Hartman
Quoted 6 lines · Joshua Crofts
Currently in
musb_remove(),musb_platform_exit()drops the PHY refcount beforeusb_phy_shutdown()is called, causing a use-after-free bug.Reorder the function so that
usb_phy_shutdown()is called beforemusb_platform_exit(), the same way asmusb_init_controller()does in the error path.
...
Quoted 3 lines
Quoted 1 line
Does not apply to the usb-linus branch, please rebase and resend.
Sorry, rebased patch here:
https://lore.kernel.org/linux-usb/[email protected]
Signature · 2 lines
Kind regards, Joshua Crofts
Greg Kroah-Hartman
maintainerQuoted 41 lines · Joshua Crofts
Currently in
musb_remove(),musb_platform_exit()drops the PHY refcount beforeusb_phy_shutdown()is called, causing a use-after-free bug.Reorder the function so that
usb_phy_shutdown()is called beforemusb_platform_exit(), the same way asmusb_init_controller()does in the error path.Reported-by Sashiko <[email protected]>Fixes 39cee200c23e ("usb: musb: core: call init and shutdown for the usb phy")Signed-off-by Joshua Crofts <[email protected]>--- drivers/usb/musb/musb_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/usb/musb/musb_core.c +1
-2@@ -2642,6 +2642,7 @@ static void musb_remove(struct platform_device *pdev)musb_disable_interrupts (musb);musb_writeb (musb->mregs,MUSB_DEVCTL ,0 );spin_unlock_irqrestore (&musb->lock, flags); +usb_phy_shutdown (musb->xceiv);musb_platform_exit (musb);pm_runtime_dont_use_autosuspend (musb->controller);@@ -2650,7 +2651,6 @@ static void musb_remove(struct platform_device *pdev) musb_phy_callback =NULL ;if (musb->dma_controller)musb_dma_controller_destroy (musb->dma_controller); -usb_phy_shutdown (musb->xceiv);musb_free (musb);device_init_wakeup (dev,0 ); } ---base-commit:
6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261107-usb-uaf-fix-bedcd9cd8f4b
Quoted 4 lines
Best regards,
Signature · 1 line
Joshua Crofts
Does not apply to usb-linus
Quoted 42 lines · Greg Kroah-Hartman
Quoted 41 lines · Joshua Crofts
Currently in
musb_remove(),musb_platform_exit()drops the PHY refcount beforeusb_phy_shutdown()is called, causing a use-after-free bug.Reorder the function so that
usb_phy_shutdown()is called beforemusb_platform_exit(), the same way asmusb_init_controller()does in the error path.Reported-by Sashiko <[email protected]>Fixes 39cee200c23e ("usb: musb: core: call init and shutdown for the usb phy")Signed-off-by Joshua Crofts <[email protected]>--- drivers/usb/musb/musb_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/usb/musb/musb_core.c +1
-2@@ -2642,6 +2642,7 @@ static void musb_remove(struct platform_device *pdev)musb_disable_interrupts (musb);musb_writeb (musb->mregs,MUSB_DEVCTL ,0 );spin_unlock_irqrestore (&musb->lock, flags); +usb_phy_shutdown (musb->xceiv);musb_platform_exit (musb);pm_runtime_dont_use_autosuspend (musb->controller);@@ -2650,7 +2651,6 @@ static void musb_remove(struct platform_device *pdev) musb_phy_callback =NULL ;if (musb->dma_controller)musb_dma_controller_destroy (musb->dma_controller); -usb_phy_shutdown (musb->xceiv);musb_free (musb);device_init_wakeup (dev,0 ); } ---base-commit:
6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261107-usb-uaf-fix-bedcd9cd8f4b
Quoted 6 lines
Quoted 4 lines
Best regards,
Signature · 1 line
Joshua CroftsDoes not apply to usb-linus
I already sent a rebased v2:
https://lore.kernel.org/linux-usb/[email protected]
Signature · 2 lines
Kind regards, Joshua Crofts