Skip to content

Commit 2c51a97

Browse files
Julian Anastasovdavem330
authored andcommitted
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: 767e97e ("neigh: RCU conversion of struct neighbour") Fixes: a263b30 ("ipv4: Make neigh lookups directly in output packet path.") Fixes: 6fd6ce2 ("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>
1 parent f98f451 commit 2c51a97

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

net/core/neighbour.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,8 @@ int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb)
957957
rc = 0;
958958
if (neigh->nud_state & (NUD_CONNECTED | NUD_DELAY | NUD_PROBE))
959959
goto out_unlock_bh;
960+
if (neigh->dead)
961+
goto out_dead;
960962

961963
if (!(neigh->nud_state & (NUD_STALE | NUD_INCOMPLETE))) {
962964
if (NEIGH_VAR(neigh->parms, MCAST_PROBES) +
@@ -1013,6 +1015,13 @@ int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb)
10131015
write_unlock(&neigh->lock);
10141016
local_bh_enable();
10151017
return rc;
1018+
1019+
out_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;
10161025
}
10171026
EXPORT_SYMBOL(__neigh_event_send);
10181027

@@ -1076,6 +1085,8 @@ int neigh_update(struct neighbour *neigh, const u8 *lladdr, u8 new,
10761085
if (!(flags & NEIGH_UPDATE_F_ADMIN) &&
10771086
(old & (NUD_NOARP | NUD_PERMANENT)))
10781087
goto out;
1088+
if (neigh->dead)
1089+
goto out;
10791090

10801091
if (!(new & NUD_VALID)) {
10811092
neigh_del_timer(neigh);
@@ -1225,6 +1236,8 @@ EXPORT_SYMBOL(neigh_update);
12251236
*/
12261237
void __neigh_set_probe_once(struct neighbour *neigh)
12271238
{
1239+
if (neigh->dead)
1240+
return;
12281241
neigh->updated = jiffies;
12291242
if (!(neigh->nud_state & NUD_FAILED))
12301243
return;

0 commit comments

Comments
 (0)