netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Patch net] sit: update dev->needed_headroom in ipip6_tunnel_bind_dev()
@ 2023-04-24  0:34 Cong Wang
  2023-04-24  7:15 ` Leon Romanovsky
  2023-04-24 17:18 ` Kuniyuki Iwashima
  0 siblings, 2 replies; 3+ messages in thread
From: Cong Wang @ 2023-04-24  0:34 UTC (permalink / raw)
  To: netdev; +Cc: Cong Wang, Palash Oswal, Kuniyuki Iwashima, Eric Dumazet

From: Cong Wang <cong.wang@bytedance.com>

When a tunnel device is bound with the underlying device, its
dev->needed_headroom needs to be updated properly. IPv4 tunnels
already do the same in ip_tunnel_bind_dev().

Note, this is targeting for -net and -table, so I'd keep the fix
small. We can refactor and reuse ip_tunnel_bind_dev() for -net-next.

Fixes: 32b8a8e59c9c ("sit: add IPv4 over IPv4 support")
Reported-by: Palash Oswal <oswalpalash@gmail.com>
Link: https://lore.kernel.org/netdev/CAGyP=7fDcSPKu6nttbGwt7RXzE3uyYxLjCSE97J64pRxJP8jPA@mail.gmail.com/
Cc: Kuniyuki Iwashima <kuniyu@amazon.com>
Cc: Eric Dumazet <edumazet@google.com>
Signed-off-by: Cong Wang <cong.wang@bytedance.com>
---
 net/ipv6/sit.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
index 70d81bba5093..3a8f04ba4947 100644
--- a/net/ipv6/sit.c
+++ b/net/ipv6/sit.c
@@ -1096,11 +1096,12 @@ static netdev_tx_t sit_tunnel_xmit(struct sk_buff *skb,
 static void ipip6_tunnel_bind_dev(struct net_device *dev)
 {
 	struct net_device *tdev = NULL;
-	struct ip_tunnel *tunnel;
+	struct ip_tunnel *tunnel = netdev_priv(dev);
 	const struct iphdr *iph;
 	struct flowi4 fl4;
+	int t_hlen = tunnel->hlen + sizeof(struct iphdr);
+	int hlen = LL_MAX_HEADER;
 
-	tunnel = netdev_priv(dev);
 	iph = &tunnel->parms.iph;
 
 	if (iph->daddr) {
@@ -1123,14 +1124,15 @@ static void ipip6_tunnel_bind_dev(struct net_device *dev)
 		tdev = __dev_get_by_index(tunnel->net, tunnel->parms.link);
 
 	if (tdev && !netif_is_l3_master(tdev)) {
-		int t_hlen = tunnel->hlen + sizeof(struct iphdr);
 		int mtu;
 
 		mtu = tdev->mtu - t_hlen;
 		if (mtu < IPV6_MIN_MTU)
 			mtu = IPV6_MIN_MTU;
 		WRITE_ONCE(dev->mtu, mtu);
+		hlen = tdev->hard_header_len + tdev->needed_headroom;
 	}
+	dev->needed_headroom = t_hlen + hlen;
 }
 
 static void ipip6_tunnel_update(struct ip_tunnel *t, struct ip_tunnel_parm *p,
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Patch net] sit: update dev->needed_headroom in ipip6_tunnel_bind_dev()
  2023-04-24  0:34 [Patch net] sit: update dev->needed_headroom in ipip6_tunnel_bind_dev() Cong Wang
@ 2023-04-24  7:15 ` Leon Romanovsky
  2023-04-24 17:18 ` Kuniyuki Iwashima
  1 sibling, 0 replies; 3+ messages in thread
From: Leon Romanovsky @ 2023-04-24  7:15 UTC (permalink / raw)
  To: Cong Wang
  Cc: netdev, Cong Wang, Palash Oswal, Kuniyuki Iwashima, Eric Dumazet

On Sun, Apr 23, 2023 at 05:34:14PM -0700, Cong Wang wrote:
> From: Cong Wang <cong.wang@bytedance.com>
> 
> When a tunnel device is bound with the underlying device, its
> dev->needed_headroom needs to be updated properly. IPv4 tunnels
> already do the same in ip_tunnel_bind_dev().
> 
> Note, this is targeting for -net and -table, so I'd keep the fix
> small. We can refactor and reuse ip_tunnel_bind_dev() for -net-next.

I suggest to put these two lines under --- trailer. There is a little
value of this information in git history.

> 
> Fixes: 32b8a8e59c9c ("sit: add IPv4 over IPv4 support")
> Reported-by: Palash Oswal <oswalpalash@gmail.com>
> Link: https://lore.kernel.org/netdev/CAGyP=7fDcSPKu6nttbGwt7RXzE3uyYxLjCSE97J64pRxJP8jPA@mail.gmail.com/
> Cc: Kuniyuki Iwashima <kuniyu@amazon.com>
> Cc: Eric Dumazet <edumazet@google.com>
> Signed-off-by: Cong Wang <cong.wang@bytedance.com>
> ---
>  net/ipv6/sit.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
> index 70d81bba5093..3a8f04ba4947 100644
> --- a/net/ipv6/sit.c
> +++ b/net/ipv6/sit.c
> @@ -1096,11 +1096,12 @@ static netdev_tx_t sit_tunnel_xmit(struct sk_buff *skb,
>  static void ipip6_tunnel_bind_dev(struct net_device *dev)
>  {
>  	struct net_device *tdev = NULL;
> -	struct ip_tunnel *tunnel;
> +	struct ip_tunnel *tunnel = netdev_priv(dev);
>  	const struct iphdr *iph;
>  	struct flowi4 fl4;
> +	int t_hlen = tunnel->hlen + sizeof(struct iphdr);
> +	int hlen = LL_MAX_HEADER;

Please continue to use reversed Christmas tree in declaration of
variables.

Thanks

>  
> -	tunnel = netdev_priv(dev);
>  	iph = &tunnel->parms.iph;
>  
>  	if (iph->daddr) {
> @@ -1123,14 +1124,15 @@ static void ipip6_tunnel_bind_dev(struct net_device *dev)
>  		tdev = __dev_get_by_index(tunnel->net, tunnel->parms.link);
>  
>  	if (tdev && !netif_is_l3_master(tdev)) {
> -		int t_hlen = tunnel->hlen + sizeof(struct iphdr);
>  		int mtu;
>  
>  		mtu = tdev->mtu - t_hlen;
>  		if (mtu < IPV6_MIN_MTU)
>  			mtu = IPV6_MIN_MTU;
>  		WRITE_ONCE(dev->mtu, mtu);
> +		hlen = tdev->hard_header_len + tdev->needed_headroom;
>  	}
> +	dev->needed_headroom = t_hlen + hlen;
>  }
>  
>  static void ipip6_tunnel_update(struct ip_tunnel *t, struct ip_tunnel_parm *p,
> -- 
> 2.34.1
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Patch net] sit: update dev->needed_headroom in ipip6_tunnel_bind_dev()
  2023-04-24  0:34 [Patch net] sit: update dev->needed_headroom in ipip6_tunnel_bind_dev() Cong Wang
  2023-04-24  7:15 ` Leon Romanovsky
@ 2023-04-24 17:18 ` Kuniyuki Iwashima
  1 sibling, 0 replies; 3+ messages in thread
From: Kuniyuki Iwashima @ 2023-04-24 17:18 UTC (permalink / raw)
  To: xiyou.wangcong; +Cc: cong.wang, edumazet, kuniyu, netdev, oswalpalash

From:   Cong Wang <xiyou.wangcong@gmail.com>
Date:   Sun, 23 Apr 2023 17:34:14 -0700
> From: Cong Wang <cong.wang@bytedance.com>
> 
> When a tunnel device is bound with the underlying device, its
> dev->needed_headroom needs to be updated properly. IPv4 tunnels
> already do the same in ip_tunnel_bind_dev().
> 
> Note, this is targeting for -net and -table, so I'd keep the fix
> small. We can refactor and reuse ip_tunnel_bind_dev() for -net-next.
> 
> Fixes: 32b8a8e59c9c ("sit: add IPv4 over IPv4 support")
> Reported-by: Palash Oswal <oswalpalash@gmail.com>
> Link: https://lore.kernel.org/netdev/CAGyP=7fDcSPKu6nttbGwt7RXzE3uyYxLjCSE97J64pRxJP8jPA@mail.gmail.com/

I was about to post almost same patch today :)

Just for record, the repro was doing like this and with encap-remcsum,
encap_hlen included in hlen overflows the headroom.

  # ip link add sit1 type sit encap gue encap-remcsum mode any dev sit0
  # ip link set sit1 up
  # 
  # python3
  >>> from socket import *
  >>> s = socket(AF_INET, SOCK_DGRAM, 0)
  >>> s.setsockopt(SOL_SOCKET, SO_BINDTODEVICE, b'sit1')
  >>> s.sendto(b'hello', ('192.168.0.1', 10000))

So, I think it's worth mentioning b17f709a2401 ("gue: TX support for
using remote checksum offload option").


> Cc: Kuniyuki Iwashima <kuniyu@amazon.com>
> Cc: Eric Dumazet <edumazet@google.com>
> Signed-off-by: Cong Wang <cong.wang@bytedance.com>
> ---
>  net/ipv6/sit.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
> index 70d81bba5093..3a8f04ba4947 100644
> --- a/net/ipv6/sit.c
> +++ b/net/ipv6/sit.c
> @@ -1096,11 +1096,12 @@ static netdev_tx_t sit_tunnel_xmit(struct sk_buff *skb,
>  static void ipip6_tunnel_bind_dev(struct net_device *dev)
>  {
>  	struct net_device *tdev = NULL;
> -	struct ip_tunnel *tunnel;
> +	struct ip_tunnel *tunnel = netdev_priv(dev);
>  	const struct iphdr *iph;
>  	struct flowi4 fl4;
> +	int t_hlen = tunnel->hlen + sizeof(struct iphdr);
> +	int hlen = LL_MAX_HEADER;
>  
> -	tunnel = netdev_priv(dev);
>  	iph = &tunnel->parms.iph;
>  
>  	if (iph->daddr) {
> @@ -1123,14 +1124,15 @@ static void ipip6_tunnel_bind_dev(struct net_device *dev)
>  		tdev = __dev_get_by_index(tunnel->net, tunnel->parms.link);
>  
>  	if (tdev && !netif_is_l3_master(tdev)) {
> -		int t_hlen = tunnel->hlen + sizeof(struct iphdr);
>  		int mtu;
>  
>  		mtu = tdev->mtu - t_hlen;
>  		if (mtu < IPV6_MIN_MTU)
>  			mtu = IPV6_MIN_MTU;
>  		WRITE_ONCE(dev->mtu, mtu);
> +		hlen = tdev->hard_header_len + tdev->needed_headroom;
>  	}
> +	dev->needed_headroom = t_hlen + hlen;
>  }
>  
>  static void ipip6_tunnel_update(struct ip_tunnel *t, struct ip_tunnel_parm *p,
> -- 
> 2.34.1

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-04-24 17:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-24  0:34 [Patch net] sit: update dev->needed_headroom in ipip6_tunnel_bind_dev() Cong Wang
2023-04-24  7:15 ` Leon Romanovsky
2023-04-24 17:18 ` Kuniyuki Iwashima

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).