Skip to contentSkip to conversation

rtnetlink: call ->dellink on failure when ->newlink exists

PATCH Applied Cong Wang 2 participants 2 messages Feb 13, 2015 – Feb 15, 2015

Subsystems (2)
lore
Share & tools
lore

Cong Wang

author
#0 lore raw

PATCH 1/1 rtnetlink: call ->dellink on failure when ->newlink exists

Ignacy reported that when eth0 is down and add a vlan device on top of it like:

ip link add link eth0 name eth0.1 up type vlan id 1

We will get a refcount leak:

unregister_netdevice: waiting for eth0.1 to become free. Usage count = 2

The problem is when rtnl_configure_link() fails in rtnl_newlink(), we simply call unregister_device(), but for stacked device like vlan, we almost do nothing when we unregister the upper device, more work is done when we unregister the lower device, so call its ->dellink().

---
 net/core/rtnetlink.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
net/core/rtnetlink.c +8 -1
index 5be499b..ab293a3 100644
@@ -2162,7 +2162,14 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh)
 		}
 		err = rtnl_configure_link(dev, ifm);
 		if (err < 0) {
-			unregister_netdevice(dev);
+			if (ops->newlink) {
+				LIST_HEAD(list_kill);
+
+				ops->dellink(dev, &list_kill);
+				unregister_netdevice_many(&list_kill);
+			} else {
+				unregister_netdevice(dev);
+			}
 			goto out;
 		}
 
Signature · 1 line
1.8.3.1
maintainer Applied
#1 lore raw

From: Cong Wang <[email protected]>
Date: Fri, 13 Feb 2015 13:56:53 -0800

Quoted 9 lines

Ignacy reported that when eth0 is down and add a vlan device on top of it like:

ip link add link eth0 name eth0.1 up type vlan id 1

We will get a refcount leak:

unregister_netdevice: waiting for eth0.1 to become free. Usage count = 2

Quoted 7 lines

The problem is when rtnl_configure_link() fails in rtnl_newlink(), we simply call unregister_device(), but for stacked device like vlan, we almost do nothing when we unregister the upper device, more work is done when we unregister the lower device, so call its ->dellink().

Applied, thanks.