๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #24857

Re: [PATCH net] udp: drop skb extensions before deferring the free of a consumed skb

#24857
From: netdev-bot+sashiko
Date: Mon, 30 Nov 2026 23:57
164 lines
13169 bytes
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
Technical Details
Message-ID: <179608303318.3146.3152537105022972219@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374543-linux-kernel-netdev=dewy.ru
References: <c3d49b69-bd8d-4c34-b02d-60b64d175610@mid.andrii.net>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374543-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] udp: drop skb extensions before deferring the free of
 a consumed skb
Date: Mon, 30 Nov 2026 23:57:13 +0000
Organization: Usenet Network
Message-ID: <179608303318.3146.3152537105022972219@kernel.org>
References: <c3d49b69-bd8d-4c34-b02d-60b64d175610@mid.andrii.net>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1570128"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:KyrzDVrBSkp7aSDAqBUooAi7xcA= sha256:QMKVUzTcub8stuHlIv2qDV7SU8pnTMALzZ6EfLHIGiE=
	sha1:KH7PhwP1JSUeF62OdfGEC6H9958= sha256:tey/hpr/qXr1CHMKhcDX9/gZbBfxdevUJNUYP1RIPsU=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 4AE4F126017; Tue,  1 Dec 2026 02:57:35 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.501
X-Spam-Status: No, score=-3.501 tagged_above=-9999 required=6.31
	tests=[DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
	autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id ICa9-aGrWJAu;
	Tue,  1 Dec 2026 02:57:27 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-374543-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 7E160126013; Tue,  1 Dec 2026 02:57:18 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id 3EAD2262B5; Mon, 30 Nov 2026 23:57:16 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796083035;
	b=jWgasV7s0x7ntqwQjJLFsY3GNRWvpzEvC6zI9PqxOzwdyP1kEom6PfdOglKGMLpHwHzp
	 eOSN7ohLIM5MQqo0xQnGZf8DqFqenQ7ms8IglDtVlzCYDzbs/VeLbiCWdF/hxX0nslh98
	 DlyuwzqS9Fp9ru18BEINPqSm+9GC9Dp1mRmi4+acmnocnhtGQ43LLA82Ro4zPES96Ffsz
	 bmoksX47VHmrDkB/aW7hlVAzaO4iMUQ99ltCq2apvcSnZQO5inwCbq8Nup4syN7qjNpv9
	 sud93tgL9Kp/PIKFpt0sQPct9WslVPgafuh+RFfff3mYyfKVWxsDnkzYUwaCdnyu3LQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796083035;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=sKDNGXqlBTFmhKZM9dBGds0J/b7Els+Pe7+xBAR57E4=;
	b=BiNFwiniE++uv29oUKVU8rMyzqzfmb1an+vEA6SKUmPUH0J7Pemyc6XIVOHiDIXQQMhw
	 s+p5PY3W4KVyyDFrANcjh1Hf4LGBdMckOR2d10jrSM6aoDDSm1NG5nhs+wmz44S3c082T
	 Ezs1I9VNOgHi/tC5uKgo18cruUkM7UoyeusWCjY/hvrHQiKdSVACxvijdAaS5aJjX7i43
	 RSefjwQ0kg69iCg7OdCC1wUrdrStfdvDNRUJlAjoxt3SvGB2aPHOWO5kq5JDwG5L1UA25
	 X2ggQePDrqZWD9OeGZgkA6mZCxnq4Msuph7PCxak3gTFrhMeGaJDypPl/FI5NzPQmPg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="XcY/jNoW";
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id A5E8A606A32E;
	Mon, 30 Nov 2026 23:57:15 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=XcY/jNoW
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796083034;
	b=evwRxkjtcwHZ5xWKAOubUBEfWx3TcCvs3ZyS6wIS4Ic/sBsB+qlxsTOrsgaKzHH3N7x5
	 J2BJofOsS5i9KDP7ym3Ibx1lJfwYBXG7zoMVAm8jWH/8KeOR/sBwS21Kuy0JF/gwrrgKc
	 qIRVeOrqv5fE64pEcXBSuf6CNxlcvGgxiTXUkG8f/GBrllRNlTJ1VRC7l3m0Z8Dv4wL66
	 2bBNJz8WdmlC600GykAk5sR0QBod2UheBWQQCgsS7Q4z0EoUkIwe5HZ0XRuKfJyqqsXJx
	 SASdb4PFyaJM5V9/Ajey/cQ/Abw+yfakcV2WkpbhYDbze2HqHJ8uZyKZNWwjBPt79Lg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796083034;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=sKDNGXqlBTFmhKZM9dBGds0J/b7Els+Pe7+xBAR57E4=;
	b=cbhCztXy5HLJZoaF4c84OIY7gxEvs44o2Kx9gtzSUjpSSYF37C36MVQjHZJ4MxfrVs+L
	 GtAfRUX+MXn2eXesRq5rjOKA8A6lMPzxV0zF2fqYSo0igkaGpDGczMWq13CDhoo9oIBBq
	 iAR3EzLCiHS8Ntr04clrltl4l9lUiaNmIPJAJ+rb846kgtqWU5awpU80DM0JYjpWVgZ4P
	 q7rrauwS6sh4N3ZYZ6zETxbiUPHRoe9+vXWP4z7Vls5Jk9MV3IznBVaba3m8mWHobgvcQ
	 6f9XQBiDhMu653YJ4vVwLCEDNy4E2YCUAOVsGfXFnUyFQYcPcJmfspPd6jQLCwNXPFA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="XcY/jNoW";
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id C1F2C606A31A;
	Mon, 30 Nov 2026 23:57:14 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA21D1F000C1;
	Mon, 30 Nov 2026 23:57:13 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796083034;
	bh=sKDNGXqlBTFmhKZM9dBGds0J/b7Els+Pe7+xBAR57E4=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=XcY/jNoWQG4c3eBVSLRAz1GJeoHHf3lASfKqhH6AM9KQ4KZdv0nGWhQoEe97T3tGW
	 ABKATh+tPb903AIdFwXJmwCB1ssQBKJ1Ddl/jhWMO3RYZoigqhIsIEL13qDc1NG9lz
	 Oy3KWjdn38EsPRH69D+yPQHLrRWQhpBKYtXMS45MzLfOnq7lZ74hAjcGGvMfAD1cLn
	 9IVenPe5+tyxSLbNZSJZnT8e2pgPUvLNSmu0A0LkxM/8NQLsaUiM+Jtt/IBf8S45O3
	 D6bQCkgAmn8huN7yjTEr/bZUAda+Zth9ohAaNZBrjFgzweVF7sBb0ERQwL9G4Co1Wg
	 r4aFUV7Z9w5kg==
X-Cc: willemdebruijn.kernel@gmail.com, davem@davemloft.net, edumazet@kernel.org,
 kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, sd@queasysnail.net,
 steffen.klassert@secunet.com, netdev@vger.kernel.org, stable@vger.kernel.org
X-In-Reply-To: <c3d49b69-bd8d-4c34-b02d-60b64d175610@mid.andrii.net>
X-sashiko-severity: High
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list