* [PATCH net v2 1/2] net/smc: bound the failover cursor catch-up by what is outstanding
@ 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 ` [PATCH net v2 1/2] net/smc: bound the failover cursor catch-up by what is outstanding netdev-bot+sashiko
0 siblings, 2 replies; 4+ messages in thread
From: Piyus Kedia @ 2026-11-23 13:53 UTC (permalink / raw)
To: alibuda, Dust Li, Sidraya Jayagond, Mahanta Jambigi, netdev
Cc: Tony Lu, Wen Gu, linux-rdma, linux-s390, linux-kernel,
Kapil Vaswani, Piyus Kedia, stable
smc_switch_cursor() credits conn->sndbuf_space from the consumer cursor
the peer reported, with nothing bounding the amount:
smc_curs_copy(&cons, &conn->local_rx_ctrl.cons, conn);
if (smc_curs_comp(conn->peer_rmbe_size, &cons, &fin) < 0) {
diff = smc_curs_diff(conn->peer_rmbe_size, &fin, &cons);
smc_curs_add(conn->sndbuf_desc->len,
&conn->tx_curs_sent, diff);
smc_curs_add(conn->sndbuf_desc->len,
&conn->tx_curs_fin, diff);
smp_mb__before_atomic();
atomic_add(diff, &conn->sndbuf_space);
local_rx_ctrl.cons is whatever arrived in the peer's last CDC message.
smc_cdc_cursor_to_host() drops only a cursor that moves backward within
one wrap, so a peer can advance cons.count by nearly peer_rmbe_size and
report consuming data this side never sent. diff becomes that amount and
sndbuf_space ends above sndbuf_desc->len, which the tx path reads as free
room in the send ring:
writespace = atomic_read(&conn->sndbuf_space);
/* not more than what user space asked for */
copylen = min_t(size_t, send_remaining, writespace);
The first chunk of a two-part write is clamped against the buffer, the
second is not, so memcpy_from_msg() copies past the end of the send
buffer. The two cursors advanced beside the credit can also leave the
ring: smc_curs_add() subtracts the size only once, so a diff of two
buffers or more leaves tx_curs_sent.count at or above sndbuf_desc->len,
and smc_tx_rdma_writes() uses that count as a source offset.
A peer reaches this path on an SMC-R link group with a second link by
asking for the active one to be deleted:
smc_llc_rx_delete_link()
smc_llc_process_cli_delete_link()
smc_switch_conns()
smc_switch_cursor()
An honest peer cannot have consumed more than this side has outstanding,
so bound the catch-up by that. For a correct peer the bound changes
nothing. 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, and both cursors stay inside the send buffer.
Bounding the credit where it is added is deliberate. Clamping the copy
length in smc_tx_sendmsg() instead stops the overflow but leaves
sndbuf_space inflated, so the producer never blocks in smc_tx_wait(),
later writes can overwrite data that has not been sent yet, and SIOCOUTQ
reports a negative queue length.
How this was found: by AI-driven fuzzing built on top of syzkaller. It
reached the overflow through the other writer of sndbuf_space, the
DMB-nocopy credit patched next, on a loopback-ism connection with the
peer's consumer cursor forged by a debug patch: KASAN reported an
869056-byte write past the send buffer in smc_tx_sendmsg()
(use-after-free in _copy_from_iter). The failover route above was then
found by reading the other writers of that counter; we do not have a
multi-link SMC-R group with two RDMA devices, so that route comes from
the code and not from a run. The bound was tested on the path we can
drive, where the forged cursor no longer inflates sndbuf_space and the
write stays inside the buffer.
Fixes: c6f02ebeea3a ("net/smc: switch connections to alternate link")
Cc: stable@vger.kernel.org
Signed-off-by: Kapil Vaswani <kapil@presceralabs.ai>
Signed-off-by: Piyus Kedia <piyus@iiitd.ac.in>
---
Link: https://lore.kernel.org/all/20261122053223.2497832-2-piyus@iiitd.ac.in/
Changes in v2:
- Corrected the threat model, which was wrong in v1 in a way that matters.
v1's subject and commit message named the SMC-D DMB-nocopy path as the
attack. That path runs only when smc_ism_support_dmb_nocopy() is true,
which needs a dibs device providing support_mmapped_rdmb(), and the only
provider in the tree is drivers/dibs/dibs_loopback.c - where both ends of
the connection are the same kernel and the cursor is written by SMC
itself. It is not reachable from a hostile peer. The remotely reachable
writer is smc_switch_cursor(), which v1 did not mention at all; it is
patch 1/2 here.
- Replaced the fix. v1 clamped the copy length in smc_tx_sendmsg(). That
stops the overflow but leaves sndbuf_space inflated, so the producer never
blocks in smc_tx_wait(), later writes can overwrite data that has not been
sent yet while sendmsg() reports success, smc_tx_prepared_sends()
misreports pending bytes, and SIOCOUTQ in smc_ioctl() returns a negative
queue length. v2 bounds the credit where it is added instead, and does
not touch smc_tx.c.
- Fixed a second fault v1 left alone: the cursors advanced beside the credit
in smc_switch_cursor() could also leave the ring, because smc_curs_add()
subtracts the size only once, and smc_tx_rdma_writes() uses
tx_curs_sent.count as a source offset. Bounding the difference fixes both.
- Added Fixes: tags to both patches, each confirmed by blaming the
atomic_add() in question, and Cc: stable to 1/2 only. 2/2 is unreachable
on any device in the tree, so by stable-kernel-rules it is not a bug that
bothers anyone.
- One patch became two, since the two sites have different Fixes: tags and
different reachability.
Measured, and not: the overflow and the fix were both measured on a
loopback-ism connection with the peer's consumer cursor forged by a debug
patch - KASAN reported an 869056-byte write past a 65504-byte send buffer
without the series, and with it no report at forged cursors of 100000,
1000000 and 2000000, the credit refused because nothing was outstanding, and
ordinary SMC-D traffic unaffected (SMC_DIAG mode=2, fb_reason=0x0). The
route to the writer in 1/2 is from reading the code: we have no multi-link
SMC-R group with two RDMA devices, so the LLC DELETE_LINK path to
smc_switch_cursor() has not been exercised here.
The receive side has the same unclamped second chunk in smc_rx_recvmsg(),
credited from the peer's producer cursor; that is a separate patch, "net/smc:
validate the peer's CDC cursors against our own buffers". The two are
independent: that one bounds cons by peer_rmbe_size, which still permits "I
consumed more than you sent", so it does not bound the credit this series
bounds.
net/smc/smc_core.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c
index a3164201c142..436a702f3d8d 100644
--- a/net/smc/smc_core.c
+++ b/net/smc/smc_core.c
@@ -1057,6 +1057,7 @@ static int smc_switch_cursor(struct smc_sock *smc, struct smc_cdc_tx_pend *pend,
union smc_host_cursor cons, fin;
int rc = 0;
int diff;
+ int sent;
smc_curs_copy(&conn->tx_curs_sent, &conn->tx_curs_fin, conn);
smc_curs_copy(&fin, &conn->local_tx_ctrl_fin, conn);
@@ -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));
+
smc_curs_add(conn->sndbuf_desc->len,
&conn->tx_curs_sent, diff);
smc_curs_add(conn->sndbuf_desc->len,
--
2.34.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH net v2 2/2] net/smc: bound the DMB-nocopy send-buffer credit as well
2026-11-23 13:53 [PATCH net v2 1/2] net/smc: bound the failover cursor catch-up by what is outstanding Piyus Kedia
@ 2026-11-23 13:53 ` Piyus Kedia
2026-11-24 14:14 ` netdev-bot+sashiko
2026-11-24 14:14 ` [PATCH net v2 1/2] net/smc: bound the failover cursor catch-up by what is outstanding netdev-bot+sashiko
1 sibling, 1 reply; 4+ messages in thread
From: Piyus Kedia @ 2026-11-23 13:53 UTC (permalink / raw)
To: alibuda, Dust Li, Sidraya Jayagond, Mahanta Jambigi, netdev
Cc: Tony Lu, Wen Gu, linux-rdma, linux-s390, linux-kernel,
Kapil Vaswani, Piyus Kedia
smc_cdc_msg_recv_action() credits sndbuf_space from the peer's consumer
cursor on the SMC-D DMB-nocopy path and then assigns that cursor to this
side's tx_curs_fin:
diff_tx = smc_curs_diff(conn->sndbuf_desc->len,
&conn->tx_curs_fin,
&conn->local_rx_ctrl.cons);
/* increase local sndbuf space and fin_curs */
smp_mb__before_atomic();
atomic_add(diff_tx, &conn->sndbuf_space);
/* guarantee 0 <= sndbuf_space <= sndbuf_desc->len */
smp_mb__after_atomic();
smc_curs_copy(&conn->tx_curs_fin,
&conn->local_rx_ctrl.cons, conn);
sndbuf_space can already be non-zero when this runs, so the sum can
exceed sndbuf_desc->len and the comment asserting otherwise does not
hold; smcd_cdc_msg_to_host() takes the cursor in host order with no
validation, so tx_curs_fin can also be assigned a count outside the send
buffer.
Unlike the failover path in the previous patch this is not reachable from
a hostile peer today. The branch runs only when
smc_ism_support_dmb_nocopy() is true, which needs a dibs device providing
support_mmapped_rdmb(), and the only provider is
drivers/dibs/dibs_loopback.c - where both ends of the connection are the
same kernel and the cursor is written by SMC itself. So this is
hardening rather than a fix for an observed attack: it keeps the
invariant in the comment true by construction, keeps the cursor inside
the buffer, and stops a future device that implements the op from
inheriting the problem.
Bound the credit by what this side has outstanding and advance
tx_curs_fin by the bounded amount instead of assigning the reported
cursor. For a cursor that reflects real consumption both are the value
that is used today.
How this was found: by AI-driven fuzzing built on top of syzkaller, on a
loopback-ism connection with the peer's consumer cursor forged by a debug
patch so that it reports consuming data this side never sent. KASAN
reported an 869056-byte write past the send buffer in smc_tx_sendmsg()
(use-after-free in _copy_from_iter). With this patch the same forged
cursor credits nothing beyond the outstanding bytes.
Fixes: cc0ab806fc52 ("net/smc: adapt cursor update when sndbuf and peer DMB are merged")
Signed-off-by: Kapil Vaswani <kapil@presceralabs.ai>
Signed-off-by: Piyus Kedia <piyus@iiitd.ac.in>
---
Link: https://lore.kernel.org/all/20261122053223.2497832-2-piyus@iiitd.ac.in/
This is 2/2 of a two-patch series; there is no cover letter. The v2
changelog is under the --- line of patch 1/2, and in short: v1 was a single
patch that clamped the copy length in smc_tx_sendmsg() and named this
DMB-nocopy path as a remote attack. Both were wrong - the clamp left
sndbuf_space inflated, and this path is reachable only on loopback-ism, where
both ends are the same kernel. v2 bounds the credit at both sites where it is
added; this patch is the hardening half.
net/smc/smc_cdc.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/net/smc/smc_cdc.c b/net/smc/smc_cdc.c
index 32d6d03df321..9ffa3e422aa1 100644
--- a/net/smc/smc_cdc.c
+++ b/net/smc/smc_cdc.c
@@ -333,6 +333,7 @@ static void smc_cdc_msg_recv_action(struct smc_sock *smc,
union smc_host_cursor cons_old, prod_old;
struct smc_connection *conn = &smc->conn;
int diff_cons, diff_prod, diff_tx;
+ int sent;
smc_curs_copy(&prod_old, &conn->local_rx_ctrl.prod, conn);
smc_curs_copy(&cons_old, &conn->local_rx_ctrl.cons, conn);
@@ -361,13 +362,26 @@ static void smc_cdc_msg_recv_action(struct smc_sock *smc,
diff_tx = smc_curs_diff(conn->sndbuf_desc->len,
&conn->tx_curs_fin,
&conn->local_rx_ctrl.cons);
+ /* This difference comes from the cursor the peer
+ * reported, which is taken as it arrives. A peer
+ * cannot have consumed more than this side has
+ * outstanding, so bound it by that and advance
+ * tx_curs_fin by the bounded amount rather than
+ * assigning the reported cursor: the invariant below
+ * then holds by construction, and tx_curs_fin stays
+ * inside the send buffer.
+ */
+ sent = conn->sndbuf_desc->len -
+ atomic_read(&conn->sndbuf_space);
+ diff_tx = min_t(int, diff_tx, max_t(int, sent, 0));
+
/* increase local sndbuf space and fin_curs */
smp_mb__before_atomic();
atomic_add(diff_tx, &conn->sndbuf_space);
/* guarantee 0 <= sndbuf_space <= sndbuf_desc->len */
smp_mb__after_atomic();
- smc_curs_copy(&conn->tx_curs_fin,
- &conn->local_rx_ctrl.cons, conn);
+ smc_curs_add(conn->sndbuf_desc->len,
+ &conn->tx_curs_fin, diff_tx);
smc_tx_sndbuf_nonfull(smc);
}
--
2.34.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net v2 1/2] net/smc: bound the failover cursor catch-up by what is outstanding
2026-11-23 13:53 [PATCH net v2 1/2] net/smc: bound the failover cursor catch-up by what is outstanding 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
1 sibling, 0 replies; 4+ messages in thread
From: netdev-bot+sashiko @ 2026-11-24 14:14 UTC (permalink / raw)
To: piyus
Cc: alibuda, dust.li, sidraya, mjambigi, netdev, tonylu, guwen,
linux-rdma, linux-s390, linux-kernel, kapil, stable, kuba
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net v2 2/2] net/smc: bound the DMB-nocopy send-buffer credit as well
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
0 siblings, 0 replies; 4+ messages in thread
From: netdev-bot+sashiko @ 2026-11-24 14:14 UTC (permalink / raw)
To: piyus
Cc: alibuda, dust.li, sidraya, mjambigi, netdev, tonylu, guwen,
linux-rdma, linux-s390, linux-kernel, kapil, stable, kuba
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] In net/smc/smc_cdc.c:smc_cdc_msg_recv_action(), the new DMB-
nocopy clamp uses `sent = conn->sndbuf_desc->len -…
Pre-existing issues:
- [Low] This problem wasn't introduced by this patch, but in
net/smc/smc_cdc.c:smc_cdc_msg_recv_action() peer_rmbe_space is still…
--
net/smc: bound the DMB-nocopy send-buffer credit as well
On the SMC-D DMB-nocopy path, smc_cdc_msg_recv_action() credits
sndbuf_space from the peer's consumer cursor. This patch limits that
credit to the number of bytes this side has outstanding. It also moves
tx_curs_fin forward by the limited amount instead of copying the
peer-reported cursor into it. The commit message calls this hardening,
because only dibs_loopback provides support_mmapped_rdmb() today.
Link: https://lore.kernel.org/all/20261122053223.2497832-2-piyus@iiitd.ac.in/
> diff --git a/net/smc/smc_cdc.c b/net/smc/smc_cdc.c
> index 32d6d03df3214..9ffa3e422aa1f 100644
> --- a/net/smc/smc_cdc.c
> +++ b/net/smc/smc_cdc.c
[ ... ]
> @@ -361,13 +362,26 @@ static void smc_cdc_msg_recv_action(struct smc_sock *smc,
> diff_tx = smc_curs_diff(conn->sndbuf_desc->len,
> &conn->tx_curs_fin,
> &conn->local_rx_ctrl.cons);
> + /* This difference comes from the cursor the peer
> + * reported, which is taken as it arrives. A peer
> + * cannot have consumed more than this side has
> + * outstanding, so bound it by that and advance
> + * tx_curs_fin by the bounded amount rather than
> + * assigning the reported cursor: the invariant below
> + * then holds by construction, and tx_curs_fin stays
> + * inside the send buffer.
> + */
> + sent = conn->sndbuf_desc->len -
> + atomic_read(&conn->sndbuf_space);
> + diff_tx = min_t(int, diff_tx, max_t(int, sent, 0));
> +
> /* increase local sndbuf space and fin_curs */
> smp_mb__before_atomic();
> atomic_add(diff_tx, &conn->sndbuf_space);
> /* guarantee 0 <= sndbuf_space <= sndbuf_desc->len */
> smp_mb__after_atomic();
> - smc_curs_copy(&conn->tx_curs_fin,
> - &conn->local_rx_ctrl.cons, conn);
> + smc_curs_add(conn->sndbuf_desc->len,
> + &conn->tx_curs_fin, diff_tx);
[Severity: Low]
Is len - sndbuf_space the right bound here?
smc_tx_sendmsg() lowers sndbuf_space when data is prepared, not when it
is sent:
net/smc/smc_tx.c:smc_tx_sendmsg() {
...
atomic_sub(copylen, &conn->sndbuf_space);
...
}
On the nocopy path, smcd_cdc_msg_send() returns before it credits
sndbuf_space, so this function is the only place that adds to it. That
makes len - sndbuf_space the distance from tx_curs_fin to tx_curs_prep.
This distance includes bytes that are prepared but not yet sent.
smc_ioctl() uses the same expression for SIOCOUTQ and describes it as
"not send + not acked".
The peer can only consume up to the producer cursor it was given.
smc_tx_rdma_writes() advances that cursor together with tx_curs_sent. A
consumer cursor that claims more than tx_curs_sent is therefore clamped
only to prep - fin. The smc_curs_add() above can then move tx_curs_fin
past tx_curs_sent.
Would that break the fin <= sent <= prep ordering implied by the
tx_curs_sent ("sent data") and tx_curs_fin ("confirmed by peer") field
comments in smc.h?
If so, a later smc_tx_sendmsg() could wrap from tx_curs_prep into
[tx_curs_sent, tx_curs_prep). It would then overwrite queued data before
that data is advertised. On the nocopy path this buffer is the peer's
DMB. Today this needs a forged consumer cursor, since only loopback-ism
reaches this branch.
The memory-safety goals do look met: sndbuf_space stays <= len, and
tx_curs_fin.count stays below len. However, the new comment ("A peer
cannot have consumed more than this side has outstanding"), the variable
name sent, and the commit message ("credits nothing beyond the
outstanding bytes") seem to describe a tighter bound than the code
computes.
smc_switch_cursor() in smc_core.c uses the same formula. It advances
tx_curs_sent together with tx_curs_fin, so the ordering holds there.
Here only tx_curs_fin moves.
Would a bound like this match the comment, and leave the honest-peer
case unchanged?
sent = smc_curs_diff(conn->sndbuf_desc->len, &conn->tx_curs_fin,
&conn->tx_curs_sent);
>
> smc_tx_sndbuf_nonfull(smc);
> }
[Severity: Low]
This is a pre-existing issue, not one introduced by this patch. Earlier in
smc_cdc_msg_recv_action(), peer_rmbe_space is still credited from the
same peer-reported consumer cursor with no bound:
net/smc/smc_cdc.c:smc_cdc_msg_recv_action() {
...
diff_cons = smc_curs_diff(conn->peer_rmbe_size, &cons_old,
&conn->local_rx_ctrl.cons);
if (diff_cons) {
...
atomic_add(diff_cons, &conn->peer_rmbe_space);
/* guarantee 0 <= peer_rmbe_space <= peer_rmbe_size */
...
}
With a forged cursor, can peer_rmbe_space exceed peer_rmbe_size here?
That would make the comment false. This path runs for all SMC-R and SMC-D
connections, not only nocopy ones.
After this patch, the nocopy path bounds sndbuf_space and tx_curs_fin,
but peer_rmbe_space still takes the full diff_cons. The two counters
describe the same shared buffer, so they can now disagree. The comment
above the nocopy branch says both are updated "since peer has already
consumed the data".
smc_tx_rdma_writes() uses peer_rmbe_space to compute write_blocked and
the transmit length. The urg_tx_pend wake-up at the end of this function
also requires:
atomic_read(&conn->peer_rmbe_space) == conn->peer_rmbe_size
Would an inflated peer_rmbe_space mean the urgent data sender is never
woken through that path?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261123135327.3953509-1-piyus%40iiitd.ac.in
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-24 14:14 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-23 13:53 [PATCH net v2 1/2] net/smc: bound the failover cursor catch-up by what is outstanding 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 ` [PATCH net v2 1/2] net/smc: bound the failover cursor catch-up by what is outstanding netdev-bot+sashiko
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®