A datagram that recvmsg() has read can wait on another CPU's defer list with its secpath, so its xfrm states can outlive their network namespace. Over an IPv6 IPcomp tunnel, as an unprivileged user in a user namespace: WARNING: net/ipv6/xfrm6_tunnel.c:341 at xfrm6_tunnel_net_exit+0x7a/0x1d0 BUG: KASAN: slab-use-after-free in xfrm6_tunnel_destroy+0x3da/0x470 Write of size 8 at addr ... by task kworker/0:2/40 Drop all extensions before deferring the free. secpath_reset() alone is not enough: if a clone shares the extensions (multicast delivery) and another extension is active, it leaves the secpath in place. Made with an AI coding assistant, reviewed by the submitter. Fixes: 6de1dec1c166 ("udp: do not use skb_release_head_state() before skb_attempt_defer_free()") Link: https://lore.kernel.org/netdev/20251014060454.1841122-1-edumazet@google.com/ Suggested-by: Eric Dumazet Cc: stable@vger.kernel.org Signed-off-by: Andrii Tereshchenko --- Related, not a dependency: Henry Martin's "net: fix xfrm_state refcount underflow and leak in skb_ext COW" (net, v3, 2026-11-25) fixes the refcounts of an inactive secpath slot in skb_ext_maybe_cow(); this patch does not touch skb_ext and applies with or without it. https://lore.kernel.org/netdev/20261125020718.261041-1-bsdhenrymartin@gmail.com/ Found by an AI code review agent. It reproduces on an unmodified kernel, without fault injection; a reproducer is available to the maintainers on request. Tested with it on net and on 6.18.y, and with the UDP and xfrm selftests. net/ipv4/udp.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index d784faf939c3..365d924c77c5 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -1862,6 +1862,11 @@ void skb_consume_udp(struct sock *sk, struct sk_buff *skb, int len) if (!skb_shared(skb)) { skb_orphan(skb); + /* A deferred skb can wait on another CPU's list indefinitely, + * and its secpath holds xfrm states. recvmsg() has already + * used the secpath for IP_CMSG_PASSSEC: drop all extensions. + */ + skb_ext_reset(skb); skb_attempt_defer_free(skb); return; } base-commit: a8710eac64316fc48f29eb3c2ae0746af2100e2e -- 2.53.0