From: sashiko-bot@kernel.org
To: "Piyus Kedia" <piyus@iiitd.ac.in>
Cc: linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org,
"Heiko Carstens" <hca@linux.ibm.com>,
"Vasily Gorbik" <gor@linux.ibm.com>,
"Alexander Gordeev" <agordeev@linux.ibm.com>,
"Christian Borntraeger" <borntraeger@linux.ibm.com>
Subject: Re: [PATCH net] net/smc: bound a send by the send buffer, not by the peer's credit
Date: Mon, 23 Nov 2026 05:32:39 +0000 [thread overview]
Message-ID: <sashiko-outbox-228720@kernel.org> (raw)
In-Reply-To: <20261122053223.2497832-2-piyus@iiitd.ac.in>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] net/smc: incomplete sndbuf_space bounds in smc_tx_sendmsg() on
peer credit
--
commit f945a5f042b06d7f73ad24c4711b9b326889bb84
Author: Piyus Kedia <piyus@iiitd.ac.in>
net/smc: bound a send by the send buffer, not by the peer's credit
This commit clamps copylen in smc_tx_sendmsg() to conn->sndbuf_desc->len so
that an inflated conn->sndbuf_space credited from a peer's consumer cursor
cannot cause a single ring-buffer write to copy past the end of the send
buffer.
> diff --git a/net/smc/smc_tx.c b/net/smc/smc_tx.c
> index 0f0c6df3bf2ce..5dc489bf624ed 100644
> --- a/net/smc/smc_tx.c
> +++ b/net/smc/smc_tx.c
> @@ -235,6 +235,13 @@ int smc_tx_sendmsg(struct smc_sock *smc, struct msghdr *msg, size_t len)
> writespace = atomic_read(&conn->sndbuf_space);
> /* not more than what user space asked for */
> copylen = min_t(size_t, send_remaining, writespace);
> + /* and never more than the send buffer holds. sndbuf_space is
> + * credited in smc_cdc_msg_recv_action() from the peer's
> + * consumer cursor on the SMC-D DMB-nocopy path, so it is not a
> + * value this side computed, and the second chunk below is not
> + * clamped against the buffer the way the first one is.
> + */
> + copylen = min_t(size_t, copylen, conn->sndbuf_desc->len);
[Severity: High]
Does clamping copylen per loop iteration suffice when conn->sndbuf_space is
inflated by the peer?
Because smc_tx_sendmsg() loops while msg_data_left(msg) is non-zero, a single
sendmsg() call with len > conn->sndbuf_desc->len will subtract
conn->sndbuf_desc->len from the inflated conn->sndbuf_space and immediately
run another iteration whenever transmission is deferred or corked (for
example under MSG_MORE or TCP_CORK, where smc_tx_should_cork() stays true
because atomic_read(&conn->sndbuf_space) is still non-zero). Subsequent
iterations overwrite unsent data in sndbuf and advance conn->tx_curs_prep
more than conn->sndbuf_desc->len ahead of conn->tx_curs_sent, which causes
smc_curs_diff() in smc_tx_rdma_writes() to compute to_send >
conn->sndbuf_desc->len or permanently desynchronize the cursor wrap counters.
In addition, if diff_tx in smc_cdc_msg_recv_action() overflows the signed
32-bit conn->sndbuf_space negative, !atomic_read(&conn->sndbuf_space) does
not block and min_t(size_t, send_remaining, writespace) sign-extends the
negative writespace to a large unsigned value that this clamp turns into a
full-buffer write. Validating that conn->local_rx_ctrl.cons does not pass
conn->tx_curs_sent (and capping conn->sndbuf_space to conn->sndbuf_desc->len)
in smc_cdc_msg_recv_action() would preserve the 0 <= sndbuf_space <=
sndbuf_desc->len invariant across all iterations.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261122053223.2497832-2-piyus@iiitd.ac.in?part=1
next prev parent reply other threads:[~2026-11-23 5:32 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-22 5:32 [BUG] net/smc: out-of-bounds WRITE of 869056 bytes into a 65504-byte send buffer, from a peer-credited sndbuf_space (SMC-D DMB-nocopy) Piyus Kedia
2026-11-22 5:32 ` [PATCH net] net/smc: bound a send by the send buffer, not by the peer's credit Piyus Kedia
2026-11-23 5:32 ` sashiko-bot [this message]
2026-11-23 6:00 ` 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=sashiko-outbox-228720@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=agordeev@linux.ibm.com \
--cc=borntraeger@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=linux-rdma@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=piyus@iiitd.ac.in \
--cc=sashiko-reviews@lists.linux.dev \
/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