All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ip_tunnels: Set tunnel option flag when tunnel metadata is present
@ 2020-11-11  0:16 Yi-Hung Wei
  2020-11-11  0:25 ` Yi-Hung Wei
  2020-11-14  0:13 ` Jakub Kicinski
  0 siblings, 2 replies; 5+ messages in thread
From: Yi-Hung Wei @ 2020-11-11  0:16 UTC (permalink / raw)
  To: davem, kuba, kuznet, yoshfuji, pieter.jansenvanvuuren, netdev; +Cc: Yi-Hung Wei

Currently, we may set the tunnel option flag when the size of metadata
is zero.  For example, we set TUNNEL_GENEVE_OPT in the receive function
no matter the geneve option is present or not.  As this may result in
issues on the tunnel flags consumers, this patch fixes the issue.

Related discussion:
* https://lore.kernel.org/netdev/1604448694-19351-1-git-send-email-yihung.wei@gmail.com/T/#u

Fixes: 256c87c17c53 ("net: check tunnel option type in tunnel flags")
Signed-off-by: Yi-Hung Wei <yihung.wei@gmail.com>
---
 drivers/net/geneve.c     | 3 +--
 include/net/ip_tunnels.h | 7 ++++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/net/geneve.c b/drivers/net/geneve.c
index d07008a818df..1426bfc009bc 100644
--- a/drivers/net/geneve.c
+++ b/drivers/net/geneve.c
@@ -224,8 +224,7 @@ static void geneve_rx(struct geneve_dev *geneve, struct geneve_sock *gs,
 	if (ip_tunnel_collect_metadata() || gs->collect_md) {
 		__be16 flags;
 
-		flags = TUNNEL_KEY | TUNNEL_GENEVE_OPT |
-			(gnvh->oam ? TUNNEL_OAM : 0) |
+		flags = TUNNEL_KEY | (gnvh->oam ? TUNNEL_OAM : 0) |
 			(gnvh->critical ? TUNNEL_CRIT_OPT : 0);
 
 		tun_dst = udp_tun_rx_dst(skb, geneve_get_sk_family(gs), flags,
diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h
index 02ccd32542d0..61620677b034 100644
--- a/include/net/ip_tunnels.h
+++ b/include/net/ip_tunnels.h
@@ -478,9 +478,11 @@ static inline void ip_tunnel_info_opts_set(struct ip_tunnel_info *info,
 					   const void *from, int len,
 					   __be16 flags)
 {
-	memcpy(ip_tunnel_info_opts(info), from, len);
 	info->options_len = len;
-	info->key.tun_flags |= flags;
+	if (len > 0) {
+		memcpy(ip_tunnel_info_opts(info), from, len);
+		info->key.tun_flags |= flags;
+	}
 }
 
 static inline struct ip_tunnel_info *lwt_tun_info(struct lwtunnel_state *lwtstate)
@@ -526,7 +528,6 @@ static inline void ip_tunnel_info_opts_set(struct ip_tunnel_info *info,
 					   __be16 flags)
 {
 	info->options_len = 0;
-	info->key.tun_flags |= flags;
 }
 
 #endif /* CONFIG_INET */
-- 
2.7.4


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

* Re: [PATCH] ip_tunnels: Set tunnel option flag when tunnel metadata is present
  2020-11-11  0:16 [PATCH] ip_tunnels: Set tunnel option flag when tunnel metadata is present Yi-Hung Wei
@ 2020-11-11  0:25 ` Yi-Hung Wei
  2020-11-14  0:13 ` Jakub Kicinski
  1 sibling, 0 replies; 5+ messages in thread
From: Yi-Hung Wei @ 2020-11-11  0:25 UTC (permalink / raw)
  To: David Miller, kuba, kuznet, yoshfuji, pieter.jansenvanvuuren,
	Linux Kernel Network Developers

On Tue, Nov 10, 2020 at 4:17 PM Yi-Hung Wei <yihung.wei@gmail.com> wrote:
>
> Currently, we may set the tunnel option flag when the size of metadata
> is zero.  For example, we set TUNNEL_GENEVE_OPT in the receive function
> no matter the geneve option is present or not.  As this may result in
> issues on the tunnel flags consumers, this patch fixes the issue.
>
> Related discussion:
> * https://lore.kernel.org/netdev/1604448694-19351-1-git-send-email-yihung.wei@gmail.com/T/#u
>
> Fixes: 256c87c17c53 ("net: check tunnel option type in tunnel flags")
> Signed-off-by: Yi-Hung Wei <yihung.wei@gmail.com>
> ---

Sorry that I did not indicate in the subject line of the previous
email.  It should be "[PATCH net]".

-Yi-Hung

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

* Re: [PATCH] ip_tunnels: Set tunnel option flag when tunnel metadata is present
  2020-11-11  0:16 [PATCH] ip_tunnels: Set tunnel option flag when tunnel metadata is present Yi-Hung Wei
  2020-11-11  0:25 ` Yi-Hung Wei
@ 2020-11-14  0:13 ` Jakub Kicinski
  2020-11-14  0:46   ` Daniel Borkmann
  1 sibling, 1 reply; 5+ messages in thread
From: Jakub Kicinski @ 2020-11-14  0:13 UTC (permalink / raw)
  To: Yi-Hung Wei, Pablo Neira Ayuso, Daniel Borkmann
  Cc: davem, kuznet, yoshfuji, pieter.jansenvanvuuren, netdev

On Tue, 10 Nov 2020 16:16:40 -0800 Yi-Hung Wei wrote:
> Currently, we may set the tunnel option flag when the size of metadata
> is zero.  For example, we set TUNNEL_GENEVE_OPT in the receive function
> no matter the geneve option is present or not.  As this may result in
> issues on the tunnel flags consumers, this patch fixes the issue.
> 
> Related discussion:
> * https://lore.kernel.org/netdev/1604448694-19351-1-git-send-email-yihung.wei@gmail.com/T/#u
> 
> Fixes: 256c87c17c53 ("net: check tunnel option type in tunnel flags")
> Signed-off-by: Yi-Hung Wei <yihung.wei@gmail.com>

Seems fine to me, however BPF (and maybe Netfilter?) can set options
passed by user without checking if they are 0 length.

Daniel, Pablo, are you okay with this change or should we limit it to
just fixing the GENEVE oddness?

> diff --git a/drivers/net/geneve.c b/drivers/net/geneve.c
> index d07008a818df..1426bfc009bc 100644
> --- a/drivers/net/geneve.c
> +++ b/drivers/net/geneve.c
> @@ -224,8 +224,7 @@ static void geneve_rx(struct geneve_dev *geneve, struct geneve_sock *gs,
>  	if (ip_tunnel_collect_metadata() || gs->collect_md) {
>  		__be16 flags;
>  
> -		flags = TUNNEL_KEY | TUNNEL_GENEVE_OPT |
> -			(gnvh->oam ? TUNNEL_OAM : 0) |
> +		flags = TUNNEL_KEY | (gnvh->oam ? TUNNEL_OAM : 0) |
>  			(gnvh->critical ? TUNNEL_CRIT_OPT : 0);
>  
>  		tun_dst = udp_tun_rx_dst(skb, geneve_get_sk_family(gs), flags,

For the minimal fix we'd just need the change above, plus:

-               ip_tunnel_info_opts_set(&tun_dst->u.tun_info,
-                                       gnvh->options, gnvh->opt_len * 4,
-                                       TUNNEL_GENEVE_OPT);
+               if (gnvh->opt_len)
+                       ip_tunnel_info_opts_set(&tun_dst->u.tun_info,
+                                               gnvh->options,
+                                               gnvh->opt_len * 4,
+                                               TUNNEL_GENEVE_OPT);

Right?

> diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h
> index 02ccd32542d0..61620677b034 100644
> --- a/include/net/ip_tunnels.h
> +++ b/include/net/ip_tunnels.h
> @@ -478,9 +478,11 @@ static inline void ip_tunnel_info_opts_set(struct ip_tunnel_info *info,
>  					   const void *from, int len,
>  					   __be16 flags)
>  {
> -	memcpy(ip_tunnel_info_opts(info), from, len);
>  	info->options_len = len;
> -	info->key.tun_flags |= flags;
> +	if (len > 0) {
> +		memcpy(ip_tunnel_info_opts(info), from, len);
> +		info->key.tun_flags |= flags;
> +	}
>  }
>  
>  static inline struct ip_tunnel_info *lwt_tun_info(struct lwtunnel_state *lwtstate)
> @@ -526,7 +528,6 @@ static inline void ip_tunnel_info_opts_set(struct ip_tunnel_info *info,
>  					   __be16 flags)
>  {
>  	info->options_len = 0;
> -	info->key.tun_flags |= flags;
>  }
>  
>  #endif /* CONFIG_INET */


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

* Re: [PATCH] ip_tunnels: Set tunnel option flag when tunnel metadata is present
  2020-11-14  0:13 ` Jakub Kicinski
@ 2020-11-14  0:46   ` Daniel Borkmann
  2020-11-14  1:01     ` Jakub Kicinski
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Borkmann @ 2020-11-14  0:46 UTC (permalink / raw)
  To: Jakub Kicinski, Yi-Hung Wei, Pablo Neira Ayuso
  Cc: davem, kuznet, yoshfuji, pieter.jansenvanvuuren, netdev,
	alexei.starovoitov

On 11/14/20 1:13 AM, Jakub Kicinski wrote:
> On Tue, 10 Nov 2020 16:16:40 -0800 Yi-Hung Wei wrote:
>> Currently, we may set the tunnel option flag when the size of metadata
>> is zero.  For example, we set TUNNEL_GENEVE_OPT in the receive function
>> no matter the geneve option is present or not.  As this may result in
>> issues on the tunnel flags consumers, this patch fixes the issue.
>>
>> Related discussion:
>> * https://lore.kernel.org/netdev/1604448694-19351-1-git-send-email-yihung.wei@gmail.com/T/#u
>>
>> Fixes: 256c87c17c53 ("net: check tunnel option type in tunnel flags")
>> Signed-off-by: Yi-Hung Wei <yihung.wei@gmail.com>
> 
> Seems fine to me, however BPF (and maybe Netfilter?) can set options
> passed by user without checking if they are 0 length.
> 
> Daniel, Pablo, are you okay with this change or should we limit it to
> just fixing the GENEVE oddness?

Verifier will guarantee that buffer passed into helper is > 0, so seems
okay from BPF side.

Thanks,
Daniel

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

* Re: [PATCH] ip_tunnels: Set tunnel option flag when tunnel metadata is present
  2020-11-14  0:46   ` Daniel Borkmann
@ 2020-11-14  1:01     ` Jakub Kicinski
  0 siblings, 0 replies; 5+ messages in thread
From: Jakub Kicinski @ 2020-11-14  1:01 UTC (permalink / raw)
  To: Daniel Borkmann
  Cc: Yi-Hung Wei, Pablo Neira Ayuso, davem, kuznet, yoshfuji,
	pieter.jansenvanvuuren, netdev, alexei.starovoitov

On Sat, 14 Nov 2020 01:46:04 +0100 Daniel Borkmann wrote:
> On 11/14/20 1:13 AM, Jakub Kicinski wrote:
> > On Tue, 10 Nov 2020 16:16:40 -0800 Yi-Hung Wei wrote:  
> >> Currently, we may set the tunnel option flag when the size of metadata
> >> is zero.  For example, we set TUNNEL_GENEVE_OPT in the receive function
> >> no matter the geneve option is present or not.  As this may result in
> >> issues on the tunnel flags consumers, this patch fixes the issue.
> >>
> >> Related discussion:
> >> * https://lore.kernel.org/netdev/1604448694-19351-1-git-send-email-yihung.wei@gmail.com/T/#u
> >>
> >> Fixes: 256c87c17c53 ("net: check tunnel option type in tunnel flags")
> >> Signed-off-by: Yi-Hung Wei <yihung.wei@gmail.com>  
> > 
> > Seems fine to me, however BPF (and maybe Netfilter?) can set options
> > passed by user without checking if they are 0 length.
> > 
> > Daniel, Pablo, are you okay with this change or should we limit it to
> > just fixing the GENEVE oddness?  
> 
> Verifier will guarantee that buffer passed into helper is > 0, so seems
> okay from BPF side.

Okay then, the potential change for netfilter is limited to GENEVE
so doesn't move the needle.

Applied, thanks!

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

end of thread, other threads:[~2020-11-14  1:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-11  0:16 [PATCH] ip_tunnels: Set tunnel option flag when tunnel metadata is present Yi-Hung Wei
2020-11-11  0:25 ` Yi-Hung Wei
2020-11-14  0:13 ` Jakub Kicinski
2020-11-14  0:46   ` Daniel Borkmann
2020-11-14  1:01     ` Jakub Kicinski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.