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=1796439935; b=DEOrus+KYJsak7jeDNcKSRQoQGUBw0XXDgEmZ5YUxkoluL0T4GorLHMO7yDP5Yb1HUx0 qlCuCGF3XkbsorUUSdpajh62Za4Hh7XbpqxhOVe9nU0gO0bhmPJkKwEFKJ3Y8tk83nZsJ rzOZqaqfG7S8toF5fS1PxXiDUAN7fP65xWSyNoxsnzFqnMiY6Y9cQEb1czSvbUF8LiDdY 2U+JM+vU5a/nCzaPuR9jtcjITcQZEqWV+pBd4JXSP4gONAH6F3Wq+xcZENEe+noQCUYAz fbHlZjedh9caiTVrP7PaibT3P8rzksGde3+C1+ibQkWeqm3zn0A5FEWtOs8WNj4W9hg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796439935; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=xtzbHZM5RotimaII5tn3vZ+wh8UJKqcRjfPTn4l2vpM=; b=GkzXnhlB8PMmjOHEqEneZ6OFk6IQ51uGa1bwzkG9UeBz8BqRsJGS5tqzg4P/p9YDlhhq ZkU3tudtLiIQuL9qWknFiw6E/c/c/jMmsj+Ayv3JdQedn+97ntJYjDKQAnAD+FWZKxELf UIOQE4MYCtXiutVJ/JK4zIOF+5DXxr7OX3c6hQvwG5aTmV7tDlaan6EppmAbROs/ycVEz k3SncAezpqXAHNvZP9wxByuOHdxe9weqSssXCMkO1EaWVzmA5BUGn9ETOSCEQ2q+h7ryj CeKvzHUWTg0IsuMJSbBsdS/8ftPy+BX6/y0qV8juK/JgGqQfvS9mUHTRSHGdLfM2kCQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=OWzL2gHF; 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 46023606A322; Sat, 5 Dec 2026 03:05:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=OWzL2gHF Received: by smtp.kernel.org (Postfix) with ESMTPSA id CAF981F0092B; Sat, 5 Dec 2026 03:05:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796439934; bh=xtzbHZM5RotimaII5tn3vZ+wh8UJKqcRjfPTn4l2vpM=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=OWzL2gHFwEjlcMGQppnEBluuQOEKdkgyE8/n3d9+JwDtsPOqucrhUr3bXq906Bxj3 NIAhej1Nis7K/ywi7AF1Luo5P9mvE1/WPKl8cE0U703/maJ2lqmS8roPeaV2BoGOA8 EVWFnG7fhTpInB2smDKD7iDaAXNTvuDEWLe34ZKrd/x3raBrxIT11JENGbJR5+Wj81 137RQwAT+g5mtOw4Q7Ucx+sc0K16yqEGhxYDV870qOMCtvGEL8rkMlfdFigiYBesu3 bMfxxuGKzyU5PwZDI2/fwlZoahYV3/j4GiUBU6ounwv7BcahsQU057U9PGks4DS4/x /gA0t5b04hR0g== Subject: Re: [PATCH net v4] net/smc: serialize clcsock release against CDC receive path From: netdev-bot+sashiko@kernel.org To: goonsomeway@gmail.com Cc: alibuda@linux.alibaba.com, dust.li@linux.alibaba.com, sidraya@linux.ibm.com, mjambigi@linux.ibm.com, tonylu@linux.alibaba.com, guwen@linux.alibaba.com, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, willemb@google.com, linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org, netdev@vger.kernel.org Date: Sat, 05 Dec 2026 03:05:33 +0000 Message-ID: <179643993329.3146.692765287538829589@kernel.org> In-Reply-To: <179635082914.26472.6075133370101625319@gmail.com> References: <179635082914.26472.6075133370101625319@gmail.com> X-sashiko-severity: High Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: linux-rdma@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider. Critical: 0 · High: 1 (1) · Medium: 1 · Low: 0 If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough). - [High] The patch claims to serialize clcsock release against the CDC receive path. - [Medium] The commit message says the send path has the same race: "a sendmsg() that acquires the socket lock in the release window can… Pre-existing issues: - [High] smc_conn_free() (net/smc/smc_core.c:1301-1302) calls `cancel_work_sync(&conn->abort_work)` on SMC-R connections unless it… -- net/smc: serialize clcsock release against CDC receive path This patch moves smc_conn_free() ahead of smc_clcsock_release() in __smc_release(). It also makes smc_cdc_msg_recv() skip smc_cdc_msg_recv_action() once conn->freed is set. A conn->freed and NULL clcsock guard is added to smc_tx_is_corked(), and the conn->freed accesses now use WRITE_ONCE()/READ_ONCE(). > diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c > index bfc0c7e71a12b..1d8a602729c13 100644 > --- a/net/smc/af_smc.c > +++ b/net/smc/af_smc.c > @@ -313,13 +313,13 @@ static int __smc_release(struct smc_sock *smc) > sk->sk_prot->unhash(sk); > > if (sk->sk_state == SMC_CLOSED) { > + if (!smc->use_fallback) > + smc_conn_free(&smc->conn); [Severity: High] This is a pre-existing issue, but does moving smc_conn_free() here make a deadlock with abort_work easier to hit? For SMC-R connections, smc_conn_free() does this, and every caller holds lock_sock(): net/smc/smc_core.c:smc_conn_free() { ... smc_cdc_wait_pend_tx_wr(conn); if (current_work() != &conn->abort_work) cancel_work_sync(&conn->abort_work); ... } The work function takes the same lock first: net/smc/smc_core.c:smc_conn_abort_work() { ... lock_sock(&smc->sk); smc_conn_kill(conn, true); ... } smc_cdc_msg_validate() can queue abort_work from softirq. It does this when the peer sends a CDC with failover_validation set and a seqno ahead of local_rx_ctrl.seqno, so the peer controls the trigger: CPU0 (kworker) CPU1 (close) smc_conn_abort_work() __smc_release() [holds lock_sock] lock_sock(&smc->sk) <- sleeps smc_conn_free() cancel_work_sync(&conn->abort_work) <- waits for CPU0 Neither wait can be interrupted. The cancel_work_sync() call predates this patch (commit b286a0651e44). Commit 13085e1b5cab ("net/smc: fix deadlock triggered by cancel_delayed_work_syn()") fixed the same pattern for tx_work by dropping the lock around the cancel, which is still what smc_close_cancel_work() does. Before this patch, __smc_release() called release_sock() around smc_clcsock_release() before it reached smc_conn_free(). An abort_work already waiting in lock_sock() could then get the lock and finish. Now smc_conn_free() runs right after smc_close_active(), and the lock is never dropped in between. Say abort_work starts while smc_close_active() is sleeping, for example in smc_close_final()->smc_cdc_get_slot_and_msg_send() while it waits for a WR slot. Would that now deadlock where it used to complete? Separately, if abort_work is pending but not yet running, cancel_work_sync() cancels it and its return value is ignored. Does that leak the sock_hold() that smc_cdc_msg_validate() takes before queue_work()? > if (smc->clcsock) { > release_sock(sk); > smc_clcsock_release(smc); > lock_sock(sk); > } > - if (!smc->use_fallback) > - smc_conn_free(&smc->conn); > } > > return rc; > diff --git a/net/smc/smc_cdc.c b/net/smc/smc_cdc.c > index 32d6d03df3214..34c654e6600b7 100644 > --- a/net/smc/smc_cdc.c > +++ b/net/smc/smc_cdc.c > @@ -428,7 +428,8 @@ static void smc_cdc_msg_recv(struct smc_sock *smc, struct smc_cdc_msg *cdc) > { > sock_hold(&smc->sk); > bh_lock_sock(&smc->sk); > - smc_cdc_msg_recv_action(smc, cdc); > + if (!READ_ONCE(smc->conn.freed)) > + smc_cdc_msg_recv_action(smc, cdc); [Severity: High] Does this guard cover every place that releases clcsock? smc_accept_dequeue() releases the clcsock of an SMC_CLOSED child directly. It holds only the parent's lock. It takes neither clcsock_release_lock nor the child's sock lock, and it never calls smc_conn_free(): net/smc/af_smc.c:smc_accept_dequeue() { ... if (new_sk->sk_state == SMC_CLOSED) { new_sk->sk_prot->unhash(new_sk); if (isk->clcsock) { sock_release(isk->clcsock); isk->clcsock = NULL; } ... } A child still in the accept queue can reach SMC_CLOSED in two ways: __smc_lgr_terminate()->smc_conn_kill()->smc_close_active_abort(), or abort_work->smc_conn_kill(). In smc_close_active_abort(), the SMC_ACTIVE/APPCLOSEWAIT1/APPCLOSEWAIT2 case sets SMC_CLOSED without calling smc_conn_free(). smc_conn_kill() sets conn->killed, not conn->freed. So conn->freed stays 0 for that child. Suppose smc_cdc_rx_handler() has already looked up the connection and taken sock_hold() before it is unregistered. It is then delayed before bh_lock_sock() here, for example by vCPU preemption or preemptible softirqs on PREEMPT_RT. In that window accept() can run smc_accept_dequeue(). The handler then passes the !READ_ONCE(smc->conn.freed) check. For a close or senddone flag, smc_cdc_msg_recv_action() executes: if (smc->clcsock && smc->clcsock->sk) smc->clcsock->sk->sk_shutdown |= RCV_SHUTDOWN; Nothing orders this against the sock_release() above. Could it become a NULL dereference, or a write into a TCP sock that has been freed and perhaps reused? The commit message only states the guarantee for smc_clcsock_release(). Would smc_accept_dequeue() also need to set conn->freed, or use the same serialization, before it releases clcsock? > bh_unlock_sock(&smc->sk); > sock_put(&smc->sk); /* no free sk in softirq-context */ > } [ ... ] > diff --git a/net/smc/smc_tx.c b/net/smc/smc_tx.c > index 0f0c6df3bf2ce..a69809474df56 100644 > --- a/net/smc/smc_tx.c > +++ b/net/smc/smc_tx.c > @@ -126,8 +126,12 @@ static int smc_tx_wait(struct smc_sock *smc, int flags) > > static bool smc_tx_is_corked(struct smc_sock *smc) > { > - struct tcp_sock *tp = tcp_sk(smc->clcsock->sk); > + struct tcp_sock *tp; > > + if (smc->conn.freed || !smc->clcsock) > + return true; [Severity: Medium] The commit message says: The send path has the same class of race: smc_tx_is_corked() dereferences smc->clcsock under lock_sock(), and a sendmsg() that acquires the socket lock in the release window can still observe a detached or freed clcsock. Can any path actually get here? The only way to reach smc_tx_is_corked() is smc_sendmsg()->smc_tx_sendmsg()->smc_tx_should_cork(). __smc_release() has two callers. One is smc_release(), the ->release op, which only runs after the last file reference is gone. The other is smc_close_non_accepted(), for children that never had a user file. So it doesn't look like the release_sock()/smc_clcsock_release()/lock_sock() window in __smc_release() can overlap a sendmsg(). The other clcsock release sites look blocked too. smc_sendmsg() only accepts ACTIVE, APPCLOSEWAIT1 and INIT, and smc_tx_sendmsg() returns -ENOTCONN in INIT. A sendmsg() that slept in smc_tx_wait() repeats this check on each loop before it gets to smc_tx_should_cork(): if (smc->sk.sk_shutdown & SEND_SHUTDOWN || (smc->sk.sk_err == ECONNABORTED) || conn->killed) return -EPIPE; The message also says "A dying connection is reported as corked so no further RDMA writes are triggered while teardown is in progress." Does the guard actually do that? smc_tx_should_cork() ignores the corked result once the sndbuf is full: if ((msg->msg_flags & MSG_MORE || smc_tx_is_corked(smc)) && atomic_read(&conn->sndbuf_space)) return true; smc_tx_sendmsg() then calls smc_tx_sndbuf_nonempty(conn). That function checks conn->killed and peer_conn_abort but not conn->freed, unlike smc_tx_pending(): if (smc->sk.sk_err || conn->freed) return; When the guard does take effect, the copied bytes are counted in send_done but never pushed. Since the patch has Cc: stable, could the message either name a concrete path for the send-side race or describe this hunk as hardening? If the freed check is still wanted, would smc_tx_sendmsg() or smc_tx_sndbuf_nonempty() be a better place for it than the cork predicate? > + > + tp = tcp_sk(smc->clcsock->sk); > return (tp->nonagle & TCP_NAGLE_CORK) ? true : false; > } -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/179635082914.26472.6075133370101625319%40gmail.com