From: netdev-bot+sashiko@kernel.org
To: piyus@iiitd.ac.in
Cc: alibuda@linux.alibaba.com, dust.li@linux.alibaba.com,
sidraya@linux.ibm.com, mjambigi@linux.ibm.com,
netdev@vger.kernel.org, tonylu@linux.alibaba.com,
guwen@linux.alibaba.com, linux-rdma@vger.kernel.org,
linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org,
kapil@presceralabs.ai, stable@vger.kernel.org, kuba@kernel.org
Subject: Re: [PATCH net v2 1/2] net/smc: bound the failover cursor catch-up by what is outstanding
Date: Tue, 24 Nov 2026 14:14:19 +0000 [thread overview]
Message-ID: <179552965941.3135.8878591105354373466@kernel.org> (raw)
In-Reply-To: <20261123135327.3953509-1-piyus@iiitd.ac.in>
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 2
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 bound in smc_switch_cursor() reads sndbuf_space, then
advances tx_curs_fin and sndbuf_space.
- [Low] In smc_switch_cursor() (net/smc/smc_core.c:1080-1081), the new
bound is stored in a variable named `sent`, and the comment calls it…
- [Low] When the new clamp in smc_switch_cursor() lowers diff below the
cons - fin gap the peer reported, local_tx_ctrl.prod and…
--
net/smc: bound the failover cursor catch-up by what is outstanding
This commit clamps the diff that smc_switch_cursor() uses to advance
tx_curs_sent and tx_curs_fin and to credit sndbuf_space during SMC-R link
failover. The bound is sndbuf_desc->len - sndbuf_space. The goal is to stop
a forged peer consumer cursor from pushing sndbuf_space past the send
buffer size, which leads to an out-of-bounds write in smc_tx_sendmsg().
Link: https://lore.kernel.org/all/20261122053223.2497832-2-piyus@iiitd.ac.in/
> diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c
> index a3164201c1420..436a702f3d8de 100644
> --- a/net/smc/smc_core.c
> +++ b/net/smc/smc_core.c
[ ... ]
> @@ -1069,6 +1070,16 @@ static int smc_switch_cursor(struct smc_sock *smc, struct smc_cdc_tx_pend *pend,
> * fin above, so now prod is smaller than cons. Fix that.
> */
> diff = smc_curs_diff(conn->peer_rmbe_size, &fin, &cons);
> + /* The peer's consumer cursor is taken as it arrives, so this
> + * difference is a value the peer chose. An honest peer cannot
> + * have consumed more than this side has outstanding, so bound
> + * the catch-up by that: sndbuf_space then keeps the invariant
> + * the tx path relies on, and the cursors advanced below stay
> + * within the send buffer.
> + */
> + sent = conn->sndbuf_desc->len - atomic_read(&conn->sndbuf_space);
> + diff = min_t(int, diff, max_t(int, sent, 0));
> +
[Severity: High]
Does this bound keep sndbuf_space <= sndbuf_desc->len on the DELETE_LINK
path, given that the old link's CDC completions can still run?
smc_switch_conns() calls smc_switch_cursor() with only conn->send_lock
held:
spin_lock_bh(&conn->send_lock);
smc_switch_link_and_count(conn, to_lnk);
rc = smc_switch_cursor(smc, pend, wr_buf);
spin_unlock_bh(&conn->send_lock);
CDC send completions on the old link go through smc_cdc_tx_handler(),
which holds only bh_lock_sock():
bh_lock_sock(&smc->sk);
if (!wc_status && sndbuf_desc) {
diff = smc_curs_diff(sndbuf_desc->len,
&cdcpend->conn->tx_curs_fin,
&cdcpend->cursor);
...
atomic_add(diff, &cdcpend->conn->sndbuf_space);
...
smc_curs_copy(&conn->tx_curs_fin, &cdcpend->cursor, conn);
In smc_llc_process_cli_delete_link(), the old QP is still live when the
connections are switched. It is moved to error and drained only later, in
smcr_link_clear():
if (smc_link_downing(&lnk_del->state))
smc_switch_conns(lgr, lnk_del, false);
smcr_link_clear(lnk_del, true);
So completions for CDCs already posted on the old QP can run during or
after smc_switch_cursor().
In the concurrent case, smc_switch_cursor() snapshots sent as
prep - fin_old. The old-link handler then credits C - fin_old and sets
tx_curs_fin to C. smc_switch_cursor() then credits up to prep - fin_old
more and adds diff to the tx_curs_fin that has already moved. The total
credit is more than prep - fin_old.
In the late completion case, a peer forges cons so that the clamp moves
tx_curs_fin all the way to prep. A completion for an older cursor C then
arrives on the old QP. If C.wrap != prep.wrap, smc_curs_diff() looks only
at the wraps:
if (old->wrap != new->wrap)
return max_t(int, 0,
((size - old->count) + new->count));
It returns (len - prep.count) + C.count, which is larger than len, so
sndbuf_space moves toward 2 * len. If the wraps are equal, the credit is 0
but tx_curs_fin moves back to C. The next completion on the new link then
credits prep - C again.
Either way sndbuf_space ends up above sndbuf_desc->len. The second chunk
in smc_tx_sendmsg() then writes past the send buffer:
rc = memcpy_from_msg(sndbuf_base + chunk_off,
msg, chunk_len);
The commit message says:
For a lying one sndbuf_space keeps the invariant that
smc_tx_sendmsg(), smc_tx_prepared_sends() and SIOCOUTQ in smc_ioctl()
all depend on
Does that still hold on this path? The follow-up patch "net/smc: bound the
DMB-nocopy send-buffer credit as well" only changes the SMC-D DMB-nocopy
credit in smc_cdc_msg_recv_action(), so it doesn't cover this case.
Do the old link's TX completions also need to be quiesced or serialized
with the switch? Two options: drain them before smc_switch_cursor(), or
take the same lock and ignore completions whose cursor is behind
tx_curs_fin.
[Severity: Low]
Is sent the right name for this value? Does "what this side has
outstanding" in the comment describe it accurately?
sndbuf_desc->len - sndbuf_space is the amount prepared but not yet
confirmed (tx_curs_prep - tx_curs_fin). smc_tx_sendmsg() lowers
sndbuf_space when data is copied in, not when it is RDMA-written:
atomic_sub(copylen, &conn->sndbuf_space);
The real pre-switch send position is already lost at this point, because
smc_switch_cursor() starts with:
smc_curs_copy(&conn->tx_curs_sent, &conn->tx_curs_fin, conn);
So a lying peer can still move tx_curs_sent and tx_curs_fin up to
tx_curs_prep. Bytes that sendmsg() accepted but never wrote are then
counted as confirmed and never sent. The clamp also hides the protocol
violation: out_of_sync is not set and the connection is not aborted.
Without a race, sndbuf_space and the cursors stay in range. But the
variable name, the comment, and the commit message's "bound the catch-up
by what is outstanding" all describe a tighter bound than the code
applies. Could they be adjusted to match?
> smc_curs_add(conn->sndbuf_desc->len,
> &conn->tx_curs_sent, diff);
> smc_curs_add(conn->sndbuf_desc->len,
[Severity: Low]
When the clamp makes diff smaller than the cons - fin gap the peer
reported, where does local_tx_ctrl.prod end up?
prod was set to fin earlier, and this branch runs only when cons > fin.
Further down, prod and local_tx_ctrl_fin move forward only by the clamped
diff:
smc_curs_add(conn->peer_rmbe_size,
&conn->local_tx_ctrl.prod, diff);
smc_curs_add(conn->peer_rmbe_size,
&conn->local_tx_ctrl_fin, diff);
That leaves prod behind local_rx_ctrl.cons, which is the state the
existing "now prod is smaller than cons. Fix that." comment says this
block repairs.
The next statement recomputes peer_rmbe_space from that inverted pair:
atomic_set(&smc->conn.peer_rmbe_space, smc_write_space(conn));
and smc_write_space() computes:
space = buffer_len - smc_curs_diff(buffer_len, &cons, &prod);
If the wraps are equal, smc_curs_diff() returns 0 and peer_rmbe_space
becomes peer_rmbe_size. If cons.wrap == prod.wrap + 1, it returns
(size - cons.count) + prod.count. For example, size=100, prod=(0,90) and
cons=(1,10) give space = -80.
With a negative peer_rmbe_space, smc_tx_rdma_writes() returns early on
every call:
if (rmbespace <= 0) {
Later CDCs in smc_cdc_msg_recv_action() only add diff_cons on top of that
wrong base, so the value never recovers and the connection stops sending.
Should the clamp firing be treated as a protocol violation that aborts the
connection, rather than continuing with inconsistent flow-control state?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261123135327.3953509-1-piyus%40iiitd.ac.in
prev parent reply other threads:[~2026-11-24 14:14 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 13:53 Piyus Kedia
2026-11-23 13:53 ` [PATCH net v2 2/2] net/smc: bound the DMB-nocopy send-buffer credit as well Piyus Kedia
2026-11-24 14:14 ` netdev-bot+sashiko
2026-11-24 14:14 ` 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=179552965941.3135.8878591105354373466@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=alibuda@linux.alibaba.com \
--cc=dust.li@linux.alibaba.com \
--cc=guwen@linux.alibaba.com \
--cc=kapil@presceralabs.ai \
--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=piyus@iiitd.ac.in \
--cc=sidraya@linux.ibm.com \
--cc=stable@vger.kernel.org \
--cc=tonylu@linux.alibaba.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®