net: add a recursion limit in xmit path
As tunnel devices are going to be lockless, we need to make sure a misconfigured machine wont enter an infinite loop. Add a percpu variable, and limit to three the number of stacked xmits. Reported-by: Jesse Gross <jesse@nicira.com> Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
committed by
David S. Miller
parent
ab79ad14a2
commit
745e20f1b6
@@ -2177,6 +2177,9 @@ static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q,
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static DEFINE_PER_CPU(int, xmit_recursion);
|
||||||
|
#define RECURSION_LIMIT 3
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* dev_queue_xmit - transmit a buffer
|
* dev_queue_xmit - transmit a buffer
|
||||||
* @skb: buffer to transmit
|
* @skb: buffer to transmit
|
||||||
@@ -2242,10 +2245,15 @@ int dev_queue_xmit(struct sk_buff *skb)
|
|||||||
|
|
||||||
if (txq->xmit_lock_owner != cpu) {
|
if (txq->xmit_lock_owner != cpu) {
|
||||||
|
|
||||||
|
if (__this_cpu_read(xmit_recursion) > RECURSION_LIMIT)
|
||||||
|
goto recursion_alert;
|
||||||
|
|
||||||
HARD_TX_LOCK(dev, txq, cpu);
|
HARD_TX_LOCK(dev, txq, cpu);
|
||||||
|
|
||||||
if (!netif_tx_queue_stopped(txq)) {
|
if (!netif_tx_queue_stopped(txq)) {
|
||||||
|
__this_cpu_inc(xmit_recursion);
|
||||||
rc = dev_hard_start_xmit(skb, dev, txq);
|
rc = dev_hard_start_xmit(skb, dev, txq);
|
||||||
|
__this_cpu_dec(xmit_recursion);
|
||||||
if (dev_xmit_complete(rc)) {
|
if (dev_xmit_complete(rc)) {
|
||||||
HARD_TX_UNLOCK(dev, txq);
|
HARD_TX_UNLOCK(dev, txq);
|
||||||
goto out;
|
goto out;
|
||||||
@@ -2257,7 +2265,9 @@ int dev_queue_xmit(struct sk_buff *skb)
|
|||||||
"queue packet!\n", dev->name);
|
"queue packet!\n", dev->name);
|
||||||
} else {
|
} else {
|
||||||
/* Recursion is detected! It is possible,
|
/* Recursion is detected! It is possible,
|
||||||
* unfortunately */
|
* unfortunately
|
||||||
|
*/
|
||||||
|
recursion_alert:
|
||||||
if (net_ratelimit())
|
if (net_ratelimit())
|
||||||
printk(KERN_CRIT "Dead loop on virtual device "
|
printk(KERN_CRIT "Dead loop on virtual device "
|
||||||
"%s, fix it urgently!\n", dev->name);
|
"%s, fix it urgently!\n", dev->name);
|
||||||
|
Reference in New Issue
Block a user