netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Patch net] ipv6: avoid unregistering inet6_dev for loopback
@ 2017-06-21 21:34 Cong Wang
  2017-06-22  3:07 ` David Ahern
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Cong Wang @ 2017-06-21 21:34 UTC (permalink / raw)
  To: netdev; +Cc: Cong Wang, Andrey Konovalov, Daniel Lezcano, David Ahern

The per netns loopback_dev->ip6_ptr is unregistered and set to
NULL when its mtu is set to smaller than IPV6_MIN_MTU, this
leads to that we could set rt->rt6i_idev NULL after a
rt6_uncached_list_flush_dev() and then crash after another
call.

In this case we should just bring its inet6_dev down, rather
than unregistering it, at least prior to commit 176c39af29bc
("netns: fix addrconf_ifdown kernel panic") we always
override the case for loopback.

Thanks a lot to Andrey for finding a reliable reproducer.

Fixes: 176c39af29bc ("netns: fix addrconf_ifdown kernel panic")
Reported-by: Andrey Konovalov <andreyknvl@google.com>
Cc: Andrey Konovalov <andreyknvl@google.com>
Cc: Daniel Lezcano <dlezcano@fr.ibm.com>
Cc: David Ahern <dsahern@gmail.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
---
 net/ipv6/addrconf.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 686c923..1d2dbac 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -3369,6 +3369,7 @@ static int addrconf_notify(struct notifier_block *this, unsigned long event,
 	struct net_device *dev = netdev_notifier_info_to_dev(ptr);
 	struct netdev_notifier_changeupper_info *info;
 	struct inet6_dev *idev = __in6_dev_get(dev);
+	struct net *net = dev_net(dev);
 	int run_pending = 0;
 	int err;
 
@@ -3384,7 +3385,7 @@ static int addrconf_notify(struct notifier_block *this, unsigned long event,
 	case NETDEV_CHANGEMTU:
 		/* if MTU under IPV6_MIN_MTU stop IPv6 on this interface. */
 		if (dev->mtu < IPV6_MIN_MTU) {
-			addrconf_ifdown(dev, 1);
+			addrconf_ifdown(dev, dev != net->loopback_dev);
 			break;
 		}
 
@@ -3500,7 +3501,7 @@ static int addrconf_notify(struct notifier_block *this, unsigned long event,
 			 * IPV6_MIN_MTU stop IPv6 on this interface.
 			 */
 			if (dev->mtu < IPV6_MIN_MTU)
-				addrconf_ifdown(dev, 1);
+				addrconf_ifdown(dev, dev != net->loopback_dev);
 		}
 		break;
 
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Patch net] ipv6: avoid unregistering inet6_dev for loopback
  2017-06-21 21:34 [Patch net] ipv6: avoid unregistering inet6_dev for loopback Cong Wang
@ 2017-06-22  3:07 ` David Ahern
  2017-06-22 10:10 ` Andrey Konovalov
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: David Ahern @ 2017-06-22  3:07 UTC (permalink / raw)
  To: Cong Wang, netdev; +Cc: Andrey Konovalov, Daniel Lezcano

On 6/21/17 5:34 PM, Cong Wang wrote:
> diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
> index 686c923..1d2dbac 100644
> --- a/net/ipv6/addrconf.c
> +++ b/net/ipv6/addrconf.c
> @@ -3369,6 +3369,7 @@ static int addrconf_notify(struct notifier_block *this, unsigned long event,
>  	struct net_device *dev = netdev_notifier_info_to_dev(ptr);
>  	struct netdev_notifier_changeupper_info *info;
>  	struct inet6_dev *idev = __in6_dev_get(dev);
> +	struct net *net = dev_net(dev);

Given the number of NETDEV events and the fact that only 2 need net,
perhaps the dev_net(dev) should be inline ...

>  	int run_pending = 0;
>  	int err;
>  
> @@ -3384,7 +3385,7 @@ static int addrconf_notify(struct notifier_block *this, unsigned long event,
>  	case NETDEV_CHANGEMTU:
>  		/* if MTU under IPV6_MIN_MTU stop IPv6 on this interface. */
>  		if (dev->mtu < IPV6_MIN_MTU) {
> -			addrconf_ifdown(dev, 1);
> +			addrconf_ifdown(dev, dev != net->loopback_dev);

so:
			addrconf_ifdown(dev, dev != dev_net(dev)->loopback_dev);


>  			break;
>  		}
>  
> @@ -3500,7 +3501,7 @@ static int addrconf_notify(struct notifier_block *this, unsigned long event,
>  			 * IPV6_MIN_MTU stop IPv6 on this interface.
>  			 */
>  			if (dev->mtu < IPV6_MIN_MTU)
> -				addrconf_ifdown(dev, 1);
> +				addrconf_ifdown(dev, dev != net->loopback_dev);
>  		}
>  		break;
>  
> 

The overall idea of not destroying idev for loopback on a failure to set
MTU seems correct to me.

Acked-by: David Ahern <dsahern@gmail.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch net] ipv6: avoid unregistering inet6_dev for loopback
  2017-06-21 21:34 [Patch net] ipv6: avoid unregistering inet6_dev for loopback Cong Wang
  2017-06-22  3:07 ` David Ahern
