Article View: linux.kernel.netdev
Article #14275[PATCH net] sctp: do not free a new asoc peeled off while sendmsg slept
From: Yves Bieri
Date: Tue, 10 Nov 2026 22:42
Date: Tue, 10 Nov 2026 22:42
90 lines
14577 bytes
14577 bytes
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 <yves.bieri@theori.io>
---
Tested on net at b71c101bbb98.
The fix and this message were drafted with Claude, and reviewed and
tested by me.
net/sctp/socket.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index b5a57f6..e7e14a0 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -2082,10 +2082,20 @@ static int sctp_sendmsg(struct sock *sk, struct msghdr *msg, size_t msg_len)
/* Update snd_info with the asoc */
sctp_sendmsg_update_sinfo(asoc, sinfo, &cmsgs);
+ /* sctp_sendmsg_to_asoc() may release the socket lock while waiting,
+ * and a new asoc can be peeled off to another socket meanwhile. Hold
+ * it, and free it on error only if it is still owned by sk.
+ */
+ if (new)
+ sctp_association_hold(asoc);
+
/* 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);
base-commit: b71c101bbb9814d163c00234d43c41f0a17907d4
--
2.43.0
Technical Details
Message-ID:
<20261110224233.82977-1-yves.bieri@theori.io>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-360706-linux-kernel-netdev=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-360706-linux-kernel-netdev=dewy.ru
From: yves.bieri@theori.io (Yves Bieri)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net] sctp: do not free a new asoc peeled off while sendmsg slept
Date: Tue, 10 Nov 2026 23:42:33 +0100
Organization: Usenet Network
Message-ID: <20261110224233.82977-1-yves.bieri@theori.io>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="721856"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:9PPC4fsY9gsr1oMrq8IrI/3OMu0= sha256:31NTXOun4QSWCwMS5zZdKGTF7vf0DcXzRGNnk36m3Fc=
sha1:XFjQBHPDqzOS2ZT0nDNVBqcyxzE= sha256:eP0Jy2A+SWd/wfEZglh7P1IzzKSw/Sw2xWiEmYSkdGA=
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 28291113D97; Wed, 11 Nov 2026 01:44:29 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.05
X-Spam-Status: No, score=-3.05 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, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=theori.io
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 wB5Vcai1Uo7s;
Wed, 11 Nov 2026 01:44:24 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-360706-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=theori.io
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mail.dewy.ru (Postfix) with ESMTPS id 7084A113D89; Wed, 11 Nov 2026 01:44:16 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sea.lore.kernel.org (Postfix) with ESMTP id D016864542; Tue, 10 Nov 2026 22:42:59 +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=1794350579;
b=jCQSUnTsZQCJ/06GU1F67Cl5qG/+wBqn0WdOf63PiNZSfC0XiqJmbXyOXEG6paSngxq/
CKVuyX02HMFpLTMfrwwBRaIjJ04PThcWOWR3pq71RaWyciOP4GeFjW/BKPS0DowceeJAa
Amtxe6OlOH7mI1drBplfQlyyJNtsSPn1HZyrBq0rFrOsKPBA0S00wcEJMff1r+7cCIEMU
HAJMOPCCh29na3DQ+xPacz+oOYMWuvo8e1G3KDsVnUUEPKY+88TJSHew5r8frQs5XW6l6
Z2OWgdxddfrO3WfiLYsv04y0Zv5OjX4HAM22KLlNpECIotwf9yeKfMnY88rV3FAWH1Q==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794350579;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State:
X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:Date:Message-ID:
X-Mailer:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
List-Unsubscribe:List-Owner:Precedence:MIME-Version:
Content-Transfer-Encoding;
bh=65ccBi3rzxm73dF4Hh1JDA1NcutcYotrBjNv9MyOyhM=;
b=DZWevuic/pjDnRGI+hpav1ABW4sbQCNPz+MZbvimC795hMkHcQ2xd/b7GDlFqSdv616K
sNLvbRxHCfdOMj3/bhSdfc9zsnXlTPMRn+GzKlDYy7laHOiesnG6l5m8Ta+dx3eiJEkNa
bvhv0JIWF1oLS+kaPbqUGUgcJ8RIma7vyFkmQeazpWcfQKWHDR2xAbEpQz/WrwL09+Fjk
z+dBYXqpANoL2xp/0zkrYJhtSba/ArkS5/kNlPCam/GnJexdhJq5YAmRzn60jtGB9Cwth
HXYbZol2Cyq2scqCeFgErZSyB3l4cVkRhqQF+er27W8Smjy1xf+XYJ7ML7z80FgB1iw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=theori.io header.i=@theori.io header.a=rsa-sha256 header.s=google2026 header.b=B97Y8h0+;
dmarc=pass header.from=theori.io;
spf=pass smtp.mailfrom=theori.io;
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 03E99606A33A;
Tue, 10 Nov 2026 22:42:59 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=theori.io header.i=@theori.io header.a=rsa-sha256 header.s=google2026 header.b=B97Y8h0+
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.225.71
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1794350578;
b=CnnYuwRpBFV5Jb54hbUAXp2+FnQbjp94ugH+5FMzH/NdyWZUhV+baaPKqfuKEF2OgHzE
dFWga247D5j5p+N0sbV739LYfeYW6n8tk86ADf6BQMs0VypIxGpe0o9op9IoD3whNZf6d
sWUrvfS+3niDqSm7QJ6d6kebMdMuPVbqCsOi6MCBS3dPqOjdvJ491cUvbKwg2TBK9pLr2
ACmVd9xQheaOEWQNhLua0/AvhTAY0C6quhhFR1sseqC2D/R+NuefiPSg6u3eTFaD6ir2P
YQZFIBXItc4iJGaZD1Y8es6R4JMu+MWmAVxQXAzI6vtJvPV6joeCP59wvQyVVOntmKw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794350578;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received:
From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version:
Content-Transfer-Encoding;
bh=65ccBi3rzxm73dF4Hh1JDA1NcutcYotrBjNv9MyOyhM=;
b=2Z63nGjoCUd2RORk1uDdtVKooOkBxGLuQCk8iXkjOxJQOazr0bj2ZWBPkjlOnPSXAImT
XAaTJkuxpOE8uFK99ROMJF3Tf+w8zoM6LeHtkCQocrXUV21hSguP+in2akep2Y6/ViaNc
xQ+5tqRgh1LiYnUDoTygIr5rJD2h981atSNMzTR26RCbDRttSYNDCxnZ9FDJ4ypYhn6BO
t5PwlGzbtahcrabZJEpBnIiG/spUSyRWMCr1IzNf/bA31pGwet5KYd2mjFaZUxnSD9O1K
fTjFj69i0QSYWZ06YBztNKdcelASyasDS1VOul6ox/JQEH7FINLaA43D0MEfosN+tyA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=theori.io;
spf=pass smtp.mailfrom=theori.io;
dkim=pass header.d=theori.io header.i=@theori.io header.a=rsa-sha256 header.s=google2026 header.b=B97Y8h0+;
arc=none smtp.remote-ip=74.125.225.71
X-Received: from mail-wr2-f7.google.com (mail-wr2-f7.google.com [74.125.225.71])
(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B6D4606A320
for <netdev@vger.kernel.org>; Tue, 10 Nov 2026 22:42:56 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8B6D4606A320
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=theori.io
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=theori.io
X-Received: by mail-wr2-f7.google.com with SMTP id ffacd0b85a97d-48df951fd31so1048795f8f.0
for <netdev@vger.kernel.org>; Tue, 10 Nov 2026 14:42:56 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=theori.io; s=google2026; t=1794350575; x=1794955375; darn=vger.kernel.org;
h=content-transfer-encoding:mime-version:message-id:date:subject:cc
:to:from:from:to:cc:subject:date:message-id:reply-to:content-type;
bh=65ccBi3rzxm73dF4Hh1JDA1NcutcYotrBjNv9MyOyhM=;
b=B97Y8h0+lfe0/AHj05Oi62WQcXmqYayJBwOKgM1wVexj6YwUmIAqvFuBFFwUuqlfgS
IcISOfys3nOJeliQbQCcJI93jcdbdCp0miw66BPLtx4h+/++Za5uIfBKuLI3ATz3lC3j
HeqMIeq50joZTvZ26NwuKH5VbWUCHE66zQK6M3eYQ2ECiTJi8//6KaCbID4zOxfEgcu/
teqJcgi6kRX+vyvKE1n6iRdOchyPXoxjB5BhNTAjzDzu5FJNS2/I4f8zopNLKYtM+VV5
ee0+gKenqyZmr7UVHrh0ElNeP59/hS3F0+poENrwM70ne0tofjwHpS1Zkci6R7Y/Ok6L
jqDA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1794350575; x=1794955375;
h=content-transfer-encoding:mime-version:message-id:date:subject:cc
:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date
:message-id:reply-to:content-type;
bh=65ccBi3rzxm73dF4Hh1JDA1NcutcYotrBjNv9MyOyhM=;
b=YUYabKEehyiV6/5WU8gwpY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HoROJ9j/fqx+uvWnvC4
vgw1EcSH1X6vVQwMQSFLVzNShBqncMLSWNtnl3/IOQpXTN/+rfxRQwzpLd6ILLCu/ycP7/Vkn6I
BrTMJN0cOtGnwJD9zXHZLX9x18q2IfTDDo/JO+ekOUwb7GJxoRjPwmmNLpNzMenYL1kAXvHL4tU
STU1/VQ==
X-Received: by 2002:a05:6000:2308:b0:48e:6f76:de9c with SMTP id ffacd0b85a97d-499c6e9636amr523356f8f.28.1794350574841;
Tue, 10 Nov 2026 14:42:54 -0800 (PST)
X-Received: from localhost.localdomain (bbcs-110-227.pub.wingo.ch. [144.2.110.227])
by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4983585923bsm7599946f8f.11.2026.11.10.14.42.52
(version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256);
Tue, 10 Nov 2026 14:42:53 -0800 (PST)
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,
Yves Bieri <yves.bieri@theori.io>,
stable@vger.kernel.org
X-Mailer: git-send-email 2.54.0
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