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 3/3] net/smc: skip the DMB nocopy accounting until the send buffer is set
Date: Tue, 17 Nov 2026 01:06:25 +0000 [thread overview]
Message-ID: <179487758596.3136.12928828467382443502@kernel.org> (raw)
In-Reply-To: <20261112-b4-disp-1c8d3a53-v6-3-36a38ae35021@proton.me>
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 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 new NULL check only covers the time before
smcd_buf_attach().
- [Medium] The patch stops the NULL dereference, but it keeps processing
a CDC that, by the patch's own new comment, can come from the old peer…
--
net/smc: skip the DMB nocopy accounting until the send buffer is set
This patch changes smcd_buf_attach() to publish conn->sndbuf_desc with a
release store once sndbuf_space has been set. While sndbuf_desc is still
NULL, smc_cdc_msg_recv_action() now skips the SMC-D DMB nocopy accounting.
The aim is to avoid a NULL dereference when the old peer of a reused DMB
sends a consumer update before the new connection has attached its send
buffer.
> diff --git a/net/smc/smc_cdc.c b/net/smc/smc_cdc.c
> index b3bcc206efe3e..4a4a279b405b1 100644
> --- a/net/smc/smc_cdc.c
> +++ b/net/smc/smc_cdc.c
[ ... ]
> @@ -357,12 +358,19 @@ static void smc_cdc_msg_recv_action(struct smc_sock *smc,
> * peer RMB, then update tx_curs_fin and sndbuf_space
> * here since peer has already consumed the data.
> */
> + sndbuf_desc = NULL;
> if (conn->lgr->is_smcd &&
> smc_ism_support_dmb_nocopy(conn->lgr->smcd)) {
> + /* NULL until smcd_buf_attach(), but the old peer of
> + * a reused DMB can already signal us.
> + */
> + sndbuf_desc = smp_load_acquire(&conn->sndbuf_desc);
> + }
> + if (sndbuf_desc) {
[Severity: Medium]
The NULL dereference is gone. But the new comment says this CDC can come
from the old peer of a reused DMB, so should it be processed at all?
smcd_cdc_rx_tsklet() passes the CDC here without checking its seqno, token
or source. smcd_cdc_msg_to_host() then overwrites local_rx_ctrl.prod, cons,
prod_flags and conn_state_flags unconditionally:
net/smc/smc_cdc.h:smcd_cdc_msg_to_host() {
...
smc_curs_copy(&local->cons, &temp, conn);
local->prod_flags = peer->cons.prod_flags;
local->conn_state_flags = peer->cons.conn_state_flags;
}
Only the tx_curs_fin/sndbuf_space sync is skipped here. The connection may
still be in its CLC handshake, and the rest of smc_cdc_msg_recv_action()
still runs on the stale data:
- diff_cons is added to peer_rmbe_space
- diff_prod is added to bytes_to_rcv, and sk_data_ready() is called
- stale peer_conn_abort, peer_conn_closed or peer_done_writing flags set
sk_err = ECONNRESET, RCV_SHUTDOWN and SOCK_DONE, and queue close_work
For an abort, smc_close_passive_abort_received() then moves the socket
from SMC_INIT to SMC_PROCESSABORT.
Can stale flags from an unrelated connection reset or close a connection
that is still in its handshake?
This also leaves a cursor mismatch behind. local_rx_ctrl.cons ends up at
the stale value X, while tx_curs_fin stays at {0,0}.
smcd_conn_save_peer_info() resets peer_rmbe_space but not
local_rx_ctrl.cons:
net/smc/af_smc.c:smcd_conn_save_peer_info() {
...
atomic_set(&smc->conn.peer_rmbe_space, smc->conn.peer_rmbe_size);
...
}
The first real CDC from the new peer (cons Y) is then diffed against X:
- Same wrap and Y.count <= X.count: diff_cons is 0, and peer_rmbe_space
stays below its real value from then on.
- Different wraps: peer_rmbe_space is credited past peer_rmbe_size, which
breaks 0 <= peer_rmbe_space <= peer_rmbe_size.
In both cases peer_rmbe_space can no longer equal peer_rmbe_size. So this
check later in the function never fires:
if (diff_cons && conn->urg_tx_pend &&
atomic_read(&conn->peer_rmbe_space) == conn->peer_rmbe_size) {
Would a MSG_OOB sender then block in smc_tx_sendmsg()->smc_tx_wait() until
a timeout or a signal?
The commit message says:
The update's cursors and flags are still applied to the new
connection, as those of a CDC that leaves the consumer cursor alone
already are.
Is that comparison accurate? A CDC that leaves the consumer cursor alone
does not create a cons/tx_curs_fin mismatch.
A CDC that moves the consumer cursor before smcd_buf_attach() cannot come
from the real peer. That is the reasoning behind "Nothing of ours can have
been consumed before the attach".
Would it be better to drop such a CDC, or to stop reusing a DMB that a
previous peer can still signal, instead of applying part of it?
> /* Calculate consumed data and
> * increment free send buffer space.
> */
> - diff_tx = smc_curs_diff(conn->sndbuf_desc->len,
> + diff_tx = smc_curs_diff(sndbuf_desc->len,
> &conn->tx_curs_fin,
> &conn->local_rx_ctrl.cons);
> /* increase local sndbuf space and fin_curs */
> diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c
> index 9ef9019bc4974..982cfc79ee1cc 100644
> --- a/net/smc/smc_core.c
> +++ b/net/smc/smc_core.c
> @@ -2654,9 +2654,10 @@ int smcd_buf_attach(struct smc_sock *smc)
> buf_desc->cpu_addr =
> (u8 *)buf_desc->cpu_addr + sizeof(struct smcd_cdc_msg);
> buf_desc->len -= sizeof(struct smcd_cdc_msg);
> - conn->sndbuf_desc = buf_desc;
> - conn->sndbuf_desc->used = 1;
> - atomic_set(&conn->sndbuf_space, conn->sndbuf_desc->len);
> + buf_desc->used = 1;
> + atomic_set(&conn->sndbuf_space, buf_desc->len);
> + /* Set last; pairs with the acquire in smc_cdc_msg_recv_action() */
> + smp_store_release(&conn->sndbuf_desc, buf_desc);
[Severity: High]
Does this only close the window before attach? The old peer that still
holds the reused DMB token can keep signalling after this store.
Once sndbuf_desc is published, the new "if (sndbuf_desc)" branch in
smc_cdc_msg_recv_action() runs on the foreign consumer cursor:
diff_tx = smc_curs_diff(sndbuf_desc->len,
&conn->tx_curs_fin,
&conn->local_rx_ctrl.cons);
...
atomic_add(diff_tx, &conn->sndbuf_space);
Right after attach, tx_curs_fin is {0,0} and sndbuf_space is len. A stale
cons X with X.wrap != 0 gives diff_tx = len + X.count, so sndbuf_space
becomes 2 * len + X.count.
Can sndbuf_space grow past sndbuf_desc->len this way? peer_rmbe_space
would be over-credited in the same way.
smc_tx_sendmsg() sizes its copy only from sndbuf_space:
net/smc/smc_tx.c:smc_tx_sendmsg() {
...
copylen = min_t(size_t, send_remaining, writespace);
...
chunk_len = copylen - chunk_len; /* remainder */
...
}
With prep.count == 0, the second chunk is len + X.count bytes, written at
offset 0.
Would memcpy_from_msg() then write X.count bytes of user data past the end
of the attached peer DMB? With CONFIG_HARDENED_USERCOPY this would hit a
usercopy_abort() BUG instead.
Smaller inflations would overwrite data that has not been consumed yet, and
tx_curs_fin would be left at the foreign baseline.
The underlying problem seems to be that a DMB is handed to a new
connection while a previous peer is still attached. smc_buf_unuse() only
does this:
WRITE_ONCE(conn->rmb_desc->used, 0);
The token stays registered. __smc_buf_create()->smc_ism_set_conn() maps the
sba_idx to the new connection, so dibs_lo_move_data() delivers the old
peer's signals there.
One way to reach this: smc_listen_decline() calls smc_conn_abort() after
the client has already run smcd_buf_attach() and moved to SMC_ACTIVE.
Would it be better to stop reusing the DMB while a peer is attached, or to
drop signals that do not come from the current peer, instead of making the
receive path tolerate a NULL sndbuf_desc?
> return 0;
>
> free:
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112-b4-disp-1c8d3a53-v6-0-36a38ae35021%40proton.me
prev parent reply other threads:[~2026-11-17 1:06 UTC|newest]
Thread overview: 6+ 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-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-17 1:06 ` netdev-bot+sashiko
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-17 1:06 ` netdev-bot+sashiko [this message]
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=179487758596.3136.12928828467382443502@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
all inboxes | Powered by JetHome®