All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Aibing Chen" <chenaibing@cmss.chinamobile.com>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH v2] net: hso: fix tx skb leak and a race on the stashed skb
Date: Mon, 16 Nov 2026 10:16:56 +0000	[thread overview]
Message-ID: <sashiko-outbox-216704@kernel.org> (raw)
In-Reply-To: <20261115101646.244-1-chenaibing@cmss.chinamobile.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] net: hso: race between hso_resume() and hso_net_close() leaks
  skb or starts URBs
--

commit 6454f405b890c90cd5c9d28c2b1b886b3625e833
Author: Aibing Chen <chenaibing@cmss.chinamobile.com>

net: hso: fix tx skb leak and a race on the stashed skb

This commit frees any pending skb in hso_net_close() and uses xchg() in
both hso_net_close() and hso_resume() to take ownership of skb_tx_buf.

Link: https://lore.kernel.org/all/6af74e31.fe96acdb.12252b.0009.GAE@google.com/

> diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
> index 71caa3764b239..ba59bdefd203d 100644
> --- a/drivers/net/usb/hso.c
> +++ b/drivers/net/usb/hso.c
> @@ -720,6 +720,7 @@ static int hso_net_open(struct net_device *net)
>  static int hso_net_close(struct net_device *net)
>  {
>  	struct hso_net *odev = netdev_priv(net);
> +	struct sk_buff *skb;
>  
>  	/* we don't need the queue anymore */
>  	netif_stop_queue(net);
> @@ -728,6 +729,14 @@ static int hso_net_close(struct net_device *net)
>  
>  	hso_stop_net_device(odev->parent);
>  
> +	/*
> +	 * Take ownership of a frame stashed by hso_net_start_xmit() and drop it.
> +	 * hso_resume() takes it the same way, so only one of the two paths frees
> +	 * it.
> +	 */
> +	skb = xchg(&odev->skb_tx_buf, NULL);
> +	dev_kfree_skb(skb);
> +
>  	/* done */
>  	return 0;
>  }
> @@ -3032,6 +3041,7 @@ static int hso_resume(struct usb_interface *iface)
>  {
>  	int i, result = 0;
>  	struct hso_net *hso_net;
> +	struct sk_buff *skb;
>  
>  	/* Start all serial ports */
>  	for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
> @@ -3054,13 +3064,17 @@ static int hso_resume(struct usb_interface *iface)
>  			if (hso_net->flags & IFF_UP) {
>  				/* First transmit any lingering data,
>  				   then restart the device. */
> -				if (hso_net->skb_tx_buf) {
> +				skb = xchg(&hso_net->skb_tx_buf, NULL);
> +				if (skb) {
>  					dev_dbg(&iface->dev,
>  						"Transmitting"
>  						" lingering data\n");
> -					hso_net_start_xmit(hso_net->skb_tx_buf,
> -							   hso_net->net);
> -					hso_net->skb_tx_buf = NULL;
> +					if (test_bit(HSO_NET_RUNNING,
> +						     &hso_net->flags))
> +						hso_net_start_xmit(skb,
> +								   hso_net->net);
> +					else
> +						dev_kfree_skb(skb);
>  				}
>  				result = hso_start_net_device(network_table[i]);
>  				if (result)

[Severity: Medium]
Can hso_resume() still race with hso_net_close() and leak skb or restart
URBs on a closed interface?

Nothing serializes the HSO_NET_RUNNING check in hso_resume() against
hso_net_close():

CPU0                              CPU1
hso_resume()
  skb = xchg(&hso_net->skb_tx_buf, NULL)
  test_bit(HSO_NET_RUNNING, ...)  [true]
                                  hso_net_close()
                                    clear_bit(HSO_NET_RUNNING, ...)
                                    hso_stop_net_device()
                                    xchg(&odev->skb_tx_buf, NULL)  [NULL]
  hso_net_start_xmit(skb, ...)
    /* if hso_get_activity() == -EAGAIN */
    odev->skb_tx_buf = skb        <-- leaked after close finished
  hso_start_net_device()          <-- submits RX URBs on closed device

If hso_get_activity() returns -EAGAIN during hso_net_start_xmit(), skb is
stashed back into odev->skb_tx_buf after hso_net_close() has already
drained it, leaking skb on disconnect or the next hso_net_open().  If
hso_get_activity() succeeds instead, hso_net_start_xmit() and
hso_start_net_device() submit TX and RX URBs after hso_stop_net_device()
killed them; even if HSO_NET_RUNNING is cleared before test_bit() so skb
is freed, hso_resume() still calls hso_start_net_device() unconditionally.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261115101646.244-1-chenaibing@cmss.chinamobile.com?part=1

  reply	other threads:[~2026-11-16 10:16 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-14  9:31 [PATCH] net: hso: fix tx skb leak when the device stops Aibing Chen
2026-11-15  9:31 ` sashiko-bot
2026-11-15 10:16 ` [PATCH v2] net: hso: fix tx skb leak and a race on the stashed skb Aibing Chen
2026-11-16 10:16   ` sashiko-bot [this message]
2026-11-16 10:23   ` netdev-bot+sashiko
2026-11-15 21:20 ` [PATCH] net: hso: fix tx skb leak when the device stops netdev-bot+sashiko
2026-11-17  8:47 ` [PATCH net v3] net: hso: fix stashed tx skb leak and replay race Aibing Chen
2026-11-18  8:47   ` sashiko-bot

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-216704@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=chenaibing@cmss.chinamobile.com \
    --cc=linux-usb@vger.kernel.org \
    --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.