* [PATCH net v2] net/smc: validate the peer's CDC cursors against our own buffers
@ 2026-11-22 4:21 Piyus Kedia
2026-11-22 13:39 ` Dust Li
0 siblings, 1 reply; 3+ messages in thread
From: Piyus Kedia @ 2026-11-22 4:21 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
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, on either
transport.
smcr_cdc_msg_to_host() and smcd_cdc_msg_to_host() copy 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;
- smc_rx_splice() walks PAGE_ALIGN(len + offset) / PAGE_SIZE pages calling
vmalloc_to_page() without checking the result, and get_page() then
dereferences NULL once the walk passes the end of the RMB.
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() - and splice()
oopses on the NULL page.
Validate both cursors where each transport accepts the message, so that one
test per transport 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.
The SMC-R check sits next to the existing length and sequence-number tests
in smc_cdc_rx_handler(). SMC-D needs its own, because smcd_cdc_rx_tsklet()
reads the cursors straight out of the DMB the peer writes into, in host
byte order and with no validation of any kind on that path today.
How this was found: by AI-driven fuzzing built on top of syzkaller. Its
analysis was then checked by hand against the code, and all three faults
were reproduced on net.git main under KASAN, with the patched kernel clean
on the same three reproducers and ordinary SMC-R and SMC-D traffic
unaffected.
Signed-off-by: Kapil Vaswani <kapil@presceralabs.ai>
Signed-off-by: Piyus Kedia <piyus@iiitd.ac.in>
---
net/smc/smc_cdc.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
diff --git a/net/smc/smc_cdc.c b/net/smc/smc_cdc.c
index 32d6d03df..8d24e0c83 100644
--- a/net/smc/smc_cdc.c
+++ b/net/smc/smc_cdc.c
@@ -433,6 +433,18 @@ static void smc_cdc_msg_recv(struct smc_sock *smc, struct smc_cdc_msg *cdc)
sock_put(&smc->sk); /* no free sk in softirq-context */
}
+static bool smcd_cdc_cursors_invalid(struct smc_connection *conn,
+ struct smcd_cdc_msg *cdc)
+{
+ if (!conn->rmb_desc)
+ return true;
+ if (cdc->prod.count > (u32)conn->rmb_desc->len)
+ return true;
+ if (cdc->cons.count > (u32)conn->peer_rmbe_size)
+ return true;
+ return false;
+}
+
/* Schedule a tasklet for this connection. Triggered from the ISM device IRQ
* handler to indicate update in the DMBE.
*
@@ -452,6 +464,15 @@ static void smcd_cdc_rx_tsklet(struct tasklet_struct *t)
data_cdc = (struct smcd_cdc_msg *)conn->rmb_desc->cpu_addr;
smcd_curs_copy(&cdc.prod, &data_cdc->prod, conn);
smcd_curs_copy(&cdc.cons, &data_cdc->cons, conn);
+ /* This CDC was written by the peer into the DMB we published to it, so
+ * both cursors are peer-supplied and index buffers described on this
+ * side. Nothing else checks them, and smc_cdc_msg_recv_action() uses
+ * the producer cursor as a receive length and the consumer cursor to
+ * credit sndbuf_space - which under DMB-nocopy is the memory the peer
+ * itself owns. Unlike the SMC-R path these values are host order.
+ */
+ if (smcd_cdc_cursors_invalid(conn, &cdc))
+ return;
smc = container_of(conn, struct smc_sock, conn);
smc_cdc_msg_recv(smc, (struct smc_cdc_msg *)&cdc);
}
@@ -466,6 +487,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 +540,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:
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net v2] net/smc: validate the peer's CDC cursors against our own buffers
2026-11-22 4:21 [PATCH net v2] net/smc: validate the peer's CDC cursors against our own buffers Piyus Kedia
@ 2026-11-22 13:39 ` Dust Li
2026-11-22 14:06 ` Piyus Kedia
0 siblings, 1 reply; 3+ messages in thread
From: Dust Li @ 2026-11-22 13:39 UTC (permalink / raw)
To: Piyus Kedia, alibuda, Sidraya Jayagond, Mahanta Jambigi, netdev
Cc: Tony Lu, Wen Gu, linux-rdma, linux-s390, linux-kernel, Kapil Vaswani
On 2026-11-22 09:51:20, Piyus Kedia wrote:
>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, on either
>transport.
>
>smcr_cdc_msg_to_host() and smcd_cdc_msg_to_host() copy 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;
> - smc_rx_splice() walks PAGE_ALIGN(len + offset) / PAGE_SIZE pages calling
> vmalloc_to_page() without checking the result, and get_page() then
> dereferences NULL once the walk passes the end of the RMB.
I think Bryam's patch is solving the same problem here:
https://lore.kernel.org/netdev/20261112-b4-disp-0287c16e-v9-0-e5e8fa688177@proton.me
Best regards,
Dust
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net v2] net/smc: validate the peer's CDC cursors against our own buffers
2026-11-22 13:39 ` Dust Li
@ 2026-11-22 14:06 ` Piyus Kedia
0 siblings, 0 replies; 3+ messages in thread
From: Piyus Kedia @ 2026-11-22 14:06 UTC (permalink / raw)
To: dust.li
Cc: alibuda, Sidraya Jayagond, Mahanta Jambigi, netdev, Tony Lu,
Wen Gu, linux-rdma, linux-s390, linux-kernel, Kapil Vaswani
Hi Dust,
Thanks for pointing this out. I checked that Bryam's patch indeed
fixes the same issue. Please drop this patch.
Best,
Piyus
On Sun, Nov 22, 2026 at 7:09 PM Dust Li <dust.li@linux.alibaba.com> wrote:
>
> On 2026-11-22 09:51:20, Piyus Kedia wrote:
> >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, on either
> >transport.
> >
> >smcr_cdc_msg_to_host() and smcd_cdc_msg_to_host() copy 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;
> > - smc_rx_splice() walks PAGE_ALIGN(len + offset) / PAGE_SIZE pages calling
> > vmalloc_to_page() without checking the result, and get_page() then
> > dereferences NULL once the walk passes the end of the RMB.
>
> I think Bryam's patch is solving the same problem here:
> https://lore.kernel.org/netdev/20261112-b4-disp-0287c16e-v9-0-e5e8fa688177@proton.me
>
> Best regards,
> Dust
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-22 14:06 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-22 4:21 [PATCH net v2] net/smc: validate the peer's CDC cursors against our own buffers Piyus Kedia
2026-11-22 13:39 ` Dust Li
2026-11-22 14:06 ` Piyus Kedia
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®