From: Jiri Bohac <jbohac@suse•cz>
To: netdev@vger•kernel.org
Cc: Hideaki YOSHIFUJI <yoshfuji@linux-ipv6•org>,
David Miller <davem@davemloft•net>
Subject: IPv6: race condition in __ipv6_ifa_notify() and dst_free() ?
Date: Tue, 20 Apr 2010 19:44:01 +0200 [thread overview]
Message-ID: <20100420174401.GB1334@midget.suse.cz> (raw)
Hi,
I found what I believe is a race condition in __ipv6_ifa_notify(), in the call
to dst_free().
__ipv6_ifa_notify() contains:
case RTM_DELADDR:
if (ifp->idev->cnf.forwarding)
addrconf_leave_anycast(ifp);
addrconf_leave_solict(ifp->idev, &ifp->addr);
dst_hold(&ifp->rt->u.dst);
if (ip6_del_rt(ifp->rt))
dst_free(&ifp->rt->u.dst);
break;
AFAICT, ip6_del_rt() will call dst_free() itself if it finds and actually
deletes the route:
ip6_del_rt() -> __ip6_del_rt() -> fib6_del() -> fib6_del_route() ->
-> rt6_release() -> dst_free()
If it fails (like when it races with another invocation of ip6_del_rt()), it
will return nonzero and this will cause the above code to call dst_free() on its own.
dst_free() has no protection against concurrent invocation and if
two invocations make it through the "if (dst->obsolete > 1)"
check before one of them calls __dst_free(), the same dst_entry
may end up either:
1) dst_destroy()ed and put on the dst_garbage.list, or
2) put on the dst_garbage.list twice
both resulting in trouble once the GC is run.
One possible code path leading to two invocations of __ipv6_ifa_notify() seems
to be when two bonding slaves receive a NS/NA with the bonds IPv6 address when
the bonding master is in the DAD phase with a tentative address:
netif_receive_skb() gets invoked on two CPUs and sets skb->dev to the bonding master ...
... ip6_mc_input() -> ip6_input_finish() -> icmpv6_rcv() -> ndisc_rcv() ->
-> ndisc_recv_ns() -> addrconf_dad_failure() -> ipv6_del_addr() -> ipv6_ifa_notify() ->
-> __ipv6_ifa_notify
What is the reason __ipv6_ifa_notify() calls dst_free() when
ip6_del_rt() fails? I don't see a way ip6_del_rt() could fail
with the dst still needing to be freed.
I am just testing whether the following will help:
--- a/net/ipv6/addrconf.c 2010-04-17 00:12:32.000000000 +0200
+++ b/net/ipv6/addrconf.c 2010-04-20 19:07:35.000000000 +0200
@@ -3974,8 +3974,7 @@ static void __ipv6_ifa_notify(int event,
addrconf_leave_anycast(ifp);
addrconf_leave_solict(ifp->idev, &ifp->addr);
dst_hold(&ifp->rt->u.dst);
- if (ip6_del_rt(ifp->rt))
- dst_free(&ifp->rt->u.dst);
+ ip6_del_rt(ifp->rt);
break;
}
}
Thanks,
--
Jiri Bohac <jbohac@suse•cz>
SUSE Labs, SUSE CZ
next reply other threads:[~2010-04-20 17:44 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-20 17:44 Jiri Bohac [this message]
2010-04-20 17:57 ` IPv6: race condition in __ipv6_ifa_notify() and dst_free() ? Eric Dumazet
2010-04-20 20:49 ` Jiri Bohac
2010-04-20 20:57 ` Eric Dumazet
2010-04-20 21:16 ` Stephen Hemminger
2010-04-20 21:35 ` Jiri Bohac
2010-04-21 21:34 ` Jiri Bohac
2010-04-22 2:32 ` Herbert Xu
2010-04-22 7:43 ` David Miller
2010-04-22 14:25 ` Herbert Xu
2010-04-22 15:49 ` Jiri Bohac
2010-04-22 16:17 ` Stephen Hemminger
2010-04-23 1:54 ` David Miller
2010-04-23 2:10 ` Herbert Xu
2010-04-23 15:05 ` Herbert Xu
2010-05-18 11:02 ` [0/4] Fix addrconf race conditions Herbert Xu
2010-05-18 11:04 ` [PATCH 1/4] ipv6: Replace inet6_ifaddr->dead with state Herbert Xu
2010-05-18 17:23 ` Stephen Hemminger
2010-05-18 22:27 ` David Miller
2010-05-18 11:04 ` [PATCH 2/4] ipv6: Use state_lock to protect ifa state Herbert Xu
2010-05-18 11:04 ` [PATCH 3/4] ipv6: Use POSTDAD state Herbert Xu
2010-05-18 11:04 ` [PATCH 4/4] ipv6: Never schedule DAD timer on dead address Herbert Xu
2010-05-18 17:25 ` [0/4] Fix addrconf race conditions Stephen Hemminger
2010-05-18 22:27 ` David Miller
2010-05-18 22:35 ` Herbert Xu
2010-04-27 15:50 ` IPv6: race condition in __ipv6_ifa_notify() and dst_free() ? Jiri Bohac
2010-04-27 15:55 ` Herbert Xu
2010-05-09 6:48 ` Herbert Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100420174401.GB1334@midget.suse.cz \
--to=jbohac@suse$(echo .)cz \
--cc=davem@davemloft$(echo .)net \
--cc=netdev@vger$(echo .)kernel.org \
--cc=yoshfuji@linux-ipv6$(echo .)org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox