* [PATCH net v2] net/smc: serialize clcsock release against CDC receive path
@ 2026-11-24 7:29 Qican Ma
2026-12-01 2:54 ` willemb
0 siblings, 1 reply; 3+ messages in thread
From: Qican Ma @ 2026-11-24 7:29 UTC (permalink / raw)
To: alibuda, dust.li, sidraya, mjambigi
Cc: tonylu, guwen, davem, edumazet, kuba, pabeni, horms, linux-rdma,
linux-s390, netdev
In smc_cdc_msg_recv_action(), receiving a close or senddone flag writes
RCV_SHUTDOWN to smc->clcsock->sk->sk_shutdown while holding only
bh_lock_sock(&smc->sk). Meanwhile __smc_release() drops the socket lock
and calls smc_clcsock_release() (which clears smc->clcsock and calls
sock_release() under clcsock_release_lock) before calling
smc_conn_free(&smc->conn). Even on paths that call smc_conn_free() first,
an in-flight SMC-R softirq that already looked up the connection in
smc_cdc_rx_handler() can still enter smc_cdc_msg_recv() concurrently with
smc_clcsock_release() and dereference or write through a freed clcsock.
Free the SMC connection before releasing clcsock in __smc_release(),
matching smc_close_active_abort() and smc_close_passive_work(). Because
smc_conn_free() sets conn->freed = 1 while lock_sock(sk) is held and
release_sock(sk) synchronizes on sk->sk_lock.slock before
smc_clcsock_release() runs, checking !smc->conn.freed under
bh_lock_sock(&smc->sk) in smc_cdc_msg_recv() guarantees that no CDC
handler accesses smc->clcsock once smc_clcsock_release() can start.
Found with an LLM-assisted code review tool and verified by inspection on
v7.4-rc4 (b6a9fa34ce4). Build-tested only; not runtime-tested due to lack
of an SMC-R/SMC-D setup.
Fixes: b38d732477e4 ("smc: socket closing and linkgroup cleanup")
Cc: stable@vger.kernel.org
Signed-off-by: Qican Ma <goonsomeway@gmail.com>
---
v2: resend via direct SMTP to fix line-wrapping corruption in v1;
verified clean git am on net/main both standalone and on top of
Bryam Vargas's v9 CDC cursor bounds series.
net/smc/af_smc.c | 4 ++--
net/smc/smc_cdc.c | 3 ++-
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
index bfc0c7e71a1..1d8a602729c 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);
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 32d6d03df32..499a2473b79 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 (!smc->conn.freed)
+ smc_cdc_msg_recv_action(smc, cdc);
bh_unlock_sock(&smc->sk);
sock_put(&smc->sk); /* no free sk in softirq-context */
}
--
2.50.1 (Apple Git-155)
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH net v2] net/smc: serialize clcsock release against CDC receive path
2026-11-24 7:29 [PATCH net v2] net/smc: serialize clcsock release against CDC receive path Qican Ma
@ 2026-12-01 2:54 ` willemb
2026-12-01 6:17 ` Qican Ma
0 siblings, 1 reply; 3+ messages in thread
From: willemb @ 2026-12-01 2:54 UTC (permalink / raw)
To: Qican Ma, alibuda, dust.li, sidraya, mjambigi
Cc: tonylu, guwen, davem, edumazet, kuba, pabeni, horms, linux-rdma,
linux-s390, netdev
Qican Ma wrote:
> In smc_cdc_msg_recv_action(), receiving a close or senddone flag writes
> RCV_SHUTDOWN to smc->clcsock->sk->sk_shutdown while holding only
> bh_lock_sock(&smc->sk). Meanwhile __smc_release() drops the socket lock
> and calls smc_clcsock_release() (which clears smc->clcsock and calls
> sock_release() under clcsock_release_lock) before calling
> smc_conn_free(&smc->conn). Even on paths that call smc_conn_free() first,
> an in-flight SMC-R softirq that already looked up the connection in
> smc_cdc_rx_handler() can still enter smc_cdc_msg_recv() concurrently with
> smc_clcsock_release() and dereference or write through a freed clcsock.
> Free the SMC connection before releasing clcsock in __smc_release(),
> matching smc_close_active_abort() and smc_close_passive_work(). Because
> smc_conn_free() sets conn->freed = 1 while lock_sock(sk) is held and
> release_sock(sk) synchronizes on sk->sk_lock.slock before
> smc_clcsock_release() runs, checking !smc->conn.freed under
> bh_lock_sock(&smc->sk) in smc_cdc_msg_recv() guarantees that no CDC
> handler accesses smc->clcsock once smc_clcsock_release() can start.
> Found with an LLM-assisted code review tool and verified by inspection on
> v7.4-rc4 (b6a9fa34ce4). Build-tested only; not runtime-tested due to lack
> of an SMC-R/SMC-D setup.
> Fixes: b38d732477e4 ("smc: socket closing and linkgroup cleanup")
> Cc: stable@vger.kernel.org
> Signed-off-by: Qican Ma <goonsomeway@gmail.com>
> ---
> v2: resend via direct SMTP to fix line-wrapping corruption in v1;
> verified clean git am on net/main both standalone and on top of
> Bryam Vargas's v9 CDC cursor bounds series.
> net/smc/af_smc.c | 4 ++--
> net/smc/smc_cdc.c | 3 ++-
> 2 files changed, 4 insertions(+), 3 deletions(-)
> diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
> index bfc0c7e71a1..1d8a602729c 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);
> 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 32d6d03df32..499a2473b79 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 (!smc->conn.freed)
> + smc_cdc_msg_recv_action(smc, cdc);
> bh_unlock_sock(&smc->sk);
> sock_put(&smc->sk); /* no free sk in softirq-context */
smc_conn_free() sets conn->freed = 1 (net/smc/smc_core.c:1287) under
lock_sock(sk) without holding sk->sk_lock.slock, whereas
smc_cdc_msg_recv() now reads smc->conn.freed concurrently under
bh_lock_sock(&smc->sk). Even though release_sock(sk) synchronizes on
sk->sk_lock.slock before smc_clcsock_release() starts, the concurrent
write and read are not mutually excluded and will trigger a KCSAN data
race. Use READ_ONCE(smc->conn.freed) here paired with
WRITE_ONCE(conn->freed, 1) in smc_conn_free() (and WRITE_ONCE() in
smc_conn_create()).
> }
> --
> 2.50.1 (Apple Git-155)
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH net v2] net/smc: serialize clcsock release against CDC receive path
2026-12-01 2:54 ` willemb
@ 2026-12-01 6:17 ` Qican Ma
0 siblings, 0 replies; 3+ messages in thread
From: Qican Ma @ 2026-12-01 6:17 UTC (permalink / raw)
To: willemb
Cc: alibuda, dust.li, sidraya, mjambigi, edumazet, kuba, pabeni,
horms, linux-rdma, linux-s390, netdev
Hi Willem,
Thanks for the careful review - you are right, the conn->freed write in
smc_conn_free() (under lock_sock) and the new read in smc_cdc_msg_recv()
(under bh_lock_sock) are not mutually excluded and would trigger a KCSAN
data race.
I have sent v3 with WRITE_ONCE(conn->freed, ...) in smc_conn_free() and
smc_conn_create() paired with READ_ONCE(smc->conn.freed) on the CDC side.
Thanks,
Qican Ma
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-01 6:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 7:29 [PATCH net v2] net/smc: serialize clcsock release against CDC receive path Qican Ma
2026-12-01 2:54 ` willemb
2026-12-01 6:17 ` Qican Ma
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox