Article View: linux.kernel.netdev
Article #17550Re: [PATCH net v6 2/3] net/smc: clear the buffer pointers before registering a connection
From: netdev-bot+sashiko
Date: Tue, 17 Nov 2026 01:06
Date: Tue, 17 Nov 2026 01:06
147 lines
14043 bytes
14043 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 ยท High: 1 ยท Medium: 0 ยท 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] This patch still leaves rmb_desc and sndbuf_desc dangling while
the connection can be found by its token.
--
net/smc: clear the buffer pointers before registering a connection
This patch clears conn->rmb_desc and conn->sndbuf_desc under the socket
spinlock in smc_conn_create(). The goal is that a retried handshake does
not register the connection under a new token with stale buffer pointers.
It also makes smc_cdc_msg_recv_action() return early when rmb_desc is
NULL.
Closes: https://lore.kernel.org/all/179241208347.3135.18021879529736748765@kernel.org/
> diff --git a/net/smc/smc_cdc.c b/net/smc/smc_cdc.c
> index ee5ba6c7a5b4a..b3bcc206efe3e 100644
> --- a/net/smc/smc_cdc.c
> +++ b/net/smc/smc_cdc.c
> @@ -334,6 +334,10 @@ static void smc_cdc_msg_recv_action(struct smc_sock *smc,
> struct smc_connection *conn = &smc->conn;
> int diff_cons, diff_prod, diff_tx;
>
> + /* smc_conn_create() can have cleared rmb_desc */
> + if (!smp_load_acquire(&conn->rmb_desc))
> + return;
> +
> smc_curs_copy(&prod_old, &conn->local_rx_ctrl.prod, conn);
> smc_curs_copy(&cons_old, &conn->local_rx_ctrl.cons, conn);
> smc_cdc_msg_to_host(&conn->local_rx_ctrl, cdc, conn);
> @@ -484,7 +488,8 @@ static void smc_cdc_rx_handler(struct ib_wc *wc, void *buf)
> read_lock_bh(&lgr->conns_lock);
> conn = smc_lgr_find_conn(ntohl(cdc->token), lgr);
> /* The connection is in the token tree before __smc_buf_create()
> - * sets its RMB: drop a CDC that comes earlier.
> + * sets its RMB: drop a CDC that comes earlier. rmb_desc is cleared
> + * under the socket spinlock; smc_cdc_msg_recv_action() tests it there.
> */
> if (!conn || conn->out_of_sync || !smp_load_acquire(&conn->rmb_desc)) {
> read_unlock_bh(&lgr->conns_lock);
> diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c
> index 02269cede641e..9ef9019bc4974 100644
> --- a/net/smc/smc_core.c
> +++ b/net/smc/smc_core.c
> @@ -2024,6 +2024,15 @@ int smc_conn_create(struct smc_sock *smc, struct smc_init_info *ini)
> spinlock_t *lgr_lock;
> int rc = 0;
>
> + /* A retried handshake comes back with the buffer pointers of the
> + * failed attempt still set: clear them before the connection is
> + * registered. smc_cdc_msg_recv_action() tests rmb_desc under this lock.
> + */
> + spin_lock_bh(&smc->sk.sk_lock.slock);
> + WRITE_ONCE(conn->rmb_desc, NULL);
> + WRITE_ONCE(conn->sndbuf_desc, NULL);
> + spin_unlock_bh(&smc->sk.sk_lock.slock);
[Severity: High]
Is this clear too late to close the window the commit message describes?
smc_conn_free() releases the buffers while the connection is still in the
token tree, and it does so without the socket spinlock:
net/smc/smc_core.c:smc_conn_free() {
...
if (!list_empty(&lgr->list))
smc_buf_unuse(conn, lgr); /* allow buffer reuse */
smc_lgr_unregister_conn(conn);
...
}
smc_buf_unuse() leaves conn->rmb_desc and conn->sndbuf_desc set. For
SMC-R, smcr_buf_unuse() either frees the descriptor or puts it back in
the pool:
net/smc/smc_core.c:smcr_buf_unuse() {
...
if (buf_desc->is_reg_err) {
...
smc_lgr_buf_list_del(lgr, is_rmb, buf_desc);
...
smc_buf_free(lgr, is_rmb, buf_desc);
} else {
memzero_explicit(buf_desc->cpu_addr, buf_desc->len);
WRITE_ONCE(buf_desc->used, 0);
}
}
In the second case, smc_buf_get_slot() can give the RMB to another
connection.
Between smc_buf_unuse() and smc_lgr_unregister_conn(), smc_cdc_rx_handler()
can still find the connection for a CDC that carries the old token. The
CDC passes the non-NULL rmb_desc test there. The new test in
smc_cdc_msg_recv_action() also rejects only NULL, so the handler goes on
to:
diff_prod = smc_curs_diff(conn->rmb_desc->len, &prod_old,
&conn->local_rx_ctrl.prod);
It also reaches conn->rmb_desc->cpu_addr through
smc_cdc_handle_urg_data_arrival().
When is_reg_err is set, is this a use-after-free of the smc_buf_desc?
When it is not set, isn't the CDC applied to an RMB that may now belong to
another connection?
There are two more cases. A handler that looked up the connection before
smc_lgr_unregister_conn() and takes the slock any time before a retry
reaches smc_conn_create() sees the same stale pointer. If no retry happens,
nothing ever clears the pointers. SMC-R also has no RX drain on this path,
since smc_cdc_wait_pend_tx_wr() only waits for TX completions.
is_reg_err gets set when smc_wr_reg_send() fails in smcr_link_reg_buf():
-EINTR from a signal during connect(), -EIO from a flushed REG_MR WR, or
-EPIPE on timeout. A negative CONFIRM_RKEY response from the peer leads to
the returned-to-pool case. The token comes from the global nexttoken
counter in smc_lgr_register_conn(), so the peer can predict it.
The patch notes say "a pointer seen set stays set", and the new comment
in smc_cdc_rx_handler() points to the slock re-test.
Does a set pointer mean the buffer still belongs to this connection,
though?
Could the pointers instead be cleared under the slock where the buffers
are released, in smc_buf_unuse()/smc_conn_free()? Or could the token be
unregistered before the buffers are released? Either would replace the
clear in smc_conn_create() rather than add to it.
> lgr_list = ini->is_smcd ? &ini->ism_dev[ini->ism_selected]->lgr_list :
> &smc_lgr_list.list;
> lgr_lock = ini->is_smcd ? &ini->ism_dev[ini->ism_selected]->lgr_lock :
--
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112-b4-disp-1c8d3a53-v6-0-36a38ae35021%40proton.me
Technical Details
Message-ID:
<179487758425.3136.7345936021290037161@kernel.org>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-364867-linux-kernel-netdev=dewy.ruReferences:
<20261112-b4-disp-1c8d3a53-v6-2-36a38ae35021@proton.me>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-364867-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net v6 2/3] net/smc: clear the buffer pointers before registering a connection Date: Tue, 17 Nov 2026 01:06:24 +0000 Organization: Usenet Network Message-ID: <179487758425.3136.7345936021290037161@kernel.org> References: <20261112-b4-disp-1c8d3a53-v6-2-36a38ae35021@proton.me> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2208694"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:CroCqtOlld+ydO55MUvZGcKzVIg= sha256:BZPVf5FX4J51fZMu7V8W1x6A7McKZKR8YE0mLgNkonU= sha1:NqGri5OylYpaRYCN7x4yENSdC1c= sha256:M3R+QvWMaidR/C2B2XICYuCGKbytJ4R4E6qsBJTUbXY= 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 61F6B114DEF; Tue, 17 Nov 2026 04:06:48 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.401 X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, 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] 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 e4Tj2fsDhkic; Tue, 17 Nov 2026 04:06:44 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-364867-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 sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mail.dewy.ru (Postfix) with ESMTPS id 8E9FA114DC6; Tue, 17 Nov 2026 04:06:34 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sin.lore.kernel.org (Postfix) with ESMTP id D64B024109; Tue, 17 Nov 2026 01:06:30 +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=1794877587; b=Ny4SbALHsxLd5Fz9zPO+MU1f7mTSvmUcF1iTml54WKKIK25h+hhwMRZDbagr0AoqBUEF wi1S3OavPli1QYE66URIDHjXUO+HMouQa2TpyC2Wbqts+fcAJKTfnYSwbzIhon9INANiT 9A6J2cMH7mEzu/GWIk/GYV0tGxGpKlAGvtjHhlHkG7nD1sukJWysA067dLxW50cu5KmzJ vLyskwmTUsAnBB0scwDq5nABfidru+JN7ybnehtMaObBJ1p+DPt3bPUmE/CAy/9z+vdcA q1RpkOP7pr2k+exIePElfsgVW0PGMs7RhnX0I+NnYqVM3p26HpInQ1Vr72alRbuvbUQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794877587; 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=FtCHv2hJNjrIBksgmbvYqxzyYPeLptLTLEm0XlQYrJE=; b=Bq54EsfOtZU9jr6ptPjqcQ2ZgZ7VhpcMBxqmMI1r8Bje4qWIdA3XIT23Js7Ih9zPLP+d iijCixW9PjeMFGry8YEWq5LxXsR5paeMbnVC5xskGnu31F5yMeRcDI2rZNCQBPoRmDXLd EUwctwoP1bnTBqBfT7C9e2suXenBV4F0UYvAWxnAwtHK25WerOnfhGyK2f7lEudJYWO4V Q1Jff7OMr1SQpVaZ3VZEm7106T8B3qbrB5d6/ylxCvoKQiuUQebKqP2RHWHzItm2Edm3y fja7NaNRL6nc8VoeQ6t1GCe5FR3ghtmCNbH48dZsLpEUWAsxKpTl1sqKBH114xcZINg== 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=PTE+JNZE; 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 19319606A33B; Tue, 17 Nov 2026 01:06:27 +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=PTE+JNZE 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=1794877586; b=4zqYHRoNFQbRPGwDuTrTVf82JUcXa4WlX8lOIuL8FN+PUTkhW/rPH+Nks742+HJm9EI2 LlAMa2eYQXijW4dgp95mykmk1H/sGKPyFTyiawzvnlZrAEP3ogVYEuYMpvfGSsmI1ymhQ RWhytzp7MlBSxigmj3bLo18aC1oblf56g0kErs/6rAu9KiVtxqFrCnMPWBPpwrF2RzSVP nXxeFr7UAFPlzoEn8puPnzi+rOFUXYPDFvUGAH3zUc5zhcux6bk408iEekakc7uHYEOVw 7BBBTHtZkyNNMNbO1xWiRR8QOVUB3sUU7/VHIaAP0dxWwHV03gcAt7ndtgaK01sNCgw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794877586; 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=FtCHv2hJNjrIBksgmbvYqxzyYPeLptLTLEm0XlQYrJE=; b=VKemAaOeZkFSntUVNYawPs1scbM/ywABuMcCdTkoRCaD2c/8muGeAi23sCyDQmmSVEC7 oXOHqOzInX3FHWhLaxnCniYKd2Wmsd4gSa8bZJfziFgGMcfraoGf7YuFtokvykwXQNMHO MyQ7O/EizXuO5IC61vkz0McnJX52YU0LXIOHgjNf5Rrwfm8qOY7pg1UY3oFm6k6at552A Pvl3LyFaNpPtu1xmK1+UGVOkzMHUqKqe0+atNDe4+H4v/9dItYkKaE9n2tQ9aL3b8q5pR Y8IYsnKz/dqCHSIvdHF8+MsWgyI7KSmzz1eIMXU8yHqxaPu90CDHJ467OuLF03z6cvw== 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=PTE+JNZE; 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 35031606A31C; Tue, 17 Nov 2026 01:06:25 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4BBE1F000C4; Tue, 17 Nov 2026 01:06:24 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794877585; bh=FtCHv2hJNjrIBksgmbvYqxzyYPeLptLTLEm0XlQYrJE=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=PTE+JNZEjBjJVRA530hJmDLXRIG1kp1wjjGGDbIsDzH+JavxPVvqtldEbXgOMBHYm HDBdV2y0af7sCnrsAzl5Moj64afbGw7cIDiK1TcT1ejfIC6eSpYmrgGCmjlss6FgXL xkg2vINFVhqWT6+98+6OYVPrXjUadR3WFVGmnCow0qDA1ZUxDAS+bZMafrrTZOAxzF Yy4YVd9X8pj0tZ/pz18uzvrwUxymI3KkYOy/RktGWETS3wvWpnsaUeGglr3v5QYMoP gjZaNU8fKug9rLS6tB4gQoTQmo0rW94rAXZzSmOiU+Ik/jeOdO86gIX5SlzaGuq9Yu i9aZmv3PU/HCg== X-Cc: mjambigi@linux.ibm.com, kuba@kernel.org, dust.li@linux.alibaba.com, davem@davemloft.net, edumazet@kernel.org, sidraya@linux.ibm.com, pabeni@redhat.com, alibuda@linux.alibaba.com, hwippel@linux.ibm.com, linux-kernel@vger.kernel.org, wenjia@linux.ibm.com, netdev@vger.kernel.org, hidayath@linux.ibm.com, ubraun@linux.ibm.com, tonylu@linux.alibaba.com, linux-rdma@vger.kernel.org, guwen@linux.alibaba.com, linux-s390@vger.kernel.org, horms@kernel.org X-In-Reply-To: <20261112-b4-disp-1c8d3a53-v6-2-36a38ae35021@proton.me> 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