]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/3.14.36/rtnetlink-call-dellink-on-failure-when-newlink-exists.patch
5.1-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 3.14.36 / rtnetlink-call-dellink-on-failure-when-newlink-exists.patch
1 From foo@baz Wed Mar 11 11:43:33 CET 2015
2 From: WANG Cong <xiyou.wangcong@gmail.com>
3 Date: Fri, 13 Feb 2015 13:56:53 -0800
4 Subject: rtnetlink: call ->dellink on failure when ->newlink exists
5
6 From: WANG Cong <xiyou.wangcong@gmail.com>
7
8 [ Upstream commit 7afb8886a05be68e376655539a064ec672de8a8e ]
9
10 Ignacy reported that when eth0 is down and add a vlan device
11 on top of it like:
12
13 ip link add link eth0 name eth0.1 up type vlan id 1
14
15 We will get a refcount leak:
16
17 unregister_netdevice: waiting for eth0.1 to become free. Usage count = 2
18
19 The problem is when rtnl_configure_link() fails in rtnl_newlink(),
20 we simply call unregister_device(), but for stacked device like vlan,
21 we almost do nothing when we unregister the upper device, more work
22 is done when we unregister the lower device, so call its ->dellink().
23
24 Reported-by: Ignacy Gawedzki <ignacy.gawedzki@green-communications.fr>
25 Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
26 Signed-off-by: David S. Miller <davem@davemloft.net>
27 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
28 ---
29 net/core/rtnetlink.c | 12 ++++++++++--
30 1 file changed, 10 insertions(+), 2 deletions(-)
31
32 --- a/net/core/rtnetlink.c
33 +++ b/net/core/rtnetlink.c
34 @@ -2030,8 +2030,16 @@ replay:
35 }
36 }
37 err = rtnl_configure_link(dev, ifm);
38 - if (err < 0)
39 - unregister_netdevice(dev);
40 + if (err < 0) {
41 + if (ops->newlink) {
42 + LIST_HEAD(list_kill);
43 +
44 + ops->dellink(dev, &list_kill);
45 + unregister_netdevice_many(&list_kill);
46 + } else {
47 + unregister_netdevice(dev);
48 + }
49 + }
50 out:
51 put_net(dest_net);
52 return err;