diff options
author | Eric Dumazet <eric.dumazet@gmail.com> | 2013-06-28 05:37:42 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-07-28 19:29:44 -0400 |
commit | ac294f13d331cb3e315fd922ae505619f853818b (patch) | |
tree | 16a680f780feabd34c3222ba8d212f4f5b036d02 | |
parent | ce08aa04215ea3309c47677f55d3b52d31d6a97a (diff) |
neighbour: fix a race in neigh_destroy()
[ Upstream commit c9ab4d85de222f3390c67aedc9c18a50e767531e ]
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 <joe.jin@oracle.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | net/core/neighbour.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/net/core/neighbour.c b/net/core/neighbour.c index 5c56b217b999..ce90b0264db5 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c | |||
@@ -231,7 +231,7 @@ static void neigh_flush_dev(struct neigh_table *tbl, struct net_device *dev) | |||
231 | we must kill timers etc. and move | 231 | we must kill timers etc. and move |
232 | it to safe state. | 232 | it to safe state. |
233 | */ | 233 | */ |
234 | skb_queue_purge(&n->arp_queue); | 234 | __skb_queue_purge(&n->arp_queue); |
235 | n->arp_queue_len_bytes = 0; | 235 | n->arp_queue_len_bytes = 0; |
236 | n->output = neigh_blackhole; | 236 | n->output = neigh_blackhole; |
237 | if (n->nud_state & NUD_VALID) | 237 | if (n->nud_state & NUD_VALID) |
@@ -286,7 +286,7 @@ static struct neighbour *neigh_alloc(struct neigh_table *tbl, struct net_device | |||
286 | if (!n) | 286 | if (!n) |
287 | goto out_entries; | 287 | goto out_entries; |
288 | 288 | ||
289 | skb_queue_head_init(&n->arp_queue); | 289 | __skb_queue_head_init(&n->arp_queue); |
290 | rwlock_init(&n->lock); | 290 | rwlock_init(&n->lock); |
291 | seqlock_init(&n->ha_lock); | 291 | seqlock_init(&n->ha_lock); |
292 | n->updated = n->used = now; | 292 | n->updated = n->used = now; |
@@ -708,7 +708,9 @@ void neigh_destroy(struct neighbour *neigh) | |||
708 | if (neigh_del_timer(neigh)) | 708 | if (neigh_del_timer(neigh)) |
709 | pr_warn("Impossible event\n"); | 709 | pr_warn("Impossible event\n"); |
710 | 710 | ||
711 | skb_queue_purge(&neigh->arp_queue); | 711 | write_lock_bh(&neigh->lock); |
712 | __skb_queue_purge(&neigh->arp_queue); | ||
713 | write_unlock_bh(&neigh->lock); | ||
712 | neigh->arp_queue_len_bytes = 0; | 714 | neigh->arp_queue_len_bytes = 0; |
713 | 715 | ||
714 | if (dev->netdev_ops->ndo_neigh_destroy) | 716 | if (dev->netdev_ops->ndo_neigh_destroy) |
@@ -858,7 +860,7 @@ static void neigh_invalidate(struct neighbour *neigh) | |||
858 | neigh->ops->error_report(neigh, skb); | 860 | neigh->ops->error_report(neigh, skb); |
859 | write_lock(&neigh->lock); | 861 | write_lock(&neigh->lock); |
860 | } | 862 | } |
861 | skb_queue_purge(&neigh->arp_queue); | 863 | __skb_queue_purge(&neigh->arp_queue); |
862 | neigh->arp_queue_len_bytes = 0; | 864 | neigh->arp_queue_len_bytes = 0; |
863 | } | 865 | } |
864 | 866 | ||
@@ -1210,7 +1212,7 @@ int neigh_update(struct neighbour *neigh, const u8 *lladdr, u8 new, | |||
1210 | 1212 | ||
1211 | write_lock_bh(&neigh->lock); | 1213 | write_lock_bh(&neigh->lock); |
1212 | } | 1214 | } |
1213 | skb_queue_purge(&neigh->arp_queue); | 1215 | __skb_queue_purge(&neigh->arp_queue); |
1214 | neigh->arp_queue_len_bytes = 0; | 1216 | neigh->arp_queue_len_bytes = 0; |
1215 | } | 1217 | } |
1216 | out: | 1218 | out: |