ip_gre: check packet length and mtu correctly in erspan_fb_xmit
Subsystems (3)
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.
--- net/ipv4/ip_gre.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
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) {pskb_trim (skb, dev->mtu); truncate = true; }
Signature · 1 line
2.7.4
From: William Tu
Quoted 17 lines
Sent: 05 October 2017 01:14
Similarly to early patch forerspan_xmit(), theARPHDR_ETHERdevice is the length of the whole ether packet. Soskb->lenshould subtract thedev->hard_header_len.Fixes 1a66a836da63 ("gre: add collect_md mode to ERSPAN tunnel")Signed-off-by William Tu <[email protected]>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
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
-0pskb_trim (skb, dev->mtu); truncate = true;
Is that pskb_trim() now truncating to the correct size?
David
Quoted 21 lines · David Laight
From: William Tu
Quoted 20 lines
Sent: 05 October 2017 01:14
Similarly to early patch forerspan_xmit(), theARPHDR_ETHERdevice is the length of the whole ether packet. Soskb->lenshould subtract thedev->hard_header_len.Fixes 1a66a836da63 ("gre: add collect_md mode to ERSPAN tunnel")Signed-off-by William Tu <[email protected]>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@@ -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 checkskb->len>dev->hard_header_len+dev->mtusince 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
-0pskb_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
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 checkskb->len>dev->hard_header_len+dev->mtusince 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
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 checkskb->len>dev->hard_header_len+dev->mtusince 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
David Miller
maintainerFrom: William Tu <[email protected]>
Date: Fri, 6 Oct 2017 15:09:29 -0700
Quoted 4 lines
Yes, adding another field in the struct
net_devicecan avoid the arithmetic operation. I'm not sure it's a good idea to add new field since there are already a lot innet_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?
Quoted 10 lines · David Miller
From: William Tu <[email protected]>
Date: Fri, 6 Oct 2017 15:09:29 -0700Quoted 4 lines
Yes, adding another field in the struct
net_devicecan avoid the arithmetic operation. I'm not sure it's a good idea to add new field since there are already a lot innet_device. Let's wait to see how others think.Why would you add it to
net_devicewhen you can add it toip_tunnel?
I see. I will add it to ip_tunnel and resubmit the patch. Thanks!