Patch "net: usb: lan78xx: Fix double free issue with interrupt buffer allocation" has been added to the 6.1-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

    net: usb: lan78xx: Fix double free issue with interrupt buffer allocation

to the 6.1-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:
     net-usb-lan78xx-fix-double-free-issue-with-interrupt.patch
and it can be found in the queue-6.1 subdirectory.

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



commit 9491c4c822a7e11205e05a7501d08b5fe9f5a2f0
Author: Oleksij Rempel <o.rempel@xxxxxxxxxxxxxx>
Date:   Sat Nov 16 14:05:57 2024 +0100

    net: usb: lan78xx: Fix double free issue with interrupt buffer allocation
    
    [ Upstream commit 03819abbeb11117dcbba40bfe322b88c0c88a6b6 ]
    
    In lan78xx_probe(), the buffer `buf` was being freed twice: once
    implicitly through `usb_free_urb(dev->urb_intr)` with the
    `URB_FREE_BUFFER` flag and again explicitly by `kfree(buf)`. This caused
    a double free issue.
    
    To resolve this, reordered `kmalloc()` and `usb_alloc_urb()` calls to
    simplify the initialization sequence and removed the redundant
    `kfree(buf)`.  Now, `buf` is allocated after `usb_alloc_urb()`, ensuring
    it is correctly managed by  `usb_fill_int_urb()` and freed by
    `usb_free_urb()` as intended.
    
    Fixes: a6df95cae40b ("lan78xx: Fix memory allocation bug")
    Cc: John Efstathiades <john.efstathiades@xxxxxxxxxxxxx>
    Signed-off-by: Oleksij Rempel <o.rempel@xxxxxxxxxxxxxx>
    Link: https://patch.msgid.link/20241116130558.1352230-1-o.rempel@xxxxxxxxxxxxxx
    Signed-off-by: Jakub Kicinski <kuba@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c
index 366e83ed0a973..b18afd2c7aeed 100644
--- a/drivers/net/usb/lan78xx.c
+++ b/drivers/net/usb/lan78xx.c
@@ -4417,29 +4417,30 @@ static int lan78xx_probe(struct usb_interface *intf,
 
 	period = ep_intr->desc.bInterval;
 	maxp = usb_maxpacket(dev->udev, dev->pipe_intr);
-	buf = kmalloc(maxp, GFP_KERNEL);
-	if (!buf) {
+
+	dev->urb_intr = usb_alloc_urb(0, GFP_KERNEL);
+	if (!dev->urb_intr) {
 		ret = -ENOMEM;
 		goto out5;
 	}
 
-	dev->urb_intr = usb_alloc_urb(0, GFP_KERNEL);
-	if (!dev->urb_intr) {
+	buf = kmalloc(maxp, GFP_KERNEL);
+	if (!buf) {
 		ret = -ENOMEM;
-		goto out6;
-	} else {
-		usb_fill_int_urb(dev->urb_intr, dev->udev,
-				 dev->pipe_intr, buf, maxp,
-				 intr_complete, dev, period);
-		dev->urb_intr->transfer_flags |= URB_FREE_BUFFER;
+		goto free_urbs;
 	}
 
+	usb_fill_int_urb(dev->urb_intr, dev->udev,
+			 dev->pipe_intr, buf, maxp,
+			 intr_complete, dev, period);
+	dev->urb_intr->transfer_flags |= URB_FREE_BUFFER;
+
 	dev->maxpacket = usb_maxpacket(dev->udev, dev->pipe_out);
 
 	/* Reject broken descriptors. */
 	if (dev->maxpacket == 0) {
 		ret = -ENODEV;
-		goto out6;
+		goto free_urbs;
 	}
 
 	/* driver requires remote-wakeup capability during autosuspend. */
@@ -4447,7 +4448,7 @@ static int lan78xx_probe(struct usb_interface *intf,
 
 	ret = lan78xx_phy_init(dev);
 	if (ret < 0)
-		goto out7;
+		goto free_urbs;
 
 	ret = register_netdev(netdev);
 	if (ret != 0) {
@@ -4469,10 +4470,8 @@ static int lan78xx_probe(struct usb_interface *intf,
 
 out8:
 	phy_disconnect(netdev->phydev);
-out7:
+free_urbs:
 	usb_free_urb(dev->urb_intr);
-out6:
-	kfree(buf);
 out5:
 	lan78xx_unbind(dev, intf);
 out4:




[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