Commit 4681bfc9 authored by WANG Cong's avatar WANG Cong Committed by Luis Henriques

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

commit 7afb8886 upstream.

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().
Reported-by: default avatarIgnacy Gawedzki <ignacy.gawedzki@green-communications.fr>
Signed-off-by: default avatarCong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
[ luis: backported to 3.16: based on davem's backport to 3.14 ]
Signed-off-by: default avatarLuis Henriques <luis.henriques@canonical.com>
parent c5846c32
...@@ -2069,8 +2069,16 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh) ...@@ -2069,8 +2069,16 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh)
} }
} }
err = rtnl_configure_link(dev, ifm); err = rtnl_configure_link(dev, ifm);
if (err < 0) 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);
}
}
out: out:
put_net(dest_net); put_net(dest_net);
return err; return err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment