* Re: [PATCH] USB: hso: fix skb leak on device close and teardown
2026-11-29 14:31 [PATCH] USB: hso: fix skb leak on device close and teardown zhengzongmin
2026-11-29 16:52 ` Greg KH
@ 2026-11-30 14:31 ` sashiko-bot
2026-11-30 15:28 ` netdev-bot+sashiko
2 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-30 14:31 UTC (permalink / raw)
To: zhengzongmin, linux-usb
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] USB: hso: race between hso_net_close() and hso_resume() on
skb_tx_buf
- [Low] USB: hso: missing Fixes trailer for skb_tx_buf leak fix
--
commit 3d6f9f23f19489f009b13c37018dd2945051ad93
Author: zhengzongmin <zhengzongmin8@gmail.com>
> USB: hso: fix skb leak on device close and teardown
>
> hso_net_start_xmit() stashes an outgoing skb in odev->skb_tx_buf when
> hso_get_activity() returns -EAGAIN. Neither hso_net_close() nor
> hso_free_net_device() frees that skb, so when the device is brought
> down or disconnected before it resumes, the skb and its head buffer
> are permanently leaked. syzbot hit this with an IPv6 Router
> Solicitation packet allocated by ndisc_send_rs().
>
> Free the stashed skb in both paths. dev_kfree_skb() is NULL-safe, so
> no extra check is needed, and clear the pointer afterwards.
>
> Reported-by: syzbot+bf62ca9997f43d2fa521@syzkaller.appspotmail.com
> Signed-off-by: zhengzongmin <zhengzongmin8@gmail.com>
[Severity: Low]
Should this bug fix include a Fixes: tag for the commit that introduced
skb_tx_buf stashing:
Fixes: 72dc1c096c70 ("HSO: add option hso driver")
> diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
> index 71caa3764b239..2f46d51269d0a 100644
> --- a/drivers/net/usb/hso.c
> +++ b/drivers/net/usb/hso.c
> @@ -726,6 +726,11 @@ static int hso_net_close(struct net_device *net)
> /* no longer running */
> clear_bit(HSO_NET_RUNNING, &odev->flags);
>
> + /* Release a packet stashed by hso_net_start_xmit() when the device
> + * was busy. Otherwise it leaks when the device is brought down. */
> + dev_kfree_skb(odev->skb_tx_buf);
> + odev->skb_tx_buf = NULL;
[Severity: High]
Can freeing odev->skb_tx_buf here race with hso_resume() and cause a
use-after-free and double free?
When hso_get_activity() returns -EAGAIN during transmit, it schedules
async_get_intf to resume the USB interface. hso_resume() runs under the
USB device PM lock without holding rtnl_lock or any lock shared with
hso_net_close(), and only clears skb_tx_buf after hso_net_start_xmit()
has transmitted and freed it:
drivers/net/usb/hso.c:hso_resume() {
...
if (hso_net->flags & IFF_UP) {
/* First transmit any lingering data,
then restart the device. */
if (hso_net->skb_tx_buf) {
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 the interface is brought down while async_get_intf (or system resume)
is running hso_resume(), both paths can consume the same skb:
CPU0 CPU1 (kworker / async_get_intf)
hso_resume()
if (hso_net->flags & IFF_UP)
skb = hso_net->skb_tx_buf
hso_net_close()
clear_bit(HSO_NET_RUNNING, ...)
dev_kfree_skb(odev->skb_tx_buf)
odev->skb_tx_buf = NULL
hso_net_start_xmit(skb, ...)
memcpy(..., skb->data, skb->len)
<-- use-after-free
dev_kfree_skb(skb)
<-- double free
--
Sashiko AI review · https://sashiko.dev/#/patchset/6b0c372a.1800fd7e.25977e.57fb@mx.google.com?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] USB: hso: fix skb leak on device close and teardown
2026-11-29 14:31 [PATCH] USB: hso: fix skb leak on device close and teardown zhengzongmin
2026-11-29 16:52 ` Greg KH
2026-11-30 14:31 ` sashiko-bot
@ 2026-11-30 15:28 ` netdev-bot+sashiko
2 siblings, 0 replies; 4+ messages in thread
From: netdev-bot+sashiko @ 2026-11-30 15:28 UTC (permalink / raw)
To: zhengzongmin8; +Cc: linux-usb, netdev, linux-kernel, kuba
Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 (2) · Low: 3 (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 new free of odev->skb_tx_buf in hso_net_close()
(drivers/net/usb/hso.c:731-732) is not synchronized with hso_resume()…
- [Low] The patch fixes a syzbot-reported skb leak that every stable
kernel with this driver has, but it has no Fixes: tag and no Cc:…
- [Low] The comment added in hso_free_net_device() (lines 2365-2366) says
a stashed skb "may survive hso_net_close() if the device was never…
- [Low] Both new free sites (hso_net_close() line 731 and
hso_free_net_device() line 2367) release a packet that was never…
Pre-existing issues:
- [Medium] This problem wasn't introduced by this patch, but hso_resume()
can lose the stashed skb.
- [Medium] This problem wasn't introduced by this patch, but stashing an
skb leaves a runtime-PM reference held after the interface goes down.
- [Low] This problem wasn't introduced by this patch, but hso_resume()
(line 3064) tests `hso_net->flags & IFF_UP`.
--
USB: hso: fix skb leak on device close and teardown
This patch frees the skb that hso_net_start_xmit() stashes in skb_tx_buf
when hso_get_activity() returns -EAGAIN. The free is added to both
hso_net_close() and hso_free_net_device(), to fix a syzbot-reported leak
of an IPv6 Router Solicitation skb.
> Reported-by: syzbot+bf62ca9997f43d2fa521@syzkaller.appspotmail.com
> Signed-off-by: zhengzongmin <zhengzongmin8@gmail.com>
[Severity: Low]
Should this have a Fixes: tag and Cc: stable? The logic in
hso_net_start_xmit() that stashes the skb without ever freeing it seems
to come from the original driver commit:
Fixes: 72dc1c096c70 ("HSO: add option hso driver")
Also, the "USB: hso:" subject prefix doesn't follow the netdev convention
for drivers/net/usb/. Would "net: usb: hso:" fit the net tree better?
> diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
> index 71caa3764b239..2f46d51269d0a 100644
> --- a/drivers/net/usb/hso.c
> +++ b/drivers/net/usb/hso.c
> @@ -726,6 +726,11 @@ static int hso_net_close(struct net_device *net)
> /* no longer running */
> clear_bit(HSO_NET_RUNNING, &odev->flags);
>
> + /* Release a packet stashed by hso_net_start_xmit() when the device
> + * was busy. Otherwise it leaks when the device is brought down. */
> + dev_kfree_skb(odev->skb_tx_buf);
> + odev->skb_tx_buf = NULL;
[Severity: High]
Can this free race with hso_resume(), which also uses this skb?
By the time hso_net_start_xmit() stashes the skb, hso_get_activity() has
already scheduled async_get_intf:
hso_get_activity() {
if (hso_dev->usb->state == USB_STATE_SUSPENDED) {
if (!hso_dev->is_active) {
hso_dev->is_active = 1;
schedule_work(&hso_dev->async_get_intf);
}
}
...
}
That worker calls usb_autopm_get_interface(). This runtime-resumes the
device and runs hso_resume(), which holds neither RTNL nor any driver
lock:
hso_resume() {
...
if (hso_net->flags & IFF_UP) {
...
if (hso_net->skb_tx_buf) {
...
hso_net_start_xmit(hso_net->skb_tx_buf,
hso_net->net);
hso_net->skb_tx_buf = NULL;
}
...
}
hso_net_close() runs under RTNL only, and it doesn't cancel or flush
async_get_intf. Clearing HSO_NET_RUNNING before the free doesn't help
against a resume that has already passed the IFF_UP check.
One possible interleaving:
kworker (hso_resume) ndo_stop (hso_net_close)
passes flags & IFF_UP check
loads hso_net->skb_tx_buf
clear_bit(HSO_NET_RUNNING, ...)
dev_kfree_skb(odev->skb_tx_buf)
odev->skb_tx_buf = NULL
hso_net_start_xmit(skb)
memcpy(..., skb->data, skb->len)
dev_kfree_skb(skb)
Wouldn't that read the freed skb (and send its contents in the bulk-OUT
URB), and then free it a second time?
The reverse order also looks possible. hso_net_start_xmit() frees the
skb inside hso_resume(). Before hso_resume() sets skb_tx_buf to NULL,
hso_net_close() loads the stale pointer and frees it again.
hso_resume() also reads skb_tx_buf twice without READ_ONCE(). If the
second read happens after close has stored NULL, hso_net_start_xmit()
gets a NULL skb and dereferences skb->data.
Before this patch, the same race could only leak the skb.
hso_free_interface() cancels async_get_intf before the teardown free, so
close looks like the main trigger.
Does this free need to be serialized with hso_resume()? For example, both
paths could take and clear the pointer under a lock. Another option is to
flush async_get_intf and synchronize with runtime resume in ndo_stop.
[Severity: Low]
This isn't a bug, but dev_kfree_skb() is consume_skb(). That means
drop_monitor and the skb tracepoints see this untransmitted packet as
normally consumed. hso_net_start_xmit() already returned NETDEV_TX_OK
for it, and net->stats.tx_dropped isn't incremented here either.
Would kfree_skb() or kfree_skb_reason(), plus a tx_dropped increment,
report the drop correctly? The new free in hso_free_net_device() has the
same issue.
[Severity: Medium]
This is a pre-existing issue, but discarding the stashed skb here leaves
the runtime PM reference taken for it still held. When the skb was
stashed, hso_get_activity() set is_active = 1, and async_get_intf called
usb_autopm_get_interface().
For the net hso_device, the only matching hso_put_activity() is in
write_bulk_callback(). That runs only when a TX URB completes, and it
returns early if HSO_NET_RUNNING is clear:
write_bulk_callback() {
...
if (!odev || !test_bit(HSO_NET_RUNNING, &odev->flags)) {
...
return;
}
...
hso_put_activity(odev->parent);
...
}
Here the skb is freed without being submitted, and hso_resume() skips the
port once RUNNING is cleared. Does is_active then stay at 1, with the
interface's autopm usage count still raised, so the modem can't
autosuspend while the interface is down? This free would be a natural
place to balance it.
> +
> hso_stop_net_device(odev->parent);
>
> /* done */
> @@ -2357,6 +2362,11 @@ static void hso_free_net_device(struct hso_device *hso_dev)
> if (hso_net->net)
> unregister_netdev(hso_net->net);
>
> + /* A stashed skb may survive hso_net_close() if the device was never
> + * brought up; make sure it is freed on the teardown path too. */
> + dev_kfree_skb(hso_net->skb_tx_buf);
> + hso_net->skb_tx_buf = NULL;
[Severity: Low]
Can a device that was never brought up have a stashed skb here?
skb_tx_buf is only set in hso_net_start_xmit(). The stack calls that only
on an up interface. hso_resume() calls it only when HSO_NET_RUNNING is
set, and that bit is set in hso_net_open(). netdev_priv is zeroed at
allocation, and hso_net_open() also sets skb_tx_buf to NULL.
If the device was up, unregister_netdev() runs ndo_stop. So
hso_net_close() has already freed and cleared the pointer before this
point.
Is this hunk effectively a no-op? Could the comment be reworded to match
the driver's actual lifecycle?
[Severity: Medium]
This is a pre-existing issue, but can hso_resume() still lose the stashed
skb, so that neither of the new frees sees it?
hso_resume() sets skb_tx_buf to NULL unconditionally after it calls
hso_net_start_xmit(). hso_get_activity() returns -EAGAIN for any state
other than USB_STATE_CONFIGURED:
if (hso_dev->usb->state != USB_STATE_CONFIGURED)
return -EAGAIN;
Suppose a disconnect marks the device NOTATTACHED while resume is in
progress. hso_net_start_xmit() then stashes the same skb again:
if (hso_get_activity(odev->parent) == -EAGAIN) {
odev->skb_tx_buf = skb;
return NETDEV_TX_OK;
}
hso_resume() then overwrites the only reference with NULL, and the skb
leaks. Would clearing the field before the call avoid this?
skb = hso_net->skb_tx_buf;
hso_net->skb_tx_buf = NULL;
hso_net_start_xmit(skb, hso_net->net);
[Severity: Low]
This is a pre-existing issue, but the hso_resume() check that guards the
drain of skb_tx_buf masks the driver's flags word with a netdev flag:
if (hso_net->flags & IFF_UP) {
hso_net->flags holds bit indices, and the comment above HSO_NET_RUNNING
says "use *_bit operations on it. (bit indices not values.)". The check
works only because IFF_UP (0x1) happens to equal BIT(HSO_NET_RUNNING).
Should it be test_bit(HSO_NET_RUNNING, &hso_net->flags) instead?
> +
> /* start freeing */
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/6b0c372a.1800fd7e.25977e.57fb%40mx.google.com
^ permalink raw reply [flat|nested] 4+ messages in thread