Skip to contentSkip to conversation

release oob skb when received in-band and fix setsockopt ret

PATCH In review Brandon Ho 2 participants 3 messages Mar 27 – Mar 30 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

Brandon Ho

author
#0 lore raw

PATCH 1/1 release oob skb when received in-band and fix setsockopt ret

---
 kernel/evl/net/skb.c | 3 +++
 net/core/skbuff.c    | 2 ++
 net/core/sock.c      | 1 +
 3 files changed, 6 insertions(+)
kernel/evl/net/skb.c +3 -0
index 50090c181..9cd52e3e7 100644
@@ -55,6 +55,9 @@
  *                                                -> free_skb_oob(skb)
  *                        -> dev_kfree_skb(skb)
  *                                -> consume_skb(skb) [1]
+ * 			   |
+ * 			     __consume_stateless_skb(skb)
+ * 						  -> free_skb_oob(skb)
  */
 
 #define SKB_RECYCLING_THRESHOLD 32
net/core/skbuff.c +2 -0
index e532fd636..b4dc5e1c9 100644
@@ -1621,6 +1621,8 @@ EXPORT_SYMBOL(consume_skb);
 void __consume_stateless_skb(struct sk_buff *skb)
 {
 	trace_consume_skb(skb, __builtin_return_address(0));
+	if (skb_release_oob(skb))
+		return;
 	skb_release_data(skb, SKB_CONSUMED);
 	kfree_skbmem(skb);
 }
net/core/sock.c +1 -0
index 3321ff386..70a313c1f 100644
@@ -1721,6 +1721,7 @@ int sk_getsockopt(struct sock *sk, int level, int optname,
 			goto lenout;
 		if (ret != -ENOIOCTLCMD)
 			return ret;
+		ret = 0;
 	}
 
 	memset(&v, 0, sizeof(v));
Signature · 1 line
2.43.0
#1 lore raw
Quoted 26 lines · Brandon Ho
---
 kernel/evl/net/skb.c | 3 +++
 net/core/skbuff.c    | 2 ++
 net/core/sock.c      | 1 +
 3 files changed, 6 insertions(+)
kernel/evl/net/skb.c +3 -0
index 50090c181..9cd52e3e7 100644
@@ -55,6 +55,9 @@
  *                                                -> free_skb_oob(skb)
  *                        -> dev_kfree_skb(skb)
  *                                -> consume_skb(skb) [1]
+ * 			   |
+ * 			     __consume_stateless_skb(skb)
+ * 						  -> free_skb_oob(skb)
  */
 
 #define SKB_RECYCLING_THRESHOLD 32
net/core/skbuff.c +0 -0
index e532fd636..b4dc5e1c9 100644

net/core/skbuff.c EXPORT_SYMBOL(consume_skb); · line 1628

Quoted 8 lines
net/core/skbuff.c +2 -0
@@ -1621,6 +1621,8 @@ EXPORT_SYMBOL(consume_skb);
 void __consume_stateless_skb(struct sk_buff *skb)
 {
 	trace_consume_skb(skb, __builtin_return_address(0));
+	if (skb_release_oob(skb))
+		return;
 	skb_release_data(skb, SKB_CONSUMED);
 	kfree_skbmem(skb);
 }

__consume_stateless_skb() should never be called from the oob stage, or receive any oob-managed skb, which makes the redirection via skb_release_oob() pointless. Did you identify any code path which would hand over oob skbs to skb_consume_udp() for release?

net/core/sock.c int sk_getsockopt(struct sock *sk, int level, int optname, · line 1727

Quoted 12 lines
net/core/sock.c +1 -0
index 3321ff386..70a313c1f 100644
@@ -1721,6 +1721,7 @@ int sk_getsockopt(struct sock *sk, int level, int optname,
 			goto lenout;
 		if (ret != -ENOIOCTLCMD)
 			return ret;
+		ret = 0;
 	}
 
 	memset(&v, 0, sizeof(v));

We don't need this, all following code paths either assign this variable prior to using it, or simply return an immediate value. The original code does not initialize this variable on entry, which confirms the latter.

PS: on a general note, please split patches addressing unrelated topics.

Signature · 1 line
Philippe.

A message that is not in the archive (sent off-list or not yet received): SA1P110MB12788B81A19D6618E2ADA984D352A@SA1P110MB1278.NAMP110.PROD.OUTLOOK.COM

#3 lore raw
Quoted 8 lines · Brandon Ho
Quoted 4 lines

__consume_stateless_skb() should never be called from the oob stage, or receive any oob-managed skb, which makes the redirection via skb_release_oob() pointless. Did you identify any code path which would hand over oob skbs to skb_consume_udp() for release?

The code path I found was udp_recvmsg->skb_consume_udp->__consume_stateless_skb — I would run into ENOMEM without the skb_release_oob.

Ok, I better understand the issue now. You likely have an oob-enabled driver receiving packets, in which case some skbs left by the evl core to the regular netstack for handling may indeed be pulled from oob pools and never released back. So your patch does make sense.

Quoted 8 lines
Quoted 4 lines

We don't need this, all following code paths either assign this variable prior to using it, or simply return an immediate value. The original code does not initialize this variable on entry, which confirms the latter.

Oops sorry I meant to make the patch in sk_setsockopt — that one returns ret at the end. I was getting ENOIOCTLCMD when calling setsockopt for SO_REUSEADDR.

Ok, got it. You must be working with the v6.1.y-cip kernel series, right? v6.12.y-cip, v6.18 and v7.0 don't have this issue (anymore). Word of caution: v6.1.y-cip+{dovetail/evl} is semi-EOL, some kind zombie state. v6.12.y-cip is the current SLTS for us, you may want to upgrade if possible.

Quoted 4 lines
Quoted 1 line

PS: on a general note, please split patches addressing unrelated topics.

Sorry I'll make new patches

Np, you are welcome.

PS: mentioning the target kernel release for those patches may help.

Signature · 1 line
Philippe.