]> git.baikalelectronics.ru Git - kernel.git/commitdiff
Revert "net: mdiobus: Fix memory leak in __mdiobus_register"
authorPavel Skripkin <paskripkin@gmail.com>
Thu, 30 Sep 2021 17:49:42 +0000 (20:49 +0300)
committerJakub Kicinski <kuba@kernel.org>
Fri, 1 Oct 2021 00:11:58 +0000 (17:11 -0700)
This reverts commit b71ec078bb0a1f5fe4da4f9bf106661cc5cd303d.

This patch is correct in the sense that we _should_ call device_put() in
case of device_register() failure, but the problem in this code is more
vast.

We need to set bus->state to UNMDIOBUS_REGISTERED before calling
device_register() to correctly release the device in mdiobus_free().
This patch prevents us from doing it, since in case of device_register()
failure put_device() will be called 2 times and it will cause UAF or
something else.

Also, Reported-by: tag in revered commit was wrong, since syzbot
reported different leak in same function.

Link: https://lore.kernel.org/netdev/20210928092657.GI2048@kadam/
Acked-by: Yanfei Xu <yanfei.xu@windriver.com>
Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
Link: https://lore.kernel.org/r/f12fb1faa4eccf0f355788225335eb4309ff2599.1633024062.git.paskripkin@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/phy/mdio_bus.c

index 6f4b4e5df6397cbc836b60ccedaece93cef48408..53f034fc2ef7983527faa32fc7589e93eb8f04bc 100644 (file)
@@ -537,7 +537,6 @@ int __mdiobus_register(struct mii_bus *bus, struct module *owner)
        err = device_register(&bus->dev);
        if (err) {
                pr_err("mii_bus %s failed to register\n", bus->id);
-               put_device(&bus->dev);
                return -EINVAL;
        }