]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/5.1.5/rtnetlink-always-put-ifla_link-for-links-with-a-link-netnsid.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 5.1.5 / rtnetlink-always-put-ifla_link-for-links-with-a-link-netnsid.patch
1 From foo@baz Wed 22 May 2019 08:34:59 AM CEST
2 From: Sabrina Dubroca <sd@queasysnail.net>
3 Date: Tue, 14 May 2019 15:12:19 +0200
4 Subject: rtnetlink: always put IFLA_LINK for links with a link-netnsid
5
6 From: Sabrina Dubroca <sd@queasysnail.net>
7
8 [ Upstream commit feadc4b6cf42a53a8a93c918a569a0b7e62bd350 ]
9
10 Currently, nla_put_iflink() doesn't put the IFLA_LINK attribute when
11 iflink == ifindex.
12
13 In some cases, a device can be created in a different netns with the
14 same ifindex as its parent. That device will not dump its IFLA_LINK
15 attribute, which can confuse some userspace software that expects it.
16 For example, if the last ifindex created in init_net and foo are both
17 8, these commands will trigger the issue:
18
19 ip link add parent type dummy # ifindex 9
20 ip link add link parent netns foo type macvlan # ifindex 9 in ns foo
21
22 So, in case a device puts the IFLA_LINK_NETNSID attribute in a dump,
23 always put the IFLA_LINK attribute as well.
24
25 Thanks to Dan Winship for analyzing the original OpenShift bug down to
26 the missing netlink attribute.
27
28 v2: change Fixes tag, it's been here forever, as Nicolas Dichtel said
29 add Nicolas' ack
30 v3: change Fixes tag
31 fix subject typo, spotted by Edward Cree
32
33 Analyzed-by: Dan Winship <danw@redhat.com>
34 Fixes: d8a5ec672768 ("[NET]: netlink support for moving devices between network namespaces.")
35 Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
36 Acked-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
37 Signed-off-by: David S. Miller <davem@davemloft.net>
38 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
39 ---
40 net/core/rtnetlink.c | 16 ++++++++++------
41 1 file changed, 10 insertions(+), 6 deletions(-)
42
43 --- a/net/core/rtnetlink.c
44 +++ b/net/core/rtnetlink.c
45 @@ -1496,14 +1496,15 @@ static int put_master_ifindex(struct sk_
46 return ret;
47 }
48
49 -static int nla_put_iflink(struct sk_buff *skb, const struct net_device *dev)
50 +static int nla_put_iflink(struct sk_buff *skb, const struct net_device *dev,
51 + bool force)
52 {
53 int ifindex = dev_get_iflink(dev);
54
55 - if (dev->ifindex == ifindex)
56 - return 0;
57 + if (force || dev->ifindex != ifindex)
58 + return nla_put_u32(skb, IFLA_LINK, ifindex);
59
60 - return nla_put_u32(skb, IFLA_LINK, ifindex);
61 + return 0;
62 }
63
64 static noinline_for_stack int nla_put_ifalias(struct sk_buff *skb,
65 @@ -1520,6 +1521,8 @@ static int rtnl_fill_link_netnsid(struct
66 const struct net_device *dev,
67 struct net *src_net)
68 {
69 + bool put_iflink = false;
70 +
71 if (dev->rtnl_link_ops && dev->rtnl_link_ops->get_link_net) {
72 struct net *link_net = dev->rtnl_link_ops->get_link_net(dev);
73
74 @@ -1528,10 +1531,12 @@ static int rtnl_fill_link_netnsid(struct
75
76 if (nla_put_s32(skb, IFLA_LINK_NETNSID, id))
77 return -EMSGSIZE;
78 +
79 + put_iflink = true;
80 }
81 }
82
83 - return 0;
84 + return nla_put_iflink(skb, dev, put_iflink);
85 }
86
87 static int rtnl_fill_link_af(struct sk_buff *skb,
88 @@ -1617,7 +1622,6 @@ static int rtnl_fill_ifinfo(struct sk_bu
89 #ifdef CONFIG_RPS
90 nla_put_u32(skb, IFLA_NUM_RX_QUEUES, dev->num_rx_queues) ||
91 #endif
92 - nla_put_iflink(skb, dev) ||
93 put_master_ifindex(skb, dev) ||
94 nla_put_u8(skb, IFLA_CARRIER, netif_carrier_ok(dev)) ||
95 (dev->qdisc &&