Skip to content

Commit

Permalink
rtnetlink: call ->dellink on failure when ->newlink exists
Browse files Browse the repository at this point in the history
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: Ignacy Gawedzki <ignacy.gawedzki@green-communications.fr>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
WANG Cong authored and David S. Miller committed Feb 15, 2015
1 parent d95e2fe commit 7afb888
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion net/core/rtnetlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 7afb888

Please sign in to comment.