Patch "phy: mdio: fix memory leak" has been added to the 4.4-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

    phy: mdio: fix memory leak

to the 4.4-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:
     phy-mdio-fix-memory-leak.patch
and it can be found in the queue-4.4 subdirectory.

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



commit 6534bcad3c341cb839ab24a5256abe72c2733dd4
Author: Pavel Skripkin <paskripkin@xxxxxxxxx>
Date:   Thu Sep 30 20:50:28 2021 +0300

    phy: mdio: fix memory leak
    
    [ Upstream commit ca6e11c337daf7925ff8a2aac8e84490a8691905 ]
    
    Syzbot reported memory leak in MDIO bus interface, the problem was in
    wrong state logic.
    
    MDIOBUS_ALLOCATED indicates 2 states:
            1. Bus is only allocated
            2. Bus allocated and __mdiobus_register() fails, but
               device_register() was called
    
    In case of device_register() has been called we should call put_device()
    to correctly free the memory allocated for this device, but mdiobus_free()
    calls just kfree(dev) in case of MDIOBUS_ALLOCATED state
    
    To avoid this behaviour we need to set bus->state to MDIOBUS_UNREGISTERED
    _before_ calling device_register(), because put_device() should be
    called even in case of device_register() failure.
    
    Link: https://lore.kernel.org/netdev/YVMRWNDZDUOvQjHL@xxxxxxxxxxxxxxxxxxxxx/
    Fixes: 46abc02175b3 ("phylib: give mdio buses a device tree presence")
    Reported-and-tested-by: syzbot+398e7dc692ddbbb4cfec@xxxxxxxxxxxxxxxxxxxxxxxxx
    Reviewed-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>
    Signed-off-by: Pavel Skripkin <paskripkin@xxxxxxxxx>
    Link: https://lore.kernel.org/r/eceae1429fbf8fa5c73dd2a0d39d525aa905074d.1633024062.git.paskripkin@xxxxxxxxx
    Signed-off-by: Jakub Kicinski <kuba@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 5ea86fd57ae6..4066fb5a935a 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -264,6 +264,13 @@ int __mdiobus_register(struct mii_bus *bus, struct module *owner)
 	bus->dev.groups = NULL;
 	dev_set_name(&bus->dev, "%s", bus->id);
 
+	/* We need to set state to MDIOBUS_UNREGISTERED to correctly release
+	 * the device in mdiobus_free()
+	 *
+	 * State will be updated later in this function in case of success
+	 */
+	bus->state = MDIOBUS_UNREGISTERED;
+
 	err = device_register(&bus->dev);
 	if (err) {
 		pr_err("mii_bus %s failed to register\n", bus->id);



[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