Skip to content

Commit 6ddc108

Browse files
Eric Dumazetkamalmostafa
authored andcommitted
neighbour: fix a race in neigh_destroy()
[ Upstream commit c9ab4d8 ] There is a race in neighbour code, because neigh_destroy() uses skb_queue_purge(&neigh->arp_queue) without holding neighbour lock, while other parts of the code assume neighbour rwlock is what protects arp_queue Convert all skb_queue_purge() calls to the __skb_queue_purge() variant Use __skb_queue_head_init() instead of skb_queue_head_init() to make clear we do not use arp_queue.lock And hold neigh->lock in neigh_destroy() to close the race. Reported-by: Joe Jin <[email protected]> Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]> Signed-off-by: Kamal Mostafa <[email protected]>
1 parent 1f5ec63 commit 6ddc108

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

net/core/neighbour.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ static void neigh_flush_dev(struct neigh_table *tbl, struct net_device *dev)
239239
we must kill timers etc. and move
240240
it to safe state.
241241
*/
242-
skb_queue_purge(&n->arp_queue);
242+
__skb_queue_purge(&n->arp_queue);
243243
n->arp_queue_len_bytes = 0;
244244
n->output = neigh_blackhole;
245245
if (n->nud_state & NUD_VALID)
@@ -302,7 +302,7 @@ static struct neighbour *neigh_alloc(struct neigh_table *tbl, struct net_device
302302
if (!n)
303303
goto out_entries;
304304

305-
skb_queue_head_init(&n->arp_queue);
305+
__skb_queue_head_init(&n->arp_queue);
306306
rwlock_init(&n->lock);
307307
seqlock_init(&n->ha_lock);
308308
n->updated = n->used = now;
@@ -724,7 +724,9 @@ void neigh_destroy(struct neighbour *neigh)
724724
if (neigh_del_timer(neigh))
725725
pr_warn("Impossible event\n");
726726

727-
skb_queue_purge(&neigh->arp_queue);
727+
write_lock_bh(&neigh->lock);
728+
__skb_queue_purge(&neigh->arp_queue);
729+
write_unlock_bh(&neigh->lock);
728730
neigh->arp_queue_len_bytes = 0;
729731

730732
if (dev->netdev_ops->ndo_neigh_destroy)
@@ -870,7 +872,7 @@ static void neigh_invalidate(struct neighbour *neigh)
870872
neigh->ops->error_report(neigh, skb);
871873
write_lock(&neigh->lock);
872874
}
873-
skb_queue_purge(&neigh->arp_queue);
875+
__skb_queue_purge(&neigh->arp_queue);
874876
neigh->arp_queue_len_bytes = 0;
875877
}
876878

@@ -1222,7 +1224,7 @@ int neigh_update(struct neighbour *neigh, const u8 *lladdr, u8 new,
12221224

12231225
write_lock_bh(&neigh->lock);
12241226
}
1225-
skb_queue_purge(&neigh->arp_queue);
1227+
__skb_queue_purge(&neigh->arp_queue);
12261228
neigh->arp_queue_len_bytes = 0;
12271229
}
12281230
out:

0 commit comments

Comments
 (0)