Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: hexlabsecurity@proton.me
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
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	[thread overview]
Message-ID: <179487758425.3136.7345936021290037161@kernel.org> (raw)
In-Reply-To: <20261112-b4-disp-1c8d3a53-v6-2-36a38ae35021@proton.me>

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

  parent reply	other threads:[~2026-11-17  1:06 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-13  0:32 [PATCH net v6 0/3] net/smc: order the CDC receive path against buffer publication Bryam Vargas via B4 Relay
2026-11-13  0:32 ` [PATCH net v6 1/3] net/smc: order the CDC receive path against RMB publication Bryam Vargas via B4 Relay
2026-11-14  0:33   ` sashiko-bot
2026-11-13  0:32 ` [PATCH net v6 2/3] net/smc: clear the buffer pointers before registering a connection Bryam Vargas via B4 Relay
2026-11-14  0:33   ` sashiko-bot
2026-11-17  1:06   ` netdev-bot+sashiko [this message]
2026-11-13  0:32 ` [PATCH net v6 3/3] net/smc: skip the DMB nocopy accounting until the send buffer is set Bryam Vargas via B4 Relay
2026-11-14  0:33   ` sashiko-bot
2026-11-17  1:06   ` netdev-bot+sashiko

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=179487758425.3136.7345936021290037161@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=guwen@linux.alibaba.com \
    --cc=hexlabsecurity@proton.me \
    --cc=hidayath@linux.ibm.com \
    --cc=horms@kernel.org \
    --cc=hwippel@linux.ibm.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.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=ubraun@linux.ibm.com \
    --cc=wenjia@linux.ibm.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