Netdev List
 help / color / mirror / Atom feed
From: Dickson Wu via B4 Relay <devnull+dickson.wu.certik.com@kernel.org>
To: netdev@vger.kernel.org
Cc: John Fastabend <john.fastabend@gmail.com>,
	 Jakub Kicinski <kuba@kernel.org>,
	Sabrina Dubroca <sd@queasysnail.net>,
	 "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	 Paolo Abeni <pabeni@redhat.com>,
	Willem de Bruijn <willemb@google.com>,
	 Simon Horman <horms@kernel.org>,
	security@kernel.org
Subject: [PATCH net] tls: rx: fix skb extension reference leak
Date: Fri, 27 Nov 2026 08:47:22 +0000	[thread overview]
Message-ID: <20261127-ktls-net-v1-1-a047fdb54612@certik.com> (raw)

From: Dickson Wu <dickson.wu@certik.com>

tls_strp_load_anchor_with_queue() reuses strp->anchor for every record
and calls skb_copy_header() to copy the header of the first queued skb
onto it. skb_copy_header() goes through __copy_skb_header(), which uses
__skb_ext_copy(): it takes a reference on the source skb's extensions
and overwrites the anchor's extension pointer without dropping the
reference the anchor already held. When the received skbs carry
extensions, for example TC_SKB_EXT set by tc or SKB_EXT_BRIDGE_NF set
by br_netfilter, every reload of the anchor leaks one skb_ext.

skbuff_ext_cache is not charged to the memory cgroup, so the leaked
objects also escape memcg limits.

Drop the anchor's extensions with skb_ext_reset() before copying the
new header.

Fixes: 84c61fe1a75b ("tls: rx: do not use the standard strparser")
Signed-off-by: Dickson Wu <dickson.wu@certik.com>
---
Tested on x86_64 UML with KASAN and kmemleak at v7.4-rc4:
- kTLS RX receiving 5,000 one-byte records whose skbs carried
  TC_SKB_EXT (tc flower in a user namespace) or SKB_EXT_BRIDGE_NF
  (bridge with br_netfilter): skbuff_ext_cache grew by exactly 5,000
  objects and kmemleak reported 4,900 to 4,978 unreferenced objects
  from __skb_ext_alloc. With the fix: no growth and no reports. With the
  fix reverted: 5,000 again.
- The same kTLS traffic without extensions, and plain TCP with
  extensions: no leak before or after the fix.
- On v6.1.193 (bridge path, run from a user namespace) kmemleak
  reported 3,038 leaked skb_ext objects before the fix and none after.
  The patch applies unchanged to 6.1.y, 6.6.y, 6.12.y and 6.18.y.

A reproducer is available if it helps.

This was found and the fix prepared with AI coding tools (OpenAI Codex
agents, with review by Claude). I went over the analysis and the patch
before signing off.

 net/tls/tls_strp.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/tls/tls_strp.c b/net/tls/tls_strp.c
index 53d3256d0..8ad7f339d 100644
--- a/net/tls/tls_strp.c
+++ b/net/tls/tls_strp.c
@@ -475,6 +475,7 @@ static void tls_strp_load_anchor_with_queue(struct tls_strparser *strp, int len)
 
 	skb_shinfo(strp->anchor)->frag_list = first;
 
+	skb_ext_reset(strp->anchor);
 	skb_copy_header(strp->anchor, first);
 	strp->anchor->destructor = NULL;
 
-- 
2.43.0



             reply	other threads:[~2026-11-27 10:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27  8:47 Dickson Wu via B4 Relay [this message]
2026-11-30 16:22 ` [PATCH net] tls: rx: fix skb extension reference leak Sabrina Dubroca

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261127-ktls-net-v1-1-a047fdb54612@certik.com \
    --to=devnull+dickson.wu.certik.com@kernel.org \
    --cc=davem@davemloft.net \
    --cc=dickson.wu@certik.com \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=john.fastabend@gmail.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sd@queasysnail.net \
    --cc=security@kernel.org \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox