All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] ip_tunnel: fix potential issue in ip_tunnel_rcv
@ 2017-06-08  0:57 Haishuang Yan
  2017-06-08  0:57 ` [PATCH v2 2/2] ip6_tunnel: fix potential issue in __ip6_tnl_rcv Haishuang Yan
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Haishuang Yan @ 2017-06-08  0:57 UTC (permalink / raw)
  To: =David S. Miller, Alexey Kuznetsov, James Morris,
	Hideaki YOSHIFUJI, Patrick McHardy
  Cc: netdev, linux-kernel, Haishuang Yan, Pravin B Shelar, Haishuang Yan

When ip_tunnel_rcv fails, the tun_dst won't be freed, so move
skb_dst_set to begin and tun_dst would be freed by kfree_skb.

CC: Pravin B Shelar <pshelar@nicira.com>
Fixes: 2e15ea390e6f ("ip_gre: Add support to collect tunnel metadata.")
Signed-off-by: Haishuang Yan <yanhaishuang@cmss.chinamobile.com390e>
---
 net/ipv4/ip_tunnel.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c
index b878ecb..27fc20f 100644
--- a/net/ipv4/ip_tunnel.c
+++ b/net/ipv4/ip_tunnel.c
@@ -386,6 +386,9 @@ int ip_tunnel_rcv(struct ip_tunnel *tunnel, struct sk_buff *skb,
 	const struct iphdr *iph = ip_hdr(skb);
 	int err;
 
+	if (tun_dst)
+		skb_dst_set(skb, (struct dst_entry *)tun_dst);
+
 #ifdef CONFIG_NET_IPGRE_BROADCAST
 	if (ipv4_is_multicast(iph->daddr)) {
 		tunnel->dev->stats.multicast++;
@@ -439,9 +442,6 @@ int ip_tunnel_rcv(struct ip_tunnel *tunnel, struct sk_buff *skb,
 		skb->dev = tunnel->dev;
 	}
 
-	if (tun_dst)
-		skb_dst_set(skb, (struct dst_entry *)tun_dst);
-
 	gro_cells_receive(&tunnel->gro_cells, skb);
 	return 0;
 
-- 
1.8.3.1

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

* [PATCH v2 2/2] ip6_tunnel: fix potential issue in __ip6_tnl_rcv
  2017-06-08  0:57 [PATCH v2 1/2] ip_tunnel: fix potential issue in ip_tunnel_rcv Haishuang Yan
@ 2017-06-08  0:57 ` Haishuang Yan
  2017-06-08  2:23   ` Eric Dumazet
  2017-06-08  2:49   ` Alexei Starovoitov
  2017-06-08  2:13 ` [PATCH v2 1/2] ip_tunnel: fix potential issue in ip_tunnel_rcv Pravin Shelar
  2017-06-08  2:21 ` Eric Dumazet
  2 siblings, 2 replies; 9+ messages in thread
From: Haishuang Yan @ 2017-06-08  0:57 UTC (permalink / raw)
  To: =David S. Miller, Alexey Kuznetsov, James Morris,
	Hideaki YOSHIFUJI, Patrick McHardy
  Cc: netdev, linux-kernel, Haishuang Yan, Alexei Starovoitov

When __ip6_tnl_rcv fails, the tun_dst won't be freed, so move
skb_dst_set to begin and tun_dst would be freed by kfree_skb.

CC: Alexei Starovoitov <ast@fb.com>
Fixes: 8d79266bc48c ("ip6_tunnel: add collect_md mode to IPv6 tunnels")
Signed-off-by: Haishuang Yan <yanhaishuang@cmss.chinamobile.com>
---
 net/ipv6/ip6_tunnel.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
