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]
Date:   Wed, 4 Mar 2020 17:07:10 +0800
From:   Hangbin Liu <liuhangbin@...il.com>
To:     Rafał Miłecki <zajec5@...il.com>
Cc:     Network Development <netdev@...r.kernel.org>,
        "David S. Miller" <davem@...emloft.net>,
        Alexey Kuznetsov <kuznet@....inr.ac.ru>,
        Hideaki YOSHIFUJI <yoshfuji@...ux-ipv6.org>,
        Felix Fietkau <nbd@....name>, John Crispin <john@...ozen.org>,
        Jo-Philipp Wich <jo@...n.io>
Subject: Re: Regression: net/ipv6/mld running system out of memory (not a
 leak)

On Wed, Mar 04, 2020 at 08:44:29AM +0100, Rafał Miłecki wrote:
> > Hi Rafał,
> > 
> > When review the code, I got confused. On the latest net code, we only
> > add the allrouter address to multicast list in function
> > 1) ipv6_add_dev(), which only called when there is no idev. But link down and
> >     up would not re-create idev.
> > 2) dev_forward_change(), which only be called during forward change, this
> >     function will handle add/remove allrouter address correctly.
> 
> Sharp eye! You're right, I tracked (with just a pr_info) all usages of
> in6addr_linklocal_allrouters and none gets triggered during my testing
> routine. I'm wondering if I should start blaming my OpenWrt user space
> now.

Yeah...Hope you could help dig more.
> 
> 
> > So I still don't know how you could added the ff02::2 on same dev multi times.
> > Does just do `ip link set $dev down; ip link set $dev up` reproduce your
> > problem? Or did I miss something?
> 
> A bit old-fashioned with ifconfig but basically yes, that's my test:
> 
> iw phy phy0 interface add mon-phy0 type monitor

What does this step do? Is there a corresponding command for ip link?

> for i in $(seq 1 10); do ifconfig mon-phy0 up; ifconfig mon-phy0 down; done
> iw dev mon-phy0 del

The other cmd looks normal. BTW, I have create a new patch. The previous one
will leak ff01::1, ff02::1, ff01::2 as the link up will not re-add them.

The new patch will join and leave all node/route address when link up/down
instead of store them. But I don't think it could resolve your issue as the
code logic is not changed. If you like, you can have a try.

Thanks
Hangbin

>From 9cf504dc30198133e470ea783c3fa53a8f56a20a Mon Sep 17 00:00:00 2001
From: Hangbin Liu <liuhangbin@...il.com>
Date: Tue, 3 Mar 2020 20:58:39 +0800
Subject: [PATCH] ipv6/mcast: join and leave allnodes, allrouters addresses
 when link up/down

This patch fixes two issues:

1) When link up with IPv6 forwarding enabled, we forgot to join
sitelocal_allrouters(ff01::2) and interfacelocal_allrouters(ff05::2),
like what we do in function dev_forward_change()

2) When link down, there is no listener for the allnodes, allrouters
addresses. So we should remove them instead of storing the info in
idev->mc_tomb.

To fix these two issue, I add two new functions ipv6_mc_join_localaddr()
and ipv6_mc_leave_localaddr() to handle these addresses. And just join
leave the group in ipv6_mc_{up, down}.

Signed-off-by: Hangbin Liu <liuhangbin@...il.com>
---
 net/ipv6/addrconf.c | 22 +++++++---------------
 net/ipv6/mcast.c    | 45 ++++++++++++++++++++++++++++++++++-----------
 2 files changed, 41 insertions(+), 26 deletions(-)

diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 164c71c54b5c..8e39f569beaa 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -449,16 +449,6 @@ static struct inet6_dev *ipv6_add_dev(struct net_device *dev)
 	/* protected by rtnl_lock */
 	rcu_assign_pointer(dev->ip6_ptr, ndev);
 
-	/* Join interface-local all-node multicast group */
-	ipv6_dev_mc_inc(dev, &in6addr_interfacelocal_allnodes);
-
-	/* Join all-node multicast group */
-	ipv6_dev_mc_inc(dev, &in6addr_linklocal_allnodes);
-
-	/* Join all-router multicast group if forwarding is set */
-	if (ndev->cnf.forwarding && (dev->flags & IFF_MULTICAST))
-		ipv6_dev_mc_inc(dev, &in6addr_linklocal_allrouters);
-
 	return ndev;
 
 err_release:
@@ -481,7 +471,7 @@ static struct inet6_dev *ipv6_find_idev(struct net_device *dev)
 			return idev;
 	}
 
-	if (dev->flags&IFF_UP)
+	if (dev->flags & IFF_UP && dev->flags & IFF_MULTICAST)
 		ipv6_mc_up(idev);
 	return idev;
 }
@@ -795,7 +785,7 @@ static void dev_forward_change(struct inet6_dev *idev)
 	dev = idev->dev;
 	if (idev->cnf.forwarding)
 		dev_disable_lro(dev);
-	if (dev->flags & IFF_MULTICAST) {
+	if (dev->flags & IFF_UP && dev->flags & IFF_MULTICAST) {
 		if (idev->cnf.forwarding) {
 			ipv6_dev_mc_inc(dev, &in6addr_linklocal_allrouters);
 			ipv6_dev_mc_inc(dev, &in6addr_interfacelocal_allrouters);
@@ -3554,7 +3544,8 @@ static int addrconf_notify(struct notifier_block *this, unsigned long event,
 			}
 
 			if (!IS_ERR_OR_NULL(idev)) {
-				if (idev->if_flags & IF_READY) {
+				if (idev->if_flags & IF_READY &&
+				    dev->flags & IFF_MULTICAST) {
 					/* device is already configured -
 					 * but resend MLD reports, we might
 					 * have roamed and need to update
@@ -3839,8 +3830,9 @@ static int addrconf_ifdown(struct net_device *dev, int how)
 	/* Step 5: Discard anycast and multicast list */
 	if (how) {
 		ipv6_ac_destroy_dev(idev);
-		ipv6_mc_destroy_dev(idev);
-	} else {
+		if (dev->flags & IFF_MULTICAST)
+			ipv6_mc_destroy_dev(idev);
+	} else if (dev->flags & IFF_MULTICAST){
 		ipv6_mc_down(idev);
 	}
 
diff --git a/net/ipv6/mcast.c b/net/ipv6/mcast.c
index eaa4c2cc2fbb..1512ca906b36 100644
--- a/net/ipv6/mcast.c
+++ b/net/ipv6/mcast.c
@@ -2529,11 +2529,44 @@ void ipv6_mc_remap(struct inet6_dev *idev)
 
 /* Device going down */
 
+static void ipv6_mc_join_localaddr(struct inet6_dev *idev)
+{
+	struct net_device *dev;
+
+	dev = idev->dev;
+
+	/* Join interface-local all-node multicast group */
+	ipv6_dev_mc_inc(dev, &in6addr_interfacelocal_allnodes);
+
+	/* Join all-node multicast group */
+	ipv6_dev_mc_inc(dev, &in6addr_linklocal_allnodes);
+
+	/* Join all-router multicast group if forwarding is set */
+	if (idev->cnf.forwarding) {
+		ipv6_dev_mc_inc(dev, &in6addr_interfacelocal_allrouters);
+		ipv6_dev_mc_inc(dev, &in6addr_linklocal_allrouters);
+		ipv6_dev_mc_inc(dev, &in6addr_sitelocal_allrouters);
+	}
+}
+
+static void ipv6_mc_leave_localaddr(struct inet6_dev *idev)
+{
+	__ipv6_dev_mc_dec(idev, &in6addr_interfacelocal_allnodes);
+	__ipv6_dev_mc_dec(idev, &in6addr_linklocal_allnodes);
+
+	if (idev->cnf.forwarding) {
+		__ipv6_dev_mc_dec(idev, &in6addr_interfacelocal_allrouters);
+		__ipv6_dev_mc_dec(idev, &in6addr_linklocal_allrouters);
+		__ipv6_dev_mc_dec(idev, &in6addr_sitelocal_allrouters);
+	}
+}
+
 void ipv6_mc_down(struct inet6_dev *idev)
 {
 	struct ifmcaddr6 *i;
 
 	/* Withdraw multicast list */
+	ipv6_mc_leave_localaddr(idev);
 
 	read_lock_bh(&idev->lock);
 
@@ -2564,7 +2597,7 @@ void ipv6_mc_up(struct inet6_dev *idev)
 {
 	struct ifmcaddr6 *i;
 
-	/* Install multicast list, except for all-nodes (already installed) */
+	ipv6_mc_join_localaddr(idev);
 
 	read_lock_bh(&idev->lock);
 	ipv6_mc_reset(idev);
@@ -2603,16 +2636,6 @@ void ipv6_mc_destroy_dev(struct inet6_dev *idev)
 	ipv6_mc_down(idev);
 	mld_clear_delrec(idev);
 
-	/* Delete all-nodes address. */
-	/* We cannot call ipv6_dev_mc_dec() directly, our caller in
-	 * addrconf.c has NULL'd out dev->ip6_ptr so in6_dev_get() will
-	 * fail.
-	 */
-	__ipv6_dev_mc_dec(idev, &in6addr_linklocal_allnodes);
-
-	if (idev->cnf.forwarding)
-		__ipv6_dev_mc_dec(idev, &in6addr_linklocal_allrouters);
-
 	write_lock_bh(&idev->lock);
 	while ((i = idev->mc_list) != NULL) {
 		idev->mc_list = i->next;
-- 
2.19.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