All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ömer Mete Kaya" <omermetekaya0@gmail.com>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH net v2] usbnet: fix EVENT_RX_PAUSED race in usbnet_skb_return()
Date: Wed, 07 Oct 2026 12:08:45 +0000	[thread overview]
Message-ID: <sashiko-outbox-162975@kernel.org> (raw)
In-Reply-To: <20261006120825.342164-1-omermetekaya0@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] usbnet: missing BH disable in usbnet_resume_rx() corrupts per-CPU stats
--

commit 36ab26ed669164df5f63bb5c4faccea95151ecd0
Author: Ömer Mete Kaya <omermetekaya0@gmail.com>

usbnet: fix EVENT_RX_PAUSED race in usbnet_skb_return()

This patch fixes a race condition where usbnet_skb_return() could pass the
EVENT_RX_PAUSED check while usbnet_resume_rx() clears the flag and drains the
queue. The fix implements a double-check pattern under the rxq_pause.lock on
the slow path to prevent skbs from being stranded.

> diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
> index a19ecf718f36a..dc340ea248c6b 100644
> --- a/drivers/net/usb/usbnet.c
> +++ b/drivers/net/usb/usbnet.c
[ ... ]
> @@ -699,8 +704,9 @@ void usbnet_resume_rx(struct usbnet *dev)
>  	struct sk_buff *skb;
>  	int num = 0;
>  
> -	local_bh_disable();
> +	spin_lock_bh(&dev->rxq_pause.lock);
>  	clear_bit(EVENT_RX_PAUSED, &dev->flags);
> +	spin_unlock_bh(&dev->rxq_pause.lock);
>  
>  	while ((skb = skb_dequeue(&dev->rxq_pause)) != NULL) {
>  		usbnet_skb_return(dev, skb);
> @@ -708,7 +714,6 @@ void usbnet_resume_rx(struct usbnet *dev)
>  	}
>  
>  	queue_work(system_bh_wq, &dev->bh_work);
> -	local_bh_enable();

[Severity: High]
Does removing local_bh_disable() cause usbnet_skb_return() to execute with
preemption enabled here?

usbnet_resume_rx() is invoked by usbnet_change_mtu() during an MTU change,
which runs in process context with preemption enabled (holding the RTNL lock).
By removing the local_bh_disable() wrapper, usbnet_skb_return() is now called
with preemption enabled.

This leads to issues inside usbnet_skb_return(), such as evaluating a per-CPU
pointer in preemptible context, which triggers a kernel warning:

	struct pcpu_sw_netstats *stats64 = this_cpu_ptr(dev->net->tstats);

Additionally, on 64-bit systems, u64_stats_update_begin_irqsave() is a no-op
regarding preemption/interrupts. Without BH disabled, the update lacks mutual
exclusion against the network softirq on the same CPU, causing data races and
lost statistic increments:

	flags = u64_stats_update_begin_irqsave(&stats64->syncp);
	u64_stats_inc(&stats64->rx_packets);
	u64_stats_add(&stats64->rx_bytes, skb->len);
	u64_stats_update_end_irqrestore(&stats64->syncp, flags);

On 32-bit systems, if the thread migrates to another CPU after this_cpu_ptr()
but before taking the IRQ lock, it will concurrently modify a different CPU's
stats while that CPU processes softirqs. This race can corrupt the syncp
seqcount, causing stat readers (like ndo_get_stats64) to spin infinitely and
lock up the system.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261006120825.342164-1-omermetekaya0@gmail.com?part=1

  parent reply	other threads:[~2026-10-07 12:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-06 12:07 [PATCH net v2] usbnet: fix EVENT_RX_PAUSED race in usbnet_skb_return() Ömer Mete Kaya
2026-10-06 12:15 ` netdev-bot+sinfo
2026-10-07 12:08 ` sashiko-bot [this message]
2026-10-08 12:10 ` netdev-bot+sashiko

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=sashiko-outbox-162975@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=omermetekaya0@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.