Patch "usbnet: Fix memory leak in usbnet_disconnect()" has been added to the 5.19-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    usbnet: Fix memory leak in usbnet_disconnect()

to the 5.19-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     usbnet-fix-memory-leak-in-usbnet_disconnect.patch
and it can be found in the queue-5.19 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 274f2dc6e10bfdba2bb1f3ef3176ad24384c8997
Author: Peilin Ye <peilin.ye@xxxxxxxxxxxxx>
Date:   Thu Sep 22 21:25:51 2022 -0700

    usbnet: Fix memory leak in usbnet_disconnect()
    
    [ Upstream commit a43206156263fbaf1f2b7f96257441f331e91bb7 ]
    
    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 19cfe912c37b ("Bluetooth: btusb: Fix memory leak in
    play_deferred").  Also free urb->sg.
    
    Reported-and-tested-by: syzbot+dcd3e13cf4472f2e0ba1@xxxxxxxxxxxxxxxxxxxxxxxxx
    Fixes: 69ee472f2706 ("usbnet & cdc-ether: Autosuspend for online devices")
    Fixes: 638c5115a794 ("USBNET: support DMA SG")
    Signed-off-by: Peilin Ye <peilin.ye@xxxxxxxxxxxxx>
    Link: https://lore.kernel.org/r/20220923042551.2745-1-yepeilin.cs@xxxxxxxxx
    Signed-off-by: Jakub Kicinski <kuba@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
index 0ed09bb91c44..bccf63aac6cd 100644
--- a/drivers/net/usb/usbnet.c
+++ b/drivers/net/usb/usbnet.c
@@ -1601,6 +1601,7 @@ void usbnet_disconnect (struct usb_interface *intf)
 	struct usbnet		*dev;
 	struct usb_device	*xdev;
 	struct net_device	*net;
+	struct urb		*urb;
 
 	dev = usb_get_intfdata(intf);
 	usb_set_intfdata(intf, NULL);
@@ -1617,7 +1618,11 @@ void usbnet_disconnect (struct usb_interface *intf)
 	net = dev->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)
 		dev->driver_info->unbind(dev, intf);



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux