From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f169.google.com (mail-dy1-f169.google.com [74.125.82.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A69143B18A for ; Fri, 8 May 2026 00:15:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778199326; cv=none; b=oFdOMllVmI6IlWBTQD1rs3jkppatkOHrHh89As6LTOxL2prMpcdi1BF924QS+ORoPGNEuOqwQ73XQ5cm68ka+Vj4UJ+janFreSYgOJV0XrT6xLaJZzWKvn/Js+MmLzfIY1ucETkvTdolRveQl4jHBFLl50aSpoDGMQGDyVyt7nw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778199326; c=relaxed/simple; bh=SKEeViFbp1uXUSYeHb372Uw+KJNAO1yOkAXwhXCVyQU=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Gt5yRiVR87yiifFtYOdWtv1LrE5rQ3Dt+0uM76B/1+KtQnIqdu1QPpdmxAWJiT3+WcyA/S1K34CiZD9f0I4seJQX2pSZG20UCy2BfUXXS4wBPGHvkIL7vIOfcqgbnKgw14mTo7gDmyjMBV29M58zVJFtbmvOG4ppyt7ZjzQ+kBE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=n9qgO/B4; arc=none smtp.client-ip=74.125.82.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="n9qgO/B4" Received: by mail-dy1-f169.google.com with SMTP id 5a478bee46e88-2f30a4601bbso1626173eec.1 for ; Thu, 07 May 2026 17:15:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778199323; x=1778804123; 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; bh=7LQCxTjl/7QlKwFcwi4/FESx78z4DYB8yBxbbODWZwc=; b=n9qgO/B4xR/jX45b67IAoPWeP6O8vPd3ZC3fn0rtRW/Cn4hailsG1MIWMeDH32+cqV VvDB/4WQBRHVQl7YmuiQNa9pI9033C7Ax4n4vxO1RD3YNwejSFZcRLtGLHDBz23k1zM8 6bGjewXsaYPUeT/P6CwDZC4GnNn2heEZWAyGhFlKTm4EZcGRtYSIrRdzirI4jrlg6ij7 SXNPKahH7sykQmgYsL3Yau0DTEznYS+pH/V4TqZZp846h5pljX29MCBqP+2Ut1D8kGTv Vm0cjK5GLZtUj7ef8/kKp1i0oDXa5v7CU/Jsx4nadhNJEin1j7JRgopiFxfiiY1EQA7e OSUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778199323; x=1778804123; 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; bh=7LQCxTjl/7QlKwFcwi4/FESx78z4DYB8yBxbbODWZwc=; b=AAlP+R//CFZEGEJQdXTBFJL0JlQfvvueUMdLmhioWIxTWptZAnmMBaIfVTtmqCXC+h /IsPmvMtqLhkkQicyIpshlgtjyy0qlfvdXmKm59ZuaLVSh9MjURzP0RoOtSTFPGArDei xtJEvC5bu/xlfQtOmD33oNPe/WwT8efH3fX3YKgRR4YdWnsrlWf/rq/V1u+RqmmUyIz9 7rRodKLCWuSqumZSDHF64FCcKh+izv+BlTKR+YPbGYYjxEfBYOdP5zN1svT57bs3UtyQ Uk69zG8He9d71B76IkI0eURmxarGa67pPFObmiZQJEseNLlmjg4rpkyOSTnAQ6zPCOfX 8wSA== X-Forwarded-Encrypted: i=1; AFNElJ9qNA27ZShEaAFKyihdjxwC11YcsttqxB22LI/SkYUNu268m5c4f001IGYnM320LwKrQ+bbdaYdebGKIys=@vger.kernel.org X-Gm-Message-State: AOJu0Yx1cnRkNNYMxAddiPIgkWHEzGfsCnNyaOVrOkULt94JDoLJIB4q +CFRI8vqteixaEHn46MFLDSMcYTCORR4sW/Jh47dpzAeYdxxzfeDac/j X-Gm-Gg: Acq92OF1ZfF6N6YzKNB357tzCklwIWloETs5Sgt29h1T2GTvTry6i1OcMcVDkFyZmZg eJEnhRr7zYrixQIiJIIiiq9PoVDT9sJEj6CBmDmWphc+0Lm3OJeQzYXF+RaulU+BTewSqoEK67O w/UgTymwi3bzv+JV6Sjdo5Y5IEwTCLmytc+0v2TIAJPUfi8Uh2PoC+uExn8V0HnS/sPoiT7KyvQ NxPTsysHWYTmtmq/7RpyLhHx+4VXPkntyRUwDo9fqBvhyx/d505qYtJfLAKN168PO0KJSaCAx5S QrI9Ej5acT6Z9RRzuhwGh8W7DRXBECZrHJKn1dyhnXi6ybVWyevSaK4A+VHiy8joeqDwDoNkMny Fg+/kK9dL1m1DwrAOXAcFXsWwDo73ZQiIDdnxTqr0mlFtnbfPT/jWyaexJ90U3Kyvtlj/mf0iaD rz6XdG7NHjIHYOsWTDEtOUzyPWliws/Vehh1n3bfDSqDP2P56b X-Received: by 2002:a05:7300:e82b:b0:2ca:7eb4:3e0f with SMTP id 5a478bee46e88-2f54b897f52mr5070659eec.5.1778199322328; Thu, 07 May 2026 17:15:22 -0700 (PDT) Received: from bmorris-M3Y3522M42 ([136.24.56.26]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2f8859eafc2sm103309eec.4.2026.05.07.17.15.20 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 07 May 2026 17:15:21 -0700 (PDT) From: joycathacker@gmail.com To: marcelo.leitner@gmail.com, lucien.xin@gmail.com Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, linux-sctp@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, security@kernel.org, Ben Morris , stable@vger.kernel.org Subject: [PATCH net] sctp: revalidate list cursor after sctp_sendmsg_to_asoc() in SCTP_SENDALL Date: Thu, 7 May 2026 17:14:55 -0700 Message-ID: <20260508001455.3137-1-joycathacker@gmail.com> X-Mailer: git-send-email 2.51.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Ben Morris The SCTP_SENDALL path in sctp_sendmsg() iterates ep->asocs with list_for_each_entry_safe(), which caches the next entry in @tmp before the loop body runs. The body calls sctp_sendmsg_to_asoc(), which may drop the socket lock inside sctp_wait_for_sndbuf(). While the lock is dropped, another thread can SCTP_SOCKOPT_PEELOFF the association cached in @tmp, migrating it to a new endpoint via sctp_sock_migrate() (list_del_init() + list_add_tail() to newep->asocs), and optionally close the new socket which frees the association via kfree_rcu(). The cached @tmp can also be freed by a network ABORT for that association, processed in softirq while the lock is dropped. sctp_wait_for_sndbuf() revalidates @asoc (the current entry) on re-lock via the "sk != asoc->base.sk" and "asoc->base.dead" checks, but nothing revalidates @tmp. After a successful return, the iterator advances to the stale @tmp, yielding either a use-after-free (if the peeled socket was closed) or a list-walk onto the new endpoint's list head (type confusion of &newep->asocs as a struct sctp_association *). Both are reachable from CapEff=0; the type-confusion path gives controlled indirect call via the outqueue.sched->init_sid pointer. Fix by re-deriving @tmp from @asoc after sctp_sendmsg_to_asoc() returns. @asoc is known to still be on ep->asocs at that point: the only callers that list_del an association from ep->asocs are sctp_association_free() (which sets asoc->base.dead) and sctp_assoc_migrate() (which changes asoc->base.sk), and sctp_wait_for_sndbuf() checks both under the lock before any successful return; a tripped check propagates as err < 0 and the loop bails before the re-derive. The SCTP_ABORT path in sctp_sendmsg_check_sflags() returns 0 and the loop hits 'continue' before sctp_sendmsg_to_asoc() is ever called, so the @tmp cached by list_for_each_entry_safe() still covers the lock-held free that ba59fb027307 ("sctp: walk the list of asoc safely") was added for. Fixes: 4910280503f3 ("sctp: add support for snd flag SCTP_SENDALL process in sendmsg") Cc: stable@vger.kernel.org Assisted-by: claude:mythos Signed-off-by: Ben Morris --- net/sctp/socket.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/net/sctp/socket.c b/net/sctp/socket.c index 58d0d9747f0b..1d2568bb6bc2 100644 --- a/net/sctp/socket.c +++ b/net/sctp/socket.c @@ -1986,6 +1986,15 @@ static int sctp_sendmsg(struct sock *sk, struct msghdr *msg, size_t msg_len) goto out_unlock; iov_iter_revert(&msg->msg_iter, err); + + /* sctp_sendmsg_to_asoc() may have released the socket + * lock (sctp_wait_for_sndbuf), during which other + * associations on ep->asocs could have been peeled + * off or freed. @asoc itself is revalidated by the + * base.dead and base.sk checks in sctp_wait_for_sndbuf, + * so re-derive the cached cursor from it. + */ + tmp = list_next_entry(asoc, asocs); } goto out_unlock; -- 2.43.0