From: Piyus Kedia <piyus@iiitd.ac.in>
To: alibuda@linux.alibaba.com, Dust Li <dust.li@linux.alibaba.com>,
Sidraya Jayagond <sidraya@linux.ibm.com>,
Mahanta Jambigi <mjambigi@linux.ibm.com>,
netdev@vger.kernel.org
Cc: Tony Lu <tonylu@linux.alibaba.com>,
Wen Gu <guwen@linux.alibaba.com>,
linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org,
linux-kernel@vger.kernel.org,
Kapil Vaswani <kapil@presceralabs.ai>,
Piyus Kedia <piyus@iiitd.ac.in>
Subject: [PATCH net] net/smc: validate the peer's CDC cursors against our own buffers
Date: Sun, 22 Nov 2026 01:03:45 +0530 [thread overview]
Message-ID: <20261121193345.2148966-2-piyus@iiitd.ac.in> (raw)
In-Reply-To: <20261121193345.2148966-1-piyus@iiitd.ac.in>
A peer's CDC message carries two cursors that are offsets into buffers
described on this side: the producer cursor counts the bytes the peer has
written into the RMB we published to it, and the consumer cursor the bytes
it has taken from the RMB it published to us. Neither is checked anywhere.
smcr_cdc_msg_to_host() copies both into the connection as they arrive, and
every later user treats them as trustworthy:
- smc_cdc_msg_recv_action() adds the producer difference to
conn->bytes_to_rcv under a comment asserting
"guarantee 0 <= bytes_to_rcv <= rmb_desc->len", which nothing enforces;
- smc_cdc_handle_urg_data_arrival() reads
*(base + conn->urg_curs.count - 1), an unbounded index into the RMB;
- smc_rx_recvmsg() clamps only the first of its two ring chunks
(rmb_desc->len - cons.count) and uses the remainder unclamped for the
second, so bytes_to_rcv becomes a copy length.
A peer that reports a cursor larger than the buffer therefore makes the
kernel read past it. With a 64 KiB RMB and a forged cursor, KASAN on
7.4.0-rc3 reports a 1-byte read in the urgent-data path and a 131072-byte
read in the receive path, the latter via _copy_to_iter() - i.e. the
out-of-bounds bytes are delivered to userspace by recvmsg().
Validate both cursors where the message is accepted, next to the existing
length and sequence-number checks, so that one test covers every consumer.
Each cursor is bounded by the buffer its own arithmetic uses: the producer
cursor by conn->rmb_desc->len as in smc_cdc_msg_recv_action(), the consumer
cursor by conn->peer_rmbe_size as in the diff_cons calculation beside it.
A cursor equal to the buffer length is legitimate (a full ring), so only a
larger one is rejected. An out-of-range cursor cannot occur in a correct
peer, and the malformed message is dropped like any other.
Signed-off-by: Kapil Vaswani <kapil@presceralabs.ai>
Signed-off-by: Piyus Kedia <piyus@iiitd.ac.in>
---
net/smc/smc_cdc.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/net/smc/smc_cdc.c b/net/smc/smc_cdc.c
index 32d6d03df..03ff10fef 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;
+ return false;
+}
+
static void smc_cdc_rx_handler(struct ib_wc *wc, void *buf)
{
struct smc_link *link = (struct smc_link *)wc->qp->qp_context;
@@ -499,6 +519,9 @@ static void smc_cdc_rx_handler(struct ib_wc *wc, void *buf)
conn->local_rx_ctrl.seqno))
/* received seqno is old */
goto out;
+ if (smcr_cdc_cursors_invalid(conn, cdc))
+ /* peer cursor outside the buffer it describes */
+ goto out;
smc_cdc_msg_recv(smc, cdc);
out:
next prev parent reply other threads:[~2026-11-21 19:33 UTC|newest]
Thread overview: 3+ 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 ` Piyus Kedia [this message]
2026-11-21 19:38 ` [PATCH net] net/smc: validate the peer's CDC cursors against our own buffers netdev-bot+sinfo
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=20261121193345.2148966-2-piyus@iiitd.ac.in \
--to=piyus@iiitd.ac.in \
--cc=alibuda@linux.alibaba.com \
--cc=dust.li@linux.alibaba.com \
--cc=guwen@linux.alibaba.com \
--cc=kapil@presceralabs.ai \
--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=sidraya@linux.ibm.com \
--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®