From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796383996; b=C+TQ8xL/KttVhcdjgFSxf2ZJJCHVWdCb6OZZBXM9S38V+rWMYdiU7Ji/SgVGBTwAAZsb Exl6JquxLAHC3vRWI+puWctJgvv0+nxdTwvYrVRLNP/lsxWoNVRnxIj6qnHo4PoiBjb9b I0B5nMcSlCgrUNfJ1kMjN36auQOvFo8YJ26sJiTQkzOCbQsf99ZL+dNYHdlO7K8lRLYY2 hbLx5wXBchLXmzIQ64dfIFcFQO/BMc+CM6aLJFhCNBt6eb3Y3HaM4NAFpIi95e0r3cCFI mynVaRn9M/DHkxDISo6Tfd/MA7LibCzGv52i66LpsDNT9xjB0U7Gd3wIiLxDxkqlR8g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383996; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=maGnDlLkqHWTqrWlKSWgpPeMghNifI5QMRlxvNu8y+A=; b=HTgYMbfqf4ty45UhRzDmlZB3E9xXI3Fn/WxLr0O8SpeHGoTNYeJJI4/1vVo4fDRCZd9R iNuRFneOU8wvDtG415xP8YjSrDfJ+2gG4Dzdns6p9mPZ+6C/6PSzeaQvn9DoIkwGDbtFS beOxWfxYveCdwsYH7mDh+bLWUdv/tij3IaLIWyAx62BaZUJxccbS9ppwXSaLXnCaPOfq9 R0BhLjEJnDT/7LGiNy2TvkkJDlJ9Aui2xR0WvOhPdtm7K5CGJ3kvvXE1c0asW3ksgyB1Q MNZOzLGU7Kl2idtzTnHcMa4QC1kFyAF76xYUjdLKFuZEOJG4abmUIy6VsoR7OLMUWUg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=C866hm0D; arc=none smtp.remote-ip=100.103.45.18 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 1B72D606A32C; Fri, 4 Dec 2026 11:33:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=C866hm0D Received: by smtp.kernel.org (Postfix) with ESMTPSA id 37BCA1F000C2; Fri, 4 Dec 2026 11:33:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383995; bh=maGnDlLkqHWTqrWlKSWgpPeMghNifI5QMRlxvNu8y+A=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=C866hm0DYBxwyc2j5CoMWKd15UxAq1UF9CinSybSTlnPYhydQL9cXiCM7kHciCIgI hd8v3YrZdqB+kDKCvNV6I1Xg9ivV9/NemP+nXWWLTyTJovnFOfRn3daZmxKdPo8L+s 8rxccbuIDrLXRlQvFA+mttpq6NlTHdDBrhuawn3I= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yves Bieri , Xin Long , Jakub Kicinski Subject: [PATCH 6.12 450/555] sctp: do not free a new asoc peeled off while sendmsg slept Date: Fri, 4 Dec 2026 19:08:13 +0900 Message-ID: <20261204100626.600662136@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yves Bieri commit f2540da93a113d3f0a70fd0961e00eb849ce8342 upstream. When sctp_sendmsg() creates a new association and sending on it fails with anything but -ESRCH, it frees the association. The send can sleep in sctp_wait_for_sndbuf(), which releases the socket lock, and meanwhile another thread can peel the new association off to a new socket. The wait then returns -EPIPE, and sctp_sendmsg() frees an association that now belongs to the peeled-off socket, without holding that socket's lock. If the peeled-off socket frees the association first, e.g. on close(), sctp_sendmsg() frees it a second time. Otherwise a syscall running concurrently on the peeled-off socket can use it after sctp_sendmsg() freed it. Both are reachable by an unprivileged user. The double free on net with KASAN: BUG: KASAN: double-free in sctp_tsnmap_free+0x5c/0x80 sctp_association_free+0x1eb/0x750 sctp_sendmsg+0x15ff/0x2020 Freed by task 836: sctp_association_free+0x1eb/0x750 sctp_primitive_ABORT+0x85/0xe0 sctp_close+0x22a/0x8d0 Commit dfcb9f4f99f1 ("sctp: deny peeloff operation on asocs with threads sleeping on it") fixed this double free by denying the peeloff. Commit cea0cc80a677 ("sctp: use the right sk after waking up from wait_buf sleep") replaced that check, and commit a0ff660058b8 ("sctp: return error if the asoc has been peeled off in sctp_wait_for_sndbuf") reverted it to return -EPIPE, without restoring the check. Fix this by holding a reference on the new association while sending on it, and by freeing it on error only if this socket still owns it. asoc->base.sk only changes in sctp_sock_migrate(), which runs with this socket locked, so the ownership check is stable. The reference keeps the check safe if the new owner frees the association meanwhile. Userspace still gets -EPIPE, and the association stays with the socket it was peeled off to. This was found by Xint Code, an AI code review agent, and reproduced as an unprivileged user on net with KASAN (trace above), without modifying the kernel or using error injection. With this patch the sender gets -EPIPE and the association keeps working on the peeled-off socket. Without a peeloff, a failed send that created the association (EAGAIN, EINTR) still frees it, and a peer ABORT while the sender sleeps still frees it exactly once. The SCTP selftest sctp_vrf.sh passes. The reproducer is available on request. Fixes: a0ff660058b8 ("sctp: return error if the asoc has been peeled off in sctp_wait_for_sndbuf") Cc: stable@vger.kernel.org Signed-off-by: Yves Bieri Acked-by: Xin Long Link: https://patch.msgid.link/20261112172149.27355-1-yves.bieri@theori.io Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/sctp/socket.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) --- a/net/sctp/socket.c +++ b/net/sctp/socket.c @@ -2063,6 +2063,11 @@ static int sctp_sendmsg(struct sock *sk, asoc = transport->asoc; new = true; + /* sctp_sendmsg_to_asoc() may release the socket lock, + * and the new asoc can be peeled off meanwhile. Hold + * it, and free it on error only if sk still owns it. + */ + sctp_association_hold(asoc); } if (!sctp_style(sk, TCP) && !(sflags & SCTP_ADDR_OVER)) @@ -2084,8 +2089,11 @@ static int sctp_sendmsg(struct sock *sk, /* Send msg to the asoc */ err = sctp_sendmsg_to_asoc(asoc, msg, msg_len, transport, sinfo); - if (err < 0 && err != -ESRCH && new) - sctp_association_free(asoc); + if (new) { + if (err < 0 && err != -ESRCH && asoc->base.sk == sk) + sctp_association_free(asoc); + sctp_association_put(asoc); + } out_unlock: release_sock(sk);