From: Jakub Kicinski <kuba@kernel.org>
To: Oliver Neukum <oneukum@suse.com>
Cc: Paolo Abeni <pabeni@redhat.com>,
"Peter GJ. Park" <gyujoon.park@samsung.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
netdev@vger.kernel.org, linux-usb@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] net: usb: usbnet: fix use-after-free in race on workqueue
Date: Tue, 1 Jul 2025 18:26:17 -0700 [thread overview]
Message-ID: <20250701182617.07d6e437@kernel.org> (raw)
In-Reply-To: <ebd0bb9b-8e66-4119-b011-c1a737749fb2@suse.com>
On Tue, 1 Jul 2025 15:22:54 +0200 Oliver Neukum wrote:
> On 26.06.25 11:21, Paolo Abeni wrote:
> >> drivers/net/usb/usbnet.c | 3 +++
> >> 1 file changed, 3 insertions(+)
> >>
> >> diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
> >> index c04e715a4c2ade3bc5587b0df71643a25cf88c55..3c5d9ba7fa6660273137c80106746103f84f5a37 100644
> >> --- a/drivers/net/usb/usbnet.c
> >> +++ b/drivers/net/usb/usbnet.c
> >> @@ -1660,6 +1660,9 @@ void usbnet_disconnect (struct usb_interface *intf)
> >> usb_free_urb(dev->interrupt);
> >> kfree(dev->padding_pkt);
> >>
> >> + timer_delete_sync(&dev->delay);
> >> + tasklet_kill(&dev->bh);
> >> + cancel_work_sync(&dev->kevent);
> >> free_netdev(net);
> > This happens after unregister_netdev(), which calls usbnet_stop() that
> > already performs the above cleanup. How the race is supposed to take place?
>
> That is indeed a core question, which we really need an answer to.
> Do I interpret dev_close_many() correctly, if I state that the
> ndo_stop() method will _not_ be called if the device has never been
> opened?
Correct, open and close are paired. Most drivers would crash if we
tried to close them before they ever got opened.
> I am sorry to be a stickler here, but if that turns out to be true,
> usbnet is not the only driver that has this bug.
Shooting from the hip slightly, but its unusual for a driver to start
link monitoring before open. After all there can be no packets on a
device that's closed. Why not something like:
diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
index 9564478a79cc..b75b0b5c3abc 100644
--- a/drivers/net/usb/usbnet.c
+++ b/drivers/net/usb/usbnet.c
@@ -896,6 +896,9 @@ int usbnet_open (struct net_device *net)
int retval;
const struct driver_info *info = dev->driver_info;
+ if (dev->driver_info->flags & FLAG_LINK_INTR)
+ usbnet_link_change(dev, 0, 0);
+
if ((retval = usb_autopm_get_interface(dev->intf)) < 0) {
netif_info(dev, ifup, dev->net,
"resumption fail (%d) usbnet usb-%s-%s, %s\n",
@@ -1862,8 +1865,7 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
netif_device_attach (net);
- if (dev->driver_info->flags & FLAG_LINK_INTR)
- usbnet_link_change(dev, 0, 0);
+ netif_carrier_off(net);
return 0;
next prev parent reply other threads:[~2025-07-02 1:26 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20250625093354epcas1p1c9817df6e1d1599e8b4eb16c5715a6fd@epcas1p1.samsung.com>
2025-06-25 9:33 ` [PATCH] net: usb: usbnet: fix use-after-free in race on workqueue Peter GJ. Park
2025-06-26 9:21 ` Paolo Abeni
2025-06-27 10:47 ` [PATCH v2] " Peter GJ. Park
2025-06-27 10:59 ` [PATCH net " Peter GJ. Park
2025-07-02 1:27 ` Jakub Kicinski
2025-07-01 4:19 ` [PATCH net] " Peter GJ. Park
2025-07-01 13:22 ` [PATCH] " Oliver Neukum
2025-07-02 1:26 ` Jakub Kicinski [this message]
2025-07-02 10:54 ` Oliver Neukum
2025-07-02 18:22 ` Jakub Kicinski
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=20250701182617.07d6e437@kernel.org \
--to=kuba@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=gyujoon.park@samsung.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=oneukum@suse.com \
--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 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.