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: validate the peer's CDC cursors against our own buffers
Date: Sun, 22 Nov 2026 19:34:05 +0000 [thread overview]
Message-ID: <sashiko-outbox-228259@kernel.org> (raw)
In-Reply-To: <20261121193345.2148966-2-piyus@iiitd.ac.in>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Critical] net/smc: incomplete cursor validation in
smcr_cdc_cursors_invalid()
- [Medium] net/smc: off-by-one cursor bounds check in
smcr_cdc_cursors_invalid()
--
commit a56e3215d9b6d4c759609c097e5d65fd47a70a6a
Author: Piyus Kedia <piyus@iiitd.ac.in>
net/smc: validate the peer's CDC cursors against our own buffers
This commit adds smcr_cdc_cursors_invalid() in smc_cdc_rx_handler() to
check incoming CDC producer and consumer cursor counts against the local
RMB length and peer RMBE size before processing the message.
> diff --git a/net/smc/smc_cdc.c b/net/smc/smc_cdc.c
> index 32d6d03df3214..03ff10fef7da6 100644
> --- a/net/smc/smc_cdc.c
> +++ b/net/smc/smc_cdc.c
> @@ -466,6 +466,26 @@ void smcd_cdc_rx_init(struct smc_connection *conn)
>
> /***************************** init, exit, misc ******************************/
>
> +/* A peer's cursors are offsets into OUR buffers: the producer cursor counts the
> + * bytes it has written into the RMB we gave it, the consumer cursor the bytes it
> + * has taken from the RMB it published to us. Nothing else checks them. smcr_cdc_msg_to_host()
> + * copies both into the connection, and from there smc_cdc_msg_recv_action() adds the
> + * producer difference to conn->bytes_to_rcv and the receive path uses that as a
> + * length - so a peer that reports more than the buffer holds makes the kernel read
> + * past it.
> + */
> +static bool smcr_cdc_cursors_invalid(struct smc_connection *conn,
> + struct smc_cdc_msg *cdc)
> +{
> + if (!conn->rmb_desc)
> + return true;
> + if (ntohl(cdc->prod.count) > (u32)conn->rmb_desc->len)
> + return true;
> + if (ntohl(cdc->cons.count) > conn->peer_rmbe_size)
> + return true;
[Severity: Medium]
Should these two bounds checks use >= instead of >?
SMC cursors are 0-based offsets modulo the ring size: smc_curs_add() wraps
curs->count to 0 and increments curs->wrap as soon as curs->count >= size,
so a valid cursor never has count equal to the buffer length.
If a peer sends cdc->prod with wrap = W and count = conn->rmb_desc->len,
consuming those bytes advances conn->rx_curs_confirmed via smc_curs_add()
to wrap = W + 1 and count = 0 while conn->local_rx_ctrl.prod stays at
wrap = W and count = len. In smc_tx_consumer_update(),
smc_curs_diff_large() then sees old->wrap > new->wrap, takes the 0xffff ->
0x0000 wrap-around branch, and returns conn->rmb_desc->len instead of 0.
On sockets without SOCK_URGINLINE, an urgent cursor at wrap = W and
count = len similarly causes smc_rx_recv_urg() to compute a difference of
2 * len against the wrapped consumer cursor and erroneously set
conn->urg_rx_skip_pend = true.
> + return false;
> +}
[Severity: Critical]
Can a peer still push conn->bytes_to_rcv past conn->rmb_desc->len and
trigger the same out-of-bounds read in smc_rx_recvmsg() by advancing
cdc->prod.wrap?
smcr_cdc_cursors_invalid() checks only cdc->prod.count and
cdc->cons.count, ignoring the wrap counters and the bytes already queued:
net/smc/smc_cdc.h:smc_curs_diff() {
if (old->wrap != new->wrap)
return max_t(int, 0,
((size - old->count) + new->count));
return max_t(int, 0, (new->count - old->count));
}
If prod_old is at wrap = 0, count = 0 on a 64 KiB RMB and a single CDC
message arrives with prod.wrap = 1, prod.count = 65535,
smcr_cdc_cursors_invalid() accepts it, smc_curs_diff() returns 131071, and
smc_cdc_msg_recv_action() adds that to conn->bytes_to_rcv. A peer can
also send multiple CDC messages that increment prod.wrap before userspace
drains the buffer, accumulating arbitrary values in conn->bytes_to_rcv
(and similarly inflating conn->peer_rmbe_space past conn->peer_rmbe_size
via cdc->cons).
When smc_rx_recvmsg() then runs with copylen > conn->rmb_desc->len, its
first chunk is clamped to conn->rmb_desc->len - cons.count, but the second
chunk copies the unclamped remainder copylen - chunk_len starting at
rcvbuf_base + 0, reading past the end of the RMB into userspace. In
addition, smc_rx_update_consumer() passes copylen > conn->rmb_desc->len to
smc_curs_add(), which subtracts size only once and leaves
conn->local_tx_ctrl.cons.count >= conn->rmb_desc->len.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261121193345.2148966-2-piyus@iiitd.ac.in?part=1
next prev parent reply other threads:[~2026-11-22 19:34 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-21 19:33 [BUG] net/smc: out-of-bounds read of up to 128 KiB past the RMB from an unvalidated peer CDC cursor, reaching userspace via recvmsg (seen on 7.4.0-rc3) Piyus Kedia
2026-11-21 19:33 ` [PATCH net] net/smc: validate the peer's CDC cursors against our own buffers Piyus Kedia
2026-11-21 19:38 ` netdev-bot+sinfo
2026-11-22 4:21 ` Piyus Kedia
2026-11-22 19:34 ` sashiko-bot [this message]
2026-11-25 19:56 ` 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-228259@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.