🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
2 messages
2 total messages Started by Dickson Wu via B4 Relay Fri, 27 Nov 2026 08:47
[PATCH net] tls: rx: fix skb extension reference leak
#23490
Author: Dickson Wu via B4 Relay
Date: Fri, 27 Nov 2026 08:47
57 lines
12948 bytes
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
Re: [PATCH net] tls: rx: fix skb extension reference leak
#24691
Author: Sabrina Dubroca
Date: Mon, 30 Nov 2026 16:22
52 lines
14891 bytes
(dropped security@ since this is public)

2026-11-27, 08:47:22 +0000, Dickson Wu via B4 Relay wrote:
> 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.

Once we have
https://lore.kernel.org/all/bd169df0-f88c-417b-91aa-c9b0f11a28b8@mid.andrii.net/
tls_strp will not receive skbs with any extensions (MPTCP and PSP
combined with TLS should not be valid [1]), and it's the only case
where we would still have extensions?

[1] well, for now at least
https://lore.kernel.org/all/cover.1782123118.git.tanggeliang@kylinos.cn/
but keeping the MPTCP extension that late after MPTCP doesn't make
sense so MPTCP should also drop them before the skb reaches TLS.

> 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.

If we go with this, I think it would make more sense to do it as soon
as we're done with the current record, instead of waiting until we
start working on the new one.

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

And probably a DEBUG_NET_WARN_ON_ONCE(skb->active_extensions) in
__copy_skb_header() to help avoid this mistake.

-- 
Sabrina
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads