From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (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 E7A0E2EC54A for ; Wed, 9 Sep 2026 02:46:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788922006; cv=none; b=EnwCyzynQq7R7+b4+4fjG5/BQznYSv9gmKla/IEP0P/5C/+aTwjVyQioQxjCP05DB62fPkTJKiRVFEcKKV8BYOotX3q/I3d4FgUDncrIkV62YVbiRh8fh5f9MHaaM/gLAwwBEqTsN9PPEQ7xO1dNWPMeMr3i2FBIVLTEdZNBM8s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788922006; c=relaxed/simple; bh=FaMuIMu7x2D3aJYKdS2ouRjVT1y2n3u88iUjSdpGrRQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=hr4ub+rJVnJ0oAjnWgJfQQNaAIFUsqWJZeQa+6482/TSLkzc76X5Lcp0tYGlxNTPgOknXJFha+uKBuP0ur4dTCt43pkUcZXekKMksceFNw1NMXb963H7u6Fo9dGhszUVrtVzGmvP0Iqg6k+ltfHrSOd7lJc4JSJIvtfdwXjNwJY= 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=WR6/7I4V; arc=none smtp.client-ip=209.85.210.181 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="WR6/7I4V" Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-84e27035206so5079633b3a.3 for ; Tue, 08 Sep 2026 19:46:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788922004; x=1789526804; 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=ZO7tbb4HSzx3MW7qh3I4JqZjxCZe9pXRQ8RRhmehi7c=; b=WR6/7I4Vi0fVIYRfp6HF5e67IBBWtRGM8m0XsYWT18d0KF8DgXZGbu8/xz+pALbQ+T vCR951JMJHfo14q69GTiM9+Lo5F94xKeA2UlZ6OuVuTfLzl2ZMcnMLnwVyl8D4zM0bfA KJnbDEoxANms1VHEUfccJmXNqzoYCeREvQ3qhzSphhIJZHZmzOvPqpLuo9deyK+Da7lT 0hBLy8Z1XwoGGz5JWWht614yFm4odVliMPtQ5QtzgxcbzPdpH7DNgaJR1xZKJlsD5P1V J3AXQSbpPK4faNA4D6mLeLUy/QCxTK9NvnybOrqxohlaHDWb/qhfIfyltRQM6/sbYOhG gY0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788922004; x=1789526804; 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=ZO7tbb4HSzx3MW7qh3I4JqZjxCZe9pXRQ8RRhmehi7c=; b=Gu/vy4rmUz+VWYw3RcC3I53SxBYqs5Aa9dQapGbMM2WB2NVusn+vj3Q5Y6xwDj9/Yz 5OCdY0QH+4yT2VXnSaEdmRPwTU7lwn2a6f5Cmk+P4sVEsOw2UKxRP7NtRniXZoIeScE3 dALHW3bhw7aBDE+MVXR5Csutv3qnK+s1v9AczAP3ZGL7CtY/yyZU3R+6L6rrT9XbUc62 BptVfjgbNd9Zs5ML6uaWWcfJkyrUANvXPINTnHXeeZ/w0n/umLUYvcK6o/QtI7Q4AOnt ghjqQZs2dR7cddZni+blN7mRWJjQa8xD3z545hbmCliZyqQqoACcma/cwUkTolf/UzXr uO3A== X-Forwarded-Encrypted: i=1; AKwUvBwfkNVlB84mUgCECqqK5IcKf7pbpmGoyxWomHjxi9mz9vIWSX8fHNoK5BPSt6oiz69T/s1GMsUkoHqhogI=@vger.kernel.org X-Gm-Message-State: AFuF++lexTSX4pxiOxt+C+D0PgLSPwrGU5ZlCBEAQibf2BldEmBFt2Wa tUh/7NIHkbb8XotKHZK4wl2Q0LA7ewkJTtACshxv/aLa38r345I/8BTw X-Gm-Gg: AYBFou0J9Fc+1elT02KjrvjHzSUDLfR52Rvqsq9iVMt9/EIkBWIMFkPKLsuwhoedkzt bT/KSM/kK+wJcSixc+n1eGkYCScV7k0iByoTAGAV28gcdjD1Q/LwPyJ4niVkoezDmp+cZS52gJu Skf7Lp1EiiRSCsr7yoaUij6JifQ1NnXWQP5I6TRNcwjL6TrRNHBkhBBPsMunlwsvKksCbL3Gf64 IBnKZXk+YJak0sZEXgYb+/Axy/QtDEa92/0m6gujkuRHTaqirlahmNPcaJW5wJKugECjWN9qDP4 WZUFUvTpCEr72QJmltPHOHKHZm56xwqbV4lzhDwW79u2WvISvSDc0C2dcQMI8dyTIv0SePybHBh ebWHx4cgEwWl0IYrtiQ1t92BLLctcv/6E/hlFCuOBE2E7HJdpTldlv6sRxz3o5JjHOxdGryNJYF Af1POWgbbLcTmVlf4xbFLJH9KLqgOdNY0HlpCTygyGdKs1JGPDfSrMKCWOLFXsy02vHAOGVHjYw w== X-Received: by 2002:a05:6a21:6f12:b0:398:8870:b58f with SMTP id adf61e73a8af0-3da3a03ef42mr48516402637.14.1788922003934; Tue, 08 Sep 2026 19:46:43 -0700 (PDT) Received: from TENCENT64.site ([103.7.29.106]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-cc4554a98fesm5977157a12.30.2026.09.08.19.46.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2026 19:46:43 -0700 (PDT) From: Jun Yang X-Google-Original-From: Jun Yang To: Marcelo Ricardo Leitner , Xin Long , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Simon Horman , linux-sctp@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Jun Yang , stable@vger.kernel.org, TencentOS Corvus AI Subject: [PATCH net] sctp: check asoc->base.dead before the RCV_SHUTDOWN break in sctp_wait_for_connect() Date: Wed, 9 Sep 2026 10:46:23 +0800 Message-ID: <20260909024626.3494588-1-junvyyang@tencent.com> X-Mailer: git-send-email 2.43.7 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit sctp_wait_for_connect() sleeps with the socket lock dropped, so the association can be destroyed underneath it: an out-of-the-blue ABORT answering the INIT is drained from the backlog by that release_sock() and ends in sctp_association_free(). The loop does revalidate the association after waking, but the (sk->sk_shutdown & RCV_SHUTDOWN) break is evaluated before all of those checks and leaves the loop with err == 0. A concurrent shutdown(fd, SHUT_RD) - inert on a one-to-many socket, where it only sets the flag - therefore makes the function report a dead association as connected, and the sctp_association_put() on the way out drops the last reference. sctp_sendmsg_to_asoc() trusts that 0. Commit c863850ce22e ("sctp: not free the new asoc when sctp_wait_for_connect returns err") turns a failure into -ESRCH to stop exactly this double free, but it only covers err != 0. The freed association is then used by sctp_datamsg_from_user() and sctp_set_owner_w(), and destroyed a second time by sctp_sendmsg(). Test asoc->base.dead at the top of the loop, as commit ca3af4dd28cf ("sctp: do not free asoc when it is already dead in sctp_sendmsg") already does in sctp_wait_for_sndbuf(), so a destroyed association always leaves via do_error. Keep the existing return values rather than adding an -ESRCH escape, since sctp_wait_for_connect() is also the return value of connect(). base.dead is false on the first iteration in both callers - the socket lock is held until the first release_sock() - so nothing changes for a live association. Reproduced on v7.3-rc2. refcount_t: addition on 0; use-after-free. WARNING: lib/refcount.c:25 at refcount_warn_saturate+0xf5/0x110 CPU: 0 UID: 1000 PID: 261 Comm: poc 7.3.0-rc2 #1 sctp_association_hold+0x96/0xa0 sctp_sendmsg_to_asoc+0xc76/0x1c60 sctp_sendmsg+0x11c0/0x1ee0 __sys_sendto+0x3e7/0x470 list_del corruption, ff11000104fa2070->next is LIST_POISON1 kernel BUG at lib/list_debug.c:56! sctp_association_free+0x80/0x7c0 sctp_sendmsg+0x199f/0x1ee0 __sys_sendto+0x3e7/0x470 Fixes: 668c9beb9020 ("sctp: implement assign_number for sctp_stream_interleave") Cc: stable@vger.kernel.org Reported-by: TencentOS Corvus AI Assisted-by: tencentos-corvus-ai:hy4-preview Signed-off-by: Jun Yang --- A reproducer for this issue is available if requested. net/sctp/socket.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/net/sctp/socket.c b/net/sctp/socket.c index c7b9e325ec1c..de4bae94c9fa 100644 --- a/net/sctp/socket.c +++ b/net/sctp/socket.c @@ -9400,12 +9400,16 @@ static int sctp_wait_for_connect(struct sctp_association *asoc, long *timeo_p) for (;;) { prepare_to_wait_exclusive(&asoc->wait, &wait, TASK_INTERRUPTIBLE); + /* The asoc can be destroyed while sleeping below, and the + * RCV_SHUTDOWN break reports success, so check it first. + */ + if (asoc->base.dead) + goto do_error; if (!*timeo_p) goto do_nonblock; if (sk->sk_shutdown & RCV_SHUTDOWN) break; - if (sk->sk_err || asoc->state >= SCTP_STATE_SHUTDOWN_PENDING || - asoc->base.dead) + if (sk->sk_err || asoc->state >= SCTP_STATE_SHUTDOWN_PENDING) goto do_error; if (signal_pending(current)) goto do_interrupted; -- 2.43.7