Re: [PATCH net v6 2/3] net/smc: clear the buffer pointers before registering a connection

From: netdev-bot+sashiko

Date: Mon Nov 16 2026 - 20:06:36 EST


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@xxxxxxxxxx/

> 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