* [PATCH net] sctp: check asoc->base.dead before the RCV_SHUTDOWN break in sctp_wait_for_connect()
@ 2026-09-09 2:46 Jun Yang
2026-09-09 18:44 ` Jakub Kicinski
0 siblings, 1 reply; 2+ messages in thread
From: Jun Yang @ 2026-09-09 2:46 UTC (permalink / raw)
To: Marcelo Ricardo Leitner, Xin Long, David S . Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Simon Horman, linux-sctp, netdev, linux-kernel, Jun Yang, stable,
TencentOS Corvus AI
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 <corvus@tencent.com>
Assisted-by: tencentos-corvus-ai:hy4-preview
Signed-off-by: Jun Yang <junvyyang@tencent.com>
---
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
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH net] sctp: check asoc->base.dead before the RCV_SHUTDOWN break in sctp_wait_for_connect()
2026-09-09 2:46 [PATCH net] sctp: check asoc->base.dead before the RCV_SHUTDOWN break in sctp_wait_for_connect() Jun Yang
@ 2026-09-09 18:44 ` Jakub Kicinski
0 siblings, 0 replies; 2+ messages in thread
From: Jakub Kicinski @ 2026-09-09 18:44 UTC (permalink / raw)
To: Jun Yang
Cc: Marcelo Ricardo Leitner, Xin Long, David S . Miller,
Eric Dumazet, Paolo Abeni, Simon Horman, linux-sctp, netdev,
linux-kernel, Jun Yang, stable, TencentOS Corvus AI
On Wed, 9 Sep 2026 10:46:23 +0800 Jun Yang wrote:
> Subject: [PATCH net] sctp: check asoc->base.dead before the RCV_SHUTDOWN break in sctp_wait_for_connect()
This reportedly breaks sctp-related selftests in tree.
Please try to run those before you repost.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-09 18:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-09 2:46 [PATCH net] sctp: check asoc->base.dead before the RCV_SHUTDOWN break in sctp_wait_for_connect() Jun Yang
2026-09-09 18:44 ` Jakub Kicinski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®