@ 2017-06-22 10:10 ` Andrey Konovalov
  2017-06-22 17:22 ` David Miller
  2017-06-22 17:24 ` David Miller
  3 siblings, 0 replies; 5+ messages in thread
From: Andrey Konovalov @ 2017-06-22 10:10 UTC (permalink / raw)
  To: Cong Wang; +Cc: netdev, Daniel Lezcano, David Ahern

On Wed, Jun 21, 2017 at 11:34 PM, Cong Wang <xiyou.wangcong@gmail.com> wrote:
> The per netns loopback_dev->ip6_ptr is unregistered and set to
> NULL when its mtu is set to smaller than IPV6_MIN_MTU, this
> leads to that we could set rt->rt6i_idev NULL after a
> rt6_uncached_list_flush_dev() and then crash after another
> call.
>
> In this case we should just bring its inet6_dev down, rather
> than unregistering it, at least prior to commit 176c39af29bc
> ("netns: fix addrconf_ifdown kernel panic") we always
> override the case for loopback.
>
> Thanks a lot to Andrey for finding a reliable reproducer.

Thanks! This fixes the bug for me.

Tested-by: Andrey Konovalov <andreyknvl@google.com>

>
> Fixes: 176c39af29bc ("netns: fix addrconf_ifdown kernel panic")
> Reported-by: Andrey Konovalov <andreyknvl@google.com>
> Cc: Andrey Konovalov <andreyknvl@google.com>
> Cc: Daniel Lezcano <dlezcano@fr.ibm.com>
> Cc: David Ahern <dsahern@gmail.com>
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
> ---
>  net/ipv6/addrconf.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
> index 686c923..1d2dbac 100644
> --- a/net/ipv6/addrconf.c
> +++ b/net/ipv6/addrconf.c
> @@ -3369,6 +3369,7 @@ static int addrconf_notify(struct notifier_block *this, unsigned long event,
>         struct net_device *dev = netdev_notifier_info_to_dev(ptr);
>         struct netdev_notifier_changeupper_info *info;
>         struct inet6_dev *idev = __in6_dev_get(dev);
> +       struct net *net = dev_net(dev);
>         int run_pending = 0;
>         int err;
>
> @@ -3384,7 +3385,7 @@ static int addrconf_notify(struct notifier_block *this, unsigned long event,
>         case NETDEV_CHANGEMTU:
>                 /* if MTU under IPV6_MIN_MTU stop IPv6 on this interface. */
>                 if (dev->mtu < IPV6_MIN_MTU) {
> -                       addrconf_ifdown(dev, 1);
> +                       addrconf_ifdown(dev, dev != net->loopback_dev);
>                         break;
>                 }
>
> @@ -3500,7 +3501,7 @@ static int addrconf_notify(struct notifier_block *this, unsigned long event,
>                          * IPV6_MIN_MTU stop IPv6 on this interface.
>                          */
>                         if (dev->mtu < IPV6_MIN_MTU)
> -                               addrconf_ifdown(dev, 1);
> +                               addrconf_ifdown(dev, dev != net->loopback_dev);
>                 }
>                 break;
>
> --
> 2.5.5
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch net] ipv6: avoid unregistering inet6_dev for loopback
  2017-06-21 21:34 [Patch net] ipv6: avoid unregistering inet6_dev for loopback Cong Wang
  2017-06-22  3:07 ` David Ahern
  2017-06-22 10:10 ` Andrey Konovalov
@ 2017-06-22 17:22 ` David Miller
  2017-06-22 17:24 ` David Miller
  3 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2017-06-22 17:22 UTC (permalink / raw)
  To: xiyou.wangcong; +Cc: netdev, andreyknvl, dlezcano, dsahern

From: Cong Wang <xiyou.wangcong@gmail.com>
Date: Wed, 21 Jun 2017 14:34:58 -0700

> The per netns loopback_dev->ip6_ptr is unregistered and set to
> NULL when its mtu is set to smaller than IPV6_MIN_MTU, this
> leads to that we could set rt->rt6i_idev NULL after a
> rt6_uncached_list_flush_dev() and then crash after another
> call.
> 
> In this case we should just bring its inet6_dev down, rather
> than unregistering it, at least prior to commit 176c39af29bc
> ("netns: fix addrconf_ifdown kernel panic") we always
> override the case for loopback.
> 
> Thanks a lot to Andrey for finding a reliable reproducer.
> 
> Fixes: 176c39af29bc ("netns: fix addrconf_ifdown kernel panic")
> Reported-by: Andrey Konovalov <andreyknvl@google.com>
> Cc: Andrey Konovalov <andreyknvl@google.com>
> Cc: Daniel Lezcano <dlezcano@fr.ibm.com>
> Cc: David Ahern <dsahern@gmail.com>
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>

Applied and queued up for -stable.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch net] ipv6: avoid unregistering inet6_dev for loopback
  2017-06-21 21:34 [Patch net] ipv6: avoid unregistering inet6_dev for loopback Cong Wang
                   ` (2 preceding siblings ...)
  2017-06-22 17:22 ` David Miller
@ 2017-06-22 17:24 ` David Miller
  3 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2017-06-22 17:24 UTC (permalink / raw)
  To: xiyou.wangcong; +Cc: netdev, andreyknvl, dlezcano, dsahern

