🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #1955

[PATCH net v2] sctp: hold transport reference across connect wait

#1955
From: Seung Min Shin
Date: Sun, 11 Oct 2026 16:27
139 lines
11550 bytes
sctp_sendmsg_to_asoc() selects a transport before waiting for a new
interleaved association to become established. sctp_wait_for_connect()
drops the socket lock while sleeping.

While the lock is dropped, backlog processing can handle a COOKIE ACK and
an ASCONF DEL-IP that removes the selected transport. sctp_assoc_rm_peer()
then marks the transport dead and drops its association-owned reference.
The transport can be freed through RCU before the send path resumes.

After the wait, the stale pointer is assigned to newly created DATA or
I-DATA chunks and later dereferenced by sctp_outq_select_transport().

Hold a reference to the selected transport across
sctp_wait_for_connect(). After the socket lock is reacquired, abort the
send if the transport was marked dead. Callers without a selected
transport pass NULL and retain their existing behavior.

Cc: stable@vger.kernel.org
Fixes: 668c9beb9020 ("sctp: implement assign_number for sctp_stream_interleave")
Acked-by: Xin Long <lucien.xin@gmail.com>
Assisted-by: LLM
Signed-off-by: Seung Min Shin <guncraft2000@naver.com>
---

Notes (sctp-connect-wait-v2):
    v2:
    - Rebase onto current net/main after commit 4f1da630d13de.
    - Preserve the RCV_SHUTDOWN check added by that commit.
    - Add the stable list now that the issue is public.
    
    v1: https://lore.kernel.org/netdev/20260928152132.3705137-1-guncraft2000@naver.com/
    
    Tested on net/main af32da41b032 with CONFIG_KASAN=y on x86-64.
    
    Before the patch, the reproducer triggered a KASAN slab-use-after-free in
    sctp_outq_select_transport() on its first run. After the patch, 64 attempts
    completed without a KASAN, refcount, BUG, WARNING, oops, or panic report. A
    diagnostic run returned ESRCH in all 64 attempts and left the association in
    SCTP_ESTABLISHED state. A normal interleaved connect/send smoke test passed.

 net/sctp/socket.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index e35692dd8d30..189b89a40d46 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -75,7 +75,8 @@ static int sctp_wait_for_sndbuf(struct sctp_association *asoc,
 				struct sctp_transport *transport,
 				long *timeo_p, size_t msg_len);
 static int sctp_wait_for_packet(struct sock *sk, int *err, long *timeo_p);
-static int sctp_wait_for_connect(struct sctp_association *, long *timeo_p);
+static int sctp_wait_for_connect(struct sctp_association *,
+				 struct sctp_transport *, long *timeo_p);
 static int sctp_wait_for_accept(struct sock *sk, long timeo);
 static void sctp_wait_for_close(struct sock *sk, long timeo);
 static void sctp_destruct_sock(struct sock *sk);
