Skip to contentSkip to conversation

xps: must clear sender_cpu before forwarding

PATCH Applied Eric Dumazet 3 participants 6 messages Mar 12, 2015 – Mar 13, 2015 2 messages not in the archive

Subsystems (3)
lore
Share & tools
lore
#2 lore raw

PATCH 1/1 xps: must clear sender_cpu before forwarding

In reply to a message not in the archive

From: Eric Dumazet <[email protected]>

John reported that my previous commit added a regression on his router.

This is because sender_cpu & napi_id share a common location, so get_xps_queue() can see garbage and perform an out of bound access.

We need to make sure sender_cpu is cleared before doing the transmit, otherwise any NIC busy poll enabled (skb_mark_napi_id()) can trigger this bug.

Fixes 2bd82484bb4c ("xps: fix xps for stacked devices")
---
 include/linux/skbuff.h |    7 +++++++
 net/core/skbuff.c      |    2 +-
 net/ipv4/ip_forward.c  |    1 +
 net/ipv6/ip6_output.c  |    1 +
 4 files changed, 10 insertions(+), 1 deletion(-)
include/linux/skbuff.h +7 -0
index 30007afe70b3..f54d6659713a 100644
@@ -948,6 +948,13 @@ static inline void skb_copy_hash(struct sk_buff *to, const struct sk_buff *from)
 	to->l4_hash = from->l4_hash;
 };
 
+static inline void skb_sender_cpu_clear(struct sk_buff *skb)
+{
+#ifdef CONFIG_XPS
+	skb->sender_cpu = 0;
+#endif
+}
+
 #ifdef NET_SKBUFF_DATA_USES_OFFSET
 static inline unsigned char *skb_end_pointer(const struct sk_buff *skb)
 {
net/core/skbuff.c +1 -1
index f80507823531..434e78e5254d 100644
@@ -4173,7 +4173,7 @@ void skb_scrub_packet(struct sk_buff *skb, bool xnet)
 	skb->ignore_df = 0;
 	skb_dst_drop(skb);
 	skb->mark = 0;
-	skb->sender_cpu = 0;
+	skb_sender_cpu_clear(skb);
 	skb_init_secmark(skb);
 	secpath_reset(skb);
 	nf_reset(skb);
net/ipv4/ip_forward.c +1 -0
index 787b3c294ce6..d9bc28ac5d1b 100644
@@ -67,6 +67,7 @@ static int ip_forward_finish(struct sk_buff *skb)
 	if (unlikely(opt->optlen))
 		ip_forward_options(skb);
 
+	skb_sender_cpu_clear(skb);
 	return dst_output(skb);
 }
 
net/ipv6/ip6_output.c +1 -0
index 0a04a37305d5..7e80b61b51ff 100644
@@ -318,6 +318,7 @@ static int ip6_forward_proxy_check(struct sk_buff *skb)
 
 static inline int ip6_forward_finish(struct sk_buff *skb)
 {
+	skb_sender_cpu_clear(skb);
 	return dst_output(skb);
 }
 
maintainer Applied
#3 lore raw

From: Eric Dumazet <[email protected]>
Date: Wed, 11 Mar 2015 18:42:02 -0700

Quoted 8 lines

From: Eric Dumazet <[email protected]>

John reported that my previous commit added a regression on his router.

This is because sender_cpu & napi_id share a common location, so get_xps_queue() can see garbage and perform an out of bound access.

Quoted 8 lines

We need to make sure sender_cpu is cleared before doing the transmit, otherwise any NIC busy poll enabled (skb_mark_napi_id()) can trigger this bug.

Fixes 2bd82484bb4c ("xps: fix xps for stacked devices")

Applied, thanks Eric.

#7 lore raw
In reply to Eric Dumazet

Thanks, Eric. I will test again tomorrow.

-John

Quoted 80 lines · Eric Dumazet

From: Eric Dumazet <[email protected]>

John reported that my previous commit added a regression on his router.

This is because sender_cpu & napi_id share a common location, so get_xps_queue() can see garbage and perform an out of bound access.

We need to make sure sender_cpu is cleared before doing the transmit, otherwise any NIC busy poll enabled (skb_mark_napi_id()) can trigger this bug.

Fixes 2bd82484bb4c ("xps: fix xps for stacked devices")
---
  include/linux/skbuff.h |    7 +++++++
  net/core/skbuff.c      |    2 +-
  net/ipv4/ip_forward.c  |    1 +
  net/ipv6/ip6_output.c  |    1 +
  4 files changed, 10 insertions(+), 1 deletion(-)
include/linux/skbuff.h +7 -0
index 30007afe70b3..f54d6659713a 100644
@@ -948,6 +948,13 @@ static inline void skb_copy_hash(struct sk_buff *to, const struct sk_buff *from)
  	to->l4_hash = from->l4_hash;
  };
 
+static inline void skb_sender_cpu_clear(struct sk_buff *skb)
+{
+#ifdef CONFIG_XPS
+	skb->sender_cpu = 0;
+#endif
+}
+
  #ifdef NET_SKBUFF_DATA_USES_OFFSET
  static inline unsigned char *skb_end_pointer(const struct sk_buff *skb)
  {
net/core/skbuff.c +1 -1
index f80507823531..434e78e5254d 100644
@@ -4173,7 +4173,7 @@ void skb_scrub_packet(struct sk_buff *skb, bool xnet)
  	skb->ignore_df = 0;
  	skb_dst_drop(skb);
  	skb->mark = 0;
-	skb->sender_cpu = 0;
+	skb_sender_cpu_clear(skb);
  	skb_init_secmark(skb);
  	secpath_reset(skb);
  	nf_reset(skb);
net/ipv4/ip_forward.c +1 -0
index 787b3c294ce6..d9bc28ac5d1b 100644
@@ -67,6 +67,7 @@ static int ip_forward_finish(struct sk_buff *skb)
  	if (unlikely(opt->optlen))
  		ip_forward_options(skb);
 
+	skb_sender_cpu_clear(skb);
  	return dst_output(skb);
  }
 
net/ipv6/ip6_output.c +1 -0
index 0a04a37305d5..7e80b61b51ff 100644
@@ -318,6 +318,7 @@ static int ip6_forward_proxy_check(struct sk_buff *skb)
 
  static inline int ip6_forward_finish(struct sk_buff *skb)
  {
+	skb_sender_cpu_clear(skb);
  	return dst_output(skb);
  }
 
#4 lore raw
In reply to David Miller
Quoted 15 lines · David Miller

From: Eric Dumazet <[email protected]>
Date: Wed, 11 Mar 2015 18:42:02 -0700

Quoted 12 lines

From: Eric Dumazet <[email protected]>

John reported that my previous commit added a regression on his router.

This is because sender_cpu & napi_id share a common location, so get_xps_queue() can see garbage and perform an out of bound access.

We need to make sure sender_cpu is cleared before doing the transmit, otherwise any NIC busy poll enabled (skb_mark_napi_id()) can trigger this bug.

Quoted 5 lines
Quoted 4 lines
Fixes 2bd82484bb4c ("xps: fix xps for stacked devices")

Applied, thanks Eric.

Running this patch, I have confirmed that I no longer see panics under the conditions that I saw them previously.

-John

maintainer
#5 lore raw

From: John <[email protected]>
Date: Thu, 12 Mar 2015 19:36:38 -0700

Quoted 2 lines

Running this patch, I have confirmed that I no longer see panics under the conditions that I saw them previously.

Thanks for testing.

#6 lore raw
In reply to John
Quoted 2 lines · John

Running this patch, I have confirmed that I no longer see panics under the conditions that I saw them previously.

Thanks a lot John !