Skip to contentSkip to conversation

sk_buff: drop all skb extensions on free and skb scrubbing

PATCH Applied Florian Westphal 3 participants 5 messages Sep 26, 2019 – Sep 27, 2019

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

PATCH v2 1/1 sk_buff: drop all skb extensions on free and skb scrubbing

Now that we have a 3rd extension, add a new helper that drops the extension space and use it when we need to scrub an sk_buff.

At this time, scrubbing clears secpath and bridge netfilter data, but retains the tc skb extension, after this patch all three get cleared.

NAPI reuse/free assumes we can only have a secpath attached to skb, but it seems better to clear all extensions there as well.

v2: add unlikely hint (Eric Dumazet)

Fixes 95a7233c452a ("net: openvswitch: Set OvS recirc_id from tc chain index")
---
 include/linux/skbuff.h | 9 +++++++++
 net/core/dev.c         | 4 ++--
 net/core/skbuff.c      | 2 +-
 3 files changed, 12 insertions(+), 3 deletions(-)
include/linux/skbuff.h +9 -0
index 907209c0794e..e7d3b1a513ef 100644
@@ -4144,8 +4144,17 @@ static inline void *skb_ext_find(const struct sk_buff *skb, enum skb_ext_id id)
 
 	return NULL;
 }
+
+static inline void skb_ext_reset(struct sk_buff *skb)
+{
+	if (unlikely(skb->active_extensions)) {
+		__skb_ext_put(skb->extensions);
+		skb->active_extensions = 0;
+	}
+}
 #else
 static inline void skb_ext_put(struct sk_buff *skb) {}
+static inline void skb_ext_reset(struct sk_buff *skb) {}
 static inline void skb_ext_del(struct sk_buff *skb, int unused) {}
 static inline void __skb_ext_copy(struct sk_buff *d, const struct sk_buff *s) {}
 static inline void skb_ext_copy(struct sk_buff *dst, const struct sk_buff *s) {}
net/core/dev.c +2 -2
index 71b18e80389f..bf3ed413abaf 100644
@@ -5666,7 +5666,7 @@ EXPORT_SYMBOL(gro_find_complete_by_type);
 static void napi_skb_free_stolen_head(struct sk_buff *skb)
 {
 	skb_dst_drop(skb);
-	secpath_reset(skb);
+	skb_ext_put(skb);
 	kmem_cache_free(skbuff_head_cache, skb);
 }
 
@@ -5733,7 +5733,7 @@ static void napi_reuse_skb(struct napi_struct *napi, struct sk_buff *skb)
 	skb->encapsulation = 0;
 	skb_shinfo(skb)->gso_type = 0;
 	skb->truesize = SKB_TRUESIZE(skb_end_offset(skb));
-	secpath_reset(skb);
+	skb_ext_reset(skb);
 
 	napi->skb = skb;
 }
net/core/skbuff.c +1 -1
index f12e8a050edb..01d65206f4fb 100644
@@ -5119,7 +5119,7 @@ void skb_scrub_packet(struct sk_buff *skb, bool xnet)
 	skb->skb_iif = 0;
 	skb->ignore_df = 0;
 	skb_dst_drop(skb);
-	secpath_reset(skb);
+	skb_ext_reset(skb);
 	nf_reset(skb);
 	nf_reset_trace(skb);
 
Signature · 1 line
2.21.0
#1 lore raw
Quoted 10 lines · Florian Westphal

Now that we have a 3rd extension, add a new helper that drops the extension space and use it when we need to scrub an sk_buff.

}

net/core/skbuff.c +0 -0
index f12e8a050edb..01d65206f4fb 100644

net/core/skbuff.c void skb_scrub_packet(struct sk_buff *skb, bool xnet) · line 5124

Quoted 7 lines
net/core/skbuff.c +1 -1
@@ -5119,7 +5119,7 @@ void skb_scrub_packet(struct sk_buff *skb, bool xnet)
 	skb->skb_iif = 0;
 	skb->ignore_df = 0;
 	skb_dst_drop(skb);
-	secpath_reset(skb);
+	skb_ext_reset(skb);
 	nf_reset(skb);
 	nf_reset_trace(skb);

It is unfortunate nf_reset(skb) will call skb_ext_del(skb, SKB_EXT_BRIDGE_NF), which is useless after skb_ext_reset(skb)

Maybe time for a nf_ct_reset() helper only dealing with nfct.

#2 lore raw
Quoted 10 lines · Eric Dumazet

net/core/skbuff.c void skb_scrub_packet(struct sk_buff *skb, bool xnet) · line 5124

Quoted 4 lines
net/core/skbuff.c +1 -1
-	secpath_reset(skb);
+	skb_ext_reset(skb);
 	nf_reset(skb);
 	nf_reset_trace(skb);

It is unfortunate nf_reset(skb) will call skb_ext_del(skb, SKB_EXT_BRIDGE_NF), which is useless after skb_ext_reset(skb)

Maybe time for a nf_ct_reset() helper only dealing with nfct.

Agree, but that seems more like -next material?

#3 lore raw
Quoted 10 lines · Florian Westphal
Quoted 9 lines · Eric Dumazet

net/core/skbuff.c void skb_scrub_packet(struct sk_buff *skb, bool xnet) · line 5124

Quoted 4 lines
net/core/skbuff.c +1 -1
-	secpath_reset(skb);
+	skb_ext_reset(skb);
 	nf_reset(skb);
 	nf_reset_trace(skb);

It is unfortunate nf_reset(skb) will call skb_ext_del(skb, SKB_EXT_BRIDGE_NF), which is useless after skb_ext_reset(skb)

Quoted 3 lines
Quoted 1 line

Maybe time for a nf_ct_reset() helper only dealing with nfct.

Agree, but that seems more like -next material?

Sure.

maintainer Applied
#4 lore raw
In reply to Florian Westphal

From: Florian Westphal <[email protected]>
Date: Thu, 26 Sep 2019 20:37:05 +0200

Quoted 6 lines

Now that we have a 3rd extension, add a new helper that drops the extension space and use it when we need to scrub an sk_buff.

At this time, scrubbing clears secpath and bridge netfilter data, but retains the tc skb extension, after this patch all three get cleared.

Quoted 7 lines

NAPI reuse/free assumes we can only have a secpath attached to skb, but it seems better to clear all extensions there as well.

v2: add unlikely hint (Eric Dumazet)

Fixes 95a7233c452a ("net: openvswitch: Set OvS recirc_id from tc chain index")

Applied.