b312fc
centosplus patch [bug#12711]
b312fc
b312fc
commit 751eb6b6042a596b0080967c1a529a9fe98dac1d
b312fc
Author: Wei Yongjun <weiyongjun1@huawei.com>
b312fc
Date:   Mon Sep 5 16:06:31 2016 +0800
b312fc
b312fc
    ipv6: addrconf: fix dev refcont leak when DAD failed
b312fc
                                                        
b312fc
    In general, when DAD detected IPv6 duplicate address, ifp->state
b312fc
    will be set to INET6_IFADDR_STATE_ERRDAD and DAD is stopped by a
b312fc
    delayed work, the call tree should be like this:
b312fc
                                                                    
b312fc
    ndisc_recv_ns                                                   
b312fc
      -> addrconf_dad_failure        <- missing ifp put             
b312fc
         -> addrconf_mod_dad_work                                   
b312fc
           -> schedule addrconf_dad_work()                          
b312fc
             -> addrconf_dad_stop()  <- missing ifp hold before call it
b312fc
                                                                       
b312fc
    addrconf_dad_failure() called with ifp refcont holding but not put.
b312fc
    addrconf_dad_work() call addrconf_dad_stop() without extra holding 
b312fc
    refcount. This will not cause any issue normally.                  
b312fc
                                                                       
b312fc
    But the race between addrconf_dad_failure() and addrconf_dad_work()
b312fc
    may cause ifp refcount leak and netdevice can not be unregister,   
b312fc
    dmesg show the following messages:                                 
b312fc
                                                                       
b312fc
    IPv6: eth0: IPv6 duplicate address fe80::XX:XXXX:XXXX:XX detected!
b312fc
    ...
b312fc
    unregister_netdevice: waiting for eth0 to become free. Usage count = 1
b312fc
b312fc
    Cc: stable@vger.kernel.org
b312fc
    Fixes: c15b1ccadb32 ("ipv6: move DAD and addrconf_verify processing
b312fc
    to workqueue")
b312fc
    Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
b312fc
    Signed-off-by: David S. Miller <davem@davemloft.net>
b312fc
b312fc
    Submitted-by: alfredo
b312fc
    Applied-by: Akemi Yagi <toracat@centos.org>
b312fc
b312fc
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
b312fc
index b7d5ce6..dc65579 100644
b312fc
--- a/net/ipv6/addrconf.c
b312fc
+++ b/net/ipv6/addrconf.c
b312fc
@@ -1656,6 +1656,7 @@ void addrconf_dad_failure(struct inet6_ifaddr *ifp)
b312fc
 	spin_unlock_bh(&ifp->state_lock);
b312fc
 
b312fc
 	addrconf_mod_dad_work(ifp, 0);
b312fc
+    in6_ifa_put(ifp);
b312fc
 }
b312fc
 
b312fc
 /* Join to solicited addr multicast group.
b312fc
@@ -3300,6 +3301,7 @@ static void addrconf_dad_work(struct work_struct *w)
b312fc
 		addrconf_dad_begin(ifp);
b312fc
 		goto out;
b312fc
 	} else if (action == DAD_ABORT) {
b312fc
+        in6_ifa_hold(ifp);
b312fc
 		addrconf_dad_stop(ifp, 1);
b312fc
 		goto out;
b312fc
 	}