🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #14888

Re: [PATCH net] net: usb: rtl8150: fix rx tasklet use-after-free on disconnect

#14888
From: netdev-bot+sashiko
Date: Thu, 12 Nov 2026 04:31
197 lines
14838 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 0 (2) · Medium: 1 · 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).

- [Medium] The patch's new tasklet_kill() calls in rtl8150_disconnect()
  cannot reliably stop rx_fixup() when it keeps rescheduling itself, and…

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the stale
  dev->rx_skb pointer can lead to a double free or a device DMA into…
- [High] This problem wasn't introduced by this patch, but pegasus.c, the
  driver rtl8150 was derived from, has the same late-completion tasklet…

--

net: usb: rtl8150: fix rx tasklet use-after-free on disconnect

This adds a second tasklet_kill() in rtl8150_disconnect(), placed after
unlink_all_urbs(). It is meant to drain an RX tasklet that a late
read_bulk_callback() could have scheduled after the first kill, before the
driver data is freed.

> diff --git a/drivers/net/usb/rtl8150.c b/drivers/net/usb/rtl8150.c
> index d51e43170e033..98c36c3779564 100644
> --- a/drivers/net/usb/rtl8150.c
> +++ b/drivers/net/usb/rtl8150.c
> @@ -971,6 +971,8 @@ static void rtl8150_disconnect(struct usb_interface *intf)
>  		tasklet_kill(&dev->tl);
>  		unregister_netdev(dev->netdev);
>  		unlink_all_urbs(dev);
> +		/* A completion may have scheduled it after the first kill. */
> +		tasklet_kill(&dev->tl);

[Severity: Medium]
Can this tasklet_kill() actually end the rx_fixup() reschedule loop that the
commit message describes?

The commit message says "disabled endpoints make RX resubmissions fail, so
rx_fixup() can keep rescheduling itself". It then says "tasklet_kill()
drains any late tasklet and prevents self-rescheduling".

rtl8150_driver has no soft_unbind, so usb_unbind_interface() disables the
endpoints before calling ->disconnect(). The device is still attached, so
usb_submit_urb() passes its -ENODEV check. usb_hcd_link_urb_to_ep() then
returns -ENOENT, or -EPERM while usb_kill_urb() is in progress:

drivers/usb/core/hcd.c:usb_hcd_link_urb_to_ep() {
    ...
	if (unlikely(!urb->ep->enabled)) {
		rc = -ENOENT;
		goto done;
	}
    ...
}

In rx_fixup(), -ENODEV is the only error that skips the reschedule, and
nothing checks RTL8150_UNPLUG:

drivers/net/usb/rtl8150.c:rx_fixup() {
    ...
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);
}

tasklet_kill() only returns once the waiter sets TASKLET_STATE_SCHED
itself:

	wait_on_bit_lock(&t->state, TASKLET_STATE_SCHED, TASK_UNINTERRUPTIBLE);

tasklet_action_common() clears TASKLET_STATE_SCHED and wakes the waiter
just before it calls t->callback(t). rx_fixup() then sets the bit again
before it returns. All of this runs in non-preemptible softirq context.

On a CONFIG_SMP=n non-RT kernel, or when the waiter runs on the same CPU as
the tasklet, process context would only ever see TASKLET_STATE_SCHED set.
Wouldn't rtl8150_disconnect() then sleep in TASK_UNINTERRUPTIBLE forever
while ksoftirqd keeps running rx_fixup()?

The first tasklet_kill() already had this limitation. The new call relies
on the same assumption to close the use-after-free.

For tasklet_kill() to be reliable here, would rx_fixup() and the resched
path in read_bulk_callback() need to stop resubmitting and rescheduling
once RTL8150_UNPLUG is set?

>  		free_all_urbs(dev);
>  		free_skb_pool(dev);
>  		dev_kfree_skb(dev->rx_skb);

[Severity: High]
This is a pre-existing issue, but can dev->rx_skb still be stale when it is
freed here?

read_bulk_callback() passes dev->rx_skb to the stack, and if the pool is
empty it leaves the pointer unchanged:

	netif_rx(dev->rx_skb);
	...
	skb = pull_skb(dev);
	spin_unlock_irqrestore(&dev->rx_pool_lock, flags);
	if (!skb)
		goto resched;

	dev->rx_skb = skb;

The pool has only RX_SKB_POOL_SIZE (4) entries, and only rx_fixup() refills
it. rx_fixup() is also the only place that replaces the pointer. If every
GFP_ATOMIC allocation in fill_skb_pool() fails, it just reschedules:

	skb = pull_skb(dev);
	spin_unlock_irq(&dev->rx_pool_lock);
	if (skb == NULL)
		goto tlsched;
	dev->rx_skb = skb;

Suppose rtl8150_disconnect() runs in that state. The tasklet_kill() calls
stop the loop but leave the pointer as it is. Would dev_kfree_skb(dev->rx_skb)
then double free an skb that the network stack already consumed?

Something similar looks possible across close and open. rtl8150_close()
does not kill the tasklet or clear rx_skb. rtl8150_open() then reuses a
non-NULL rx_skb as the bulk-in buffer:

	if (dev->rx_skb == NULL)
		dev->rx_skb = pull_skb(dev);
	...
	usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1),
		      dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev);

Could the device then DMA packet data into freed memory?

[Severity: High]
This isn't a bug introduced by this patch, but pegasus.c, which rtl8150 was
derived from, seems to have the same late-completion tasklet problem. This
patch doesn't change it.

In pegasus read_bulk_callback(), when the resubmit fails, rx_tl is scheduled
without checking PEGASUS_UNPLUG again:

	else if (rx_status) {
		pegasus->flags |= PEGASUS_RX_URB_FAIL;
		goto tl_sched;
	}
	...
tl_sched:
	tasklet_schedule(&pegasus->rx_tl);

During unbind the endpoints are already disabled, so the resubmit fails with
-ENOENT. It fails with -EPERM once usb_kill_urb() has set urb->reject.

The only tasklet_kill() is in pegasus_close(), and it runs before the URBs
are killed:

	tasklet_kill(&pegasus->rx_tl);
	unlink_all_urbs(pegasus);

pegasus_disconnect() then goes from unlink_all_urbs() to free_netdev()
without draining the tasklet:

	unregister_netdev(pegasus->net);
	unlink_all_urbs(pegasus);
	free_all_urbs(pegasus);
	...
	free_netdev(pegasus->net);

Consider a completion that passes the netif_running() check before
__dev_close_many() clears __LINK_STATE_START. If it reaches
tasklet_schedule() after the tasklet_kill() in pegasus_close(), rx_tl is
left pending with no later kill.

rx_fixup() returns early on PEGASUS_UNPLUG, so there is no endless loop.
It still reads pegasus->flags, though, and tasklet_action_common() touches
the tasklet_struct inside netdev_priv(). Could either of those run after
free_netdev()?

Does pegasus_disconnect() need a tasklet_kill(&pegasus->rx_tl) after
unlink_all_urbs() too?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261110043016.56986-1-mhun512%40gmail.com
Technical Details
Message-ID: <179445789040.2199510.7426210198945271595@kernel.org>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-361502-linux-kernel-netdev=dewy.ru
References: <20261110043016.56986-1-mhun512@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-361502-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] net: usb: rtl8150: fix rx tasklet use-after-free on
 disconnect
Date: Thu, 12 Nov 2026 04:31:30 +0000
Organization: Usenet Network
Message-ID: <179445789040.2199510.7426210198945271595@kernel.org>
References: <20261110043016.56986-1-mhun512@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1009043"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:cTNEloS8+P3rWfHyI/9vSov/iyY= sha256:LBk/fZjCsbkrr2dNrXrZb+VR8oAomTq/0OxGbg6zlyc=
	sha1:iktdwS5yS1OqQZYU1LJnvxId2js= sha256:frYH5+afaA2P25lw8yyvocKvXkJ6XZ7wA+mLdieqXn8=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 889DA1140FD; Thu, 12 Nov 2026 07:32:11 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id uSfQDDx_BcG1;
	Thu, 12 Nov 2026 07:32:07 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-361502-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
	by mail.dewy.ru (Postfix) with ESMTPS id D0BA71140FC; Thu, 12 Nov 2026 07:31:57 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sin.lore.kernel.org (Postfix) with ESMTP id 674A1370CA; Thu, 12 Nov 2026 04:31:42 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1794457892;
	b=eQX5E35PaY1fqH4aNU0Ld+MLuh843CxSRBwX6ch34ZhbYo+BCyV/SyMvioqWUNSPsR6a
	 HbpMhhrfgeodHiCQU20GxPgl0hzQOdYM3RNL/Tsxu2xc6oNuorCY1pjwuoCpkK6mAuiqy
	 7Iju0sUYzw892eH1u3B7mKlok1B6HAuIetDpyKqA5hz/e/G3MZLIk4c8qtaUSkPOECQm/
	 gmQZ9qSFJmKn6Vz8oYYcwWbUk1MtwRYwfU8vV18fJnB0Z7vvATRjMUagUQWuoDCKJozoM
	 GKmh1McnGy4Kja+0o2vmHEmaFCEjt/Tu6ir+mn6UdfgoW10TFBLUSYM8yodYZt6hggQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794457892;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=ewDQkyi302TW6WSeRV08GWmgo3FjljwrHal9OxzqK/0=;
	b=DOC1rG7mPKw2X+mrYWJbwK4QCK9N8VeAFlBS0lt6KIzimj2hyuuckxoPqi4cc4nLdWHa
	 SO/aM0JpfFAe0CCOV71KTNqLjZNeo3sh099gMavAjLDCG6VQla9hstx1CSvsv5YEnrFSK
	 vsqk9Eli20YBsCwgbdlYaMwJvd+cddWkzxai/bMNuoIEWHYj6+JkBkOqeucP0596pHMj7
	 qiUofwAmlkQtvloqc1CcILufATGIpPElBZoZk8C0Hc0JkrfuumvPIzrHbq8iNRestNRio
	 jUh66s8amnh5mexyerbvMoPHZMngZ/mi8yE+lOjsxu4hFCVJyLtpWZlWkWf05eJpG4g==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ZRzl8FhK;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id B0237606A88A;
	Thu, 12 Nov 2026 04:31:32 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ZRzl8FhK
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794457891;
	b=vloR/rdNThHaNbcjNdnvAsB3UvzfRxxzBWzS4FatXve8ZKW8R5E6rJ1NzBrQjhK4lN30
	 0wIgZNw4JxXwWIsCPKBrIenn+/DKYeVmauBeDPzr+dnqil25kUsvCyyv5aNkAVAVacDem
	 cb6wYhg8qBKFDyts0/wcpci17vUCR2IL84yFnP/zilxxskZOTGqDCBe4DOfch8gSphz62
	 8AcXk64R7N80WE5MJ3nRZLIXeGajl2JV9rtqgRMeRyFFEj/2dsu29KpL3TAA4ct8t58sL
	 JhNIyr1ZP8ci2CP6gc8QvYs4B7Bsy/2XaAo/vT2k7k3W3kXvfNFgpzPLtWp030qzpag==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794457891;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=ewDQkyi302TW6WSeRV08GWmgo3FjljwrHal9OxzqK/0=;
	b=MwWoK/sCq8pbJhf2LHNL/0M1Fd+ySOMt64IlqzSUrTm/ZIfNJ+pTrY+MWiIL+Zp03V7m
	 xEeyctWe0gYUugxcGnIn8ZQYLqVGjO4BxoAkib2SO+j9pivy0Ti5Auot1V538ok4bDnTa
	 nHzBHb7kp6Sws9OY5PW9bnxb6GUAeolSyk2+ED7l6xSoPQ7QyTpQoAegbMGm5auAL5P3y
	 5mcn+ucx/XkUEa9T2mcI2SgGl8l/LWWD1avrOLaJjbgfPARNkRbSFuJTBI8ltZSfxJwXZ
	 hpTzIoRi6mxenFVF0O4gfsQOh9w/tbMXH/4y+zod3cWvxXTSO0gmQAuNVqIMqZUPHbA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ZRzl8FhK;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id CDB84606A32E;
	Thu, 12 Nov 2026 04:31:31 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id E64EC1F00A05;
	Thu, 12 Nov 2026 04:31:30 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1794457891;
	bh=ewDQkyi302TW6WSeRV08GWmgo3FjljwrHal9OxzqK/0=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=ZRzl8FhKA1apZMK9+2RxDRRzxQ+PGis7fLpNSLp49YLYMy1JjffLK5WBnjWKDUdsy
	 3xZW+qkGBRm1om1tjxXQWUYEXPfN7kjvsIZ1A/aETSBXy7uyD+i2OmV7YPJkWgs9WN
	 eiwUer4ABxovj0XBPvqhUBbR+w80yN84Bkd4qpk5hEBwsfCEJbU/vTIO3IPHA1vkm2
	 tf2vIp9rAune4VbrCSXiKunlVH11AcAZJKXXN+bDlDZ+UpbBhUGYo7YqvBrrZRIISE
	 4BXI0prC1WStkj/P085ahCPql7/7lB/m77JtwhMa+5qaFpCugaMmsuZWtcCmjVO7Q6
	 LMPRSQws2cdpw==
X-Cc: petkan@nucleusys.com, andrew+netdev@lunn.ch, davem@davemloft.net,
 edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
 linux-usb@vger.kernel.org, netdev@vger.kernel.org,
 linux-kernel@vger.kernel.org, stable@vger.kernel.org, ae878000@gmail.com
X-In-Reply-To: <20261110043016.56986-1-mhun512@gmail.com>
X-sashiko-severity: Medium
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list