Skip to contentSkip to conversation

ip_gre: check packet length and mtu correctly in erspan_fb_xmit

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

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

William Tu

author
#0 lore raw

PATCH 1/1 ip_gre: check packet length and mtu correctly in erspan_fb_xmit

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")
Cc Xin Long <[email protected]>
---
 net/ipv4/ip_gre.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/ip_gre.c +1 -1
index b279c325c7f6..10b21fe5b3a6 100644
@@ -579,7 +579,7 @@ 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) {
+	if (skb->len - dev->hard_header_len > dev->mtu) {
 		pskb_trim(skb, dev->mtu);
 		truncate = true;
 	}
Signature · 1 line
2.7.4
#1 lore raw

From: William Tu

Quoted 17 lines

Sent: 05 October 2017 01:14
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")
Cc Xin Long <[email protected]>
---
 net/ipv4/ip_gre.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/ip_gre.c +0 -0
index b279c325c7f6..10b21fe5b3a6 100644

net/ipv4/ip_gre.c static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev, · line 582

Quoted 5 lines
net/ipv4/ip_gre.c +1 -1
@@ -579,7 +579,7 @@ 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) {
+	if (skb->len - dev->hard_header_len > dev->mtu) {

Can you guarantee that skb->len > dev_hard_header_len?
It is probably safer to check skb->len > dev->hard_header_len + dev->mtu since that addition isn't going to overflow.

net/ipv4/ip_gre.c static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev, · line 584

Quoted 2 lines
net/ipv4/ip_gre.c +0 -0
 		pskb_trim(skb, dev->mtu);
 		truncate = true;

Is that pskb_trim() now truncating to the correct size?

David

author
#2 lore raw
Quoted 21 lines · David Laight

From: William Tu

Quoted 20 lines

Sent: 05 October 2017 01:14
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")
Cc Xin Long <[email protected]>
---
 net/ipv4/ip_gre.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/ip_gre.c +0 -0
index b279c325c7f6..10b21fe5b3a6 100644
@@ -579,7 +579,7 @@ static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev,
      if (gre_handle_offloads(skb, false))
              goto err_free_rt;
 
Quoted 6 lines

net/ipv4/ip_gre.c static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev, · line 582

Quoted 2 lines
net/ipv4/ip_gre.c +1 -1
-     if (skb->len > dev->mtu) {
+     if (skb->len - dev->hard_header_len > dev->mtu) {

Can you guarantee that skb->len > dev_hard_header_len?
It is probably safer to check skb->len > dev->hard_header_len + dev->mtu since that addition isn't going to overflow.

Sure, I will fix it.

Quoted 5 lines

net/ipv4/ip_gre.c static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev, · line 584

Quoted 3 lines
net/ipv4/ip_gre.c +0 -0
              pskb_trim(skb, dev->mtu);
              truncate = true;

Is that pskb_trim() now truncating to the correct size?

You're right, now I should truncate to (dev->mtu + dev_hard_header_len) Thanks
William

#3 lore raw

From: William Tu

Quoted 1 line

Sent: 05 October 2017 22:21

...

Quoted 9 lines
Quoted 6 lines

net/ipv4/ip_gre.c static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev, · line 582

Quoted 2 lines
net/ipv4/ip_gre.c +1 -1
-     if (skb->len > dev->mtu) {
+     if (skb->len - dev->hard_header_len > dev->mtu) {

Can you guarantee that skb->len > dev_hard_header_len?
It is probably safer to check skb->len > dev->hard_header_len + dev->mtu since that addition isn't going to overflow.

Sure, I will fix it.

Quoted 1 line
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
              pskb_trim(skb, dev->mtu);
              truncate = true;

Is that pskb_trim() now truncating to the correct size?

You're right, now I should truncate to (dev->mtu + dev_hard_header_len)

It might be worth caching that length in the dev structure to avoid the arithmetic on every packet.

David

author
#4 lore raw
Quoted 15 lines · David Laight

From: William Tu

Quoted 1 line

Sent: 05 October 2017 22:21

...

Quoted 12 lines
Quoted 6 lines

net/ipv4/ip_gre.c static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev, · line 582

Quoted 2 lines
net/ipv4/ip_gre.c +1 -1
-     if (skb->len > dev->mtu) {
+     if (skb->len - dev->hard_header_len > dev->mtu) {

Can you guarantee that skb->len > dev_hard_header_len?
It is probably safer to check skb->len > dev->hard_header_len + dev->mtu since that addition isn't going to overflow.

Sure, I will fix it.

Quoted 4 lines
Quoted 3 lines
              pskb_trim(skb, dev->mtu);
              truncate = true;
Quoted 9 lines
Quoted 3 lines
Quoted 1 line

Is that pskb_trim() now truncating to the correct size?

You're right, now I should truncate to (dev->mtu + dev_hard_header_len)

It might be worth caching that length in the dev structure to avoid the arithmetic on every packet.

David

Thanks for the advise.
Yes, adding another field in the struct net_device can avoid the arithmetic operation. I'm not sure it's a good idea to add new field since there are already a lot in net_device. Let's wait to see how others think.

William

maintainer
#5 lore raw

From: William Tu <[email protected]>
Date: Fri, 6 Oct 2017 15:09:29 -0700

Quoted 4 lines

Yes, adding another field in the struct net_device can avoid the arithmetic operation. I'm not sure it's a good idea to add new field since there are already a lot in net_device. Let's wait to see how others think.

Why would you add it to net_device when you can add it to ip_tunnel?

author
#6 lore raw
Quoted 10 lines · David Miller

From: William Tu <[email protected]>
Date: Fri, 6 Oct 2017 15:09:29 -0700

Quoted 4 lines

Yes, adding another field in the struct net_device can avoid the arithmetic operation. I'm not sure it's a good idea to add new field since there are already a lot in net_device. Let's wait to see how others think.

Why would you add it to net_device when you can add it to ip_tunnel?

I see. I will add it to ip_tunnel and resubmit the patch. Thanks!