From: Cong Wang <xiyou.wangcong@gmail.com>
Date: Wed, 21 Jun 2017 14:34:58 -0700

> The per netns loopback_dev->ip6_ptr is unregistered and set to
> NULL when its mtu is set to smaller than IPV6_MIN_MTU, this
> leads to that we could set rt->rt6i_idev NULL after a
> rt6_uncached_list_flush_dev() and then crash after another
> call.
> 
> In this case we should just bring its inet6_dev down, rather
> than unregistering it, at least prior to commit 176c39af29bc
> ("netns: fix addrconf_ifdown kernel panic") we always
> override the case for loopback.
> 
> Thanks a lot to Andrey for finding a reliable reproducer.
> 
> Fixes: 176c39af29bc ("netns: fix addrconf_ifdown kernel panic")
> Reported-by: Andrey Konovalov <andreyknvl@google.com>
> Cc: Andrey Konovalov <andreyknvl@google.com>
> Cc: Daniel Lezcano <dlezcano@fr.ibm.com>
> Cc: David Ahern <dsahern@gmail.com>
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>

Applied, thanks.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-06-22 17:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-21 21:34 [Patch net] ipv6: avoid unregistering inet6_dev for loopback Cong Wang
2017-06-22  3:07 ` David Ahern
2017-06-22 10:10 ` Andrey Konovalov
2017-06-22 17:22 ` David Miller
2017-06-22 17:24 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).