net: Validate frames going through the direct_xmit path
Subsystems (3)
PATCH 1/1 net: Validate frames going through the direct_xmit path
In commit 50cbe9ab5f8d92d2d4a327b56e96559d8f63a1fa "net: Validate xmit SKBs right when we pull them out of the qdisc" the validation code was moved out of dev_hard_start_xmit and into dequeue_skb. However this overlooked the fact that we do not always enqueue the skb onto a qdisc.
As a result I was seeing issues trying to connect to a vhost_net interface after this patch was applied. To resolve the issue I have added a call to validate_xmit_skb in sched_direct_xmit and this seems to have resolved the issue by restoring the validation to this xmit path.
--- net/sched/sch_generic.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
net/sched/sch_generic.c +7 -2
@@ -128,8 +128,13 @@ int sch_direct_xmit(struct sk_buff *skb, struct Qdisc *q,spin_unlock (root_lock);HARD_TX_LOCK (dev, txq,smp_processor_id ()); -if (!netif_xmit_frozen_or_stopped (txq)) - skb =dev_hard_start_xmit (skb, dev, txq, &ret); +if (!netif_xmit_frozen_or_stopped (txq)) { + skb =validate_xmit_skb (skb, dev); +if (!skb) + ret =NETDEV_TX_OK ; +else + skb =dev_hard_start_xmit (skb, dev, txq, &ret); + }HARD_TX_UNLOCK (dev, txq);
Quoted 25 lines · Alexander Duyck
In commit
50cbe9ab5f8d92d2d4a327b56e96559d8f63a1fa"net: Validate xmit SKBs right when we pull them out of the qdisc" the validation code was moved out ofdev_hard_start_xmitand intodequeue_skb. However this overlooked the fact that we do not always enqueue the skb onto a qdisc.As a result I was seeing issues trying to connect to a
vhost_netinterface after this patch was applied. To resolve the issue I have added a call tovalidate_xmit_skbinsched_direct_xmitand this seems to have resolved the issue by restoring the validation to this xmit path.Signed-off-by Alexander Duyck <[email protected]>--- net/sched/sch_generic.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)net/sched/sch_generic.c +0
-2@@ -128,8 +128,13 @@ int sch_direct_xmit(struct sk_buff *skb, struct Qdisc *q,spin_unlock (root_lock);HARD_TX_LOCK (dev, txq,smp_processor_id ()); -if (!netif_xmit_frozen_or_stopped (txq)) - skb =dev_hard_start_xmit (skb, dev, txq, &ret);
net/sched/sch_generic.c int sch_direct_xmit(struct sk_buff *skb, struct Qdisc *q, · line 140
Quoted 10 lines
net/sched/sch_generic.c +7
-0+if (!netif_xmit_frozen_or_stopped (txq)) { + skb =validate_xmit_skb (skb, dev); +if (!skb) + ret =NETDEV_TX_OK ; +else + skb =dev_hard_start_xmit (skb, dev, txq, &ret); + }HARD_TX_UNLOCK (dev, txq);
This looks very weird.
Calling validate_xmit_skb() twice per packet is not needed in the case sch_direct_xmit() is called from qdisc_restart()
This will add bad branch prediction at very minimum.
This is a TCQ_F_CAN_BYPASS issue that should be fixed there.
Quoted 34 lines · Eric Dumazet
Quoted 33 lines · Alexander Duyck
In commit
50cbe9ab5f8d92d2d4a327b56e96559d8f63a1fa"net: Validate xmit SKBs right when we pull them out of the qdisc" the validation code was moved out ofdev_hard_start_xmitand intodequeue_skb. However this overlooked the fact that we do not always enqueue the skb onto a qdisc.As a result I was seeing issues trying to connect to a
vhost_netinterface after this patch was applied. To resolve the issue I have added a call tovalidate_xmit_skbinsched_direct_xmitand this seems to have resolved the issue by restoring the validation to this xmit path.Signed-off-by Alexander Duyck <[email protected]>--- net/sched/sch_generic.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)net/sched/sch_generic.c +7
-2@@ -128,8 +128,13 @@ int sch_direct_xmit(struct sk_buff *skb, struct Qdisc *q,spin_unlock (root_lock);HARD_TX_LOCK (dev, txq,smp_processor_id ()); -if (!netif_xmit_frozen_or_stopped (txq)) - skb =dev_hard_start_xmit (skb, dev, txq, &ret); +if (!netif_xmit_frozen_or_stopped (txq)) { + skb =validate_xmit_skb (skb, dev); +if (!skb) + ret =NETDEV_TX_OK ; +else + skb =dev_hard_start_xmit (skb, dev, txq, &ret); + }
Quoted 4 lines
net/sched/sch_generic.c int sch_direct_xmit(struct sk_buff *skb, struct Qdisc *q, · line 140
Quoted 2 lines
net/sched/sch_generic.c +0
-0HARD_TX_UNLOCK (dev, txq);This looks very weird.
It's ugly, I will admit it. It was a quick hack to fix the issue I had been seeing as it was in my way.
Quoted 2 lines
Calling
validate_xmit_skb()twice per packet is not needed in the casesch_direct_xmit()is called fromqdisc_restart()
My bad, I overlooked that sch_direct_xmit is called by qdisc_restart.
Quoted 3 lines
This will add bad branch prediction at very minimum.
This is a
TCQ_F_CAN_BYPASSissue that should be fixed there.
Actually it looks like there are several issues. One is the bypass problem which is the major issue. Another side effect of the original patch is that a bad frame will cause us to exit __qdisc_run prematurely even if other frames are still in the qdisc.
Alternative patches always welcome. :-) My goal at this point is to just have my vhost_net interface work so I can get back to my other development work. I will submit a v2 in the morning if I don't see anything.
Alex
Quoted 4 lines · Alexander Duyck
Actually it looks like there are several issues. One is the bypass problem which is the major issue. Another side effect of the original patch is that a bad frame will cause us to exit
__qdisc_runprematurely even if other frames are still in the qdisc.
Hmm... maybe a the following would fix that ?
Also note we lack counters tracking these kind of events (dropped count)
net/sched/sch_generic.c +5 -1
@@ -71,9 +71,13 @@ static inline struct sk_buff *dequeue_skb(struct Qdisc *q) skb =NULL ; }else {if (!(q->flags &TCQ_F_ONETXQUEUE ) || !netif_xmit_frozen_or_stopped (txq)) { +dequeue: skb = q->dequeue (q); -if (skb) +if (skb) { skb =validate_xmit_skb (skb,qdisc_dev (q)); +if (!skb) + goto dequeue; + } } }
Quoted 4 lines · On Tue, 02 Sep 2014 19:46:34 -0700 Alexander Duyck <[email protected]>…
Alternative patches always welcome. :-) My goal at this point is to just have my
vhost_netinterface work so I can get back to my other development work. I will submit a v2 in the morning if I don't see anything.
I've posted a followup, and gave you the SoB.
Signature · 5 lines
Best regards, Jesper Dangaard Brouer MSc.CS, Sr. Network Kernel Developer at Red Hat Author of http://www.iptv-analyzer.org LinkedIn: http://www.linkedin.com/in/brouer
PATCH 1/1 qdisc: validate frames going through the direct_xmit path
In reply to Alexander DuyckIn commit 50cbe9ab5f8d ("net: Validate xmit SKBs right when we pull them out of the qdisc") the validation code was moved out of dev_hard_start_xmit and into dequeue_skb. However this overlooked the fact that we do not always enqueue the skb onto a qdisc, if qdisc have flag TCQ_F_CAN_BYPASS.
As a result Alex was seeing issues trying to connect to a vhost_net interface after this patch was applied.
Added a call to validate_xmit_skb in __dev_xmit_skb(), in the code path for qdiscs with TCQ_F_CAN_BYPASS flag.
---
net/core/dev.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
net/core/dev.c +2 -1
@@ -2739,7 +2739,8 @@ static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q,qdisc_bstats_update (q, skb); -if (sch_direct_xmit (skb, q, dev, txq, root_lock)) { + skb =validate_xmit_skb (skb, dev); +if (skb &&sch_direct_xmit (skb, q, dev, txq, root_lock)) {if (unlikely (contended)) {spin_unlock (&q->busylock); contended = false;
Re: [net-next PATCH] qdisc: validate frames going through the direct_xmit path
Quoted 8 lines · Jesper Dangaard Brouer
In commit
50cbe9ab5f8d("net: Validate xmit SKBs right when we pull them out of the qdisc") the validation code was moved out ofdev_hard_start_xmitand intodequeue_skb. However this overlooked the fact that we do not always enqueue the skb onto a qdisc, if qdisc have flagTCQ_F_CAN_BYPASS.As a result Alex was seeing issues trying to connect to a
vhost_netinterface after this patch was applied.
Quoted 7 lines
Added a call to
validate_xmit_skbin__dev_xmit_skb(), in the code path for qdiscs withTCQ_F_CAN_BYPASSflag.Fixes 50cbe9ab5f8d ("net: Validate xmit SKBs right when we pull them out of the qdisc")Signed-off-by Alexander Duyck <[email protected]>Signed-off-by Jesper Dangaard Brouer <[email protected]>---
Jesper, you missed another spot, when there is no qdisc on the device.
__dev_queue_xmit() calls dev_hard_start_xmit() around line 2886
Could we try to not add a myriad of small patches ?
Some of us will need to backport all of them.
Thanks.
Re: [net-next PATCH] qdisc: validate frames going through the direct_xmit path
Quoted 17 lines · On Wed, 03 Sep 2014 06:43:25 -0700 Eric Dumazet <[email protected]> wrote:
Quoted 8 lines · Jesper Dangaard Brouer
In commit
50cbe9ab5f8d("net: Validate xmit SKBs right when we pull them out of the qdisc") the validation code was moved out ofdev_hard_start_xmitand intodequeue_skb. However this overlooked the fact that we do not always enqueue the skb onto a qdisc, if qdisc have flagTCQ_F_CAN_BYPASS.As a result Alex was seeing issues trying to connect to a
vhost_netinterface after this patch was applied.Quoted 7 lines
Added a call to
validate_xmit_skbin__dev_xmit_skb(), in the code path for qdiscs withTCQ_F_CAN_BYPASSflag.Fixes 50cbe9ab5f8d ("net: Validate xmit SKBs right when we pull them out of the qdisc")Signed-off-by Alexander Duyck <[email protected]>Signed-off-by Jesper Dangaard Brouer <[email protected]>---
Quoted 7 lines
Jesper, you missed another spot, when there is no qdisc on the device.
__dev_queue_xmit()callsdev_hard_start_xmit()around line 2886Could we try to not add a myriad of small patches ?
Some of us will need to backport all of them.
I'm in the same backport situation ;-)
I'll send a V2 of this patch, with missed spot...
Signature · 5 lines
Best regards, Jesper Dangaard Brouer MSc.CS, Sr. Network Kernel Developer at Red Hat Author of http://www.iptv-analyzer.org LinkedIn: http://www.linkedin.com/in/brouer
Re: [net-next PATCH] qdisc: validate frames going through the direct_xmit path
Quoted 8 lines · On Wed, 3 Sep 2014 15:52:13 +0200 Jesper Dangaard Brouer <[email protected]>…
Quoted 5 lines · On Wed, 03 Sep 2014 06:43:25 -0700 Eric Dumazet <[email protected]> wrote:
Jesper, you missed another spot, when there is no qdisc on the device.
__dev_queue_xmit()callsdev_hard_start_xmit()around line 2886
Quoted 7 lines
Quoted 3 lines
Could we try to not add a myriad of small patches ?
Some of us will need to backport all of them.
I'm in the same backport situation ;-)
I'll send a V2 of this patch, with missed spot...
(to avoid doing too many patches)
In the code below (from __dev_queue_xmit()), I've added validate_xmit_skb(). (dev_hard_start_xmit() can handle if it is a NULL ptr)
HARD_TX_LOCK(dev, txq, cpu);
if (!netif_xmit_stopped(txq)) {
skb = validate_xmit_skb(skb, dev);
__this_cpu_inc(xmit_recursion);
skb = dev_hard_start_xmit(skb, dev, txq, &rc);
__this_cpu_dec(xmit_recursion);
if (dev_xmit_complete(rc)) {
HARD_TX_UNLOCK(dev, txq);
goto out;
}
}
HARD_TX_UNLOCK(dev, txq);
net_crit_ratelimited("Virtual device %s asks to queue packet!\n",
dev->name);BUT shouldn't we also handle if dev_hard_start_xmit() returns an skb pointer, which means that there were skb's left on the skb list. Due to the rc value "returned" in this case, we should see the net_crit_ratelimited() msg, but we don't handle freeing these SKBs.
Any recommentations?
Signature · 5 lines
Best regards, Jesper Dangaard Brouer MSc.CS, Sr. Network Kernel Developer at Red Hat Author of http://www.iptv-analyzer.org LinkedIn: http://www.linkedin.com/in/brouer
Re: [net-next PATCH] qdisc: validate frames going through the direct_xmit path
Quoted 38 lines · Jesper Dangaard Brouer
Quoted 8 lines · On Wed, 3 Sep 2014 15:52:13 +0200 Jesper Dangaard Brouer <[email protected]>…
Quoted 5 lines · On Wed, 03 Sep 2014 06:43:25 -0700 Eric Dumazet <[email protected]> wrote:
Jesper, you missed another spot, when there is no qdisc on the device.
__dev_queue_xmit()callsdev_hard_start_xmit()around line 2886Quoted 7 lines
Quoted 3 lines
Could we try to not add a myriad of small patches ?
Some of us will need to backport all of them.
I'm in the same backport situation ;-)
I'll send a V2 of this patch, with missed spot...
(to avoid doing too many patches)
In the code below (from
__dev_queue_xmit()), I've addedvalidate_xmit_skb(). (dev_hard_start_xmit()can handle if it is a NULL ptr)HARD_TX_LOCK(dev, txq, cpu); if (!netif_xmit_stopped(txq)) { skb = validate_xmit_skb(skb, dev); __this_cpu_inc(xmit_recursion); skb = dev_hard_start_xmit(skb, dev, txq, &rc); __this_cpu_dec(xmit_recursion); if (dev_xmit_complete(rc)) { HARD_TX_UNLOCK(dev, txq); goto out; } } HARD_TX_UNLOCK(dev, txq); net_crit_ratelimited("Virtual device %s asks to queue packet!\n", dev->name);
Quoted 7 lines
BUT shouldn't we also handle if
dev_hard_start_xmit()returns an skb pointer, which means that there were skb's left on the skb list. Due to the rc value "returned" in this case, we should see thenet_crit_ratelimited()msg, but we don't handle freeing these SKBs.Any recommentations?
First I would do the validate_xmit_skb() before HARD_TX_LOCK(dev, txq, cpu)
Then, if we have skbs that could not be transmitted, we need to free them (and possibly account the drops on the device tx_dropped). Logging a one time message would be enough.
Thanks
PATCH v2 1/1 qdisc: validate frames going through the direct_xmit path
In reply to Jesper Dangaard BrouerIn commit 50cbe9ab5f8d ("net: Validate xmit SKBs right when we pull them out of the qdisc") the validation code was moved out of dev_hard_start_xmit and into dequeue_skb.
However this overlooked the fact that we do not always enqueue the skb onto a qdisc. First situation is if qdisc have flag TCQ_F_CAN_BYPASS and qdisc is empty. Second situation is if there is no qdisc on the device, which is a common case for software devices.
Originally spotted and inital patch by Alexander Duyck. As a result Alex was seeing issues trying to connect to a vhost_net interface after commit 50cbe9ab5f8d was applied.
Added a call to validate_xmit_skb() in __dev_xmit_skb(), in the code path for qdiscs with TCQ_F_CAN_BYPASS flag, and in __dev_queue_xmit() when no qdisc.
---
V2:
- Also handle no qdisc on the device situation
Posting a V2 quickly, if DaveM wants this fixed quickly.
net/core/dev.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
net/core/dev.c +3 -1
@@ -2739,7 +2739,8 @@ static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q,qdisc_bstats_update (q, skb); -if (sch_direct_xmit (skb, q, dev, txq, root_lock)) { + skb =validate_xmit_skb (skb, dev); +if (skb &&sch_direct_xmit (skb, q, dev, txq, root_lock)) {if (unlikely (contended)) {spin_unlock (&q->busylock); contended = false;
@@ -2882,6 +2883,7 @@ static int __dev_queue_xmit(struct sk_buff *skb, void *accel_priv)HARD_TX_LOCK (dev, txq, cpu);if (!netif_xmit_stopped (txq)) { + skb =validate_xmit_skb (skb, dev);__this_cpu_inc (xmit_recursion); skb =dev_hard_start_xmit (skb, dev, txq, &rc);__this_cpu_dec (xmit_recursion);
PATCH v3 1/1 qdisc: validate frames going through the direct_xmit path
In reply to Jesper Dangaard BrouerIn commit 50cbe9ab5f8d ("net: Validate xmit SKBs right when we pull them out of the qdisc") the validation code was moved out of dev_hard_start_xmit and into dequeue_skb.
However this overlooked the fact that we do not always enqueue the skb onto a qdisc. First situation is if qdisc have flag TCQ_F_CAN_BYPASS and qdisc is empty. Second situation is if there is no qdisc on the device, which is a common case for software devices.
Originally spotted and inital patch by Alexander Duyck. As a result Alex was seeing issues trying to connect to a vhost_net interface after commit 50cbe9ab5f8d was applied.
Added a call to validate_xmit_skb() in __dev_xmit_skb(), in the code path for qdiscs with TCQ_F_CAN_BYPASS flag, and in __dev_queue_xmit() when no qdisc.
Also handle the error situation where dev_hard_start_xmit() could return a skb list, and does not return dev_xmit_complete(rc) and falls through to the kfree_skb(), in that situation it should call kfree_skb_list().
---
V2:
- Also handle no qdisc on the device situation
V3:
- In __dev_queue_xmit() move validate_xmit_skb() up before HARD_TX_LOCK and record tx_dropped if the validation failed.
- Use kfree_skb_list() instead of kfree_skb() in fallthrough err case.
net/core/dev.c | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-)
net/core/dev.c +8 -2
@@ -2739,7 +2739,8 @@ static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q,qdisc_bstats_update (q, skb); -if (sch_direct_xmit (skb, q, dev, txq, root_lock)) { + skb =validate_xmit_skb (skb, dev); +if (skb &&sch_direct_xmit (skb, q, dev, txq, root_lock)) {if (unlikely (contended)) {spin_unlock (&q->busylock); contended = false;
@@ -2879,6 +2880,10 @@ static int __dev_queue_xmit(struct sk_buff *skb, void *accel_priv)if (__this_cpu_read (xmit_recursion) >RECURSION_LIMIT ) goto recursion_alert; + skb =validate_xmit_skb (skb, dev); +if (!skb) + goto drop; +HARD_TX_LOCK (dev, txq, cpu);if (!netif_xmit_stopped (txq)) {
@@ -2904,10 +2909,11 @@ recursion_alert: } rc = -ENETDOWN ; +drop:rcu_read_unlock_bh ();atomic_long_inc (&dev->tx_dropped); -kfree_skb (skb); +kfree_skb_list (skb);return rc; out:rcu_read_unlock_bh ();
Re: [net-next PATCH V3] qdisc: validate frames going through the direct_xmit path
Quoted 14 lines · Jesper Dangaard Brouer
In commit
50cbe9ab5f8d("net: Validate xmit SKBs right when we pull them out of the qdisc") the validation code was moved out ofdev_hard_start_xmitand intodequeue_skb.However this overlooked the fact that we do not always enqueue the skb onto a qdisc. First situation is if qdisc have flag
TCQ_F_CAN_BYPASSand qdisc is empty. Second situation is if there is no qdisc on the device, which is a common case for software devices.Originally spotted and inital patch by Alexander Duyck. As a result Alex was seeing issues trying to connect to a
vhost_netinterface after commit50cbe9ab5f8dwas applied.
Quoted 8 lines
Added a call to
validate_xmit_skb()in__dev_xmit_skb(), in the code path for qdiscs withTCQ_F_CAN_BYPASSflag, and in__dev_queue_xmit()when no qdisc.Also handle the error situation where
dev_hard_start_xmit()could return a skb list, and does not returndev_xmit_complete(rc)and falls through to thekfree_skb(), in that situation it should callkfree_skb_list().
It seems that in this situation, we will return rc = -ENETDOWN, I do not think this is the right error code. Not sure if that matters...
Re: [net-next PATCH V3] qdisc: validate frames going through the direct_xmit path
Quoted 1 line · On Wed, 03 Sep 2014 09:08:27 -0700 Eric Dumazet <[email protected]> wrote:
On Wed, 2014-09-03 at 17:56 +0200, Jesper Dangaard Brouer wrote:
[...]
Quoted 7 lines
Quoted 4 lines
Also handle the error situation where
dev_hard_start_xmit()could return a skb list, and does not returndev_xmit_complete(rc)and falls through to thekfree_skb(), in that situation it should callkfree_skb_list().It seems that in this situation, we will return rc =
-ENETDOWN, I do not think this is the right error code. Not sure if that matters...
Yes, I noticed, but we have always returned this, in these kind of err situations, so I didn't want to change that behavior.
Signature · 5 lines
Best regards, Jesper Dangaard Brouer MSc.CS, Sr. Network Kernel Developer at Red Hat Author of http://www.iptv-analyzer.org LinkedIn: http://www.linkedin.com/in/brouer
Re: [net-next PATCH V3] qdisc: validate frames going through the direct_xmit path
In reply to Jesper Dangaard BrouerFrom: Jesper Dangaard Brouer <[email protected]>
Date: Wed, 03 Sep 2014 17:56:09 +0200
Quoted 18 lines
In commit
50cbe9ab5f8d("net: Validate xmit SKBs right when we pull them out of the qdisc") the validation code was moved out ofdev_hard_start_xmitand intodequeue_skb.However this overlooked the fact that we do not always enqueue the skb onto a qdisc. First situation is if qdisc have flag
TCQ_F_CAN_BYPASSand qdisc is empty. Second situation is if there is no qdisc on the device, which is a common case for software devices.Originally spotted and inital patch by Alexander Duyck. As a result Alex was seeing issues trying to connect to a
vhost_netinterface after commit50cbe9ab5f8dwas applied.Added a call to
validate_xmit_skb()in__dev_xmit_skb(), in the code path for qdiscs withTCQ_F_CAN_BYPASSflag, and in__dev_queue_xmit()when no qdisc.
Quoted 8 lines
Also handle the error situation where
dev_hard_start_xmit()could return a skb list, and does not returndev_xmit_complete(rc)and falls through to thekfree_skb(), in that situation it should callkfree_skb_list().Fixes 50cbe9ab5f8d ("net: Validate xmit SKBs right when we pull them out of the qdisc")Signed-off-by Alexander Duyck <[email protected]>Signed-off-by Jesper Dangaard Brouer <[email protected]>
Applied.