Skip to content

Commit d5485d9

Browse files
Yang Yingliangdavem330
authored andcommitted
net: neigh: don't call kfree_skb() under spin_lock_irqsave()
It is not allowed to call kfree_skb() from hardware interrupt context or with interrupts being disabled. So add all skb to a tmp list, then free them after spin_unlock_irqrestore() at once. Fixes: 66ba215 ("neigh: fix possible DoS due to net iface start/stop loop") Suggested-by: Denis V. Lunev <[email protected]> Signed-off-by: Yang Yingliang <[email protected]> Reviewed-by: Nikolay Aleksandrov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 550e9a4 commit d5485d9

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

net/core/neighbour.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,14 +309,17 @@ static int neigh_del_timer(struct neighbour *n)
309309

310310
static void pneigh_queue_purge(struct sk_buff_head *list, struct net *net)
311311
{
312+
struct sk_buff_head tmp;
312313
unsigned long flags;
313314
struct sk_buff *skb;
314315

316+
skb_queue_head_init(&tmp);
315317
spin_lock_irqsave(&list->lock, flags);
316318
skb = skb_peek(list);
317319
while (skb != NULL) {
318320
struct sk_buff *skb_next = skb_peek_next(skb, list);
319321
struct net_device *dev = skb->dev;
322+
320323
if (net == NULL || net_eq(dev_net(dev), net)) {
321324
struct in_device *in_dev;
322325

@@ -326,13 +329,16 @@ static void pneigh_queue_purge(struct sk_buff_head *list, struct net *net)
326329
in_dev->arp_parms->qlen--;
327330
rcu_read_unlock();
328331
__skb_unlink(skb, list);
329-
330-
dev_put(dev);
331-
kfree_skb(skb);
332+
__skb_queue_tail(&tmp, skb);
332333
}
333334
skb = skb_next;
334335
}
335336
spin_unlock_irqrestore(&list->lock, flags);
337+
338+
while ((skb = __skb_dequeue(&tmp))) {
339+
dev_put(skb->dev);
340+
kfree_skb(skb);
341+
}
336342
}
337343

338344
static void neigh_flush_dev(struct neigh_table *tbl, struct net_device *dev,

0 commit comments

Comments
 (0)