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=1796381181; b=RyeHDIFG5jucCYxw+0h3An/6X5IZl361QuVA08MD5obC5kmWwn0GheoN8Maa3ZiJlL4E 2f67eMCt0WfEEmYXys2YzAZjh5XdNs0L1m1pdVVTl76NpHq0rDDuy8JVpZfR4IjjMjBio TP+1cQfgAHNgEkv2nn/bgqq9t0OXcrbGAc1N8xN3eh3mVVv9kCzrQpG6NMjY9IJcYltks WLGM3vRlz35gZioav1vbo2DSRSkaBPhWqux3H5mopjBaaQ9V9x2g0kUNjzWhela480u58 kMjhoX3bPMUFRLz1ziKohXyI723dlPjr4S/ZH89M+pj4KXNDIWKtLRw/uUwPONEYClw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381181; 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=IX2B5OdWp1Qpyp1CxfXLnwi4a7ZaFNsPkmDE66WzbU4=; b=tL/LFtxC/0SRqRsr4sLRQ6NbFL8m1MSj2GJ2VGI6e5lSGGBMpemxh8LXwh3eBymtOqdN yfT1pEwu0kBlySfOUd+VUK9dYgO5ixRpfILjycsLCeWcL9keF/zm6qVcJVoKFhmuMGATT Lyj1C5+YfmkVew8xWD9/qyg7YSh/GdZGqEnLxIGaHEHdXueCEKdjI+gOLUIjcdf8nKNAY kVdhsKrjY2sH0tUqqGoBV4BYgB71SryEPGP6qc4ZSIDDtj4nP/roShzXsrvyvOyw1Pil+ 7LSLziBeWtW3Hj+0Qokz4PsCWjuOBvbVNrHgreqo1f1xxVHu8AwqDvNYL+00jNCZOhw== 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=aAugrKmQ; 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 B3E38606A32C; Fri, 4 Dec 2026 10:46:21 +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=aAugrKmQ Received: by smtp.kernel.org (Postfix) with ESMTPSA id DEB851F00937; Fri, 4 Dec 2026 10:46:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381181; bh=IX2B5OdWp1Qpyp1CxfXLnwi4a7ZaFNsPkmDE66WzbU4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=aAugrKmQ4cGPW4V8f32E13HVw7n8UaoCbakyGwcS71+gt1aT+w5F8MfNAzsTfzRK8 Jv3h97YdMjTE9UO0+Q1U0fJfdJAQhS6BB7H2K7j04TNfalynLyf43EKspqNbgKFEOM FQZXd/S7RB3U/bB9Et1zzQz6+rTcAZ7315GDl4pk= 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 7.3 594/742] sctp: do not free a new asoc peeled off while sendmsg slept Date: Fri, 4 Dec 2026 19:07:38 +0900 Message-ID: <20261204100650.902550405@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-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);