From: Chengyu Liu <lui2012qwq@gmail.com>
To: linux-usb@vger.kernel.org
Cc: b-liu@ti.com, gregkh@linuxfoundation.org, nkapron@google.com,
tony@atomide.com, bigeasy@linutronix.de, balbi@ti.com,
shimoda.yoshihiro@renesas.com, robert.jarzmik@free.fr,
Chengyu Liu <lui2012qwq@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH 4/4] usb: phy: gpio-vbus: free the interrupt before cancelling the work
Date: Fri, 13 Nov 2026 00:04:48 +0800 [thread overview]
Message-ID: <20261112160448.41566-5-lui2012qwq@gmail.com> (raw)
In-Reply-To: <20261112160448.41566-1-lui2012qwq@gmail.com>
gpio_vbus_remove() cancels gpio_vbus->work while the VBUS sensing GPIO
interrupt is still live: it is devm-managed and freed only at detach,
and gpio_vbus_irq() schedules the work with a 100 ms debounce delay.
A plug event landing after the cancel re-arms the work, and its timer
then fires on the freed gpio_vbus_data.
Free the interrupt first, which also waits for any running handler,
so nothing can re-arm the work past the cancel.
Found by static analysis and confirmed with a KASAN reproducer:
slab-use-after-free write in __run_timer_base() within one debounce
interval of unregistering the device while its VBUS GPIO is toggled
(object allocated by gpio_vbus_probe() via devm_kmalloc(), freed by
devres_release_all() at unbind).
Fixes: c2344f13b59e ("USB: gpio_vbus: add delayed vbus_session calls")
Cc: stable@vger.kernel.org
Signed-off-by: Chengyu Liu <lui2012qwq@gmail.com>
---
The reproducer instantiates the unmodified driver on a gpio-sim
chip in QEMU and toggles the line while the device is unregistered;
it widens the remove()-to-detach window with a 500 ms sleep, logic
otherwise unmodified. Repeated runs: 5/5 KASAN splats without the
fix, 0/5 with it. The KASAN report and the reproducer kit follow
in this thread. Also build-tested on x86_64 (USB_GPIO_VBUS).
Fix written with AI assistance.
drivers/usb/phy/phy-gpio-vbus-usb.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/drivers/usb/phy/phy-gpio-vbus-usb.c b/drivers/usb/phy/phy-gpio-vbus-usb.c
index 60b7c1219dd2..82d2301c3804 100644
--- a/drivers/usb/phy/phy-gpio-vbus-usb.c
+++ b/drivers/usb/phy/phy-gpio-vbus-usb.c
@@ -325,6 +325,14 @@ static void gpio_vbus_remove(struct platform_device *pdev)
struct gpio_vbus_data *gpio_vbus = platform_get_drvdata(pdev);
device_init_wakeup(&pdev->dev, 0);
+
+ /*
+ * The VBUS sensing GPIO interrupt is devm-managed and freed only
+ * at detach, and its handler schedules the work with a 100ms
+ * delay; free the interrupt before cancelling the work so a
+ * late plug event cannot re-arm it past the cancel.
+ */
+ devm_free_irq(&pdev->dev, gpio_vbus->irq, pdev);
cancel_delayed_work_sync(&gpio_vbus->work);
usb_remove_phy(&gpio_vbus->phy);
--
2.25.1
next prev parent reply other threads:[~2026-11-12 16:05 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-12 16:04 [PATCH 0/4] usb: stop timers/works left armed on teardown Chengyu Liu
2026-11-12 16:04 ` [PATCH 1/4] usb: musb: cancel irq_work after masking interrupts in musb_remove() Chengyu Liu
2026-11-12 16:04 ` [PATCH 2/4] usb: musb: dsps: free the VBUS interrupt before the child teardown Chengyu Liu
2026-11-12 16:04 ` [PATCH 3/4] usb: gadget: r8a66597: free the IRQ before deleting the timer Chengyu Liu
2026-11-12 16:18 ` sashiko-bot
2026-11-12 16:04 ` Chengyu Liu [this message]
2026-11-12 16:16 ` [PATCH 4/4] usb: phy: gpio-vbus: free the interrupt before cancelling the work sashiko-bot
2026-11-12 16:10 ` [PATCH 0/4] usb: stop timers/works left armed on teardown Chengyu Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261112160448.41566-5-lui2012qwq@gmail.com \
--to=lui2012qwq@gmail.com \
--cc=b-liu@ti.com \
--cc=balbi@ti.com \
--cc=bigeasy@linutronix.de \
--cc=gregkh@linuxfoundation.org \
--cc=linux-usb@vger.kernel.org \
--cc=nkapron@google.com \
--cc=robert.jarzmik@free.fr \
--cc=shimoda.yoshihiro@renesas.com \
--cc=stable@vger.kernel.org \
--cc=tony@atomide.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox