* Re: [PATCH net] udp: drop skb extensions before deferring the free of a consumed skb
2026-11-29 23:56 [PATCH net] udp: drop skb extensions before deferring the free of a consumed skb Andrii Tereshchenko
@ 2026-11-30 23:57 ` netdev-bot+sashiko
0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sashiko @ 2026-11-30 23:57 UTC (permalink / raw)
To: opensource
Cc: willemdebruijn.kernel, davem, edumazet, kuba, pabeni, horms, sd,
steffen.klassert, netdev, stable
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 1 (1) · Medium: 0 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] The new skb_ext_reset(skb) in skb_consume_udp()
(net/ipv4/udp.c:1869) drops extensions only on the head skb.
Pre-existing issues:
- [High] TCP has the same deferred-free problem this patch fixes for UDP,
and it is not fixed.
--
udp: drop skb extensions before deferring the free of a consumed skb
This patch calls skb_ext_reset() in skb_consume_udp() before a consumed,
unshared skb is handed to skb_attempt_defer_free(). The goal is to stop a
datagram's secpath, and the xfrm states it references, from waiting on a
remote CPU's defer list after their network namespace is gone.
Link: https://lore.kernel.org/netdev/20251014060454.1841122-1-edumazet@google.com/
> diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
> index d784faf939c3b..365d924c77c5a 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);
[Severity: High]
Does this cover reassembled datagrams? skb_ext_reset() drops extensions
only on the head skb. Fragments that were not coalesced stay on
skb_shinfo(head)->frag_list, and each keeps its own skb_ext and sec_path.
In tunnel mode the inner packet is fragmented before encapsulation, so
xfrm_input() gives each fragment its own secpath. inet_frag_queue_insert()
only checks that the secpaths match:
net/ipv4/inet_fragment.c:inet_frag_queue_insert() {
...
/* The reassembled skb keeps the first fragment's secpath. */
if (last && !secpath_equal(last, skb))
return IPFRAG_MIXED_SECPATH;
...
}
inet_frag_reasm_finish() then links the non-coalesced fragments into
frag_list and leaves their extensions alone:
net/ipv4/inet_fragment.c:inet_frag_reasm_finish() {
...
if (try_coalesce && skb_try_coalesce(head, fp, &stolen,
&delta)) {
kfree_skb_partial(fp, stolen);
} else {
fp->prev = NULL;
memset(&fp->rbnode, 0, sizeof(fp->rbnode));
fp->sk = NULL;
...
*nextp = fp;
nextp = &fp->next;
}
...
}
nf_ct_frag6_reasm() passes try_coalesce as false. With IPv6 conntrack
defrag active in the netns, every non-head fragment therefore lands on
frag_list. ipv6/reassembly.c passes true, but skb_try_coalesce() can
still fail.
skb_attempt_defer_free(head) then queues the head and its frag_list on
the remote CPU. The fragments' xfrm_state references are dropped only
when that CPU flushes its list:
skb_attempt_defer_free(head)
... remote CPU flush ...
skb_release_data()
kfree_skb_list(frag_list)
skb_ext_put()
With a UDP datagram larger than the inner MTU, can the
xfrm6_tunnel_net_exit() warning and xfrm6_tunnel_destroy() use-after-free
from the commit message still happen?
Do the frag_list skbs need their extensions released here too, or
should skbs like these not be deferred at all?
> skb_attempt_defer_free(skb);
> return;
> }
[Severity: High]
This isn't a bug introduced by this patch, but does TCP have the same
problem? The commit message says secpath_reset() alone is not enough,
and TCP uses only that:
include/net/tcp.h:tcp_cleanup_skb() {
skb_dst_drop(skb);
secpath_reset(skb);
}
If another extension is active and the ext is shared with a clone,
__skb_ext_del() clears the active bit and returns without calling
skb_ext_put_sp():
net/core/skbuff.c:__skb_ext_del() {
...
skb->active_extensions &= ~(1 << id);
if (skb->active_extensions == 0) {
...
}
if (refcount_read(&ext->refcnt) > 1)
return;
...
}
tcp_eat_recv_skb() then defers the free without calling skb_ext_reset():
net/ipv4/tcp.c:tcp_eat_recv_skb() {
...
if (likely(skb->destructor == sock_rfree)) {
sock_rfree(skb);
skb->destructor = NULL;
skb->sk = NULL;
return skb_attempt_defer_free(skb);
}
...
}
Here is one possible sequence:
- A bridged skb keeps SKB_EXT_BRIDGE_NF (or TC_SKB_EXT) through local
delivery.
- xfrm_input() adds SEC_PATH to the same ext.
- packet_rcv() clones the skb for an AF_PACKET tap.
If the packet socket's clone is freed first, the deferred TCP skb holds
the last ext reference. __skb_ext_put() then releases the xfrm states
only when the remote CPU flushes its defer list.
MPTCP already calls skb_ext_reset() in __mptcp_move_skb() before its skbs
reach the defer path. That seems to leave TCP as the only
skb_attempt_defer_free() caller that relies on secpath_reset() alone.
Should tcp_eat_recv_skb() or tcp_cleanup_skb() also call skb_ext_reset()?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/c3d49b69-bd8d-4c34-b02d-60b64d175610%40mid.andrii.net
^ permalink raw reply [flat|nested] 2+ messages in thread