lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20210930064503.GA7992@linux.intel.com>
Date:   Thu, 30 Sep 2021 14:45:03 +0800
From:   Wong Vee Khee <vee.khee.wong@...ux.intel.com>
To:     Pavel Skripkin <paskripkin@...il.com>
Cc:     andrew@...n.ch, hkallweit1@...il.com, linux@...linux.org.uk,
        davem@...emloft.net, kuba@...nel.org, buytenh@...vell.com,
        afleming@...escale.com, netdev@...r.kernel.org,
        linux-kernel@...r.kernel.org,
        syzbot+398e7dc692ddbbb4cfec@...kaller.appspotmail.com,
        Dan Carpenter <dan.carpenter@...cle.com>
Subject: Re: [PATCH v3 2/2] phy: mdio: fix memory leak

On Thu, Sep 30, 2021 at 09:19:54AM +0300, Pavel Skripkin wrote:
> 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@shell.armlinux.org.uk/
> Fixes: 46abc02175b3 ("phylib: give mdio buses a device tree presence")
> Reported-and-tested-by: syzbot+398e7dc692ddbbb4cfec@...kaller.appspotmail.com
> Reviewed-by: Dan Carpenter <dan.carpenter@...cle.com>
> Signed-off-by: Pavel Skripkin <paskripkin@...il.com>
> ---
> 
> Changes in v3:
> 	s/==/=/
> 	Added Dan's Reviewed-by tag
> 
> Changes in v2:
> 	Removed new state, since MDIOBUS_UNREGISTERED can be used. Also, moved
> 	bus->state initialization _before_ device_register() call, because
> 	Yanfei's patch is reverted in [v2 1/2]
> 
> ---
>  drivers/net/phy/mdio_bus.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
> index 53f034fc2ef7..a5f910d4a7be 100644
> --- a/drivers/net/phy/mdio_bus.c
> +++ b/drivers/net/phy/mdio_bus.c
> @@ -534,6 +534,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 realese

Typo here. s/realese/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);

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