lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <34fa2e8db1eed23297405cd9144afd6c10ccc392.1600770261.git.sd@queasysnail.net>
Date:   Thu,  1 Oct 2020 09:59:28 +0200
From:   Sabrina Dubroca <sd@...asysnail.net>
To:     netdev@...r.kernel.org
Cc:     Sabrina Dubroca <sd@...asysnail.net>
Subject: [PATCH net 04/12] rtnetlink: always put IFLA_LINK for links with ndo_get_iflink

The test that nla_put_iflink() uses to detect whether a device has a
lower link doesn't work with network namespaces, as a device can have
the same ifindex as its parent:

    ip netns add main
    ip netns add peer
    ip -net main link add dummy0 type dummy
    ip -net main link add link dummy0 macvlan0 netns peer type macvlan
    ip -net main link show type dummy
        # 9: dummy0: <BROADCAST,NOARP> mtu 1500 qdisc noop ...
    ip -net peer link show type macvlan
        # 9: macvlan0@if9: <BROADCAST,MULTICAST> mtu 1500 qdisc noop ...

Instead of calling dev_get_iflink(), we can use the existence of the
ndo_get_iflink operation (which dev_get_iflink would call) to check if
a device has a lower link.

I previously tried to fix this with commit feadc4b6cf42 ("rtnetlink:
always put IFLA_LINK for links with a link-netnsid") but didn't get to
the root of the problem.

Fixes: d8a5ec672768 ("[NET]: netlink support for moving devices between network namespaces.")
Signed-off-by: Sabrina Dubroca <sd@...asysnail.net>
---
 net/core/rtnetlink.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index c35b3f02b4f9..a8459fb59ccd 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -1549,12 +1549,13 @@ static int put_master_ifindex(struct sk_buff *skb, struct net_device *dev)
 
 static int nla_put_iflink(struct sk_buff *skb, const struct net_device *dev)
 {
-	int ifindex = dev_get_iflink(dev);
+	if (dev->netdev_ops && dev->netdev_ops->ndo_get_iflink) {
+		int ifindex = dev->netdev_ops->ndo_get_iflink(dev);
 
-	if (dev->ifindex == ifindex)
-		return 0;
+		return nla_put_u32(skb, IFLA_LINK, ifindex);
+	}
 
-	return nla_put_u32(skb, IFLA_LINK, ifindex);
+	return 0;
 }
 
 static noinline_for_stack int nla_put_ifalias(struct sk_buff *skb,
-- 
2.28.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