Skip to content

Commit eefb45e

Browse files
Chinmay Agarwaldavem330
authored andcommitted
neighbour: Prevent Race condition in neighbour subsytem
Following Race Condition was detected: <CPU A, t0>: Executing: __netif_receive_skb() ->__netif_receive_skb_core() -> arp_rcv() -> arp_process().arp_process() calls __neigh_lookup() which takes a reference on neighbour entry 'n'. Moves further along, arp_process() and calls neigh_update()-> __neigh_update(). Neighbour entry is unlocked just before a call to neigh_update_gc_list. This unlocking paves way for another thread that may take a reference on the same and mark it dead and remove it from gc_list. <CPU B, t1> - neigh_flush_dev() is under execution and calls neigh_mark_dead(n) marking the neighbour entry 'n' as dead. Also n will be removed from gc_list. Moves further along neigh_flush_dev() and calls neigh_cleanup_and_release(n), but since reference count increased in t1, 'n' couldn't be destroyed. <CPU A, t3>- Code hits neigh_update_gc_list, with neighbour entry set as dead. <CPU A, t4> - arp_process() finally calls neigh_release(n), destroying the neighbour entry and we have a destroyed ntry still part of gc_list. Fixes: eb4e8fa("neighbour: Prevent a dead entry from updating gc_list") Signed-off-by: Chinmay Agarwal <chinagar@codeaurora.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 83d686a commit eefb45e

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

net/core/neighbour.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ static void neigh_update_gc_list(struct neighbour *n)
131131
write_lock_bh(&n->tbl->lock);
132132
write_lock(&n->lock);
133133

134+
if (n->dead)
135+
goto out;
136+
134137
/* remove from the gc list if new state is permanent or if neighbor
135138
* is externally learned; otherwise entry should be on the gc list
136139
*/
@@ -147,6 +150,7 @@ static void neigh_update_gc_list(struct neighbour *n)
147150
atomic_inc(&n->tbl->gc_entries);
148151
}
149152

153+
out:
150154
write_unlock(&n->lock);
151155
write_unlock_bh(&n->tbl->lock);
152156
}

0 commit comments

Comments
 (0)