Skip to contentSkip to conversation

net: usb: rtl8150: break cycle between tasklet and URB

PATCH Superseded Oliver Neukum 5 participants 6 messages Nov 12 – Nov 19

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: usb: rtl8150: break cycle between tasklet and URB

The tasklet can resubmit the URB, which in turn can resubmit the tasklet. The cycle needs to be broken. The simplest way to do so is to prevent the resubmission of the URBs by poisoning them.

Fixes eff674a514bd3 ("USB: rtl8150_disconnect() needs tasklet_kill()")
---
 drivers/net/usb/rtl8150.c | 31 ++++++++++++++++++++++++++-----
 1 file changed, 26 insertions(+), 5 deletions(-)
drivers/net/usb/rtl8150.c +26 -5
index d51e43170e03..846e6329d571 100644
@@ -343,6 +343,13 @@ static int alloc_all_urbs(rtl8150_t * dev)
 		return 0;
 	}
 
+	/*
+	 * They need to be blocked so that open()
+	 * can unblock them
+	 */
+	usb_block_urb(dev->rx_urb);
+	usb_block_urb(dev->tx_urb);
+	usb_block_urb(dev->intr_urb);
 	return 1;
 }
 
@@ -353,11 +360,18 @@ static void free_all_urbs(rtl8150_t * dev)
 	usb_free_urb(dev->intr_urb);
 }
 
+static void reenable_all_urbs(rtl8150_t *dev)
+{
+	usb_unpoison_urb(dev->rx_urb);
+	usb_unpoison_urb(dev->tx_urb);
+	usb_unpoison_urb(dev->intr_urb);
+}
+
 static void unlink_all_urbs(rtl8150_t * dev)
 {
-	usb_kill_urb(dev->rx_urb);
-	usb_kill_urb(dev->tx_urb);
-	usb_kill_urb(dev->intr_urb);
+	usb_poison_urb(dev->rx_urb);
+	usb_poison_urb(dev->tx_urb);
+	usb_poison_urb(dev->intr_urb);
 }
 
 static inline struct sk_buff *pull_skb(rtl8150_t *dev)
@@ -425,6 +439,11 @@ static void read_bulk_callback(struct urb *urb)
 	netdev->stats.rx_bytes += pkt_len;
 
 	spin_lock_irqsave(&dev->rx_pool_lock, flags);
+	/* prevent an eteral loop */
+	if (test_bit(RTL8150_UNPLUG, &dev->flags)) {
+		spin_unlock_irqrestore(&dev->rx_pool_lock, flags);
+		return;
+	}
 	skb = pull_skb(dev);
 	spin_unlock_irqrestore(&dev->rx_pool_lock, flags);
 	if (!skb)
@@ -518,7 +537,7 @@ static void intr_callback(struct urb *urb)
 	res = usb_submit_urb (urb, GFP_ATOMIC);
 	if (res == -ENODEV)
 		netif_device_detach(dev->netdev);
-	else if (res)
+	else if (res != -EPERM)
 		dev_err(&dev->udev->dev,
 			"can't resubmit intr, %s-%s/input0, status %d\n",
 			dev->udev->bus->bus_name, dev->udev->devpath, res);
@@ -751,6 +770,7 @@ static int rtl8150_open(struct net_device *netdev)
 	if (!dev->rx_skb)
 		return -ENOMEM;
 
+	reenable_all_urbs(dev);
 	set_registers(dev, IDR, 6, netdev->dev_addr);
 
 	usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1),
@@ -969,8 +989,9 @@ static void rtl8150_disconnect(struct usb_interface *intf)
 	if (dev) {
 		set_bit(RTL8150_UNPLUG, &dev->flags);
 		tasklet_kill(&dev->tl);
-		unregister_netdev(dev->netdev);
 		unlink_all_urbs(dev);
+		tasklet_kill(&dev->tl);
+		unregister_netdev(dev->netdev);
 		free_all_urbs(dev);
 		free_skb_pool(dev);
 		dev_kfree_skb(dev->rx_skb);
Signature · 1 line
2.56.0
#1 lore raw
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.

- Whether the issue was actually triggered, or is only theoretical (e.g. found by LLM and not proven at runtime). If it was triggered please include the symptoms, like the stack trace or kernel messages.

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then.

The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.

#2 lore raw
Quoted 5 lines · On 12.11.26 11:52, [email protected] wrote:

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then.

This is in response to a patch by Myeonghung Pak, whose patch tried to fix the issue, but failed to, as Sashiko found out.

HTH
Oliver

#3 lore raw
In reply to Oliver Neukum
Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [High] net: usb: rtl8150: infinite tasklet loop on -EPERM in rx_fixup() - [High] net: usb: rtl8150: double…

Thank you for your contribution! Sashiko AI review found 4 potential issues to consider:
- [High] net: usb: rtl8150: infinite tasklet loop on -EPERM in rx_fixup()
- [High] net: usb: rtl8150: double free of dev->rx_skb on unplug in read_bulk_callback()
- [Medium] net: usb: rtl8150: false dev_err() on res == 0 in intr_callback()
- [Medium] net: usb: rtl8150: unbalanced URB reject count on error in rtl8150_open()
It also noticed 1 related pre-existing issue this patch does not introduce:
- [High] net: usb: rtl8150: dangling rx_skb pointer in read_bulk_callback() [1]
--

commit bed5b8274af4c5f050a94925def40d4d88f1a
Author: Oliver Neukum <[email protected]>

net: usb: rtl8150: break cycle between tasklet and URB

This commit replaces usb_kill_urb() with usb_poison_urb() in unlink_all_urbs(), blocks URBs at allocation time and unpoisons them on open, and checks RTL8150_UNPLUG in read_bulk_callback() to break the resubmission cycle between dev->rx_urb and dev->tl on disconnect.

Quoted 28 lines
drivers/net/usb/rtl8150.c +13 -0
index d51e43170e033..846e6329d571c 100644
@@ -343,6 +343,13 @@ static int alloc_all_urbs(rtl8150_t * dev)
 		return 0;
 	}
 
+	/*
+	 * They need to be blocked so that open()
+	 * can unblock them
+	 */
+	usb_block_urb(dev->rx_urb);
+	usb_block_urb(dev->tx_urb);
+	usb_block_urb(dev->intr_urb);
 	return 1;
 }
 
@@ -353,11 +360,18 @@ static void free_all_urbs(rtl8150_t * dev)
 	usb_free_urb(dev->intr_urb);
 }
 
+static void reenable_all_urbs(rtl8150_t *dev)
+{
+	usb_unpoison_urb(dev->rx_urb);
+	usb_unpoison_urb(dev->tx_urb);
+	usb_unpoison_urb(dev->intr_urb);
+}

drivers/net/usb/rtl8150.c static void free_all_urbs(rtl8150_t * dev) · line 375

Quoted 10 lines
drivers/net/usb/rtl8150.c +4 -3
+
 static void unlink_all_urbs(rtl8150_t * dev)
 {
-	usb_kill_urb(dev->rx_urb);
-	usb_kill_urb(dev->tx_urb);
-	usb_kill_urb(dev->intr_urb);
+	usb_poison_urb(dev->rx_urb);
+	usb_poison_urb(dev->tx_urb);
+	usb_poison_urb(dev->intr_urb);
 }

[Severity: High]
Can poisoning dev->rx_urb cause rx_fixup() to spin in an infinite tasklet loop on -EPERM?

Once unlink_all_urbs() poisons dev->rx_urb in rtl8150_close() or rtl8150_disconnect(), usb_submit_urb(dev->rx_urb, GFP_ATOMIC) returns -EPERM. Neither read_bulk_callback() nor rx_fixup() ignores -EPERM, and rx_fixup() never checks RTL8150_UNPLUG:

drivers/net/usb/rtl8150.c:rx_fixup() {
    ...
	if (test_bit(RX_URB_FAIL, &dev->flags))
		if (dev->rx_skb)
			goto try_again;
    ...
try_again:
	status = usb_submit_urb(dev->rx_urb, GFP_ATOMIC);
	if (status == -ENODEV) {
		netif_device_detach(dev->netdev);
	} else if (status) {
		set_bit(RX_URB_FAIL, &dev->flags);
		goto tlsched;
	}
    ...
tlsched:
	tasklet_schedule(&dev->tl);
}

If dev->tl is scheduled when unlink_all_urbs() poisons dev->rx_urb (or if read_bulk_callback() hits -EPERM at goon: during rtl8150_close() where RTL8150_UNPLUG is not set), rx_fixup() sets RX_URB_FAIL and reschedules dev->tl in a tight softirq loop, locking up softirq processing on Close and hanging tasklet_kill(&dev->tl) in rtl8150_disconnect().

drivers/net/usb/rtl8150.c static void read_bulk_callback(struct urb *urb) · line 449

Quoted 12 lines
drivers/net/usb/rtl8150.c +5 -0
@@ -425,6 +439,11 @@ static void read_bulk_callback(struct urb *urb)
 	netdev->stats.rx_bytes += pkt_len;
 
 	spin_lock_irqsave(&dev->rx_pool_lock, flags);
+	/* prevent an eteral loop */
+	if (test_bit(RTL8150_UNPLUG, &dev->flags)) {
+		spin_unlock_irqrestore(&dev->rx_pool_lock, flags);
+		return;
+	}
 	skb = pull_skb(dev);
 	spin_unlock_irqrestore(&dev->rx_pool_lock, flags);
 	if (!skb)

[Severity: High]
Does returning here when RTL8150_UNPLUG is set cause a double free of dev->rx_skb?

Just before taking dev->rx_pool_lock, read_bulk_callback() passes dev->rx_skb to netif_rx(). Returning without clearing dev->rx_skb to NULL leaves the consumed skb pointer in dev->rx_skb, which rtl8150_disconnect() then frees a second time via dev_kfree_skb(dev->rx_skb).

[Severity: High]
This problem wasn't introduced by this patch, but read_bulk_callback() also leaves [1] dev->rx_skb holding a dangling pointer to the skb handed to netif_rx() whenever pull_skb() returns NULL and jumps to resched:. If the device is disconnected before rx_fixup() replaces dev->rx_skb, rtl8150_disconnect() double frees dev->rx_skb, and if the device is closed and reopened or suspended and resumed in that state, rtl8150_open() or rtl8150_resume() resubmits dev->rx_urb using the freed skb buffer.

drivers/net/usb/rtl8150.c static void intr_callback(struct urb *urb) · line 543

Quoted 9 lines
drivers/net/usb/rtl8150.c +1 -1
@@ -518,7 +537,7 @@ static void intr_callback(struct urb *urb)
 	res = usb_submit_urb (urb, GFP_ATOMIC);
 	if (res == -ENODEV)
 		netif_device_detach(dev->netdev);
-	else if (res)
+	else if (res != -EPERM)
 		dev_err(&dev->udev->dev,
 			"can't resubmit intr, %s-%s/input0, status %d\n",
 			dev->udev->bus->bus_name, dev->udev->devpath, res);

[Severity: Medium]
Doesn't "else if (res != -EPERM)" evaluate to true when usb_submit_urb() succeeds with res == 0? That logs a false dev_err() on every interrupt URB completion unless the check is "else if (res && res != -EPERM)".

drivers/net/usb/rtl8150.c static int rtl8150_open(struct net_device *netdev) · line 776

Quoted 8 lines
drivers/net/usb/rtl8150.c +1 -0
@@ -751,6 +770,7 @@ static int rtl8150_open(struct net_device *netdev)
 	if (!dev->rx_skb)
 		return -ENOMEM;
 
+	reenable_all_urbs(dev);
 	set_registers(dev, IDR, 6, netdev->dev_addr);
 
 	usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1),

[Severity: Medium]
What happens to the URB reject count if usb_submit_urb() fails in rtl8150_open()?

reenable_all_urbs() decrements urb->reject from 1 to 0 on all three URBs, and the error paths in rtl8150_open() return without calling unlink_all_urbs() to re-poison them (only calling usb_kill_urb(dev->rx_urb) when dev->intr_urb submission fails):

drivers/net/usb/rtl8150.c:rtl8150_open() {
    ...
	if ((res = usb_submit_urb(dev->rx_urb, GFP_KERNEL))) {
		if (res == -ENODEV)
			netif_device_detach(dev->netdev);
		dev_warn(&netdev->dev, "rx_urb submit failed: %d\n", res);
		return res;
	}
    ...
	if ((res = usb_submit_urb(dev->intr_urb, GFP_KERNEL))) {
		if (res == -ENODEV)
			netif_device_detach(dev->netdev);
		dev_warn(&netdev->dev, "intr_urb submit failed: %d\n", res);
		usb_kill_urb(dev->rx_urb);
		return res;
	}
    ...
}

Because rtl8150_close() is not called when rtl8150_open() fails, the next rtl8150_open() call decrements urb->reject from 0 to -1, causing all subsequent usb_submit_urb() calls to fail with -EPERM and causing a later unlink_all_urbs() to increment urb->reject back to 0 instead of poisoning the URBs.

[1] https://sashiko.dev/#/bug/linux-361a8ebc-4be5-4126-a2d9-b88d108064a9

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#4 lore raw
In reply to Oliver Neukum
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider.

Critical: 1 · High: 2 (1) · Medium: 3 · Low: 0

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Critical] The new RTL8150_UNPLUG check under rx_pool_lock in read_bulk_callback() (line 443) runs after netif_rx(dev->rx_skb) (line…
- [High] The patch turns unlink_all_urbs() from usb_kill_urb() into usb_poison_urb().
- [High] rtl8150_disconnect() relies on tasklet_kill() to stop rx_fixup(), but once the URBs are poisoned rx_fixup() reschedules…
- [Medium] intr_callback() in drivers/net/usb/rtl8150.c changes else if (res) to else if (res != -EPERM).
- [Medium] The patch adds a counting protocol on urb->reject:
alloc_all_urbs() blocks (+1), rtl8150_open() calls reenable_all_urbs()…
- [Medium] The commit message says only that the URBs are poisoned to stop the tasklet<->URB resubmission cycle.

Pre-existing issues:
- [High] Pre-existing stale rx_skb ownership bug (this problem wasn't introduced by this patch, but it can corrupt memory).

--

net: usb: rtl8150: break cycle between tasklet and URB

This patch switches unlink_all_urbs() from usb_kill_urb() to usb_poison_urb(). The URBs are blocked at allocation time and unblocked in rtl8150_open(). It also adds an RTL8150_UNPLUG check in read_bulk_callback(), changes the intr_callback() error check, and reorders rtl8150_disconnect() so it poisons the URBs and kills the tasklet a second time before unregister_netdev().

Quoted 4 lines
drivers/net/usb/rtl8150.c +0 -0
index d51e43170e033..846e6329d571c 100644

[ ... ]

Quoted 10 lines
drivers/net/usb/rtl8150.c +6 -0
@@ -353,11 +360,18 @@ static void free_all_urbs(rtl8150_t * dev)
 	usb_free_urb(dev->intr_urb);
 }
 
+static void reenable_all_urbs(rtl8150_t *dev)
+{
+	usb_unpoison_urb(dev->rx_urb);
+	usb_unpoison_urb(dev->tx_urb);
+	usb_unpoison_urb(dev->intr_urb);
+}

drivers/net/usb/rtl8150.c static void free_all_urbs(rtl8150_t * dev) · line 375

Quoted 10 lines
drivers/net/usb/rtl8150.c +4 -3
+
 static void unlink_all_urbs(rtl8150_t * dev)
 {
-	usb_kill_urb(dev->rx_urb);
-	usb_kill_urb(dev->tx_urb);
-	usb_kill_urb(dev->intr_urb);
+	usb_poison_urb(dev->rx_urb);
+	usb_poison_urb(dev->tx_urb);
+	usb_poison_urb(dev->intr_urb);
 }

[Severity: High]
unlink_all_urbs() is also called from rtl8150_close(). That function does not kill the tasklet and does not set RTL8150_UNPLUG:

drivers/net/usb/rtl8150.c:rtl8150_close() {
	netif_stop_queue(netdev);
	if (!test_bit(RTL8150_UNPLUG, &dev->flags))
		disable_net_traffic(dev);
	unlink_all_urbs(dev);
	...
}

After close, rx_urb now stays poisoned until the next open. The rx_fixup() tasklet may still be pending at that point. read_bulk_callback() schedules it whenever the 4-entry pool is empty, which happens often under RX load. If it then runs, it gets -EPERM and handles it like any other error:

drivers/net/usb/rtl8150.c:rx_fixup() {
	...
	if (test_bit(RX_URB_FAIL, &dev->flags))
		if (dev->rx_skb)
			goto try_again;
	...
try_again:
	status = usb_submit_urb(dev->rx_urb, GFP_ATOMIC);
	if (status == -ENODEV) {
		netif_device_detach(dev->netdev);
	} else if (status) {
		set_bit(RX_URB_FAIL, &dev->flags);
		goto tlsched;
	...
tlsched:
	tasklet_schedule(&dev->tl);
}

Does this leave the tasklet rescheduling itself forever on a downed interface, until open() unpoisons the URB or disconnect() kills the tasklet? With usb_kill_urb(), submissions were only blocked while the kill was in progress, so this loop could not form.

Could the cycle be broken inside rx_fixup() instead, by treating -EPERM as terminal? Or could rtl8150_close() quiesce the tasklet?

drivers/net/usb/rtl8150.c static void read_bulk_callback(struct urb *urb) · line 446

Quoted 9 lines
drivers/net/usb/rtl8150.c +5 -0
@@ -425,6 +439,11 @@ static void read_bulk_callback(struct urb *urb)
 	netdev->stats.rx_bytes += pkt_len;
 
 	spin_lock_irqsave(&dev->rx_pool_lock, flags);
+	/* prevent an eteral loop */
+	if (test_bit(RTL8150_UNPLUG, &dev->flags)) {
+		spin_unlock_irqrestore(&dev->rx_pool_lock, flags);
+		return;
+	}

[Severity: Critical]
This check runs after netif_rx(dev->rx_skb) has already handed the skb to the stack. The early return skips the dev->rx_skb = skb assignment, so dev->rx_skb still points at an skb the stack now owns.

Can this sequence double free the skb?

CPU1 read_bulk_callback()
test_bit(RTL8150_UNPLUG) -> clear
netif_rx(dev->rx_skb)

                            CPU2 rtl8150_disconnect()
                              set_bit(RTL8150_UNPLUG, &dev->flags)
  spin_lock_irqsave(&dev->rx_pool_lock)
  test_bit(RTL8150_UNPLUG) -> set, return
                              unlink_all_urbs()  (waits for callback)
                              tasklet_kill()
                              unregister_netdev()
                              ...
                              dev_kfree_skb(dev->rx_skb)

The set_bit() in rtl8150_disconnect() is not done under rx_pool_lock, so the lock does not serialize against it. This is the flag-as-gate pattern described in the networking-drivers guide.

It also isn't clear what the check prevents. Without it, the resubmit returns -EPERM and the second tasklet_kill() in disconnect handles the scheduled tasklet.

Also, there's a typo in the comment: "eteral".

drivers/net/usb/rtl8150.c static void read_bulk_callback(struct urb *urb) · line 449

Quoted 3 lines
drivers/net/usb/rtl8150.c +0 -0
 	skb = pull_skb(dev);
 	spin_unlock_irqrestore(&dev->rx_pool_lock, flags);
 	if (!skb)

[Severity: High]
This is a pre-existing issue, not introduced by this patch, but it can corrupt memory. When pull_skb() returns NULL here, the goto resched path leaves dev->rx_skb pointing at the skb that was just passed to netif_rx().

rx_fixup() replaces dev->rx_skb only when pull_skb() succeeds:

drivers/net/usb/rtl8150.c:rx_fixup() {
	...
	skb = pull_skb(dev);
	spin_unlock_irq(&dev->rx_pool_lock);
	if (skb == NULL)
		goto tlsched;
	dev->rx_skb = skb;
	...
}

If the atomic allocations in fill_skb_pool() keep failing, the stale pointer stays in place.

An ifdown/ifup in that state reaches this check in rtl8150_open():

	if (dev->rx_skb == NULL)
		dev->rx_skb = pull_skb(dev);

The stale pointer is then reused as rx_urb's transfer buffer. Can the device then DMA into a freed skb?

On disconnect, tasklet_kill() can take TASKLET_STATE_SCHED in the gap between tasklet_clear_sched() and rx_fixup()'s own tasklet_schedule(). That ends the loop with the pointer still stale, and dev_kfree_skb(dev->rx_skb) in rtl8150_disconnect() would free it a second time.

The new RTL8150_UNPLUG early return above reaches the same stale state more easily.

[ ... ]

drivers/net/usb/rtl8150.c static void intr_callback(struct urb *urb) · line 543

Quoted 9 lines
drivers/net/usb/rtl8150.c +1 -1
@@ -518,7 +537,7 @@ static void intr_callback(struct urb *urb)
 	res = usb_submit_urb (urb, GFP_ATOMIC);
 	if (res == -ENODEV)
 		netif_device_detach(dev->netdev);
-	else if (res)
+	else if (res != -EPERM)
 		dev_err(&dev->udev->dev,
 			"can't resubmit intr, %s-%s/input0, status %d\n",
 			dev->udev->bus->bus_name, dev->udev->devpath, res);

[Severity: Medium]
A successful usb_submit_urb() returns 0, which is neither -ENODEV nor -EPERM. Won't this print "can't resubmit intr ... status 0" on every successful resubmit of the interrupt URB?

Was this meant to be:

	else if (res && res != -EPERM)

The resubmit in read_bulk_callback() keeps the non-zero check. The commit message doesn't mention this change.

drivers/net/usb/rtl8150.c static int rtl8150_open(struct net_device *netdev) · line 774

Quoted 6 lines
drivers/net/usb/rtl8150.c +1 -0
@@ -751,6 +770,7 @@ static int rtl8150_open(struct net_device *netdev)
 	if (!dev->rx_skb)
 		return -ENOMEM;
 
+	reenable_all_urbs(dev);
 	set_registers(dev, IDR, 6, netdev->dev_addr);

[Severity: Medium]
reenable_all_urbs() runs before URB submissions that can fail. What happens to urb->reject if usb_submit_urb() fails later in rtl8150_open()?

The rx_urb failure path returns directly. The intr_urb failure path only calls usb_kill_urb(dev->rx_urb), which leaves reject unchanged.

__dev_open() does not call ndo_stop when ndo_open fails, so reject would be left at 0 with the interface down. The next rtl8150_open() would then take it to -1 through usb_unpoison_urb(), which is a plain atomic_dec().

usb_hcd_link_urb_to_ep() rejects any non-zero value:

drivers/usb/core/hcd.c:usb_hcd_link_urb_to_ep() {
	...
	if (unlikely(atomic_read(&urb->reject))) {
		rc = -EPERM;
	...
}

Does every later open then fail with -EPERM and push reject further negative, until the driver is rebound or the device replugged?

A later poison in rtl8150_disconnect() would also only bring reject from -1 back to 0. The URBs would then not be blocked during teardown.

The rtl8150_close() tasklet loop above is one way to reach these error paths. reenable_all_urbs() lets the tasklet's submit race with the submit here, and open() can then get -EBUSY.

Should these error paths block the URBs again before returning?

[ ... ]

drivers/net/usb/rtl8150.c static void rtl8150_disconnect(struct usb_interface *intf) · line 993

Quoted 7 lines
drivers/net/usb/rtl8150.c +1 -1
@@ -969,8 +989,9 @@ static void rtl8150_disconnect(struct usb_interface *intf)
 	if (dev) {
 		set_bit(RTL8150_UNPLUG, &dev->flags);
 		tasklet_kill(&dev->tl);
-		unregister_netdev(dev->netdev);
 		unlink_all_urbs(dev);
+		tasklet_kill(&dev->tl);

[Severity: High]
Can these tasklet_kill() calls hang? Once the URBs are poisoned, rx_fixup() reschedules itself on every run: -EPERM, then RX_URB_FAIL, then tasklet_schedule().

tasklet_action_common() clears the SCHED bit right before running the callback:

kernel/softirq.c:tasklet_action_common() {
	...
				if (tasklet_clear_sched(t)) {
					if (t->use_callback) {
						trace_tasklet_entry(t, t->callback);
						t->callback(t);
	...
}

rx_fixup() then sets the bit again through tasklet_schedule() before the softirq run returns.

On a UP kernel, or when the disconnect task shares a CPU with ksoftirqd, wait_on_bit_lock() in tasklet_kill() would never see the bit clear. Would disconnect then sleep in TASK_UNINTERRUPTIBLE forever?

The loop is reliably running at disconnect time after an earlier ifdown under RX load (see the rtl8150_close() comment above). This applies to a soft unbind, where the device is still configured and usb_submit_urb() returns -EPERM rather than -ENODEV. On SMP the loop can also start from an RX completion racing the poison here.

Would it be safer to break the cycle inside rx_fixup(), by not rescheduling on -EPERM or when RTL8150_UNPLUG is set?

drivers/net/usb/rtl8150.c static void rtl8150_disconnect(struct usb_interface *intf) · line 997

Quoted 4 lines
drivers/net/usb/rtl8150.c +1 -0
+		unregister_netdev(dev->netdev);
 		free_all_urbs(dev);
 		free_skb_pool(dev);
 		dev_kfree_skb(dev->rx_skb);

[Severity: Medium]
The commit message says:

The simplest way to do so is to prevent the resubmission of the URBs by poisoning them.

The patch also makes several other changes:

- It blocks all URBs in alloc_all_urbs() and unblocks them in rtl8150_open(), which affects every ifup/ifdown.
- It moves unregister_netdev() after unlink_all_urbs() and adds a second tasklet_kill().
- It changes the intr_callback() error reporting.
- It adds the RTL8150_UNPLUG check in read_bulk_callback().

Could the commit message describe these changes as well?

The reordering here also has a visible effect. On a soft unbind with the device still configured, the netdev stays registered and running after tx_urb is poisoned. rtl8150_start_xmit() then gets -EPERM instead of -ENODEV and takes this branch for every packet:

		else {
			dev_warn(&netdev->dev, "failed tx_urb %d\n", res);
			netdev->stats.tx_errors++;
			netif_start_queue(netdev);
		}

This continues until unregister_netdev() closes the interface. Is that intended?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112104548.693456-1-oneukum%40suse.com
maintainer
#5 lore raw
In reply to Oliver Neukum
Quoted 7 lines · Oliver Neukum

The tasklet can resubmit the URB, which in turn can resubmit the tasklet. The cycle needs to be broken. The simplest way to do so is to prevent the resubmission of the URBs by poisoning them.

Fixes eff674a514bd3 ("USB: rtl8150_disconnect() needs tasklet_kill()")

Sashiko feedback looks relevant. Also please include the info about issue provenience and the impact into the next revision changelog.

Thanks,

Paolo