🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
3 messages
3 total messages Started by Qican Ma Tue, 24 Nov 2026 03:21
[PATCH net] net/smc: serialize clcsock release against CDC receive path
#21493
Author: Qican Ma
Date: Tue, 24 Nov 2026 03:21
68 lines
13773 bytes
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>
---
 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)
Re: [PATCH net] net/smc: serialize clcsock release against CDC receive path
#21505
Author: Dust Li
Date: Tue, 24 Nov 2026 04:25
28 lines
9914 bytes
On 2026-11-23 19:21:06, 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.

This fails to apply to net/main

Best regards,
Dust
Re: [PATCH net] net/smc: serialize clcsock release against CDC receive path
#21573
Author: Qican Ma
Date: Tue, 24 Nov 2026 07:29
15 lines
11560 bytes
Hi Dust,

Apologies for the trouble - our v1 mail had the 95-char hunk header on
smc_cdc_msg_recv() line-wrapped by the Gmail HTTP gateway.

Note that this clcsock release vs CDC receive race is an independent
issue from Bryam Vargas's CDC cursor bounds series, and I have verified
that it applies cleanly with zero conflicts both directly on net/main
(4392bb809812) and on top of his 6-patch v9 series.

I am sending a clean [PATCH net v2] via direct SMTP right away.

Best regards,
Qican Ma
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads