netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ip_forward: Drop frames with attached skb->sk
@ 2015-04-14  5:52 Sebastian Poehn
  2015-04-14  6:07 ` Stephen Hemminger
  2015-04-14  6:33 ` yzhu1
  0 siblings, 2 replies; 9+ messages in thread
From: Sebastian Poehn @ 2015-04-14  5:52 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, fw, eric.dumazet

Initial discussion was:
[FYI] xfrm: Don't lookup sk_policy for timewait sockets

Forwarded frames should not have a socket attached. Especially
tw sockets will lead to panics later-on in the stack.

This was observed with TPROXY assigning a tw socket and broken
policy routing (misconfigured). As a result frame enters
forwarding path instead of input. We cannot solve this in
TPROXY as it cannot know that policy routing is broken.

Signed-off-by: Sebastian Poehn <sebastian.poehn@gmail.com>
---
diff --git a/net/ipv4/ip_forward.c b/net/ipv4/ip_forward.c
index 939992c..2fc3b3e 100644
--- a/net/ipv4/ip_forward.c
+++ b/net/ipv4/ip_forward.c
@@ -82,6 +82,10 @@ int ip_forward(struct sk_buff *skb)
 	if (skb->pkt_type != PACKET_HOST)
 		goto drop;
 
+	/* this should happen neither */
+	if (unlikely(skb->sk))
+		goto drop;
+
 	if (skb_warn_if_lro(skb))
 		goto drop;
--

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

* Re: [PATCH] ip_forward: Drop frames with attached skb->sk
  2015-04-14  5:52 [PATCH] ip_forward: Drop frames with attached skb->sk Sebastian Poehn
@ 2015-04-14  6:07 ` Stephen Hemminger
  2015-04-14  6:18   ` Sebastian Poehn
  2015-04-14  6:33 ` yzhu1
  1 sibling, 1 reply; 9+ messages in thread
From: Stephen Hemminger @ 2015-04-14  6:07 UTC (permalink / raw)
  To: Sebastian Poehn; +Cc: David Miller, netdev, fw, eric.dumazet

On Tue, 14 Apr 2015 07:52:04 +0200
Sebastian Poehn <sebastian.poehn@gmail.com> wrote:

>  
> +	/* this should happen neither */
> +	if (unlikely(skb->sk))
> +		goto drop;
> +

With gcc, all goto's are already treated as unlikely().

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

* Re: [PATCH] ip_forward: Drop frames with attached skb->sk
  2015-04-14  6:07 ` Stephen Hemminger
@ 2015-04-14  6:18   ` Sebastian Poehn
  2015-04-14 16:50     ` David Miller
  0 siblings, 1 reply; 9+ messages in thread
From: Sebastian Poehn @ 2015-04-14  6:18 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: Sebastian Poehn, David Miller, netdev, fw, eric.dumazet

On Mon, 2015-04-13 at 23:07 -0700, Stephen Hemminger wrote:
> On Tue, 14 Apr 2015 07:52:04 +0200
> Sebastian Poehn <sebastian.poehn@gmail.com> wrote:
> 
> >  
> > +	/* this should happen neither */
> > +	if (unlikely(skb->sk))
> > +		goto drop;
> > +
> 
> With gcc, all goto's are already treated as unlikely().

Thanks for that recommendation. But before I re-cook: What about Clang
and ICC?

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

* Re: [PATCH] ip_forward: Drop frames with attached skb->sk
  2015-04-14  5:52 [PATCH] ip_forward: Drop frames with attached skb->sk Sebastian Poehn
  2015-04-14  6:07 ` Stephen Hemminger
@ 2015-04-14  6:33 ` yzhu1
  2015-04-14  6:40   ` Sebastian Poehn
  1 sibling, 1 reply; 9+ messages in thread
From: yzhu1 @ 2015-04-14  6:33 UTC (permalink / raw)
  To: Sebastian Poehn, David Miller; +Cc: netdev, fw, eric.dumazet

On 04/14/2015 01:52 PM, Sebastian Poehn wrote:
> Initial discussion was:
> [FYI] xfrm: Don't lookup sk_policy for timewait sockets
>
> Forwarded frames should not have a socket attached. Especially
> tw sockets will lead to panics later-on in the stack.
>
> This was observed with TPROXY assigning a tw socket and broken
> policy routing (misconfigured). As a result frame enters
> forwarding path instead of input. We cannot solve this in
> TPROXY as it cannot know that policy routing is broken.
>
> Signed-off-by: Sebastian Poehn <sebastian.poehn@gmail.com>
> ---
> diff --git a/net/ipv4/ip_forward.c b/net/ipv4/ip_forward.c
> index 939992c..2fc3b3e 100644
> --- a/net/ipv4/ip_forward.c
> +++ b/net/ipv4/ip_forward.c
> @@ -82,6 +82,10 @@ int ip_forward(struct sk_buff *skb)
>   	if (skb->pkt_type != PACKET_HOST)
>   		goto drop;
>   
> +	/* this should happen neither */
Sorry. "neither" should be "either"?

Zhu Yanjun
> +	if (unlikely(skb->sk))
> +		goto drop;
> +
>   	if (skb_warn_if_lro(skb))
>   		goto drop;
> --
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

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

* Re: [PATCH] ip_forward: Drop frames with attached skb->sk
  2015-04-14  6:33 ` yzhu1
@ 2015-04-14  6:40   ` Sebastian Poehn
  2015-04-14 11:54     ` Eric Dumazet
  0 siblings, 1 reply; 9+ messages in thread
From: Sebastian Poehn @ 2015-04-14  6:40 UTC (permalink / raw)
  To: yzhu1; +Cc: Sebastian Poehn, David Miller, netdev, fw, eric.dumazet

On Tue, 2015-04-14 at 14:33 +0800, yzhu1 wrote:
> On 04/14/2015 01:52 PM, Sebastian Poehn wrote:
> > Initial discussion was:
> > [FYI] xfrm: Don't lookup sk_policy for timewait sockets
> >
> > Forwarded frames should not have a socket attached. Especially
> > tw sockets will lead to panics later-on in the stack.
> >
> > This was observed with TPROXY assigning a tw socket and broken
> > policy routing (misconfigured). As a result frame enters
> > forwarding path instead of input. We cannot solve this in
> > TPROXY as it cannot know that policy routing is broken.
> >
> > Signed-off-by: Sebastian Poehn <sebastian.poehn@gmail.com>
> > ---
> > diff --git a/net/ipv4/ip_forward.c b/net/ipv4/ip_forward.c
> > index 939992c..2fc3b3e 100644
> > --- a/net/ipv4/ip_forward.c
> > +++ b/net/ipv4/ip_forward.c
> > @@ -82,6 +82,10 @@ int ip_forward(struct sk_buff *skb)
> >   	if (skb->pkt_type != PACKET_HOST)
> >   		goto drop;
> >   
> > +	/* this should happen neither */
> Sorry. "neither" should be "either"?

        /* that should never happen */
        if (skb->pkt_type != PACKET_HOST)
                goto drop;

        /* this should happen neither */
        if (unlikely(skb->sk))
                goto drop;

Both of them should never happen.

> 
> Zhu Yanjun
> > +	if (unlikely(skb->sk))
> > +		goto drop;
> > +
> >   	if (skb_warn_if_lro(skb))
> >   		goto drop;
> > --
> >
> >
> > --
> > To unsubscribe from this list: send the line "unsubscribe netdev" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> >
> 

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

* Re: [PATCH] ip_forward: Drop frames with attached skb->sk
  2015-04-14  6:40   ` Sebastian Poehn
@ 2015-04-14 11:54     ` Eric Dumazet
  2015-04-14 18:23       ` David Miller
  0 siblings, 1 reply; 9+ messages in thread
From: Eric Dumazet @ 2015-04-14 11:54 UTC (permalink / raw)
  To: Sebastian Poehn; +Cc: yzhu1, David Miller, netdev, fw

On Tue, 2015-04-14 at 08:40 +0200, Sebastian Poehn wrote:
> On Tue, 2015-04-14 at 14:33 +0800, yzhu1 wrote:
> > On 04/14/2015 01:52 PM, Sebastian Poehn wrote:
> > > Initial discussion was:
> > > [FYI] xfrm: Don't lookup sk_policy for timewait sockets
> > >
> > > Forwarded frames should not have a socket attached. Especially
> > > tw sockets will lead to panics later-on in the stack.
> > >
> > > This was observed with TPROXY assigning a tw socket and broken
> > > policy routing (misconfigured). As a result frame enters
> > > forwarding path instead of input. We cannot solve this in
> > > TPROXY as it cannot know that policy routing is broken.
> > >
> > > Signed-off-by: Sebastian Poehn <sebastian.poehn@gmail.com>
> > > ---
> > > diff --git a/net/ipv4/ip_forward.c b/net/ipv4/ip_forward.c
> > > index 939992c..2fc3b3e 100644
> > > --- a/net/ipv4/ip_forward.c
> > > +++ b/net/ipv4/ip_forward.c
> > > @@ -82,6 +82,10 @@ int ip_forward(struct sk_buff *skb)
> > >   	if (skb->pkt_type != PACKET_HOST)
> > >   		goto drop;
> > >   
> > > +	/* this should happen neither */
> > Sorry. "neither" should be "either"?
> 
>         /* that should never happen */
>         if (skb->pkt_type != PACKET_HOST)
>                 goto drop;
> 
>         /* this should happen neither */
>         if (unlikely(skb->sk))
>                 goto drop;
> 
> Both of them should never happen.

I do not feel the comment is useful in this form.

I would prefer explicit TPROXY reference, maybe using this :

#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TPROXY)
	if (skb->sk)
		goto drop;
#endif

changelog will precisely describes the problem for the curious readers.

Thanks !

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

* Re: [PATCH] ip_forward: Drop frames with attached skb->sk
  2015-04-14  6:18   ` Sebastian Poehn
@ 2015-04-14 16:50     ` David Miller
  0 siblings, 0 replies; 9+ messages in thread
From: David Miller @ 2015-04-14 16:50 UTC (permalink / raw)
  To: sebastian.poehn; +Cc: stephen, netdev, fw, eric.dumazet

From: Sebastian Poehn <sebastian.poehn@gmail.com>
Date: Tue, 14 Apr 2015 08:18:40 +0200

> On Mon, 2015-04-13 at 23:07 -0700, Stephen Hemminger wrote:
>> On Tue, 14 Apr 2015 07:52:04 +0200
>> Sebastian Poehn <sebastian.poehn@gmail.com> wrote:
>> 
>> >  
>> > +	/* this should happen neither */
>> > +	if (unlikely(skb->sk))
>> > +		goto drop;
>> > +
>> 
>> With gcc, all goto's are already treated as unlikely().
> 
> Thanks for that recommendation. But before I re-cook: What about Clang
> and ICC?

I think even if this is the case with gcc, it's good documentation.

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

* Re: [PATCH] ip_forward: Drop frames with attached skb->sk
  2015-04-14 11:54     ` Eric Dumazet
@ 2015-04-14 18:23       ` David Miller
  2015-04-15  7:32         ` Sebastian Poehn
  0 siblings, 1 reply; 9+ messages in thread
From: David Miller @ 2015-04-14 18:23 UTC (permalink / raw)
  To: eric.dumazet; +Cc: sebastian.poehn, Yanjun.Zhu, netdev, fw

From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Tue, 14 Apr 2015 04:54:47 -0700

> On Tue, 2015-04-14 at 08:40 +0200, Sebastian Poehn wrote:
>> On Tue, 2015-04-14 at 14:33 +0800, yzhu1 wrote:
>> > On 04/14/2015 01:52 PM, Sebastian Poehn wrote:
>> > > Initial discussion was:
>> > > [FYI] xfrm: Don't lookup sk_policy for timewait sockets
>> > >
>> > > Forwarded frames should not have a socket attached. Especially
>> > > tw sockets will lead to panics later-on in the stack.
>> > >
>> > > This was observed with TPROXY assigning a tw socket and broken
>> > > policy routing (misconfigured). As a result frame enters
>> > > forwarding path instead of input. We cannot solve this in
>> > > TPROXY as it cannot know that policy routing is broken.
>> > >
>> > > Signed-off-by: Sebastian Poehn <sebastian.poehn@gmail.com>
>> > > ---
>> > > diff --git a/net/ipv4/ip_forward.c b/net/ipv4/ip_forward.c
>> > > index 939992c..2fc3b3e 100644
>> > > --- a/net/ipv4/ip_forward.c
>> > > +++ b/net/ipv4/ip_forward.c
>> > > @@ -82,6 +82,10 @@ int ip_forward(struct sk_buff *skb)
>> > >   	if (skb->pkt_type != PACKET_HOST)
>> > >   		goto drop;
>> > >   
>> > > +	/* this should happen neither */
>> > Sorry. "neither" should be "either"?
>> 
>>         /* that should never happen */
>>         if (skb->pkt_type != PACKET_HOST)
>>                 goto drop;
>> 
>>         /* this should happen neither */
>>         if (unlikely(skb->sk))
>>                 goto drop;
>> 
>> Both of them should never happen.
> 
> I do not feel the comment is useful in this form.
> 
> I would prefer explicit TPROXY reference, maybe using this :
> 
> #if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TPROXY)
> 	if (skb->sk)
> 		goto drop;
> #endif
> 
> changelog will precisely describes the problem for the curious readers.

I suspect we really want this test unconditionally, because we are not able
to safely operate past this point if skb->sk is NULL regardless of what made
it that way.

At least, I'll sleep more soundly at night :)

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

* Re: [PATCH] ip_forward: Drop frames with attached skb->sk
  2015-04-14 18:23       ` David Miller
@ 2015-04-15  7:32         ` Sebastian Poehn
  0 siblings, 0 replies; 9+ messages in thread
From: Sebastian Poehn @ 2015-04-15  7:32 UTC (permalink / raw)
  To: David Miller; +Cc: eric.dumazet, sebastian.poehn, Yanjun.Zhu, netdev, fw

On Tue, 2015-04-14 at 14:23 -0400, David Miller wrote:
> From: Eric Dumazet <eric.dumazet@gmail.com>
> Date: Tue, 14 Apr 2015 04:54:47 -0700
> 
> > On Tue, 2015-04-14 at 08:40 +0200, Sebastian Poehn wrote:
> >> On Tue, 2015-04-14 at 14:33 +0800, yzhu1 wrote:
> >> > On 04/14/2015 01:52 PM, Sebastian Poehn wrote:
> >> > > Initial discussion was:
> >> > > [FYI] xfrm: Don't lookup sk_policy for timewait sockets
> >> > >
> >> > > Forwarded frames should not have a socket attached. Especially
> >> > > tw sockets will lead to panics later-on in the stack.
> >> > >
> >> > > This was observed with TPROXY assigning a tw socket and broken
> >> > > policy routing (misconfigured). As a result frame enters
> >> > > forwarding path instead of input. We cannot solve this in
> >> > > TPROXY as it cannot know that policy routing is broken.
> >> > >
> >> > > Signed-off-by: Sebastian Poehn <sebastian.poehn@gmail.com>
> >> > > ---
> >> > > diff --git a/net/ipv4/ip_forward.c b/net/ipv4/ip_forward.c
> >> > > index 939992c..2fc3b3e 100644
> >> > > --- a/net/ipv4/ip_forward.c
> >> > > +++ b/net/ipv4/ip_forward.c
> >> > > @@ -82,6 +82,10 @@ int ip_forward(struct sk_buff *skb)
> >> > >   	if (skb->pkt_type != PACKET_HOST)
> >> > >   		goto drop;
> >> > >   
> >> > > +	/* this should happen neither */
> >> > Sorry. "neither" should be "either"?
> >> 
> >>         /* that should never happen */
> >>         if (skb->pkt_type != PACKET_HOST)
> >>                 goto drop;
> >> 
> >>         /* this should happen neither */
> >>         if (unlikely(skb->sk))
> >>                 goto drop;
> >> 
> >> Both of them should never happen.
> > 
> > I do not feel the comment is useful in this form.
> > 
> > I would prefer explicit TPROXY reference, maybe using this :
> > 
> > #if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TPROXY)
> > 	if (skb->sk)
> > 		goto drop;
> > #endif
> > 
> > changelog will precisely describes the problem for the curious readers.
> 
> I suspect we really want this test unconditionally, because we are not able
> to safely operate past this point if skb->sk is NULL regardless of what made
> it that way.
> 
> At least, I'll sleep more soundly at night :)

I will send out a v2 patch like that when merge window has closed.
---
 		goto drop;
 
+	if (unlikely(skb->sk))
+		goto drop;
+
 	if (skb_warn_if_lro(skb))
 		goto drop;

---

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

end of thread, other threads:[~2015-04-15  7:32 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-14  5:52 [PATCH] ip_forward: Drop frames with attached skb->sk Sebastian Poehn
2015-04-14  6:07 ` Stephen Hemminger
2015-04-14  6:18   ` Sebastian Poehn
2015-04-14 16:50     ` David Miller
2015-04-14  6:33 ` yzhu1
2015-04-14  6:40   ` Sebastian Poehn
2015-04-14 11:54     ` Eric Dumazet
2015-04-14 18:23       ` David Miller
2015-04-15  7:32         ` Sebastian Poehn

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).