Commit a4320615 authored by Peilin Ye's avatar Peilin Ye Committed by Jakub Kicinski

usbnet: Fix memory leak in usbnet_disconnect()

Currently usbnet_disconnect() unanchors and frees all deferred URBs
using usb_scuttle_anchored_urbs(), which does not free urb->context,
causing a memory leak as reported by syzbot.

Use a usb_get_from_anchor() while loop instead, similar to what we did
in commit 19cfe912 ("Bluetooth: btusb: Fix memory leak in
play_deferred").  Also free urb->sg.

Reported-and-tested-by: syzbot+dcd3e13cf4472f2e0ba1@syzkaller.appspotmail.com
Fixes: 69ee472f ("usbnet & cdc-ether: Autosuspend for online devices")
Fixes: 638c5115 ("USBNET: support DMA SG")
Signed-off-by: default avatarPeilin Ye <peilin.ye@bytedance.com>
Link: https://lore.kernel.org/r/20220923042551.2745-1-yepeilin.cs@gmail.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 6052a4c1
...@@ -1598,6 +1598,7 @@ void usbnet_disconnect (struct usb_interface *intf) ...@@ -1598,6 +1598,7 @@ void usbnet_disconnect (struct usb_interface *intf)
struct usbnet *dev; struct usbnet *dev;
struct usb_device *xdev; struct usb_device *xdev;
struct net_device *net; struct net_device *net;
struct urb *urb;
dev = usb_get_intfdata(intf); dev = usb_get_intfdata(intf);
usb_set_intfdata(intf, NULL); usb_set_intfdata(intf, NULL);
...@@ -1614,7 +1615,11 @@ void usbnet_disconnect (struct usb_interface *intf) ...@@ -1614,7 +1615,11 @@ void usbnet_disconnect (struct usb_interface *intf)
net = dev->net; net = dev->net;
unregister_netdev (net); unregister_netdev (net);
usb_scuttle_anchored_urbs(&dev->deferred); while ((urb = usb_get_from_anchor(&dev->deferred))) {
dev_kfree_skb(urb->context);
kfree(urb->sg);
usb_free_urb(urb);
}
if (dev->driver_info->unbind) if (dev->driver_info->unbind)
dev->driver_info->unbind(dev, intf); dev->driver_info->unbind(dev, intf);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment