* [PATCH net] tls: rx: fix skb extension reference leak
@ 2026-11-27 8:47 Dickson Wu via B4 Relay
2026-11-30 16:22 ` Sabrina Dubroca
0 siblings, 1 reply; 2+ messages in thread
From: Dickson Wu via B4 Relay @ 2026-11-27 8:47 UTC (permalink / raw)
To: netdev
Cc: John Fastabend, Jakub Kicinski, Sabrina Dubroca, David S. Miller,
Eric Dumazet, Paolo Abeni, Willem de Bruijn, Simon Horman,
security
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
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH net] tls: rx: fix skb extension reference leak
2026-11-27 8:47 [PATCH net] tls: rx: fix skb extension reference leak Dickson Wu via B4 Relay
@ 2026-11-30 16:22 ` Sabrina Dubroca
0 siblings, 0 replies; 2+ messages in thread
From: Sabrina Dubroca @ 2026-11-30 16:22 UTC (permalink / raw)
To: dickson.wu
Cc: netdev, John Fastabend, Jakub Kicinski, David S. Miller,
Eric Dumazet, Paolo Abeni, Willem de Bruijn, Simon Horman
(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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-30 16:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 8:47 [PATCH net] tls: rx: fix skb extension reference leak Dickson Wu via B4 Relay
2026-11-30 16:22 ` Sabrina Dubroca
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox