net: dev_queue_xmit_nit fixes
Subsystems (2)
cover net: dev_queue_xmit_nit fixes
First patch is a fix for the netdev discussion ``PROBLEM: Software injected vlan tagged packets are unable to be identified using recent BPF modifications'' and the second one I spotted while doing the first fix.
Daniel Borkmann (2):
net: dev_queue_xmit_nit: fix skb->vlan_tci field value
net: dev_queue_xmit_nit: fix potential NULL ptr dereference
net/core/dev.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
Signature · 1 line
1.7.11.7
PATCH 1/2 net: dev_queue_xmit_nit: fix skb->vlan_tci field value
VLAN packets that are locally injected through taps will loose their skb->vlan_tci value when they pass dev_hard_start_xmit and get looped back to a packet sniffer via dev_queue_xmit_nit. Besides others, this meta data is used in Linux socket filtering for VLANs. Tested with a VLAN ancillary ops filter.
Patch is based on a previous version by Jiri Pirko.
--- net/core/dev.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
net/core/dev.c +13 -0
@@ -1775,6 +1775,19 @@ static void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev)struct packet_type *ptype;struct sk_buff *skb2 =NULL ;struct packet_type *pt_prev =NULL ; +struct ethhdr *ehdr; + +/* Network taps could make use of skb->vlan_tci, which got wiped +* out. Hence, we need to reset it correctly. +*/ +skb_reset_mac_header (skb); + ehdr =eth_hdr (skb); + +if (ehdr->h_proto ==__constant_htons (ETH_P_8021Q )) { + skb2 =vlan_untag (skb); +if (likely (skb2)) + skb = skb2; + }rcu_read_lock ();list_for_each_entry_rcu (ptype, &ptype_all, list) {
Signature · 1 line
1.7.11.7
PATCH 2/2 net: dev_queue_xmit_nit: fix potential NULL ptr dereference
In reply to Daniel BorkmannCommit 71d9dec24dce548bf699815c976cf063ad9257e2 (``net: increase skb->users instead of skb_clone()'') introduced a skb_clone in dev_queue_xmit_nit that, when NULL, leaves the loop, but can still be injected into pt_prev->func().
--- net/core/dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/dev.c +1 -1
@@ -1827,7 +1827,7 @@ static void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev) pt_prev = ptype; } } -if (pt_prev) +if (skb2 && pt_prev) pt_prev->func (skb2, skb->dev, pt_prev, skb->dev);rcu_read_unlock (); }
Signature · 1 line
1.7.11.7
Re: [PATCH net 2/2] net: dev_queue_xmit_nit: fix potential NULL ptr dereference
Quoted 17 lines · Daniel Borkmann
Commit
71d9dec24dce548bf699815c976cf063ad9257e2(``net: increaseskb->usersinstead ofskb_clone()'') introduced askb_cloneindev_queue_xmit_nitthat, when NULL, leaves the loop, but can still be injected intopt_prev->func().Cc Changli Gao <[email protected]>Cc Eric Dumazet <[email protected]>Signed-off-by Daniel Borkmann <[email protected]>--- net/core/dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/core/dev.c +0
-0
net/core/dev.c static void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev) · line 1833
Quoted 8 lines
net/core/dev.c +1
-1@@ -1827,7 +1827,7 @@ static void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev) pt_prev = ptype; } } -if (pt_prev) +if (skb2 && pt_prev) pt_prev->func (skb2, skb->dev, pt_prev, skb->dev);rcu_read_unlock (); }
My opinion is this patch is not needed.
pt_prev can be set only if skb2 is not NULL
Re: [PATCH net 2/2] net: dev_queue_xmit_nit: fix potential NULL ptr dereference
Quoted 29 lines · Eric Dumazet
Quoted 17 lines · Daniel Borkmann
Commit
71d9dec24dce548bf699815c976cf063ad9257e2(``net: increaseskb->usersinstead ofskb_clone()'') introduced askb_cloneindev_queue_xmit_nitthat, when NULL, leaves the loop, but can still be injected intopt_prev->func().Cc Changli Gao <[email protected]>Cc Eric Dumazet <[email protected]>Signed-off-by Daniel Borkmann <[email protected]>--- net/core/dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/core/dev.c +0
-0net/core/dev.c static void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev) · line 1833
Quoted 8 lines
net/core/dev.c +1
-1@@ -1827,7 +1827,7 @@ static void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev) pt_prev = ptype; } } -if (pt_prev) +if (skb2 && pt_prev) pt_prev->func (skb2, skb->dev, pt_prev, skb->dev);rcu_read_unlock (); }My opinion is this patch is not needed.
Quoted 1 line
pt_prevcan be set only if skb2 is not NULL
Agreed, I missed that, thanks.
Re: [PATCH net 1/2] net: dev_queue_xmit_nit: fix skb->vlan_tci field value
In reply to Daniel BorkmannAgreed with the fix. This fixes the issue introduced by this change :l
Quoted 6 lines · Daniel Borkmann
VLAN packets that are locally injected through taps will loose their
skb->vlan_tcivalue when they passdev_hard_start_xmitand get looped back to a packet sniffer viadev_queue_xmit_nit. Besides others, this meta data is used in Linux socket filtering for VLANs. Tested with a VLAN ancillary ops filter.
Quoted 7 lines
Patch is based on a previous version by Jiri Pirko.
Cc Eric Dumazet <[email protected]>Cc Ani Sinha <[email protected]>Cc Jiri Pirko <[email protected]>Reported-by Paul Pearce <[email protected]>Signed-off-by Daniel Borkmann <[email protected]>
Re: [PATCH net 1/2] net: dev_queue_xmit_nit: fix skb->vlan_tci field value
In reply to Daniel BorkmannQuoted 31 lines · Daniel Borkmann
VLAN packets that are locally injected through taps will loose their
skb->vlan_tcivalue when they passdev_hard_start_xmitand get looped back to a packet sniffer viadev_queue_xmit_nit. Besides others, this meta data is used in Linux socket filtering for VLANs. Tested with a VLAN ancillary ops filter.Patch is based on a previous version by Jiri Pirko.
Cc Eric Dumazet <[email protected]>Cc Ani Sinha <[email protected]>Cc Jiri Pirko <[email protected]>Reported-by Paul Pearce <[email protected]>Signed-off-by Daniel Borkmann <[email protected]>--- net/core/dev.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)net/core/dev.c +6
-0@@ -1775,6 +1775,19 @@ static void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev)struct packet_type *ptype;struct sk_buff *skb2 =NULL ;struct packet_type *pt_prev =NULL ; +struct ethhdr *ehdr; + +/* Network taps could make use of skb->vlan_tci, which got wiped +* out. Hence, we need to reset it correctly. +*/ +skb_reset_mac_header (skb);
net/core/dev.c static void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev) · line 1793
Quoted 10 lines
net/core/dev.c +7
-0+ ehdr =eth_hdr (skb); + +if (ehdr->h_proto ==__constant_htons (ETH_P_8021Q )) { + skb2 =vlan_untag (skb); +if (likely (skb2)) + skb = skb2; + }rcu_read_lock ();list_for_each_entry_rcu (ptype, &ptype_all, list) {
This patch is wrong (it adds a leak), and not needed.
If a packet has no vlan_tci, its for a good reason.
We want sniffer see the packet content as is.
Re: [PATCH net 1/2] net: dev_queue_xmit_nit: fix skb->vlan_tci field value
In reply to Daniel BorkmannQuoted 28 lines · Tue, Jan 08, 2013 at 07:51:32PM CET, [email protected] wrote:
VLAN packets that are locally injected through taps will loose their
skb->vlan_tcivalue when they passdev_hard_start_xmitand get looped back to a packet sniffer viadev_queue_xmit_nit. Besides others, this meta data is used in Linux socket filtering for VLANs. Tested with a VLAN ancillary ops filter.Patch is based on a previous version by Jiri Pirko.
Cc Eric Dumazet <[email protected]>Cc Ani Sinha <[email protected]>Cc Jiri Pirko <[email protected]>Reported-by Paul Pearce <[email protected]>Signed-off-by Daniel Borkmann <[email protected]>---
net/core/dev.c| 13 +++++++++++++1 file changed, 13 insertions(+)net/core/dev.c +3
-0@@ -1775,6 +1775,19 @@ static void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev)struct packet_type *ptype;struct sk_buff *skb2 =NULL ;struct packet_type *pt_prev =NULL ; +struct ethhdr *ehdr; + +/* Network taps could make use of skb->vlan_tci, which got wiped
net/core/dev.c static void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev) · line 1790
Quoted 10 lines
net/core/dev.c +10
-0+* out. Hence, we need to reset it correctly. +*/ +skb_reset_mac_header (skb); + ehdr =eth_hdr (skb); + +if (ehdr->h_proto ==__constant_htons (ETH_P_8021Q )) { + skb2 =vlan_untag (skb); +if (likely (skb2)) + skb = skb2; + }
Hmm, nitpick, I think that better would be to do: skb = vlan_untag(skb); if (unlikely(!skb)) return; I believe that better is to deliver skbs in consistent way and to do not deliver at all in case of -ENOMEM
Re: [PATCH net 1/2] net: dev_queue_xmit_nit: fix skb->vlan_tci field value
In reply to Eric DumazetQuoted 40 lines · Tue, Jan 08, 2013 at 09:04:52PM CET, [email protected] wrote:
Quoted 39 lines · Daniel Borkmann
VLAN packets that are locally injected through taps will loose their
skb->vlan_tcivalue when they passdev_hard_start_xmitand get looped back to a packet sniffer viadev_queue_xmit_nit. Besides others, this meta data is used in Linux socket filtering for VLANs. Tested with a VLAN ancillary ops filter.Patch is based on a previous version by Jiri Pirko.
Cc Eric Dumazet <[email protected]>Cc Ani Sinha <[email protected]>Cc Jiri Pirko <[email protected]>Reported-by Paul Pearce <[email protected]>Signed-off-by Daniel Borkmann <[email protected]>--- net/core/dev.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)net/core/dev.c +13
-0@@ -1775,6 +1775,19 @@ static void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev)struct packet_type *ptype;struct sk_buff *skb2 =NULL ;struct packet_type *pt_prev =NULL ; +struct ethhdr *ehdr; + +/* Network taps could make use of skb->vlan_tci, which got wiped +* out. Hence, we need to reset it correctly. +*/ +skb_reset_mac_header (skb); + ehdr =eth_hdr (skb); + +if (ehdr->h_proto ==__constant_htons (ETH_P_8021Q )) { + skb2 =vlan_untag (skb); +if (likely (skb2)) + skb = skb2; + }
Quoted 8 lines
net/core/dev.c static void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev) · line 1793
Quoted 2 lines
net/core/dev.c +0
-0rcu_read_lock ();list_for_each_entry_rcu (ptype, &ptype_all, list) {This patch is wrong (it adds a leak), and not needed.
If a packet has no
vlan_tci, its for a good reason.We want sniffer see the packet content as is.
The issue is that for exmaple in af_packet the function packet_rcv() expects vlan_tci to be filled out as that is on RX path ensured by __netif_receive_skb(). However on TX path, dev_queue_xmit_nit() is called with vlan_tci cleaned in case the device does not have TX vlan accel enabled. This patch is trying to fix this difference.
Quoted 7 lines
--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH net 1/2] net: dev_queue_xmit_nit: fix skb->vlan_tci field value
Quoted 6 lines · Jiri Pirko
The issue is that for exmaple in
af_packetthe functionpacket_rcv()expectsvlan_tcito be filled out as that is on RX path ensured by__netif_receive_skb(). However on TX path,dev_queue_xmit_nit()is called withvlan_tcicleaned in case the device does not have TX vlan accel enabled. This patch is trying to fix this difference.
I perfectly understood that, and I repeat :
I want to see the difference.
A filter cannot expect skb->vlan_tci is set for all packets.
If a device doesn't have TX vlan accel, vlan_tci is 0.
packet sniffing is already slow, we don't want to force an extra copy with vlan_untag() killer.
If you want to fix/extend af_packet, do this in af_packet.