Skip to contentSkip to conversation

ixgbe: ixgbe_atr() bug fixes

RFC PATCH Superseded Sowmini Varadhan 2 participants 7 messages Oct 17, 2016

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover ixgbe: ixgbe_atr() bug fixes

Two bug fixes:
- ixgbe_atr() should check for protocol == udp in the skb->encapsulation case (instead of !=)
- ixgbe_atr() should make sure the non-paged data has the needed network/transport header for computing l4_proto.

Sowmini Varadhan (2):
ixgbe: ixgbe_atr() should access udp_hdr(skb) only for UDP packets
ixgbe: ixgbe_atr() compute l4_proto only if non-paged data has
network/transport headers

 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c |   20 +++++++++++++++++++-
 1 files changed, 19 insertions(+), 1 deletions(-)
#1 lore raw

RFC PATCH v2 1/2 ixgbe: ixgbe_atr() should access udp_hdr(skb) only for UDP packets

Commit 9f12df906cd8 ("ixgbe: Store VXLAN port number in network order") incorrectly checks for hdr.ipv4->protocol != IPPROTO_UDP
in ixgbe_atr(). This check should be for "==" instead.

---
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +1 -1
index a244d9a..eceb47b 100644
@@ -7653,7 +7653,7 @@ static void ixgbe_atr(struct ixgbe_ring *ring,
 	hdr.network = skb_network_header(skb);
 	if (skb->encapsulation &&
 	    first->protocol == htons(ETH_P_IP) &&
-	    hdr.ipv4->protocol != IPPROTO_UDP) {
+	    hdr.ipv4->protocol == IPPROTO_UDP) {
 		struct ixgbe_adapter *adapter = q_vector->adapter;
 
 		/* verify the port is recognized as VXLAN */
Signature · 1 line
1.7.1
#2 lore raw

RFC PATCH v2 2/2 ixgbe: ixgbe_atr() compute l4_proto only if non-paged data has network/transport headers

In reply to Sowmini Varadhan

For some Tx paths (e.g., tpacket_snd()), ixgbe_atr may be passed down an sk_buff that has the network and transport header in the paged data, so it needs to make sure these headers are available in the headlen bytes to calculate the l4_proto.

This patch expect that network and transport headers are already available in the non-paged header dat. The assumption is that the caller has set this up if l4_proto based Tx steering is desired.

---
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +18 -0
index eceb47b..2cc1dae 100644
@@ -54,6 +54,7 @@
 #include <net/pkt_cls.h>
 #include <net/tc_act/tc_gact.h>
 #include <net/tc_act/tc_mirred.h>
+#include <net/vxlan.h>
 
 #include "ixgbe.h"
 #include "ixgbe_common.h"
@@ -7651,11 +7652,16 @@ static void ixgbe_atr(struct ixgbe_ring *ring,
 	/* snag network header to get L4 type and address */
 	skb = first->skb;
 	hdr.network = skb_network_header(skb);
+	if (hdr.network <= skb->data || hdr.network >= skb_tail_pointer(skb))
+		return;
 	if (skb->encapsulation &&
 	    first->protocol == htons(ETH_P_IP) &&
 	    hdr.ipv4->protocol == IPPROTO_UDP) {
 		struct ixgbe_adapter *adapter = q_vector->adapter;
 
+		if (skb_tail_pointer(skb) < hdr.network + VXLAN_HEADROOM)
+			return;
+
 		/* verify the port is recognized as VXLAN */
 		if (adapter->vxlan_port &&
 		    udp_hdr(skb)->dest == adapter->vxlan_port)
@@ -7666,15 +7672,27 @@ static void ixgbe_atr(struct ixgbe_ring *ring,
 			hdr.network = skb_inner_network_header(skb);
 	}
 
+	/* Make sure we have at least [minimum IPv4 header + TCP]
+	 * or [IPv6 header] bytes
+	 */
+	if (skb_tail_pointer(skb) < hdr.network + 40)
+		return;
+
 	/* Currently only IPv4/IPv6 with TCP is supported */
 	switch (hdr.ipv4->version) {
 	case IPVERSION:
 		/* access ihl as u8 to avoid unaligned access on ia64 */
 		hlen = (hdr.network[0] & 0x0F) << 2;
+		if (skb_tail_pointer(skb) < hdr.network + hlen +
+					    sizeof(struct tcphdr))
+			return;
 		l4_proto = hdr.ipv4->protocol;
 		break;
 	case 6:
 		hlen = hdr.network - skb->data;
+		if (skb_tail_pointer(skb) < hdr.network + hlen +
+					    sizeof(struct tcphdr))
+			return;
 		l4_proto = ipv6_find_hdr(skb, &hlen, IPPROTO_TCP, NULL, NULL);
 		hlen -= hdr.network - skb->data;
 		break;
Signature · 1 line
1.7.1
#3 lore raw

Re: [Intel-wired-lan] [PATCH V2 RFC 2/2] ixgbe: ixgbe_atr() compute l4_proto only if non-paged data has network/transport headers

Quoted 29 lines · Sowmini Varadhan

For some Tx paths (e.g., tpacket_snd()), ixgbe_atr may be passed down an sk_buff that has the network and transport header in the paged data, so it needs to make sure these headers are available in the headlen bytes to calculate the l4_proto.

This patch expect that network and transport headers are already available in the non-paged header dat. The assumption is that the caller has set this up if l4_proto based Tx steering is desired.

---
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +1 -0
index eceb47b..2cc1dae 100644
@@ -54,6 +54,7 @@
 #include <net/pkt_cls.h>
 #include <net/tc_act/tc_gact.h>
 #include <net/tc_act/tc_mirred.h>
+#include <net/vxlan.h>
 
 #include "ixgbe.h"
 #include "ixgbe_common.h"

drivers/net/ethernet/intel/ixgbe/ixgbe_main.c static void ixgbe_atr(struct ixgbe_ring *ring, · line 7656

Quoted 5 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +2 -0
@@ -7651,11 +7652,16 @@ static void ixgbe_atr(struct ixgbe_ring *ring,
        /* snag network header to get L4 type and address */
        skb = first->skb;
        hdr.network = skb_network_header(skb);
+       if (hdr.network <= skb->data || hdr.network >= skb_tail_pointer(skb))
+               return;

I would say you probably only need the first check here for skb->data and could probably skip the second part. You will be testing for skb_tail_pointer in all the other tests you added so this check is redundant anyway.

Also you might want to go through and wrap these with unlikely() since most of these are exception cases.

Quoted 29 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +12 -0
        if (skb->encapsulation &&
            first->protocol == htons(ETH_P_IP) &&
            hdr.ipv4->protocol == IPPROTO_UDP) {
                struct ixgbe_adapter *adapter = q_vector->adapter;
 
+               if (skb_tail_pointer(skb) < hdr.network + VXLAN_HEADROOM)
+                       return;
+
                /* verify the port is recognized as VXLAN */
                if (adapter->vxlan_port &&
                    udp_hdr(skb)->dest == adapter->vxlan_port)
@@ -7666,15 +7672,27 @@ static void ixgbe_atr(struct ixgbe_ring *ring,
                        hdr.network = skb_inner_network_header(skb);
        }
 
+       /* Make sure we have at least [minimum IPv4 header + TCP]
+        * or [IPv6 header] bytes
+        */
+       if (skb_tail_pointer(skb) < hdr.network + 40)
+               return;
+
        /* Currently only IPv4/IPv6 with TCP is supported */
        switch (hdr.ipv4->version) {
        case IPVERSION:
                /* access ihl as u8 to avoid unaligned access on ia64 */
                hlen = (hdr.network[0] & 0x0F) << 2;
+               if (skb_tail_pointer(skb) < hdr.network + hlen +
+                                           sizeof(struct tcphdr))
+                       return;

drivers/net/ethernet/intel/ixgbe/ixgbe_main.c static void ixgbe_atr(struct ixgbe_ring *ring, · line 7698

Quoted 10 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +3 -0
                l4_proto = hdr.ipv4->protocol;
                break;
        case 6:
                hlen = hdr.network - skb->data;
+               if (skb_tail_pointer(skb) < hdr.network + hlen +
+                                           sizeof(struct tcphdr))
+                       return;
                l4_proto = ipv6_find_hdr(skb, &hlen, IPPROTO_TCP, NULL, NULL);
                hlen -= hdr.network - skb->data;
                break;

I believe one more check is needed after this block to verify the TCP header fields are present.

So you probably need to add a check for "skb_tail_pointer(skb) < (hdr.network + hlen + 20)".

Thanks.

- Alex

#4 lore raw

Re: [Intel-wired-lan] [PATCH V2 RFC 2/2] ixgbe: ixgbe_atr() compute l4_proto only if non-paged data has network/transport headers

Quoted 7 lines · Alexander Duyck

I would say you probably only need the first check here for skb->data and could probably skip the second part. You will be testing for skb_tail_pointer in all the other tests you added so this check is redundant anyway.

Also you might want to go through and wrap these with unlikely() since most of these are exception cases.

Ok.. v3 will have this.

Quoted 19 lines
Quoted 8 lines
        /* Currently only IPv4/IPv6 with TCP is supported */
        switch (hdr.ipv4->version) {
        case IPVERSION:
                /* access ihl as u8 to avoid unaligned access on ia64 */
                hlen = (hdr.network[0] & 0x0F) << 2;
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +3 -0
+               if (skb_tail_pointer(skb) < hdr.network + hlen +
+                                           sizeof(struct tcphdr))
+                       return;

drivers/net/ethernet/intel/ixgbe/ixgbe_main.c static void ixgbe_atr(struct ixgbe_ring *ring, · line 7698

Quoted 10 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +3 -0
                l4_proto = hdr.ipv4->protocol;
                break;
        case 6:
                hlen = hdr.network - skb->data;
+               if (skb_tail_pointer(skb) < hdr.network + hlen +
+                                           sizeof(struct tcphdr))
+                       return;
                l4_proto = ipv6_find_hdr(skb, &hlen, IPPROTO_TCP, NULL, NULL);
                hlen -= hdr.network - skb->data;
                break;
Quoted 5 lines

I believe one more check is needed after this block to verify the TCP header fields are present.

So you probably need to add a check for "skb_tail_pointer(skb) < (hdr.network + hlen + 20)".

But isnt that the same thing as the checks before l4_proto computation above?

--Sowmini

#5 lore raw

Re: [Intel-wired-lan] [PATCH V2 RFC 2/2] ixgbe: ixgbe_atr() compute l4_proto only if non-paged data has network/transport headers

Quoted 30 lines · Sowmini Varadhan
Quoted 7 lines · Alexander Duyck

I would say you probably only need the first check here for skb->data and could probably skip the second part. You will be testing for skb_tail_pointer in all the other tests you added so this check is redundant anyway.

Also you might want to go through and wrap these with unlikely() since most of these are exception cases.

Ok.. v3 will have this.

Quoted 19 lines
Quoted 18 lines
        /* Currently only IPv4/IPv6 with TCP is supported */
        switch (hdr.ipv4->version) {
        case IPVERSION:
                /* access ihl as u8 to avoid unaligned access on ia64 */
                hlen = (hdr.network[0] & 0x0F) << 2;
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +6 -0
+               if (skb_tail_pointer(skb) < hdr.network + hlen +
+                                           sizeof(struct tcphdr))
+                       return;
                l4_proto = hdr.ipv4->protocol;
                break;
        case 6:
                hlen = hdr.network - skb->data;
+               if (skb_tail_pointer(skb) < hdr.network + hlen +
+                                           sizeof(struct tcphdr))
+                       return;
                l4_proto = ipv6_find_hdr(skb, &hlen, IPPROTO_TCP, NULL, NULL);
                hlen -= hdr.network - skb->data;
                break;
Quoted 7 lines
Quoted 5 lines

I believe one more check is needed after this block to verify the TCP header fields are present.

So you probably need to add a check for "skb_tail_pointer(skb) < (hdr.network + hlen + 20)".

But isnt that the same thing as the checks before l4_proto computation above?

Sort of. The problem is IPv6 can include extension headers and that can totally mess with us. So we need to do one more check to verify that we have enough space for IPv6 w/ TCP which would be hdr.raw + 20
+ hlenl.

Thanks.

- Alex

#6 lore raw

Re: [Intel-wired-lan] [PATCH V2 RFC 2/2] ixgbe: ixgbe_atr() compute l4_proto only if non-paged data has network/transport headers

Quoted 10 lines · Alexander Duyck
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
        /* Currently only IPv4/IPv6 with TCP is supported */
        switch (hdr.ipv4->version) {
        case IPVERSION:
                /* access ihl as u8 to avoid unaligned access on ia64 */
                hlen = (hdr.network[0] & 0x0F) << 2;
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +3 -0
+               if (skb_tail_pointer(skb) < hdr.network + hlen +
+                                           sizeof(struct tcphdr))
+                       return;
                l4_proto = hdr.ipv4->protocol;
                break;
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/net/ethernet/intel/ixgbe/ixgbe_main.c static void ixgbe_atr(struct ixgbe_ring *ring, · line 7698

Quoted 8 lines
        case 6:
                hlen = hdr.network - skb->data;
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +3 -0
+               if (skb_tail_pointer(skb) < hdr.network + hlen +
+                                           sizeof(struct tcphdr))
+                       return;
                l4_proto = ipv6_find_hdr(skb, &hlen, IPPROTO_TCP, NULL, NULL);
                hlen -= hdr.network - skb->data;
                break;

:

Quoted 9 lines
Quoted 4 lines
Quoted 2 lines

So you probably need to add a check for "skb_tail_pointer(skb) < (hdr.network + hlen + 20)".

But isnt that the same thing as the checks before l4_proto computation above?

Sort of. The problem is IPv6 can include extension headers and that can totally mess with us. So we need to do one more check to verify that we have enough space for IPv6 w/ TCP which would be hdr.raw + 20
+ hlenl.

Yes, you are right. So given that I already check that I have at least 40 bytes past the network header, and ipv6_find_hdr will pull up exthdrs as needed, my checks are not needed, and the real ones should happen after we come out of that switch().

--Sowmini