* [PATCH] phy: phy-bcm-ns2-usbdrd: cancel extcon work on unbind to avoid use-after-free
@ 2026-11-07 10:02 hyunjungg
2026-11-09 15:49 ` Ray Jui
0 siblings, 1 reply; 2+ messages in thread
From: hyunjungg @ 2026-11-07 10:02 UTC (permalink / raw)
To: Vinod Koul, Florian Fainelli, linux-phy
Cc: Ray Jui, Scott Branden, bcm-kernel-feedback-list, linux-kernel,
Hyunjung Ko, stable
From: Hyunjung Ko <hj351016@gmail.com>
ns2_drd_phy_probe() schedules driver->wq_extcon (extcon_work), which is
also queued from the ID/VBUS GPIO interrupt handler gpio_irq_handler().
The work handler dereferences the driver data via container_of().
struct ns2_phy_driver is allocated with devm_kzalloc() and the driver has
no remove callback, so on unbind devres frees it after probe's resources
are released. The GPIO interrupts are released with devm_request_irq(),
but free_irq() only stops further interrupts; it does not cancel a delayed
work that is already queued. probe() queues wq_extcon with a debounce
delay before returning, and the GPIO interrupt can queue it too, so on
unbind the pending work can run after ns2_phy_driver has been freed,
dereferencing freed memory (use-after-free).
Register the work with devm_delayed_work_autocancel() instead of
INIT_DELAYED_WORK(). It is set up before the GPIO interrupts are
requested, so on unwind devres frees the interrupts first - after which
the work can no longer be queued - and then cancels the work while the
driver data is still valid. extcon_work() does not re-queue itself, so a
single cancel drains it.
Found by static analysis and code review; not runtime-reproduced (needs
Broadcom Northstar2 USB DRD PHY hardware).
Fixes: 787f24543c4a ("phy: phy-bcm-ns2-usbdrd: Broadcom USB DRD PHY driver for Northstar2")
Cc: stable@vger.kernel.org
Signed-off-by: Hyunjung Ko <hj351016@gmail.com>
---
drivers/phy/broadcom/phy-bcm-ns2-usbdrd.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/phy/broadcom/phy-bcm-ns2-usbdrd.c b/drivers/phy/broadcom/phy-bcm-ns2-usbdrd.c
index 171bf09..4b8930b 100644
--- a/drivers/phy/broadcom/phy-bcm-ns2-usbdrd.c
+++ b/drivers/phy/broadcom/phy-bcm-ns2-usbdrd.c
@@ -6,6 +6,7 @@
#include <linux/gpio/consumer.h>
#include <linux/init.h>
#include <linux/interrupt.h>
+#include <linux/devm-helpers.h>
#include <linux/io.h>
#include <linux/iopoll.h>
#include <linux/irq.h>
@@ -339,7 +340,9 @@ static int ns2_drd_phy_probe(struct platform_device *pdev)
if (ret < 0)
driver->debounce_jiffies = msecs_to_jiffies(GPIO_DELAY);
- INIT_DELAYED_WORK(&driver->wq_extcon, extcon_work);
+ ret = devm_delayed_work_autocancel(dev, &driver->wq_extcon, extcon_work);
+ if (ret)
+ return ret;
driver->id_irq = gpiod_to_irq(driver->id_gpiod);
if (driver->id_irq < 0) {
--
2.43.0
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] phy: phy-bcm-ns2-usbdrd: cancel extcon work on unbind to avoid use-after-free
2026-11-07 10:02 [PATCH] phy: phy-bcm-ns2-usbdrd: cancel extcon work on unbind to avoid use-after-free hyunjungg
@ 2026-11-09 15:49 ` Ray Jui
0 siblings, 0 replies; 2+ messages in thread
From: Ray Jui @ 2026-11-09 15:49 UTC (permalink / raw)
To: hyunjungg
Cc: Vinod Koul, Florian Fainelli, linux-phy, Ray Jui, Scott Branden,
bcm-kernel-feedback-list, linux-kernel, stable
[-- Attachment #1.1: Type: text/plain, Size: 2971 bytes --]
On Sat, Nov 7, 2026 at 3:03 AM hyunjungg <hj351016@gmail.com> wrote:
>
> From: Hyunjung Ko <hj351016@gmail.com>
>
> ns2_drd_phy_probe() schedules driver->wq_extcon (extcon_work), which is
> also queued from the ID/VBUS GPIO interrupt handler gpio_irq_handler().
> The work handler dereferences the driver data via container_of().
>
> struct ns2_phy_driver is allocated with devm_kzalloc() and the driver has
> no remove callback, so on unbind devres frees it after probe's resources
> are released. The GPIO interrupts are released with devm_request_irq(),
This description here is misleading. I think you should say, "The GPIO
interrupts are requested with devm_request_irq(), and so released by
devres".
> but free_irq() only stops further interrupts; it does not cancel a delayed
> work that is already queued. probe() queues wq_extcon with a debounce
> delay before returning, and the GPIO interrupt can queue it too, so on
> unbind the pending work can run after ns2_phy_driver has been freed,
> dereferencing freed memory (use-after-free).
>
> Register the work with devm_delayed_work_autocancel() instead of
> INIT_DELAYED_WORK(). It is set up before the GPIO interrupts are
> requested, so on unwind devres frees the interrupts first - after which
> the work can no longer be queued - and then cancels the work while the
> driver data is still valid. extcon_work() does not re-queue itself, so a
> single cancel drains it.
>
> Found by static analysis and code review; not runtime-reproduced (needs
> Broadcom Northstar2 USB DRD PHY hardware).
>
> Fixes: 787f24543c4a ("phy: phy-bcm-ns2-usbdrd: Broadcom USB DRD PHY driver for Northstar2")
> Cc: stable@vger.kernel.org
> Signed-off-by: Hyunjung Ko <hj351016@gmail.com>
> ---
> drivers/phy/broadcom/phy-bcm-ns2-usbdrd.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/phy/broadcom/phy-bcm-ns2-usbdrd.c b/drivers/phy/broadcom/phy-bcm-ns2-usbdrd.c
> index 171bf09..4b8930b 100644
> --- a/drivers/phy/broadcom/phy-bcm-ns2-usbdrd.c
> +++ b/drivers/phy/broadcom/phy-bcm-ns2-usbdrd.c
> @@ -6,6 +6,7 @@
> #include <linux/gpio/consumer.h>
> #include <linux/init.h>
> #include <linux/interrupt.h>
> +#include <linux/devm-helpers.h>
nit. but the existing include files are in alphabetical order, so
please also follow that in your change.
> #include <linux/io.h>
> #include <linux/iopoll.h>
> #include <linux/irq.h>
> @@ -339,7 +340,9 @@ static int ns2_drd_phy_probe(struct platform_device *pdev)
> if (ret < 0)
> driver->debounce_jiffies = msecs_to_jiffies(GPIO_DELAY);
>
> - INIT_DELAYED_WORK(&driver->wq_extcon, extcon_work);
> + ret = devm_delayed_work_autocancel(dev, &driver->wq_extcon, extcon_work);
> + if (ret)
> + return ret;
>
> driver->id_irq = gpiod_to_irq(driver->id_gpiod);
> if (driver->id_irq < 0) {
> --
> 2.43.0
>
[-- Attachment #1.2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 5449 bytes --]
[-- Attachment #2: Type: text/plain, Size: 112 bytes --]
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-09 15:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-07 10:02 [PATCH] phy: phy-bcm-ns2-usbdrd: cancel extcon work on unbind to avoid use-after-free hyunjungg
2026-11-09 15:49 ` Ray Jui
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox