diff mbox series

[v4,1/2] Revert "net: mdiobus: Fix memory leak in __mdiobus_register"

Message ID f12fb1faa4eccf0f355788225335eb4309ff2599.1633024062.git.paskripkin@gmail.com (mailing list archive)
State Accepted
Commit 10eff1f5788b6ffac212c254e2f3666219576889
Delegated to: Netdev Maintainers
Headers show
Series [v4,1/2] Revert "net: mdiobus: Fix memory leak in __mdiobus_register" | expand

Checks

Context Check Description
netdev/tree_selection success Guessing tree name failed - patch did not apply

Commit Message

Pavel Skripkin Sept. 30, 2021, 5:49 p.m. UTC
This reverts commit ab609f25d19858513919369ff3d9a63c02cd9e2e.

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>
---

Chnages in v4:
	No changes

Changes in v3:
	CC Yanfei -> Acked-by Yanfei

Changes in v2:
	Added this revert

---
 drivers/net/phy/mdio_bus.c | 1 -
 1 file changed, 1 deletion(-)

Comments

patchwork-bot+netdevbpf@kernel.org Oct. 1, 2021, 12:40 a.m. UTC | #1
Hello:

This series was applied to netdev/net.git (refs/heads/master):

On Thu, 30 Sep 2021 20:49:42 +0300 you wrote:
> This reverts commit ab609f25d19858513919369ff3d9a63c02cd9e2e.
> 
> 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.
> 
> [...]

Here is the summary with links:
  - [v4,1/2] Revert "net: mdiobus: Fix memory leak in __mdiobus_register"
    https://git.kernel.org/netdev/net/c/10eff1f5788b
  - [v4,2/2] phy: mdio: fix memory leak
    https://git.kernel.org/netdev/net/c/ca6e11c337da

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
diff mbox series

Patch

diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 6f4b4e5df639..53f034fc2ef7 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -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;
 	}