* [PATCH net] net/smc: validate peer CDC cursors against buffer bounds and window
@ 2026-11-24 3:21 Qican Ma
2026-11-24 4:16 ` Dust Li
0 siblings, 1 reply; 3+ messages in thread
From: Qican Ma @ 2026-11-24 3:21 UTC (permalink / raw)
To: alibuda, dust.li, sidraya, mjambigi
Cc: tonylu, guwen, davem, edumazet, kuba, pabeni, horms, linux-rdma,
linux-s390, netdev
smc_cdc_cursor_to_host() only checks cursor monotonicity and
smcd_cdc_msg_to_host() copies peer cursors without any validation. Neither
verifies that prod.count < conn->rmb_desc->len or
cons.count < conn->peer_rmbe_size, nor that the resulting cursor deltas
stay within available buffer capacity. A malformed or malicious peer CDC
message can therefore:
1. Drive conn->urg_curs.count past conn->rmb_desc->len in
smc_cdc_handle_urg_data_arrival(), causing an out-of-bounds read from
conn->rmb_desc->cpu_addr exposed via recvmsg(MSG_OOB).
2. Inflate conn->bytes_to_rcv past conn->rmb_desc->len (either via an
out-of-range prod.count or repeated wrap increments), causing the
second chunk iteration in smc_rx_recvmsg() to copy past the end of
rcvbuf_base.
3. On SMC-D dmb_nocopy links, inflate conn->sndbuf_space past
conn->sndbuf_desc->len, causing the second chunk iteration in
smc_tx_sendmsg() to write past the end of sndbuf_base.
Decode incoming CDC messages into a temporary smc_host_cdc_msg and verify
both cursor offsets and their deltas against rmb_desc->len,
peer_rmbe_size, and (for dmb_nocopy) sndbuf_desc->len before committing
the update to conn->local_rx_ctrl.
Found with an LLM-assisted code review tool and verified by inspection on
v7.4-rc4 (b6a9fa34ce4). Build-tested only; not runtime-tested due to lack
of an SMC-R/SMC-D setup.
Fixes: 5f08318f617b ("smc: connection data control (CDC)")
Cc: stable@vger.kernel.org
Signed-off-by: Qican Ma <goonsomeway@gmail.com>
---
net/smc/smc_cdc.c | 46 +++++++++++++++++++++++++++++++++++++---------
1 file changed, 37 insertions(+), 9 deletions(-)
diff --git a/net/smc/smc_cdc.c b/net/smc/smc_cdc.c
index 32d6d03df32..fd5e296e8be 100644
--- a/net/smc/smc_cdc.c
+++ b/net/smc/smc_cdc.c
@@ -332,14 +332,48 @@ 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;
+ struct smc_host_cdc_msg rx_ctrl = {};
+ int diff_cons, diff_prod, diff_tx = 0;
smc_curs_copy(&prod_old, &conn->local_rx_ctrl.prod, conn);
smc_curs_copy(&cons_old, &conn->local_rx_ctrl.cons, conn);
- smc_cdc_msg_to_host(&conn->local_rx_ctrl, cdc, conn);
+ rx_ctrl.prod = prod_old;
+ rx_ctrl.cons = cons_old;
+ smc_cdc_msg_to_host(&rx_ctrl, cdc, conn);
+
+ if (rx_ctrl.prod.count >= conn->rmb_desc->len ||
+ rx_ctrl.cons.count >= conn->peer_rmbe_size)
+ return;
diff_cons = smc_curs_diff(conn->peer_rmbe_size, &cons_old,
- &conn->local_rx_ctrl.cons);
+ &rx_ctrl.cons);
+ if (diff_cons > conn->peer_rmbe_size - atomic_read(&conn->peer_rmbe_space))
+ return;
+
+ if (diff_cons && conn->lgr->is_smcd &&
+ smc_ism_support_dmb_nocopy(conn->lgr->smcd)) {
+ if (rx_ctrl.cons.count >= conn->sndbuf_desc->len)
+ return;
+ diff_tx = smc_curs_diff(conn->sndbuf_desc->len,
+ &conn->tx_curs_fin, &rx_ctrl.cons);
+ if (diff_tx > conn->sndbuf_desc->len - atomic_read(&conn->sndbuf_space))
+ return;
+ }
+
+ diff_prod = smc_curs_diff(conn->rmb_desc->len, &prod_old,
+ &rx_ctrl.prod);
+ if (diff_prod > conn->rmb_desc->len - atomic_read(&conn->bytes_to_rcv))
+ return;
+
+ conn->local_rx_ctrl.common.type = rx_ctrl.common.type;
+ conn->local_rx_ctrl.len = rx_ctrl.len;
+ conn->local_rx_ctrl.seqno = rx_ctrl.seqno;
+ conn->local_rx_ctrl.token = rx_ctrl.token;
+ smc_curs_copy(&conn->local_rx_ctrl.prod, &rx_ctrl.prod, conn);
+ smc_curs_copy(&conn->local_rx_ctrl.cons, &rx_ctrl.cons, conn);
+ conn->local_rx_ctrl.prod_flags = rx_ctrl.prod_flags;
+ conn->local_rx_ctrl.conn_state_flags = rx_ctrl.conn_state_flags;
+
if (diff_cons) {
/* peer_rmbe_space is decreased during data transfer with RDMA
* write
@@ -355,12 +389,6 @@ static void smc_cdc_msg_recv_action(struct smc_sock *smc,
*/
if (conn->lgr->is_smcd &&
smc_ism_support_dmb_nocopy(conn->lgr->smcd)) {
- /* Calculate consumed data and
- * increment free send buffer space.
- */
- 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);
--
2.50.1 (Apple Git-155)
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH net] net/smc: validate peer CDC cursors against buffer bounds and window
2026-11-24 3:21 [PATCH net] net/smc: validate peer CDC cursors against buffer bounds and window Qican Ma
@ 2026-11-24 4:16 ` Dust Li
2026-11-24 7:28 ` Qican Ma
0 siblings, 1 reply; 3+ messages in thread
From: Dust Li @ 2026-11-24 4:16 UTC (permalink / raw)
To: Qican Ma, alibuda, sidraya, mjambigi
Cc: tonylu, guwen, davem, edumazet, kuba, pabeni, horms, linux-rdma,
linux-s390, netdev
On 2026-11-23 19:21:01, Qican Ma wrote:
>smc_cdc_cursor_to_host() only checks cursor monotonicity and
>smcd_cdc_msg_to_host() copies peer cursors without any validation. Neither
>verifies that prod.count < conn->rmb_desc->len or
>cons.count < conn->peer_rmbe_size, nor that the resulting cursor deltas
>stay within available buffer capacity. A malformed or malicious peer CDC
>message can therefore:
>
>1. Drive conn->urg_curs.count past conn->rmb_desc->len in
> smc_cdc_handle_urg_data_arrival(), causing an out-of-bounds read from
> conn->rmb_desc->cpu_addr exposed via recvmsg(MSG_OOB).
>2. Inflate conn->bytes_to_rcv past conn->rmb_desc->len (either via an
> out-of-range prod.count or repeated wrap increments), causing the
> second chunk iteration in smc_rx_recvmsg() to copy past the end of
> rcvbuf_base.
>3. On SMC-D dmb_nocopy links, inflate conn->sndbuf_space past
> conn->sndbuf_desc->len, causing the second chunk iteration in
> smc_tx_sendmsg() to write past the end of sndbuf_base.
>
>Decode incoming CDC messages into a temporary smc_host_cdc_msg and verify
>both cursor offsets and their deltas against rmb_desc->len,
>peer_rmbe_size, and (for dmb_nocopy) sndbuf_desc->len before committing
>the update to conn->local_rx_ctrl.
Have you checked this patch ?
https://lore.kernel.org/netdev/20261112-b4-disp-0287c16e-v9-0-e5e8fa688177@proton.me
Best regards,
Dust
>
>Found with an LLM-assisted code review tool and verified by inspection on
>v7.4-rc4 (b6a9fa34ce4). Build-tested only; not runtime-tested due to lack
>of an SMC-R/SMC-D setup.
You can test using SMC-R & rxe + veth
Best regards,
Dust
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net] net/smc: validate peer CDC cursors against buffer bounds and window
2026-11-24 4:16 ` Dust Li
@ 2026-11-24 7:28 ` Qican Ma
0 siblings, 0 replies; 3+ messages in thread
From: Qican Ma @ 2026-11-24 7:28 UTC (permalink / raw)
To: dust.li, alibuda, sidraya, mjambigi
Cc: tonylu, guwen, davem, edumazet, kuba, pabeni, horms, linux-rdma,
linux-s390, netdev
Hi Dust,
Thank you for the pointer and the testing tip!
I checked Bryam Vargas's v9 series (specifically patches 1/6, 2/6 and
3/6) and confirmed that it covers the same cursor and accumulator bound
issues completely. Please disregard this patch as superseded by his
series.
Best regards,
Qican Ma
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-24 7:29 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 3:21 [PATCH net] net/smc: validate peer CDC cursors against buffer bounds and window Qican Ma
2026-11-24 4:16 ` Dust Li
2026-11-24 7:28 ` Qican Ma
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox