Skip to contentSkip to conversation

usb: musb: fix use-after-free in musb_remove()

PATCH Superseded Joshua Crofts 3 participants 6 messages Nov 7 – Nov 20

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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.

Fixes 39cee200c23e ("usb: musb: core: call init and shutdown for the usb phy")
---
 drivers/usb/musb/musb_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/musb/musb_core.c +1 -1
index 73ac25f53698..8e52246de948 100644
@@ -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
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 7 lines

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.

Quoted 5 lines
Fixes 39cee200c23e ("usb: musb: core: call init and shutdown for the usb phy")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to Joshua Crofts
Quoted 41 lines · Joshua Crofts

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.

Fixes 39cee200c23e ("usb: musb: core: call init and shutdown for the usb phy")
---
 drivers/usb/musb/musb_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/musb/musb_core.c +1 -2
index 73ac25f53698..8e52246de948 100644
@@ -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

#3 lore raw
Quoted 7 lines · Greg Kroah-Hartman
Quoted 6 lines · Joshua Crofts

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.

...

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
#4 lore raw
In reply to Joshua Crofts
Quoted 41 lines · Joshua Crofts

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.

Fixes 39cee200c23e ("usb: musb: core: call init and shutdown for the usb phy")
---
 drivers/usb/musb/musb_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/musb/musb_core.c +1 -2
index 73ac25f53698..8e52246de948 100644
@@ -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

#5 lore raw
Quoted 42 lines · Greg Kroah-Hartman
Quoted 41 lines · Joshua Crofts

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.

Fixes 39cee200c23e ("usb: musb: core: call init and shutdown for the usb phy")
---
 drivers/usb/musb/musb_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/musb/musb_core.c +1 -2
index 73ac25f53698..8e52246de948 100644
@@ -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 Crofts

Does 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