index 9b37f97..bf45f1b 100644
--- a/net/ipv6/ip6_tunnel.c
+++ b/net/ipv6/ip6_tunnel.c
@@ -789,6 +789,9 @@ static int __ip6_tnl_rcv(struct ip6_tnl *tunnel, struct sk_buff *skb,
 	const struct ipv6hdr *ipv6h = ipv6_hdr(skb);
 	int err;
 
+	if (tun_dst)
+		skb_dst_set(skb, (struct dst_entry *)tun_dst);
+
 	if ((!(tpi->flags & TUNNEL_CSUM) &&
 	     (tunnel->parms.i_flags & TUNNEL_CSUM)) ||
 	    ((tpi->flags & TUNNEL_CSUM) &&
@@ -852,9 +855,6 @@ static int __ip6_tnl_rcv(struct ip6_tnl *tunnel, struct sk_buff *skb,
 
 	skb_scrub_packet(skb, !net_eq(tunnel->net, dev_net(tunnel->dev)));
 
-	if (tun_dst)
-		skb_dst_set(skb, (struct dst_entry *)tun_dst);
-
 	gro_cells_receive(&tunnel->gro_cells, skb);
 	return 0;
 
-- 
1.8.3.1

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

* Re: [PATCH v2 1/2] ip_tunnel: fix potential issue in ip_tunnel_rcv
  2017-06-08  0:57 [PATCH v2 1/2] ip_tunnel: fix potential issue in ip_tunnel_rcv Haishuang Yan
  2017-06-08  0:57 ` [PATCH v2 2/2] ip6_tunnel: fix potential issue in __ip6_tnl_rcv Haishuang Yan
@ 2017-06-08  2:13 ` Pravin Shelar
  2017-06-08  3:07   ` 严海双
  2017-06-08  3:15   ` Eric Dumazet
  2017-06-08  2:21 ` Eric Dumazet
  2 siblings, 2 replies; 9+ messages in thread
From: Pravin Shelar @ 2017-06-08  2:13 UTC (permalink / raw)
  To: Haishuang Yan
  Cc: =David S. Miller, Alexey Kuznetsov, James Morris,
	Hideaki YOSHIFUJI, Patrick McHardy,
	Linux Kernel Network Developers, linux-kernel, Pravin B Shelar,
	Haishuang Yan

On Wed, Jun 7, 2017 at 5:57 PM, Haishuang Yan
<yanhaishuang@cmss.chinamobile.com> wrote:
> When ip_tunnel_rcv fails, the tun_dst won't be freed, so move
> skb_dst_set to begin and tun_dst would be freed by kfree_skb.
>
> CC: Pravin B Shelar <pshelar@nicira.com>
> Fixes: 2e15ea390e6f ("ip_gre: Add support to collect tunnel metadata.")
> Signed-off-by: Haishuang Yan <yanhaishuang@cmss.chinamobile.com390e>
> ---
>  net/ipv4/ip_tunnel.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c
> index b878ecb..27fc20f 100644
> --- a/net/ipv4/ip_tunnel.c
> +++ b/net/ipv4/ip_tunnel.c
> @@ -386,6 +386,9 @@ int ip_tunnel_rcv(struct ip_tunnel *tunnel, struct sk_buff *skb,
>         const struct iphdr *iph = ip_hdr(skb);
>         int err;
>
> +       if (tun_dst)
> +               skb_dst_set(skb, (struct dst_entry *)tun_dst);
> +
If dst is set so early, skb_scrub_packet() would remove the tunnel dst
reference.
It is better to call skb_dst_drop() from error code path.

>  #ifdef CONFIG_NET_IPGRE_BROADCAST
>         if (ipv4_is_multicast(iph->daddr)) {
>                 tunnel->dev->stats.multicast++;
> @@ -439,9 +442,6 @@ int ip_tunnel_rcv(struct ip_tunnel *tunnel, struct sk_buff *skb,
>                 skb->dev = tunnel->dev;
>         }
>
> -       if (tun_dst)
> -               skb_dst_set(skb, (struct dst_entry *)tun_dst);
> -
>         gro_cells_receive(&tunnel->gro_cells, skb);
>         return 0;
>
> --
> 1.8.3.1
>
>
>

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

* Re: [PATCH v2 1/2] ip_tunnel: fix potential issue in ip_tunnel_rcv
  2017-06-08  0:57 [PATCH v2 1/2] ip_tunnel: fix potential issue in ip_tunnel_rcv Haishuang Yan
  2017-06-08  0:57 ` [PATCH v2 2/2] ip6_tunnel: fix potential issue in __ip6_tnl_rcv Haishuang Yan
  2017-06-08  2:13 ` [PATCH v2 1/2] ip_tunnel: fix potential issue in ip_tunnel_rcv Pravin Shelar
@ 2017-06-08  2:21 ` Eric Dumazet
  2 siblings, 0 replies; 9+ messages in thread
From: Eric Dumazet @ 2017-06-08  2:21 UTC (permalink / raw)
  To: Haishuang Yan; +Cc: netdev, linux-kernel, Pravin B Shelar, Haishuang Yan

On Thu, 2017-06-08 at 08:57 +0800, Haishuang Yan wrote:
> When ip_tunnel_rcv fails, the tun_dst won't be freed, so move
> skb_dst_set to begin and tun_dst would be freed by kfree_skb.
> 
> CC: Pravin B Shelar <pshelar@nicira.com>
> Fixes: 2e15ea390e6f ("ip_gre: Add support to collect tunnel metadata.")
> Signed-off-by: Haishuang Yan <yanhaishuang@cmss.chinamobile.com390e>
> ---

Acked-by: Eric Dumazet <edumazet@google.com>

Thanks a lot.

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

* Re: [PATCH v2 2/2] ip6_tunnel: fix potential issue in __ip6_tnl_rcv
  2017-06-08  0:57 ` [PATCH v2 2/2] ip6_tunnel: fix potential issue in __ip6_tnl_rcv Haishuang Yan
@ 2017-06-08  2:23   ` Eric Dumazet
  2017-06-08  2:49   ` Alexei Starovoitov
  1 sibling, 0 replies; 9+ messages in thread
From: Eric Dumazet @ 2017-06-08  2:23 UTC (permalink / raw)
  To: Haishuang Yan; +Cc: netdev

On Thu, 2017-06-08 at 08:57 +0800, Haishuang Yan wrote:
> When __ip6_tnl_rcv fails, the tun_dst won't be freed, so move
> skb_dst_set to begin and tun_dst would be freed by kfree_skb.
> 
> CC: Alexei Starovoitov <ast@fb.com>
> Fixes: 8d79266bc48c ("ip6_tunnel: add collect_md mode to IPv6 tunnels")
> Signed-off-by: Haishuang Yan <yanhaishuang@cmss.chinamobile.com>
> ---

Acked-by: Eric Dumazet <edumazet@google.com>

Thanks !

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

* Re: [PATCH v2 2/2] ip6_tunnel: fix potential issue in __ip6_tnl_rcv
  2017-06-08  0:57 ` [PATCH v2 2/2] ip6_tunnel: fix potential issue in __ip6_tnl_rcv Haishuang Yan
  2017-06-08  2:23   ` Eric Dumazet
@ 2017-06-08  2:49   ` Alexei Starovoitov
  1 sibling, 0 replies; 9+ messages in thread
From: Alexei Starovoitov @ 2017-06-08  2:49 UTC (permalink / raw)
  To: Haishuang Yan
  Cc: =David S. Miller, Alexey Kuznetsov, James Morris,
	Hideaki YOSHIFUJI, Patrick McHardy, netdev, linux-kernel,
	Alexei Starovoitov

On Thu, Jun 08, 2017 at 08:57:56AM +0800, Haishuang Yan wrote:
> When __ip6_tnl_rcv fails, the tun_dst won't be freed, so move
> skb_dst_set to begin and tun_dst would be freed by kfree_skb.
> 
> CC: Alexei Starovoitov <ast@fb.com>
> Fixes: 8d79266bc48c ("ip6_tunnel: add collect_md mode to IPv6 tunnels")
> Signed-off-by: Haishuang Yan <yanhaishuang@cmss.chinamobile.com>

Good catch. Thanks!
Acked-by: Alexei Starovoitov <ast@kernel.org>

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

* Re: [PATCH v2 1/2] ip_tunnel: fix potential issue in ip_tunnel_rcv
  2017-06-08  2:13 ` [PATCH v2 1/2] ip_tunnel: fix potential issue in ip_tunnel_rcv Pravin Shelar
@ 2017-06-08  3:07   ` 严海双
  2017-06-08  3:15   ` Eric Dumazet
  1 sibling, 0 replies; 9+ messages in thread
From: 严海双 @ 2017-06-08  3:07 UTC (permalink / raw)
  To: Pravin Shelar
  Cc: =David S. Miller, Alexey Kuznetsov, James Morris,
	Hideaki YOSHIFUJI, Patrick McHardy,
	Linux Kernel Network Developers, LKML, Pravin B Shelar



> On 8 Jun 2017, at 10:13 AM, Pravin Shelar <pshelar@ovn.org> wrote:
> 
> On Wed, Jun 7, 2017 at 5:57 PM, Haishuang Yan
> <yanhaishuang@cmss.chinamobile.com> wrote:
>> When ip_tunnel_rcv fails, the tun_dst won't be freed, so move
>> skb_dst_set to begin and tun_dst would be freed by kfree_skb.
>> 
>> CC: Pravin B Shelar <pshelar@nicira.com>
>> Fixes: 2e15ea390e6f ("ip_gre: Add support to collect tunnel metadata.")
>> Signed-off-by: Haishuang Yan <yanhaishuang@cmss.chinamobile.com390e>
>> ---
>> net/ipv4/ip_tunnel.c | 6 +++---
>> 1 file changed, 3 insertions(+), 3 deletions(-)
>> 
>> diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c
>> index b878ecb..27fc20f 100644
>> --- a/net/ipv4/ip_tunnel.c
>> +++ b/net/ipv4/ip_tunnel.c
>> @@ -386,6 +386,9 @@ int ip_tunnel_rcv(struct ip_tunnel *tunnel, struct sk_buff *skb,
>>        const struct iphdr *iph = ip_hdr(skb);
>>        int err;
>> 
>> +       if (tun_dst)
>> +               skb_dst_set(skb, (struct dst_entry *)tun_dst);
>> +
> If dst is set so early, skb_scrub_packet() would remove the tunnel dst
> reference.
> It is better to call skb_dst_drop() from error code path.

Yes, I will change it in v3 commit, thanks!

> 
>> #ifdef CONFIG_NET_IPGRE_BROADCAST
>>        if (ipv4_is_multicast(iph->daddr)) {
>>                tunnel->dev->stats.multicast++;
>> @@ -439,9 +442,6 @@ int ip_tunnel_rcv(struct ip_tunnel *tunnel, struct sk_buff *skb,
>>                skb->dev = tunnel->dev;
>>        }
>> 
>> -       if (tun_dst)
>> -               skb_dst_set(skb, (struct dst_entry *)tun_dst);
>> -
>>        gro_cells_receive(&tunnel->gro_cells, skb);
>>        return 0;
>> 
>> --
>> 1.8.3.1
>> 
>> 
>> 
> 

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

* Re: [PATCH v2 1/2] ip_tunnel: fix potential issue in ip_tunnel_rcv
  2017-06-08  2:13 ` [PATCH v2 1/2] ip_tunnel: fix potential issue in ip_tunnel_rcv Pravin Shelar
  2017-06-08  3:07   ` 严海双
@ 2017-06-08  3:15   ` Eric Dumazet
  2017-06-08  4:06     ` Pravin Shelar
  1 sibling, 1 reply; 9+ messages in thread
From: Eric Dumazet @ 2017-06-08  3:15 UTC (permalink / raw)
  To: Pravin Shelar
  Cc: Haishuang Yan, =David S. Miller, Alexey Kuznetsov, James Morris,
	Hideaki YOSHIFUJI, Patrick McHardy,
	Linux Kernel Network Developers, linux-kernel, Pravin B Shelar,
	Haishuang Yan

On Wed, 2017-06-07 at 19:13 -0700, Pravin Shelar wrote:
> On Wed, Jun 7, 2017 at 5:57 PM, Haishuang Yan
> <yanhaishuang@cmss.chinamobile.com> wrote:
> > When ip_tunnel_rcv fails, the tun_dst won't be freed, so move
> > skb_dst_set to begin and tun_dst would be freed by kfree_skb.
> >
> > CC: Pravin B Shelar <pshelar@nicira.com>
> > Fixes: 2e15ea390e6f ("ip_gre: Add support to collect tunnel metadata.")
> > Signed-off-by: Haishuang Yan <yanhaishuang@cmss.chinamobile.com390e>
> > ---
> >  net/ipv4/ip_tunnel.c | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c
> > index b878ecb..27fc20f 100644
> > --- a/net/ipv4/ip_tunnel.c
> > +++ b/net/ipv4/ip_tunnel.c
> > @@ -386,6 +386,9 @@ int ip_tunnel_rcv(struct ip_tunnel *tunnel, struct sk_buff *skb,
> >         const struct iphdr *iph = ip_hdr(skb);
> >         int err;
> >
> > +       if (tun_dst)
> > +               skb_dst_set(skb, (struct dst_entry *)tun_dst);
> > +
> If dst is set so early, skb_scrub_packet() would remove the tunnel dst
> reference.
> It is better to call skb_dst_drop() from error code path.

Do we really want to keep a dst from another namespace if
skb_scrub_packet() is called with xnet=true ?

 

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

* Re: [PATCH v2 1/2] ip_tunnel: fix potential issue in ip_tunnel_rcv
  2017-06-08  3:15   ` Eric Dumazet
@ 2017-06-08  4:06     ` Pravin Shelar
  0 siblings, 0 replies; 9+ messages in thread
From: Pravin Shelar @ 2017-06-08  4:06 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: Haishuang Yan, =David S. Miller, Alexey Kuznetsov, James Morris,
	Hideaki YOSHIFUJI, Patrick McHardy,
	Linux Kernel Network Developers, linux-kernel, Pravin B Shelar,
	Haishuang Yan

On Wed, Jun 7, 2017 at 8:15 PM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
> On Wed, 2017-06-07 at 19:13 -0700, Pravin Shelar wrote:
>> On Wed, Jun 7, 2017 at 5:57 PM, Haishuang Yan
>> <yanhaishuang@cmss.chinamobile.com> wrote:
>> > When ip_tunnel_rcv fails, the tun_dst won't be freed, so move
>> > skb_dst_set to begin and tun_dst would be freed by kfree_skb.
>> >
>> > CC: Pravin B Shelar <pshelar@nicira.com>
>> > Fixes: 2e15ea390e6f ("ip_gre: Add support to collect tunnel metadata.")
>> > Signed-off-by: Haishuang Yan <yanhaishuang@cmss.chinamobile.com390e>
>> > ---
>> >  net/ipv4/ip_tunnel.c | 6 +++---
>> >  1 file changed, 3 insertions(+), 3 deletions(-)
>> >
>> > diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c
>> > index b878ecb..27fc20f 100644
>> > --- a/net/ipv4/ip_tunnel.c
>> > +++ b/net/ipv4/ip_tunnel.c
>> > @@ -386,6 +386,9 @@ int ip_tunnel_rcv(struct ip_tunnel *tunnel, struct sk_buff *skb,
>> >         const struct iphdr *iph = ip_hdr(skb);
>> >         int err;
>> >
>> > +       if (tun_dst)
>> > +               skb_dst_set(skb, (struct dst_entry *)tun_dst);
>> > +
>> If dst is set so early, skb_scrub_packet() would remove the tunnel dst
>> reference.
>> It is better to call skb_dst_drop() from error code path.
>
> Do we really want to keep a dst from another namespace if
> skb_scrub_packet() is called with xnet=true ?
>
tun_dst is allocated in same namespace. It is required for LWT to work.

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

end of thread, other threads:[~2017-06-08  4:06 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-08  0:57 [PATCH v2 1/2] ip_tunnel: fix potential issue in ip_tunnel_rcv Haishuang Yan
2017-06-08  0:57 ` [PATCH v2 2/2] ip6_tunnel: fix potential issue in __ip6_tnl_rcv Haishuang Yan
2017-06-08  2:23   ` Eric Dumazet
2017-06-08  2:49   ` Alexei Starovoitov
2017-06-08  2:13 ` [PATCH v2 1/2] ip_tunnel: fix potential issue in ip_tunnel_rcv Pravin Shelar
2017-06-08  3:07   ` 严海双
2017-06-08  3:15   ` Eric Dumazet
2017-06-08  4:06     ` Pravin Shelar
2017-06-08  2:21 ` Eric Dumazet

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.