🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #21503

Re: [PATCH net v4] sctp: fix use-after-free after association migration

#21503
From: netdev-bot+sashiko
Date: Tue, 24 Nov 2026 04:13
170 lines
14303 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 2 (1) · 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).

- [Medium] The patch makes deferred PMTU handling lose valid MTU
  reductions.
- [Medium] sctp: unlocked state mutation on migrated sock in
  sctp_icmp_frag_needed()

Pre-existing issues:
- [Medium] The deferral branch of sctp_icmp_frag_needed() does a non-
  atomic read-modify-write of the 1-bit field t->pmtu_pending…

--

sctp: fix use-after-free after association migration

Timer and ICMP handlers that cache asoc->base.sk now check, after taking
the BH lock, that the association still belongs to that socket. If it
has migrated, they defer the work as they would for a busy socket. The
patch also moves the PMTU size check from sctp_icmp_frag_needed() into
sctp_transport_update_pmtu(), and adds READ_ONCE()/WRITE_ONCE() pairing
for the socket pointer.

> diff --git a/net/sctp/input.c b/net/sctp/input.c
> index 9494cfa51106c..555695718abf9 100644
> --- a/net/sctp/input.c
> +++ b/net/sctp/input.c

[ ... ]

> @@ -372,12 +372,7 @@ static int sctp_add_backlog(struct sock *sk, struct sk_buff *skb)
>  void sctp_icmp_frag_needed(struct sock *sk, struct sctp_association *asoc,
>  			   struct sctp_transport *t, __u32 pmtu)
>  {
> -	if (!t ||
> -	    (t->pathmtu <= pmtu &&
> -	     t->pl.probe_size + sctp_transport_pl_hlen(t) <= pmtu))
> -		return;
> -
> -	if (sock_owned_by_user(sk)) {
> +	if (sock_owned_by_user(sk) || sk != READ_ONCE(asoc->base.sk)) {
>  		atomic_set(&t->mtu_info, pmtu);

[Severity: Medium]
The association can migrate between the READ_ONCE() of asoc->base.sk
and bh_lock_sock(sk). When that happens, sctp_err_lookup() still
returns the old socket with only the old socket's slock held. It
counts the ICMP in LINUX_MIB_LOCKDROPPEDICMPS, but it still hands asoc
and transport back to the callers.

sctp_rcv() handles the same window differently. It drops the old
lock, rereads rcvr->sk and takes the new socket's lock. Is there a
reason sctp_err_lookup() can't do the same?

As written, the migrated case falls into the deferral branches of
sctp_icmp_frag_needed() and sctp_icmp_proto_unreachable(). Those
branches still modify shared association and transport state.

sctp_icmp_frag_needed() writes t->mtu_info, asoc->pmtu_pending and
t->pmtu_pending. t->pmtu_pending is a bitfield that shares a word with
t->dead, rto_pending, hb_sent and the other transport flags. BH and
process context on the new socket update those flags under the new
socket's lock, not the one held here.

sctp_icmp_proto_unreachable() checks timer_pending() on
t->proto_unreach_timer, then takes a transport reference and calls
mod_timer(). If sctp_transport_free() runs on the new socket at the
same time, its timer_delete() of proto_unreach_timer can land before
this mod_timer(). The timer is then re-armed after teardown and keeps
the transport alive until it fires. sctp_generate_proto_unreach_event()
should then see asoc->base.dead set and bail out.

None of this is serialized against the new socket's owner. The only
lock held belongs to a socket that no longer owns the association.

The busy-socket case has a similar shape and predates this patch.
Before the patch, the migrated case ran full ICMP processing under the
wrong lock, so this is an improvement. It still isn't fully closed.

Would it be simpler to switch to the new socket's lock in
sctp_err_lookup()? Alternatively, the ICMP could be dropped entirely
once the association has moved, instead of recording deferred PMTU and
proto-unreach state.

[Severity: Medium]
Can a pending PMTU reduction get lost here?

The size filter used to run before this deferral branch. Now that it has
moved, the branch stores every Frag-Needed/PTB value in t->mtu_info,
including values at or above t->pathmtu. t->mtu_info holds only one
value, so a later report that cannot lower the MTU overwrites an earlier
pending reduction.

For example, with pathmtu=1500 and the socket owned by the user:

ICMP#1: mtu_info = 1200, pmtu_pending = 1
ICMP#2 (stale, or from another ECMP path, matching vtag): mtu_info = 1500

On the next transmit, sctp_packet_config() or sctp_sendmsg_to_asoc()
calls sctp_assoc_sync_pmtu():

net/sctp/associola.c:sctp_assoc_sync_pmtu() {
    ...
		if (t->pmtu_pending && t->dst) {
			sctp_transport_update_pmtu(t,
						   atomic_read(&t->mtu_info));
			t->pmtu_pending = 0;
		}
    ...
}

sctp_transport_update_pmtu() is called with 1500. The relocated check
returns false:

	if (t->pathmtu <= pmtu &&
	    t->pl.probe_size + sctp_transport_pl_hlen(t) <= pmtu)
		return false;

t->pmtu_pending is then cleared anyway, so the 1200 reduction is never
applied or retried.

Wouldn't the association then keep sending packets larger than the real
path MTU until another ICMP is processed? The new migrated-socket
condition also sends more ICMPs into this unfiltered branch.

>  		asoc->pmtu_pending = 1;
>  		t->pmtu_pending = 1;

[Severity: Medium]
This is a pre-existing issue, and the patch did not introduce it.
t->pmtu_pending is a 1-bit field that shares one __u32 word with other
transport flags in struct sctp_transport:

	__u32	dead:1,
		rto_pending:1,
		hb_sent:1,
		pmtu_pending:1,
		dst_pending_confirm:1,
		sack_generation:1;

Here only the cached socket's slock is held. In the busy-socket case,
the process context that owns the socket can update those bits at the
same time.

In the migrated case, code running under the new socket's lock can do
the same. Two examples are sctp_transport_free() setting
transport->dead = 1 and sctp_assoc_sync_pmtu() clearing pmtu_pending.

Could this read-modify-write of the bitfield word lose a concurrent
update to one of the other bits, such as transport->dead?

The busy-socket form of this race goes back to the original SCTP code.
This patch adds the migrated case as a second way into the same branch.
Before the patch, that case did full PMTU and retransmit processing
under the wrong lock, so the patch reduces this exposure rather than
creating it.

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120035521.2098757-1-pkfxxxing%40gmail.com
Technical Details
Message-ID: <179549363640.3135.12116855475874204489@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369992-linux-kernel-netdev=dewy.ru
References: <20261120035521.2098757-1-pkfxxxing@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369992-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v4] sctp: fix use-after-free after association migration
Date: Tue, 24 Nov 2026 04:13:56 +0000
Organization: Usenet Network
Message-ID: <179549363640.3135.12116855475874204489@kernel.org>
References: <20261120035521.2098757-1-pkfxxxing@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="4048972"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:NB5PzDomjmsCKV28awmlaM9weVs= sha256:4Q5lwuZir20Zeu88KWGSFi4ARQdx0pEQ8nFiwZhWNr8=
	sha1:sRh3LA4rwr1vN2+SMD1zJw5nVOY= sha256:vZ8Ul0yHqw3PjaEbD8sEiJlqVK0968OXsmiAYauI0IM=
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 F0E08125DCD; Tue, 24 Nov 2026 07:14:15 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, 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 p7ib0vxPiFMY;
	Tue, 24 Nov 2026 07:14:11 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-369992-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 9559E125DC7; Tue, 24 Nov 2026 07:14:03 +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 381482E787; Tue, 24 Nov 2026 04:14:01 +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=1795493639;
	b=Mee2URQG/WYVVdswN9VVdi3VkuGHhbl24Sux68TZNS/y6oJDe8u/YDMJ5UjcejWqznRK
	 JEtyOy+bHEJeyuGhdPWOLxU1WMt+s1rd7/yYFa8syW1bk6m5MpSnccijrQsL2XI83YzAg
	 v8mb99gTp999UlId0nwQq3hx7O2CFWkXS39qrIBwu7OCrCZ1Cfew0ZGNojTVxSe6SOg93
	 +Dd+rGptMbnReQYYSFOV3ThY2iBa0ZZ+4AcYHWugRCyw9eYtEYw8ZuSDy6EpcINvu5jKH
	 UpbEFIfvVSxz0O5IrBUQB68IuFvEvCPuLqOXtiQJn5fRb6u6xCAmyMPUvdl3VpvXWHA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795493639;
	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=6Mz18uN2p/y0avRq1l5xM0rYtAsdCZ52cJXPtpBaXLY=;
	b=UHWGfRwweyAjg46K02YGZuT1tPJ6WfMO/eTU0TijQhqKjhkxvxmK5idfzr2uLatUsMRK
	 wcoKUfVBD2LMGMIhc+ueFlWP7EXQMNIiY5qrzjHBiEvcqrT5PsokfEdl1yX57orDnDqRg
	 MzH4RXNLAbhgHMMDFPdwgsxRYnfIpbIK3Craafc2+EtglCfwQpnJbJukxY+xRAWMNUO/V
	 znyBmCXJZnVDY3VcI9PE8SMf8itpg9+XdIZ7BXKR2/02PrOu7bP6Fp9xLx5jpHrJ65ByW
	 1p3D5NoQxxrB++HioHyUkJ5ZnX1xZv8VXmOvXYeTGgNKV8mnz16r6yNjjvZ0y3toY0Q==
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="SpYJI/ax";
	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 1D018606A32E;
	Tue, 24 Nov 2026 04:13:59 +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=SpYJI/ax
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=1795493638;
	b=s8jknzigtrexJk9amBU7zAN8CB6BYStfyIX9zAcd+PaNJ6v1Dv+k95Lor/XzlwKVTj0U
	 z1hm65t7ojLBuRvXnBJd5JxMwJ+5C9uIguyhGHzzdLSYbhK3Nf8rcbF38HRD4fdey4CMO
	 fNZtHHorUlfTyBcOwknkixxjQme65AA+2fTU/xtAm697akDvhUtu/f/+Lb5XI5oBOT1/l
	 Cfp3FB69bnjGqZk/Ok/XqDbYsVvPNe/K7UtF3HmOnFq3EkNmcH2WEPdUc8DavyszxMNZ5
	 ZamWB+gMMkwOpInzmh2koNorpgykVIOxXCUql9fOfzc8zWZ/nL7eP6B4fsVXdlaQtTA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795493638;
	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=6Mz18uN2p/y0avRq1l5xM0rYtAsdCZ52cJXPtpBaXLY=;
	b=h+wiWRKw+hFdCBuhc7oEQmRJZaUxVuhaWprkYxcfypPuoojdEYImjQu2jOdENTLkZe7G
	 oAVjzvxqz6fvFZ3eV87LB0GxtOKiybkGACm+2bQXSOSE4QtclPQM9ayEnt+9DXiWi0iT9
	 sMEdSniBmNmLCydlJYO3gHzKOm/Ya+0Qu8kmFvSUrMMz5MbGTVbarsnlJ8vQ4OstqAghi
	 Mkk5wX4edsvXjOnGVTJaH8aI7rBEvunKD8fIEGXQddKozPJv0bsFKlMzAs5g0vhsEoiJH
	 MpiR6q4kk15+8Arv2/P2QxonbrBSVZlFHjQQbCnNqyN49hl+3SIhWMGLdYrgdq45XxA==
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="SpYJI/ax";
	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 3A02F606A31E;
	Tue, 24 Nov 2026 04:13:57 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id E79A81F000CA;
	Tue, 24 Nov 2026 04:13:56 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795493637;
	bh=6Mz18uN2p/y0avRq1l5xM0rYtAsdCZ52cJXPtpBaXLY=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=SpYJI/axf8WNeJkwDE7+V76Cv8RwmhFLP/Le5I3eJ5sRf4PpPaoEWaXNfGZySa0EM
	 UcAvBspjLQv6eu0Ka3FTdNQq8aqAZJt00yNn6c3KIWxDrCOREwIIXE+ERjSIMywt1A
	 EPOxl0g6V1wWY4mSxAvSQKe/7w8efIWOpu4W550iipiVMVvEpI/mdDWNgljMl6jZsF
	 2QNEz5jvlo3Svz/yCVQBB763Fo3hPwG0mLx57YvZ9lFORazkQB+RhraT+tooatqnK3
	 /04Yi5fgH0qCbqIGDrnutTnMSAckhExEM98xWwGZZxpJnWOZ9cC/as+JQt6rh2s6VH
	 zbWB+NUjY38gw==
X-Cc: marcelo.leitner@gmail.com, lucien.xin@gmail.com, kuba@kernel.org,
 linux-sctp@vger.kernel.org, netdev@vger.kernel.org,
 linux-kernel@vger.kernel.org
X-In-Reply-To: <20261120035521.2098757-1-pkfxxxing@gmail.com>
X-sashiko-severity: Medium
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