aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulian Anastasov <ja@ssi.bg>2015-06-16 15:56:39 -0400
committerDavid S. Miller <davem@davemloft.net>2015-06-21 12:43:40 -0400
commit2c51a97f76d20ebf1f50fef908b986cb051fdff9 (patch)
treedb087ec45b63ad4d7b1530ac01d4bb37f5148b2f
parentf98f4514d07871da7a113dd9e3e330743fd70ae4 (diff)
neigh: do not modify unlinked entries
The lockless lookups can return entry that is unlinked. Sometimes they get reference before last neigh_cleanup_and_release, sometimes they do not need reference. Later, any modification attempts may result in the following problems: 1. entry is not destroyed immediately because neigh_update can start the timer for dead entry, eg. on change to NUD_REACHABLE state. As result, entry lives for some time but is invisible and out of control. 2. __neigh_event_send can run in parallel with neigh_destroy while refcnt=0 but if timer is started and expired refcnt can reach 0 for second time leading to second neigh_destroy and possible crash. Thanks to Eric Dumazet and Ying Xue for their work and analyze on the __neigh_event_send change. Fixes: 767e97e1e0db ("neigh: RCU conversion of struct neighbour") Fixes: a263b3093641 ("ipv4: Make neigh lookups directly in output packet path.") Fixes: 6fd6ce2056de ("ipv6: Do not depend on rt->n in ip6_finish_output2().") Cc: Eric Dumazet <eric.dumazet@gmail.com> Cc: Ying Xue <ying.xue@windriver.com> Signed-off-by: Julian Anastasov <ja@ssi.bg> Acked-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--net/core/neighbour.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/net/core/neighbour.c b/net/core/neighbour.c
index 3de654256028..2237c1b3cdd2 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -957,6 +957,8 @@ int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb)
957 rc = 0; 957 rc = 0;
958 if (neigh->nud_state & (NUD_CONNECTED | NUD_DELAY | NUD_PROBE)) 958 if (neigh->nud_state & (NUD_CONNECTED | NUD_DELAY | NUD_PROBE))
959 goto out_unlock_bh; 959 goto out_unlock_bh;
960 if (neigh->dead)
961 goto out_dead;
960 962
961 if (!(neigh->nud_state & (NUD_STALE | NUD_INCOMPLETE))) { 963 if (!(neigh->nud_state & (NUD_STALE | NUD_INCOMPLETE))) {
962 if (NEIGH_VAR(neigh->parms, MCAST_PROBES) + 964 if (NEIGH_VAR(neigh->parms, MCAST_PROBES) +
@@ -1013,6 +1015,13 @@ out_unlock_bh:
1013 write_unlock(&neigh->lock); 1015 write_unlock(&neigh->lock);
1014 local_bh_enable(); 1016 local_bh_enable();
1015 return rc; 1017 return rc;
1018
1019out_dead:
1020 if (neigh->nud_state & NUD_STALE)
1021 goto out_unlock_bh;
1022 write_unlock_bh(&neigh->lock);
1023 kfree_skb(skb);
1024 return 1;
1016} 1025}
1017EXPORT_SYMBOL(__neigh_event_send); 1026EXPORT_SYMBOL(__neigh_event_send);
1018 1027
@@ -1076,6 +1085,8 @@ int neigh_update(struct neighbour *neigh, const u8 *lladdr, u8 new,
1076 if (!(flags & NEIGH_UPDATE_F_ADMIN) && 1085 if (!(flags & NEIGH_UPDATE_F_ADMIN) &&
1077 (old & (NUD_NOARP | NUD_PERMANENT))) 1086 (old & (NUD_NOARP | NUD_PERMANENT)))
1078 goto out; 1087 goto out;
1088 if (neigh->dead)
1089 goto out;
1079 1090
1080 if (!(new & NUD_VALID)) { 1091 if (!(new & NUD_VALID)) {
1081 neigh_del_timer(neigh); 1092 neigh_del_timer(neigh);
@@ -1225,6 +1236,8 @@ EXPORT_SYMBOL(neigh_update);
1225 */ 1236 */
1226void __neigh_set_probe_once(struct neighbour *neigh) 1237void __neigh_set_probe_once(struct neighbour *neigh)
1227{ 1238{
1239 if (neigh->dead)
1240 return;
1228 neigh->updated = jiffies; 1241 neigh->updated = jiffies;
1229 if (!(neigh->nud_state & NUD_FAILED)) 1242 if (!(neigh->nud_state & NUD_FAILED))
1230 return; 1243 return;