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
Subject: Re: [PATCH net v4] net/smc: serialize clcsock release against CDC receive path
Date: Sat, 05 Dec 2026 03:05:33 +0000 [thread overview]
Message-ID: <179643993329.3146.692765287538829589@kernel.org> (raw)
In-Reply-To: <179635082914.26472.6075133370101625319@gmail.com>
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
prev parent reply other threads:[~2026-12-05 3:05 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 2:20 [PATCH net v4] net/smc: serialize clcsock release against CDC receive path Qican Ma
2026-12-04 6:36 ` Mahanta Jambigi
2026-12-05 3:05 ` netdev-bot+sashiko [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179643993329.3146.692765287538829589@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=alibuda@linux.alibaba.com \
--cc=davem@davemloft.net \
--cc=dust.li@linux.alibaba.com \
--cc=edumazet@kernel.org \
--cc=goonsomeway@gmail.com \
--cc=guwen@linux.alibaba.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=mjambigi@linux.ibm.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sidraya@linux.ibm.com \
--cc=tonylu@linux.alibaba.com \
--cc=willemb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox