Skip to contentSkip to conversation

net: bridge: fix net device refcount tracking issue in error path

PATCH Applied Eric Dumazet 2 participants 2 messages Jan 12, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: bridge: fix net device refcount tracking issue in error path

From: Eric Dumazet <[email protected]>

I left one dev_put() in br_add_if() error path and sure enough syzbot found its way.

As the tracker is allocated in new_nbp(), we must make sure to properly free it.

We have to call dev_put_track(dev, &p->dev_tracker) before @p object is freed, of course. This is not an issue because br_add_if() owns a reference on @dev.

Fixes b2dcdc7f731d ("net: bridge: add net device refcount tracker")
---
 net/bridge/br_if.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/bridge/br_if.c +2 -1
index a52ad81596b72dde8e9a0affccd38c91ab59315d..55f47cadb114038920c01bf43e43500e07a3539c 100644
@@ -615,6 +615,7 @@ int br_add_if(struct net_bridge *br, struct net_device *dev,
 	err = dev_set_allmulti(dev, 1);
 	if (err) {
 		br_multicast_del_port(p);
+		dev_put_track(dev, &p->dev_tracker);
 		kfree(p);	/* kobject not yet init'd, manually free */
 		goto err1;
 	}
@@ -724,10 +725,10 @@ int br_add_if(struct net_bridge *br, struct net_device *dev,
 	sysfs_remove_link(br->ifobj, p->dev->name);
 err2:
 	br_multicast_del_port(p);
+	dev_put_track(dev, &p->dev_tracker);
 	kobject_put(&p->kobj);
 	dev_set_allmulti(dev, -1);
 err1:
-	dev_put(dev);
 	return err;
 }
 
Signature · 1 line
2.34.1.575.g55b058a8bb-goog
#1 lore raw
This patch was applied to netdev/net.git (master) by David S. Miller <[email protected]>:

Hello:

This patch was applied to netdev/net.git (master)
by David S. Miller <[email protected]>:

Quoted 9 lines · On Wed, 12 Jan 2022 04:53:00 -0800 you wrote:

From: Eric Dumazet <[email protected]>

I left one dev_put() in br_add_if() error path and sure enough syzbot found its way.

As the tracker is allocated in new_nbp(), we must make sure to properly free it.

[...]

Here is the summary with links:
- [net] net: bridge: fix net device refcount tracking issue in error path

    https://git.kernel.org/netdev/net/c/fcfb894d5952

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html