@@ -1245,7 +1246,7 @@ static int __sctp_connect(struct sock *sk, struct sockaddr *kaddrs,
 		*assoc_id = asoc->assoc_id;
 
 	timeo = sock_sndtimeo(sk, flags & O_NONBLOCK);
-	return sctp_wait_for_connect(asoc, &timeo);
+	return sctp_wait_for_connect(asoc, NULL, &timeo);
 
 out_free:
 	pr_debug("%s: took out_free path with asoc:%p kaddrs:%p err:%d\n",
@@ -1843,7 +1844,7 @@ static int sctp_sendmsg_to_asoc(struct sctp_association *asoc,
 
 		if (asoc->ep->intl_enable) {
 			timeo = sock_sndtimeo(sk, 0);
-			err = sctp_wait_for_connect(asoc, &timeo);
+			err = sctp_wait_for_connect(asoc, transport, &timeo);
 			if (err || sk->sk_shutdown & RCV_SHUTDOWN) {
 				err = -ESRCH;
 				goto err;
@@ -1881,7 +1882,7 @@ static int sctp_sendmsg_to_asoc(struct sctp_association *asoc,
 
 	if (unlikely(wait_connect)) {
 		timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT);
-		sctp_wait_for_connect(asoc, &timeo);
+		sctp_wait_for_connect(asoc, NULL, &timeo);
 	}
 
 	err = msg_len;
@@ -9381,7 +9382,9 @@ static bool sctp_writeable(const struct sock *sk)
 /* Wait for an association to go into ESTABLISHED state. If timeout is 0,
  * returns immediately with EINPROGRESS.
  */
-static int sctp_wait_for_connect(struct sctp_association *asoc, long *timeo_p)
+static int sctp_wait_for_connect(struct sctp_association *asoc,
+				 struct sctp_transport *transport,
+				 long *timeo_p)
 {
 	struct sock *sk = asoc->base.sk;
 	int err = 0;
@@ -9390,12 +9393,16 @@ static int sctp_wait_for_connect(struct sctp_association *asoc, long *timeo_p)
 
 	pr_debug("%s: asoc:%p, timeo:%ld\n", __func__, asoc, *timeo_p);
 
-	/* Increment the association's refcnt.  */
+	/* Hold references while the socket lock is dropped. */
+	if (transport)
+		sctp_transport_hold(transport);
 	sctp_association_hold(asoc);
 
 	for (;;) {
 		prepare_to_wait_exclusive(&asoc->wait, &wait,
 					  TASK_INTERRUPTIBLE);
+		if (transport && transport->dead)
+			goto do_transport_dead;
 		if (!*timeo_p)
 			goto do_nonblock;
 		if (sk->sk_shutdown & RCV_SHUTDOWN)
@@ -9424,7 +9431,8 @@ static int sctp_wait_for_connect(struct sctp_association *asoc, long *timeo_p)
 out:
 	finish_wait(&asoc->wait, &wait);
 
-	/* Release the association's refcnt.  */
+	if (transport)
+		sctp_transport_put(transport);
 	sctp_association_put(asoc);
 
 	return err;
@@ -9443,6 +9451,10 @@ static int sctp_wait_for_connect(struct sctp_association *asoc, long *timeo_p)
 do_nonblock:
 	err = -EINPROGRESS;
 	goto out;
+
+do_transport_dead:
+	err = -EAGAIN;
+	goto out;
 }
 
 static int sctp_wait_for_accept(struct sock *sk, long timeo)

base-commit: af32da41b0327b9c6a37856ba82b6760d6c8d10e
-- 
2.34.1
Technical Details
Message-ID: <20261011162750.1529631-1-guncraft2000@naver.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-344538-linux-kernel-netdev=dewy.ru

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-344538-linux-kernel-netdev=dewy.ru
From: guncraft2000@naver.com (Seung Min Shin)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net v2] sctp: hold transport reference across connect wait
Date: Sun, 11 Oct 2026 16:27:50 +0000
Organization: Usenet Network
Message-ID: <20261011162750.1529631-1-guncraft2000@naver.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1576259"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:VFRKdjyPuDL3qREJbXAiV4vN5YU= sha256:sVQp0yVd/ojMQGu/d5170nX6uuqe6H87uYpjuuH3h/E=
	sha1:tZye3c792HwLT9dWTy3XM9DQnqg= sha256:opveJxtZ0z6O3SIjKlFlHD2hoaZSv0+aaBiZ2+7NEtA=
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 BFE4510FA23; Sun, 11 Oct 2026 19:38:20 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -0.749
X-Spam-Status: No, score=-0.749 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
	FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	MAILING_LIST_MULTI=-1, 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=naver.com
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 ig_qirUptp40;
	Sun, 11 Oct 2026 19:38:12 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-344538-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=naver.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id EBE3E10FA16; Sun, 11 Oct 2026 19:38:06 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1])
	by sea.lore.kernel.org (Postfix) with ESMTP id B11A42CC09; Sun, 11 Oct 2026 16:38:03 +0000 (UTC)
X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 2CAE630568B;
	Sun, 11 Oct 2026 16:38:03 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=naver.com header.i=@naver.com header.b="GG23faiI"
X-Received: from cvsmtppost36.nm.naver.com (cvsmtppost36.nm.naver.com [114.111.35.243])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3072D2DC357
	for <netdev@vger.kernel.org>; Sun, 11 Oct 2026 16:38:00 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.111.35.243
X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1791736683; cv=none; b=GjKJ2dPCt+y2b9lk2Sct2758Hz4MkAV2QoLw5ceD2sULbp/vcLEk8CpPhf1o/zj77XdLLqxyLWxvWlB6V2puVPM1hfW9Q0PZaq2SgXjZl8KJlggs3F0HMvL/4NDfhhaAU8HTeGlru972V+97CWbUB7W2ZaD7O1uOlEJjwBeENmo=
X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1791736683; c=relaxed/simple;
	bh=mfRz2zk9VSkKhAjFcY7J3woD/6Sps4QomEr2JVkpR0E=;
	h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=mzeZjLAVERn/Zc00EYZ9OM2SbLsmYW/UBS0lIf+gs9Q7xoEhiGC2MQlUxHL3zDty5kbXJy4+HjMx6vEAA9D0hguEgQ0VCl0IMWcdoMwUOtQbMiimdNQz4Dze9QN8AnxnSJv6VuInLb/PYQvaTh2uTSfq3iVLBa75n1tHIWpg4UU=
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=naver.com; spf=pass smtp.mailfrom=naver.com; dkim=pass (2048-bit key) header.d=naver.com header.i=@naver.com header.b=GG23faiI; arc=none smtp.client-ip=114.111.35.243
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=naver.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=naver.com
X-Received: from cvsendbo016.nm ([10.112.24.39])
  by cvsmtppost36.nm.naver.com with ESMTP id LjU5JPdhQLSOxvzj12PYIA
  for <netdev@vger.kernel.org>;
  Sun, 11 Oct 2026 16:27:51 -0000
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=naver.com; s=s20171208;
	t=1791736071; bh=mfRz2zk9VSkKhAjFcY7J3woD/6Sps4QomEr2JVkpR0E=;
	h=From:To:Subject:Date:Message-Id:From:Subject:Feedback-ID:
	 X-Works-Security;
	b=GG23faiIDkvzzL9ASf//+PBZ0J78fWOf0B2a3HzDTvRlZj06LY0LdgOgcjy7v/F3G
	 7/fOWD8Cp85kAO/5B9MieEVH28hRbctRt2andbisnWxUrA4m5O5iQDPW/ksH3ZUYjU
	 xr6iUN8FxdjJn8ll7asG6uTWV++j6DiFJQPcwl55QevEQoYxqhWLeNp0CCzbz+D1HL
	 F/PTJPN2Lad3Lpem1S4OsvfSyB0xMq9GkO0v7HMUtOG8E0zcu6VA/IuZJoauyMNPSD
	 NkAmYd8XATWN2Qz7nt9/f47v3OVjo3DaHeTT7thTyzHGShbnphKwjn1y44AS0D9mre
	 J+QDTgQLoGDVQ==
X-Session-ID: NltzlvSiR0Wm6FzDlyrr8Q
X-Works-Send-Opt: 0rRoWNkNjHmmKAidp4JZKHmmjAumjAurKAKmKqtwaACYkEljxBmwjAg=
X-Works-Smtp-Source: lqKmFqulFqJZ+HmmFqMq+6E=
X-Received: from localhost.localdomain ([125.130.170.186])
  by cvnsmtp003.nm.naver.com with ESMTP id NltzlvSiR0Wm6FzDlyrr8Q
  for <multiple recipients>
  (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384);
  Sun, 11 Oct 2026 16:27:50 -0000
X-Cc: "David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>,
	linux-sctp@vger.kernel.org,
	netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
X-Mailer: git-send-email 2.34.1
X-Precedence: bulk
X-Mailing-List: netdev@vger.kernel.org
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>