Commit af6739a5 authored by Eric Dumazet's avatar Eric Dumazet Committed by Willy Tarreau

neighbour: fix a race in neigh_destroy()

[ Upstream commit c9ab4d85 ]

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: default avatarJoe Jin <joe.jin@oracle.com>
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarWilly Tarreau <w@1wt.eu>
parent 6597b256
...@@ -222,7 +222,7 @@ static void neigh_flush_dev(struct neigh_table *tbl, struct net_device *dev) ...@@ -222,7 +222,7 @@ static void neigh_flush_dev(struct neigh_table *tbl, struct net_device *dev)
we must kill timers etc. and move we must kill timers etc. and move
it to safe state. it to safe state.
*/ */
skb_queue_purge(&n->arp_queue); __skb_queue_purge(&n->arp_queue);
n->output = neigh_blackhole; n->output = neigh_blackhole;
if (n->nud_state & NUD_VALID) if (n->nud_state & NUD_VALID)
n->nud_state = NUD_NOARP; n->nud_state = NUD_NOARP;
...@@ -276,7 +276,7 @@ static struct neighbour *neigh_alloc(struct neigh_table *tbl) ...@@ -276,7 +276,7 @@ static struct neighbour *neigh_alloc(struct neigh_table *tbl)
if (!n) if (!n)
goto out_entries; goto out_entries;
skb_queue_head_init(&n->arp_queue); __skb_queue_head_init(&n->arp_queue);
rwlock_init(&n->lock); rwlock_init(&n->lock);
n->updated = n->used = now; n->updated = n->used = now;
n->nud_state = NUD_NONE; n->nud_state = NUD_NONE;
...@@ -646,7 +646,9 @@ void neigh_destroy(struct neighbour *neigh) ...@@ -646,7 +646,9 @@ void neigh_destroy(struct neighbour *neigh)
kfree(hh); kfree(hh);
} }
skb_queue_purge(&neigh->arp_queue); write_lock_bh(&neigh->lock);
__skb_queue_purge(&neigh->arp_queue);
write_unlock_bh(&neigh->lock);
dev_put(neigh->dev); dev_put(neigh->dev);
neigh_parms_put(neigh->parms); neigh_parms_put(neigh->parms);
...@@ -789,7 +791,7 @@ static void neigh_invalidate(struct neighbour *neigh) ...@@ -789,7 +791,7 @@ static void neigh_invalidate(struct neighbour *neigh)
neigh->ops->error_report(neigh, skb); neigh->ops->error_report(neigh, skb);
write_lock(&neigh->lock); write_lock(&neigh->lock);
} }
skb_queue_purge(&neigh->arp_queue); __skb_queue_purge(&neigh->arp_queue);
} }
/* Called when a timer expires for a neighbour entry. */ /* Called when a timer expires for a neighbour entry. */
...@@ -1105,7 +1107,7 @@ int neigh_update(struct neighbour *neigh, const u8 *lladdr, u8 new, ...@@ -1105,7 +1107,7 @@ int neigh_update(struct neighbour *neigh, const u8 *lladdr, u8 new,
n1->output(skb); n1->output(skb);
write_lock_bh(&neigh->lock); write_lock_bh(&neigh->lock);
} }
skb_queue_purge(&neigh->arp_queue); __skb_queue_purge(&neigh->arp_queue);
} }
out: out:
if (update_isrouter) { if (update_isrouter) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment