On Tue, Apr 25, 2017 at 09:17:29AM -0700, David Ahern wrote: [...] > > All of those faults are fixed by regenerating the host route if the > existing one has been moved to the gc list, something that can be > determined by checking if the rt6i_ref counter is 0. Acked-by: Martin KaFai Lau <ka...@fb.com>
> > Fixes: f1705ec197e7 ("net: ipv6: Make address flushing on ifdown optional") > Reported-by: Dmitry Vyukov <dvyu...@google.com> > Reported-by: Andrey Konovalov <andreyk...@google.com> > Signed-off-by: David Ahern <d...@cumulusnetworks.com> > --- > v4 > - move 'prev = ifp->rt;' under spinlock as requested by Eric > > v3 > - removed 'if (prev)' and just call ip6_rt_put; added comment about spinlock > > v2 > - change ifp->rt under spinlock vs cmpxchg > - add comment about rt6i_ref == 0 > > net/ipv6/addrconf.c | 14 ++++++++++++-- > 1 file changed, 12 insertions(+), 2 deletions(-) > > diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c > index 80ce478c4851..0ea96c4d334d 100644 > --- a/net/ipv6/addrconf.c > +++ b/net/ipv6/addrconf.c > @@ -3271,14 +3271,24 @@ static void addrconf_gre_config(struct net_device > *dev) > static int fixup_permanent_addr(struct inet6_dev *idev, > struct inet6_ifaddr *ifp) > { > - if (!ifp->rt) { > - struct rt6_info *rt; > + /* rt6i_ref == 0 means the host route was removed from the > + * FIB, for example, if 'lo' device is taken down. In that > + * case regenerate the host route. > + */ > + if (!ifp->rt || !atomic_read(&ifp->rt->rt6i_ref)) { > + struct rt6_info *rt, *prev; > > rt = addrconf_dst_alloc(idev, &ifp->addr, false); > if (unlikely(IS_ERR(rt))) > return PTR_ERR(rt); > > + /* ifp->rt can be accessed outside of rtnl */ > + spin_lock(&ifp->lock); > + prev = ifp->rt; > ifp->rt = rt; > + spin_unlock(&ifp->lock); > + > + ip6_rt_put(prev); > } > > if (!(ifp->flags & IFA_F_NOPREFIXROUTE)) { > -- > 2.1.4 >