Skip to contentSkip to conversation

ip_forward: Drop frames with attached skb->sk

PATCH Superseded Sebastian Poehn 5 participants 9 messages Apr 14, 2015 – Apr 15, 2015

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ip_forward: Drop frames with attached skb->sk

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.

---

net/ipv4/ip_forward.c +4 -1
index 939992c..2fc3b3e 100644
@@ -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;
--
#1 lore raw

net/ipv4/ip_forward.c int ip_forward(struct sk_buff *skb) · line 88

Quoted 5 lines · On Tue, 14 Apr 2015 07:52:04 +0200 Sebastian Poehn <[email protected]>…
net/ipv4/ip_forward.c +4 -0
+	/* this should happen neither */
+	if (unlikely(skb->sk))
+		goto drop;
+

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

#2 lore raw
Quoted 10 lines · Stephen Hemminger

net/ipv4/ip_forward.c int ip_forward(struct sk_buff *skb) · line 88

Quoted 5 lines · On Tue, 14 Apr 2015 07:52:04 +0200 Sebastian Poehn <[email protected]>…
net/ipv4/ip_forward.c +4 -0
+	/* 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?

#4 lore raw
In reply to Sebastian Poehn
Quoted 18 lines · Sebastian Poehn

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.

---

net/ipv4/ip_forward.c +0 -0
index 939992c..2fc3b3e 100644

net/ipv4/ip_forward.c int ip_forward(struct sk_buff *skb) · line 85

Quoted 4 lines
net/ipv4/ip_forward.c +1 -0
@@ -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

Quoted 13 lines
net/ipv4/ip_forward.c +3 -2
+	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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw
Quoted 22 lines · On Tue, 2015-04-14 at 14:33 +0800, yzhu1 wrote:
Quoted 21 lines · Sebastian Poehn

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.

---

net/ipv4/ip_forward.c +0 -0
index 939992c..2fc3b3e 100644
@@ -82,6 +82,10 @@ int ip_forward(struct sk_buff *skb)
  	if (skb->pkt_type != PACKET_HOST)
  		goto drop;
 
Quoted 2 lines

net/ipv4/ip_forward.c int ip_forward(struct sk_buff *skb) · line 85

Quoted 1 line
net/ipv4/ip_forward.c +1 -0
+	/* 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.

Quoted 16 lines

Zhu Yanjun

Quoted 13 lines
net/ipv4/ip_forward.c +3 -2
+	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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw
Quoted 34 lines · Sebastian Poehn
Quoted 22 lines · On Tue, 2015-04-14 at 14:33 +0800, yzhu1 wrote:
Quoted 21 lines · Sebastian Poehn

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.

---

net/ipv4/ip_forward.c +0 -0
index 939992c..2fc3b3e 100644
@@ -82,6 +82,10 @@ int ip_forward(struct sk_buff *skb)
  	if (skb->pkt_type != PACKET_HOST)
  		goto drop;
 
Quoted 2 lines

net/ipv4/ip_forward.c int ip_forward(struct sk_buff *skb) · line 85

Quoted 1 line
net/ipv4/ip_forward.c +1 -0
+	/* 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;
Quoted 1 line

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 !

maintainer
#3 lore raw
In reply to Sebastian Poehn

From: Sebastian Poehn <[email protected]>
Date: Tue, 14 Apr 2015 08:18:40 +0200

Quoted 12 lines · Stephen Hemminger
Quoted 10 lines

net/ipv4/ip_forward.c int ip_forward(struct sk_buff *skb) · line 88

Quoted 5 lines · On Tue, 14 Apr 2015 07:52:04 +0200 Sebastian Poehn <[email protected]>…
net/ipv4/ip_forward.c +4 -0
+	/* this should happen neither */
+	if (unlikely(skb->sk))
+		goto drop;
+

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

Quoted 2 lines

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.

maintainer
#7 lore raw
In reply to Eric Dumazet

From: Eric Dumazet <[email protected]>
Date: Tue, 14 Apr 2015 04:54:47 -0700

Quoted 39 lines · Sebastian Poehn
Quoted 34 lines · On Tue, 2015-04-14 at 14:33 +0800, yzhu1 wrote:
Quoted 22 lines · Sebastian Poehn
Quoted 21 lines

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.

---

net/ipv4/ip_forward.c +0 -0
index 939992c..2fc3b3e 100644
@@ -82,6 +82,10 @@ int ip_forward(struct sk_buff *skb)
  	if (skb->pkt_type != PACKET_HOST)
  		goto drop;
 
Quoted 2 lines

net/ipv4/ip_forward.c int ip_forward(struct sk_buff *skb) · line 85

Quoted 1 line
net/ipv4/ip_forward.c +1 -0
+	/* 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;
Quoted 1 line

Both of them should never happen.

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

Quoted 8 lines

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

#8 lore raw
Quoted 49 lines · David Miller

From: Eric Dumazet <[email protected]>
Date: Tue, 14 Apr 2015 04:54:47 -0700

Quoted 46 lines · Sebastian Poehn
Quoted 34 lines · On Tue, 2015-04-14 at 14:33 +0800, yzhu1 wrote:
Quoted 22 lines · Sebastian Poehn
Quoted 21 lines

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.

---

net/ipv4/ip_forward.c +0 -0
index 939992c..2fc3b3e 100644
@@ -82,6 +82,10 @@ int ip_forward(struct sk_buff *skb)
  	if (skb->pkt_type != PACKET_HOST)
  		goto drop;
 
Quoted 2 lines

net/ipv4/ip_forward.c int ip_forward(struct sk_buff *skb) · line 85

Quoted 1 line
net/ipv4/ip_forward.c +1 -0
+	/* 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;
Quoted 1 line

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

Quoted 7 lines
Quoted 1 line

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;

---