🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #27224

Re: [PATCH net v4] net/smc: serialize clcsock release against CDC receive path

#27224
From: netdev-bot+sashiko
Date: Sat, 05 Dec 2026 03:05
244 lines
17063 bytes
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
Technical Details
Message-ID: <179643993329.3146.692765287538829589@kernel.org>
Path: mbox-mo1.pugleaf.net!news-fra.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ro.newsdeef.eu!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377806-linux-kernel-netdev=dewy.ru
References: <179635082914.26472.6075133370101625319@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-fra.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ro.newsdeef.eu!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377806-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v4] net/smc: serialize clcsock release against CDC
 receive path
Date: Sat, 05 Dec 2026 03:05:33 +0000
Organization: Usenet Network
Message-ID: <179643993329.3146.692765287538829589@kernel.org>
References: <179635082914.26472.6075133370101625319@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2940779"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:flbAgAPi5/9czh6qYDVBUuu1vu8= sha256:rGEZ/xYT0BCo5QYwlTP+6GR3BIUlH/+pwE5Q9tETAMU=
	sha1:fo5shR9Q971+lo/lH7SNXakKJOE= sha256:UM7dJcjmLd+7Tna96xYg3K12L3/6bDTe9Y1SfPW43sQ=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 7EC17117D54; Sat,  5 Dec 2026 06:05:58 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.541
X-Spam-Status: No, score=-3.541 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id zihuMdWrxMV3;
	Sat,  5 Dec 2026 06:05:51 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-377806-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id E2FD1117D20; Sat,  5 Dec 2026 06:05:40 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id CE50736690; Sat,  5 Dec 2026 03:05:36 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796439936;
	b=nN0qXKGwMuOQvpyyXtu7K9xT/Xs1PTkXsF2Rnj6HAQhwqEyNve+YcCMFV/b7tUx53T6v
	 RiMhB4xbG7Az3rdgt6vwbRKRstDkmh9GsUXF74gCJw2C9oLobJb5mNLSOJKyUVk7WtfxJ
	 maljY/01hdSkTO8ju64BqGOWKVI/a/9pOa8/iR8MoRr0/l1J6ARdTtlkc0wGiTHzXn25x
	 U6JeKwZL5xP02ZFXioRew8A439yXvhin7BWUQbZktiP8yV7AloMY41uExtbJBFE5pttSJ
	 yuQ4mMApthrfVejaL46zrQ8Qv5ZSteFxIFnbgd+3XtXUNl+oa81VKC2TnjMXDMFVwjQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796439936;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=xtzbHZM5RotimaII5tn3vZ+wh8UJKqcRjfPTn4l2vpM=;
	b=ZaX4g8b6Kaj/LVNiW+qmxB9KL3KJxI/B7+URJ+ycLNaysh1L0IldXSh2FsSkZZVvDEVR
	 mSvR8Dg1xmhETukt56aPhjVka15/9kdLZzsmK/fom6HHSllDB//1PEt/WTuClkLqieNnb
	 BQ1mtDHsinHnYQ/QnJ2OyXzj0rNTO0Jk3aSeG2bNLqcz3BHXEDwn3VeOZNi838jtTCAK5
	 HK1RZLwtk8OgIMvEQQIg97oPZhAG0+i7BZQqs2jLBg7IcB3fg99bQEvzRk8+YfTEbX9/S
	 2XFF/b38W6S4JvyeOXWmdpQsrvrh3qN5A9Ihcb6asiU6MMzxxUf3+NeSPxz+DuD7m8Q==
X-ARC-Authentication-Results: i=2; 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=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 28403606A339;
	Sat,  5 Dec 2026 03:05:36 +0000 (UTC)
X-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
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-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==
X-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==
X-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
X-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)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id CAF981F0092B;
	Sat,  5 Dec 2026 03:05:33 +0000 (UTC)
X-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==
X-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
X-In-Reply-To: <179635082914.26472.6075133370101625319@gmail.com>
X-sashiko-severity: High
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list