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
6 From: Sabrina Dubroca <sd@queasysnail.net>
8 [ Upstream commit feadc4b6cf42a53a8a93c918a569a0b7e62bd350 ]
10 Currently, nla_put_iflink() doesn't put the IFLA_LINK attribute when
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:
19 ip link add parent type dummy # ifindex 9
20 ip link add link parent netns foo type macvlan # ifindex 9 in ns foo
22 So, in case a device puts the IFLA_LINK_NETNSID attribute in a dump,
23 always put the IFLA_LINK attribute as well.
25 Thanks to Dan Winship for analyzing the original OpenShift bug down to
26 the missing netlink attribute.
28 v2: change Fixes tag, it's been here forever, as Nicolas Dichtel said
31 fix subject typo, spotted by Edward Cree
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>
40 net/core/rtnetlink.c | 16 ++++++++++------
41 1 file changed, 10 insertions(+), 6 deletions(-)
43 --- a/net/core/rtnetlink.c
44 +++ b/net/core/rtnetlink.c
45 @@ -1496,14 +1496,15 @@ static int put_master_ifindex(struct sk_
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,
53 int ifindex = dev_get_iflink(dev);
55 - if (dev->ifindex == ifindex)
57 + if (force || dev->ifindex != ifindex)
58 + return nla_put_u32(skb, IFLA_LINK, ifindex);
60 - return nla_put_u32(skb, IFLA_LINK, ifindex);
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,
69 + bool put_iflink = false;
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);
74 @@ -1528,10 +1531,12 @@ static int rtnl_fill_link_netnsid(struct
76 if (nla_put_s32(skb, IFLA_LINK_NETNSID, id))
84 + return nla_put_iflink(skb, dev, put_iflink);
87 static int rtnl_fill_link_af(struct sk_buff *skb,
88 @@ -1617,7 +1622,6 @@ static int rtnl_fill_ifinfo(struct sk_bu
90 nla_put_u32(skb, IFLA_NUM_RX_QUEUES, dev->num_rx_queues) ||
92 - nla_put_iflink(skb, dev) ||
93 put_master_ifindex(skb, dev) ||
94 nla_put_u8(skb, IFLA_CARRIER, netif_carrier_ok(dev)) ||