Linux USB
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: chenaibing@cmss.chinamobile.com
Cc: 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
Subject: Re: [PATCH net v3] net: hso: fix stashed tx skb leak and replay race
Date: Wed, 18 Nov 2026 14:32:17 +0000	[thread overview]
Message-ID: <179501233764.3136.7907862277727353181@kernel.org> (raw)
In-Reply-To: <20261117084732.297-1-chenaibing@cmss.chinamobile.com>

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

Critical: 0 (1) · High: 0 · 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] net: hso: race on skb_tx_buf and unlocked hso_net_start_xmit()
  in hso_resume()

Pre-existing issues:
- [Critical] This problem wasn't introduced by this patch, but it is a
  heap buffer overflow in the hso TX path that the replay this patch…

--

net: hso: fix stashed tx skb leak and replay race

This commit frees the skb stashed in skb_tx_buf when hso_net_close() runs.
It also takes the stashed skb with xchg() in both hso_net_close() and
hso_resume(), and serializes the resume replay against close with a new
per-interface mutex. The resume path now checks HSO_NET_RUNNING instead of
IFF_UP.

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..43884234c4d8f 100644
> --- a/drivers/net/usb/hso.c
> +++ b/drivers/net/usb/hso.c

[ ... ]

> @@ -3051,21 +3069,28 @@ static int hso_resume(struct usb_interface *iface)
>  		if (network_table[i] &&
>  		    (network_table[i]->interface == iface)) {
>  			hso_net = dev2net(network_table[i]);
> -			if (hso_net->flags & IFF_UP) {
> -				/* First transmit any lingering data,
> -				   then restart the device. */
> -				if (hso_net->skb_tx_buf) {
> +			mutex_lock(&hso_net->tx_replay_lock);
> +
> +			/*
> +			 * First transmit any lingering data, then restart
> +			 * the device.
> +			 */
> +			if (test_bit(HSO_NET_RUNNING, &hso_net->flags)) {
> +				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;
> +					hso_net_start_xmit(skb, hso_net->net);

[Severity: Medium]
The new tx_replay_lock orders hso_resume() against hso_net_close(),
but the other writer of skb_tx_buf is hso_net_start_xmit(), which runs
from the transmit path under the queue's TX lock and never takes
tx_replay_lock (it can't sleep there). Can the stash and the replay
still miss each other during resume?

CPU0 (xmit)                       CPU1 (usb_resume_both)
hso_net_start_xmit()
  netif_stop_queue()
  hso_get_activity()
    usb->state != CONFIGURED
    returns -EAGAIN
                                  usb_resume_device()
                                    state = USB_STATE_CONFIGURED
                                  hso_resume()
                                    xchg(&skb_tx_buf, NULL) == NULL
                                    hso_start_net_device()
  odev->skb_tx_buf = skb

At that point the frame is stashed, the queue is stopped, and nothing
is left to replay it. No TX URB was submitted, so write_bulk_callback()
never calls netif_wake_queue() or hso_put_activity(). TX on the
interface stays wedged until it is brought down. If
hso_get_activity() scheduled async_get_intf on the way in, that
runtime PM reference is never dropped either.

The direct call is also not serialized against the stack.
hso_resume() invokes the ndo_start_xmit handler without holding the
TX lock. Inside it, netif_start_queue() (on usb_submit_urb() failure)
or write_bulk_callback() -> netif_wake_queue() (on a fast completion)
can let another CPU enter hso_net_start_xmit() before the replayed
call has returned. Both calls then update net->stats concurrently.

This window already existed with the old unlocked read of skb_tx_buf.
The changelog says only one path can obtain the stashed skb, though,
so it seems worth covering in this patch. Would it work to do the
xchg() and the replay under the queue 0 TX lock, for example:

  __netif_tx_lock_bh(netdev_get_tx_queue(hso_net->net, 0))

usb_resume_device() has already marked the device configured by the
time hso_resume() runs. An xmit that takes the lock after the replay
would then send directly instead of stashing. hso_start_net_device()
submits with GFP_NOIO, so it would need to stay outside that lock.

[Severity: Critical]
This is a pre-existing issue and was not introduced by this patch, but the
replay here goes into the same unchecked copy in hso_net_start_xmit(). Can
that copy overflow mux_bulk_tx_buf?

drivers/net/usb/hso.c:hso_net_start_xmit() {
    ...
	/* Copy it from kernel memory to OUR memory */
	memcpy(odev->mux_bulk_tx_buf, skb->data, skb->len);
    ...
}

The destination is a fixed size buffer allocated in
hso_create_net_device():

	hso_net->mux_bulk_tx_buf = kzalloc(MUX_BULK_TX_BUF_SIZE, GFP_KERNEL);

and MUX_BULK_TX_BUF_SIZE is HSO__MAX_MTU, which is 2048.

I don't see anything that limits the MTU to that size. hso_net_init() sets
net->mtu = DEFAULT_MTU - 14 but never sets net->max_mtu, and hso_netdev_ops
has no .ndo_change_mtu. dev_validate_mtu() only checks the upper bound
when max_mtu is set:

	if (dev->max_mtu > 0 && new_mtu > dev->max_mtu) {

So something like "ip link set hsoX mtu 4000" would succeed. After that,
any local or forwarded traffic routed through hsoX could produce linear
skbs larger than 2048 bytes. The device doesn't advertise NETIF_F_SG, so
the core linearizes them. Those skbs would then reach the memcpy() through
dev_queue_xmit()->hso_net_start_xmit(), or through this replay in
hso_resume(), and write up to MTU - 2048 bytes of packet payload past the
end of the kmalloc-2048 object.

Would it make sense to set net->max_mtu = MUX_BULK_TX_BUF_SIZE in
hso_net_init()? Another option would be to drop frames with
skb->len > MUX_BULK_TX_BUF_SIZE in hso_net_start_xmit(), or to do both.

>  				}
>  				result = hso_start_net_device(network_table[i]);
> -				if (result)
> +				if (result) {
> +					mutex_unlock(&hso_net->tx_replay_lock);
>  					goto out;
> +				}
>  			}

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117084732.297-1-chenaibing%40cmss.chinamobile.com

      parent reply	other threads:[~2026-11-18 14:32 UTC|newest]

Thread overview: 11+ 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
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
2026-11-18 14:16   ` [PATCH net v4] " Aibing Chen
2026-11-18 14:29     ` sashiko-bot
2026-11-18 14:32   ` netdev-bot+sashiko [this message]

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=179501233764.3136.7907862277727353181@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=chenaibing@cmss.chinamobile.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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