Netdev List
 help / color / mirror / Atom feed
From: Oliver Neukum <oneukum@suse.com>
To: petkan@nucleusys.com, netdev@vger.kernel.org
Cc: Oliver Neukum <oneukum@suse.com>
Subject: [RFT 1/3] net: usb: rtl8150: break cycle between tasklet and URB
Date: Wed, 25 Nov 2026 15:43:07 +0100	[thread overview]
Message-ID: <20261125145313.58434-2-oneukum@suse.com> (raw)
In-Reply-To: <20261125145313.58434-1-oneukum@suse.com>

The driver shows two different cycles that can result in
an URB or the tasklet or both to be in active use after
disconnect() or suspend() return, which will in turn
lead to a use after free.
Firstly, the tasklet will in its error handling reschedule
itself without checking the flag that indicates that the
device has been disconnected or suspended.
Secondly, the URB and the tasklet can reschedule
respectively resubmit each other in turn. To break
that cycle in addition to checking the flag the URB
has to be poisoned.

Signed-off-by: Oliver Neukum <oneukum@suse.com>
---
 drivers/net/usb/rtl8150.c | 33 +++++++++++++++++++++++++++------
 1 file changed, 27 insertions(+), 6 deletions(-)

diff --git a/drivers/net/usb/rtl8150.c b/drivers/net/usb/rtl8150.c
index d51e43170e03..547a14beafb8 100644
--- a/drivers/net/usb/rtl8150.c
+++ b/drivers/net/usb/rtl8150.c
@@ -353,6 +353,13 @@ static void free_all_urbs(rtl8150_t * dev)
 	usb_free_urb(dev->intr_urb);
 }
 
+static void terminate_all_urbs(rtl8150_t *dev)
+{
+	usb_poison_urb(dev->rx_urb);
+	usb_poison_urb(dev->tx_urb);
+	usb_poison_urb(dev->intr_urb);
+}
+
 static void unlink_all_urbs(rtl8150_t * dev)
 {
 	usb_kill_urb(dev->rx_urb);
@@ -528,12 +535,15 @@ static int rtl8150_suspend(struct usb_interface *intf, pm_message_t message)
 {
 	rtl8150_t *dev = usb_get_intfdata(intf);
 
+	spin_lock_irq(&dev->rx_pool_lock);
+	set_bit(RTL8150_UNPLUG, &dev->flags);
+	spin_unlock_irq(&dev->rx_pool_lock);
+
 	netif_device_detach(dev->netdev);
 
-	if (netif_running(dev->netdev)) {
-		usb_kill_urb(dev->rx_urb);
-		usb_kill_urb(dev->intr_urb);
-	}
+	usb_poison_urb(dev->rx_urb);
+	usb_poison_urb(dev->intr_urb);
+
 	return 0;
 }
 
@@ -541,6 +551,13 @@ static int rtl8150_resume(struct usb_interface *intf)
 {
 	rtl8150_t *dev = usb_get_intfdata(intf);
 
+	spin_lock_irq(&dev->rx_pool_lock);
+	clear_bit(RTL8150_UNPLUG, &dev->flags);
+	spin_unlock_irq(&dev->rx_pool_lock);
+
+	usb_unpoison_urb(dev->rx_urb);
+	usb_unpoison_urb(dev->intr_urb);
+
 	netif_device_attach(dev->netdev);
 	if (netif_running(dev->netdev)) {
 		dev->rx_urb->status = 0;
@@ -618,7 +635,10 @@ static void rx_fixup(struct tasklet_struct *t)
 
 	return;
 tlsched:
-	tasklet_schedule(&dev->tl);
+	spin_lock_irq(&dev->rx_pool_lock);
+	if (!test_bit(RTL8150_UNPLUG, &dev->flags))
+		tasklet_schedule(&dev->tl);
+	spin_unlock_irq(&dev->rx_pool_lock);
 }
 
 static int enable_net_traffic(rtl8150_t * dev)
@@ -970,7 +990,8 @@ static void rtl8150_disconnect(struct usb_interface *intf)
 		set_bit(RTL8150_UNPLUG, &dev->flags);
 		tasklet_kill(&dev->tl);
 		unregister_netdev(dev->netdev);
-		unlink_all_urbs(dev);
+		terminate_all_urbs(dev);
+		tasklet_kill(&dev->tl);
 		free_all_urbs(dev);
 		free_skb_pool(dev);
 		dev_kfree_skb(dev->rx_skb);
-- 
2.56.1


  reply	other threads:[~2026-11-25 14:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 14:43 [RFT 0/2] net: usb: rtl8150: cleaning up races with ceasing IO Oliver Neukum
2026-11-25 14:43 ` Oliver Neukum [this message]
2026-11-25 14:43 ` [RFT 2/3] net: usb: rtl8150: fix race in open() error handling Oliver Neukum
2026-11-25 14:43 ` [RFT 3/3] net: usb: rtl8150: cease all IO upon close Oliver Neukum
2026-11-25 14:59 ` [RFT 0/2] net: usb: rtl8150: cleaning up races with ceasing IO netdev-bot+sinfo

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=20261125145313.58434-2-oneukum@suse.com \
    --to=oneukum@suse.com \
    --cc=netdev@vger.kernel.org \
    --cc=petkan@nucleusys.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