Skip to contentSkip to conversation

ip_gre: check packet length and mtu correctly in erspan tx

PATCH Applied William Tu 3 participants 3 messages Oct 5, 2017 – Oct 7, 2017

Subsystems (3)
lore
Share & tools
lore

William Tu

author
#0 lore raw

PATCH v2 1/1 ip_gre: check packet length and mtu correctly in erspan tx

Similarly to early patch for erspan_xmit(), the ARPHDR_ETHER device is the length of the whole ether packet. So skb->len should subtract the dev->hard_header_len.

Fixes 1a66a836da63 ("gre: add collect_md mode to ERSPAN tunnel")
Fixes 84e54fe0a5ea ("gre: introduce native tunnel support for ERSPAN")
Cc Xin Long <[email protected]>
Cc David Laight <[email protected]>

---
v1->v2:
use addition to avoid overflow
fix pskb_trim size

---
 net/ipv4/ip_gre.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
net/ipv4/ip_gre.c +4 -4
index b279c325c7f6..fb95f68d6e53 100644
@@ -579,8 +579,8 @@ static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev,
 	if (gre_handle_offloads(skb, false))
 		goto err_free_rt;
 
-	if (skb->len > dev->mtu) {
-		pskb_trim(skb, dev->mtu);
+	if (skb->len > dev->mtu + dev->hard_header_len) {
+		pskb_trim(skb, dev->mtu + dev->hard_header_len);
 		truncate = true;
 	}
 
@@ -731,8 +731,8 @@ static netdev_tx_t erspan_xmit(struct sk_buff *skb,
 	if (skb_cow_head(skb, dev->needed_headroom))
 		goto free_skb;
 
-	if (skb->len - dev->hard_header_len > dev->mtu) {
-		pskb_trim(skb, dev->mtu);
+	if (skb->len > dev->mtu + dev->hard_header_len) {
+		pskb_trim(skb, dev->mtu + dev->hard_header_len);
 		truncate = true;
 	}
 
Signature · 1 line
2.7.4
Reviewed-by on v2 1/1
#1 lore raw
Quoted 44 lines · William Tu

Similarly to early patch for erspan_xmit(), the ARPHDR_ETHER device is the length of the whole ether packet. So skb->len should subtract the dev->hard_header_len.

Fixes 1a66a836da63 ("gre: add collect_md mode to ERSPAN tunnel")
Fixes 84e54fe0a5ea ("gre: introduce native tunnel support for ERSPAN")
Cc Xin Long <[email protected]>
Cc David Laight <[email protected]>

---
v1->v2:
use addition to avoid overflow
fix pskb_trim size

---
 net/ipv4/ip_gre.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
net/ipv4/ip_gre.c +4 -5
index b279c325c7f6..fb95f68d6e53 100644
@@ -579,8 +579,8 @@ static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev,
        if (gre_handle_offloads(skb, false))
                goto err_free_rt;
 
-       if (skb->len > dev->mtu) {
-               pskb_trim(skb, dev->mtu);
+       if (skb->len > dev->mtu + dev->hard_header_len) {
+               pskb_trim(skb, dev->mtu + dev->hard_header_len);
                truncate = true;
        }
 
@@ -731,8 +731,8 @@ static netdev_tx_t erspan_xmit(struct sk_buff *skb,
        if (skb_cow_head(skb, dev->needed_headroom))
                goto free_skb;
 
-       if (skb->len - dev->hard_header_len > dev->mtu) {
-               pskb_trim(skb, dev->mtu);
+       if (skb->len > dev->mtu + dev->hard_header_len) {
+               pskb_trim(skb, dev->mtu + dev->hard_header_len);
                truncate = true;
        }
 
--
Quoted 2 lines

2.7.4

maintainer Applied
#2 lore raw
In reply to William Tu

From: William Tu <[email protected]>
Date: Thu, 5 Oct 2017 12:07:12 -0700

Quoted 7 lines

Similarly to early patch for erspan_xmit(), the ARPHDR_ETHER device is the length of the whole ether packet. So skb->len should subtract the dev->hard_header_len.

Fixes 1a66a836da63 ("gre: add collect_md mode to ERSPAN tunnel")
Fixes 84e54fe0a5ea ("gre: introduce native tunnel support for ERSPAN")

Applied.