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 v2] net: hso: fix tx skb leak and a race on the stashed skb
Date: Mon, 16 Nov 2026 10:23:34 +0000 [thread overview]
Message-ID: <179482461473.3136.10520991197009365626@kernel.org> (raw)
In-Reply-To: <20261115101646.244-1-chenaibing@cmss.chinamobile.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 1 (1) · Medium: 0 · Low: 1
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).
- [High] The v2 ownership protocol (xchg() in hso_net_close() and
hso_resume(), plus an unlocked test_bit(HSO_NET_RUNNING) in…
- [Low] In hso_resume() (drivers/net/usb/hso.c), the new inner
`test_bit(HSO_NET_RUNNING, &hso_net->flags)` re-reads a bit that the…
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but
hso_net_start_xmit() copies the whole frame into the fixed-size TX…
--
net: hso: fix tx skb leak and a race on the stashed skb
This patch frees the skb that hso_net_start_xmit() stashes in skb_tx_buf
when the interface is closed. It also uses xchg() in both hso_net_close()
and hso_resume() so that only one of them takes ownership of that skb.
On top of that, hso_resume() now drops the stashed frame instead of
transmitting it when HSO_NET_RUNNING is clear.
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
[ ... ]
> @@ -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);
[Severity: High]
Does only one of the two paths really end up owning the frame?
hso_net_close() runs under RTNL. hso_resume() runs from USB PM context,
for example the usb_autopm_get_interface() work that hso_get_activity()
schedules. The two paths don't share any lock.
Consider this interleaving:
CPU0: hso_resume()
skb = xchg(&hso_net->skb_tx_buf, NULL);
test_bit(HSO_NET_RUNNING, &hso_net->flags) returns true
CPU1: hso_net_close()
clear_bit(HSO_NET_RUNNING, &odev->flags);
hso_stop_net_device(odev->parent);
skb = xchg(&odev->skb_tx_buf, NULL); /* returns NULL */
CPU0: hso_resume()
hso_net_start_xmit(skb, hso_net->net);
Suppose hso_get_activity() returns -EAGAIN at this point. That is the
"device is still not ready" case from the commit message.
hso_net_start_xmit() then puts the skb back with a plain store:
if (hso_get_activity(odev->parent) == -EAGAIN) {
odev->skb_tx_buf = skb;
return NETDEV_TX_OK;
}
Does this leak the skb? Nothing frees it after close has done its xchg().
A later hso_net_open() overwrites the pointer with
odev->skb_tx_buf = NULL, and on disconnect the pointer is lost when the
netdev is freed.
If hso_get_activity() returns 0 instead, usb_submit_urb() on
mux_bulk_tx_urb runs after close has killed that URB. hso_resume() then
calls hso_start_net_device(), which resubmits the RX URBs on a closed
interface.
When that TX URB completes, write_bulk_callback() returns early:
if (!odev || !test_bit(HSO_NET_RUNNING, &odev->flags)) {
dev_err(&urb->dev->dev, "%s: device not running\n", __func__);
return;
}
That skips hso_put_activity() and netif_wake_queue(). Can this leave the
activity state and the autopm reference raised?
The new test_bit() narrows the window, but it is still an unlocked flag
check used as a gate. Would this need real serialization between three
places: the stash in hso_net_start_xmit(), the check-and-transmit in
hso_resume(), and the teardown in hso_net_close()? That could be a lock,
or having close wait for a resume that is already in progress.
[ ... ]
> @@ -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))
[Severity: Low]
Isn't this test_bit() checking the same bit as the enclosing
"if (hso_net->flags & IFF_UP)"? hso_net->flags is the driver's private
bitmap, and HSO_NET_RUNNING is bit index 0:
/* These definitions are used with the struct hso_net flags element */
/* - use *_bit operations on it. (bit indices not values.) */
#define HSO_NET_RUNNING 0
IFF_UP is 0x1, so the outer check already tests HSO_NET_RUNNING. The new
else branch with dev_kfree_skb() can only run if hso_net_close() clears
the bit between the two reads.
The commit message says:
hso_resume() also drops the frame instead of transmitting it when the
interface has already been stopped.
If the interface was stopped before resume, the outer check skips the
whole block. In that case hso_net_close() has already freed the frame
through its xchg().
Could the outer check be changed to
test_bit(HSO_NET_RUNNING, &hso_net->flags)? Could the commit message also
be reworded to describe what the new branch actually handles?
> + hso_net_start_xmit(skb,
> + hso_net->net);
[Severity: High]
This is a pre-existing issue, not one introduced by this patch.
hso_net_start_xmit() copies the frame into the TX bounce buffer without
checking its length:
memcpy(odev->mux_bulk_tx_buf, skb->data, skb->len);
hso_create_net_device() allocates mux_bulk_tx_buf with
kzalloc(MUX_BULK_TX_BUF_SIZE), which is 2048 bytes (HSO__MAX_MTU).
hso_net_init() only sets net->mtu = DEFAULT_MTU - 14 and never sets
net->max_mtu, and hso has no ndo_change_mtu. dev_validate_mtu() in
net/core/dev.c only enforces the upper bound when dev->max_mtu > 0.
This means something like "ip link set hsoX mtu 4000" is accepted. Can a
frame larger than 2048 bytes then overflow mux_bulk_tx_buf in
hso_net_start_xmit()? usb_fill_bulk_urb() would also send skb->len bytes
from that buffer to the device, reading past the end of the buffer.
The patched hso_resume() still passes the stashed frame to this function.
Would it make sense to set net->max_mtu = MUX_BULK_TX_BUF_SIZE in
hso_net_init()? Another option is to drop frames with
skb->len > MUX_BULK_TX_BUF_SIZE in hso_net_start_xmit().
> + else
> + dev_kfree_skb(skb);
> }
> result = hso_start_net_device(network_table[i]);
> if (result)
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261115101646.244-1-chenaibing%40cmss.chinamobile.com
next prev parent reply other threads:[~2026-11-16 10:23 UTC|newest]
Thread overview: 6+ 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 [this message]
2026-11-15 21:20 ` [PATCH] net: hso: fix tx skb leak when the device stops 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=179482461473.3136.10520991197009365626@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