Re: [PATCH net] ipv6: addrconf: increment ifp refcount before ipv6_del_addr()
From: David Ahern <hidden>
Date: 2017-10-31 16:09:41
On 10/30/17 11:47 PM, Eric Dumazet wrote:
From: Eric Dumazet <edumazet@google.com> In the (unlikely) event fixup_permanent_addr() returns a failure, addrconf_permanent_addr() calls ipv6_del_addr() without the mandatory call to in6_ifa_hold(), leading to a refcount error, spotted by syzkaller : WARNING: CPU: 1 PID: 3142 at lib/refcount.c:227 refcount_dec+0x4c/0x50 lib/refcount.c:227 Kernel panic - not syncing: panic_on_warn set ...
...
quoted hunk ↗ jump to hunk
Fixes: f1705ec197e7 ("net: ipv6: Make address flushing on ifdown optional") Signed-off-by: Eric Dumazet <edumazet@google.com> Cc: David Ahern <redacted> --- net/ipv6/addrconf.c | 1 + 1 file changed, 1 insertion(+)diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 4a96ebbf8eda5f59a6ff88e836d666a404d2bf0d..8a1c846d3df949a4638589f187120db22a3525ba 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c@@ -3335,6 +3335,7 @@ static void addrconf_permanent_addr(struct net_device *dev) if ((ifp->flags & IFA_F_PERMANENT) && fixup_permanent_addr(idev, ifp) < 0) { write_unlock_bh(&idev->lock); + in6_ifa_hold(ifp); ipv6_del_addr(ifp); write_lock_bh(&idev->lock);
Interestingly, I put the failure sequence into a loop and hit the above path closing in on 1 million times and I am not seeing a memory leak with our without this patch. The above does fix the refcnt and based on other call sites for ipv6_del_addr is the right thing to do, so... Acked-by: David Ahern <redacted>