* [PATCH net v5 1/3] net/smc: bound the wire-controlled producer cursor to the RMB
2026-07-24 0:23 [PATCH net v5 0/3] net/smc: bound wire-controlled CDC cursors against the local buffers Bryam Vargas via B4 Relay
@ 2026-07-24 0:23 ` Bryam Vargas via B4 Relay
2026-07-28 13:50 ` Paolo Abeni
2026-08-14 6:03 ` Sidraya Jayagond
2026-07-24 0:23 ` [PATCH net v5 2/3] net/smc: bound the receive length to the RMB in smc_rx_recvmsg() Bryam Vargas via B4 Relay
2026-07-24 0:23 ` [PATCH net v5 3/3] net/smc: bound the send length to the send buffer in smc_tx_sendmsg() Bryam Vargas via B4 Relay
2 siblings, 2 replies; 9+ messages in thread
From: Bryam Vargas via B4 Relay @ 2026-07-24 0:23 UTC (permalink / raw)
To: Sidraya Jayagond, Jakub Kicinski, D. Wythe, David S. Miller,
Wen Gu, Wenjia Zhang, Eric Dumazet, Tony Lu, Mahanta Jambigi,
Dust Li, Paolo Abeni
Cc: linux-s390, linux-rdma, Ursula Braun, netdev, linux-kernel,
Stefan Raspl, Simon Horman
From: Bryam Vargas <hexlabsecurity@proton.me>
smcr_cdc_msg_to_host() and smcd_cdc_msg_to_host() import a peer's
producer cursor from the wire into conn->local_rx_ctrl.prod without
bounding it against the receive buffer. The urgent-data path in
smc_cdc_msg_recv_action() then uses that count as a raw index into the
RMB, so a peer that advertises a producer cursor past rmb_desc->len
reads out of bounds of the RMB allocation in the receive tasklet and
can disclose adjacent kernel memory.
Bound the producer cursor count to rmb_desc->len at the wire-to-host
conversion, for both SMC-R and SMC-D. Bound only the producer cursor:
the consumer cursor indexes the peer's RMB and is bounded by
peer_rmbe_size, so clamping it to our rmb_desc->len would under-credit
peer_rmbe_space and stall transmit to a peer with a larger RMB.
Conforming peers are unaffected.
Fixes: de8474eb9d50 ("net/smc: urgent data support")
Cc: stable@vger.kernel.org
Signed-off-by: Bryam Vargas <hexlabsecurity@proton.me>
Reviewed-by: Dust Li <dust.li@linux.alibaba.com>
---
net/smc/smc_cdc.h | 27 ++++++++++++++++++++++++---
1 file changed, 24 insertions(+), 3 deletions(-)
diff --git a/net/smc/smc_cdc.h b/net/smc/smc_cdc.h
index 696cc11f2303..ca76ef630356 100644
--- a/net/smc/smc_cdc.h
+++ b/net/smc/smc_cdc.h
@@ -221,7 +221,8 @@ static inline void smc_host_msg_to_cdc(struct smc_cdc_msg *peer,
static inline void smc_cdc_cursor_to_host(union smc_host_cursor *local,
union smc_cdc_cursor *peer,
- struct smc_connection *conn)
+ struct smc_connection *conn,
+ int max_count)
{
union smc_host_cursor temp, old;
union smc_cdc_cursor net;
@@ -235,6 +236,15 @@ static inline void smc_cdc_cursor_to_host(union smc_host_cursor *local,
if ((old.wrap == temp.wrap) &&
(old.count > temp.count))
return;
+ /* The peer producer cursor is wire-controlled and is later used as a
+ * raw index into our RMB by the urgent path; bound its count to the
+ * RMB. max_count == 0 leaves the consumer cursor unbounded here: it
+ * indexes the peer's RMB (bounded by peer_rmbe_size, not our
+ * rmb_desc->len), so clamping it to rmb_desc->len would under-credit
+ * peer_rmbe_space and stall transmit to peers with a larger RMB.
+ */
+ if (max_count && temp.count > max_count)
+ temp.count = max_count;
smc_curs_copy(local, &temp, conn);
}
@@ -246,8 +256,13 @@ static inline void smcr_cdc_msg_to_host(struct smc_host_cdc_msg *local,
local->len = peer->len;
local->seqno = ntohs(peer->seqno);
local->token = ntohl(peer->token);
- smc_cdc_cursor_to_host(&local->prod, &peer->prod, conn);
- smc_cdc_cursor_to_host(&local->cons, &peer->cons, conn);
+ /* bound the wire-controlled producer cursor to our RMB (used as a raw
+ * index by the urgent path); leave the consumer cursor unbounded -- it
+ * indexes the peer's RMB and is bounded by peer_rmbe_size.
+ */
+ smc_cdc_cursor_to_host(&local->prod, &peer->prod, conn,
+ conn->rmb_desc->len);
+ smc_cdc_cursor_to_host(&local->cons, &peer->cons, conn, 0);
local->prod_flags = peer->prod_flags;
local->conn_state_flags = peer->conn_state_flags;
}
@@ -260,6 +275,12 @@ static inline void smcd_cdc_msg_to_host(struct smc_host_cdc_msg *local,
temp.wrap = peer->prod.wrap;
temp.count = peer->prod.count;
+ /* the peer producer cursor is wire-controlled and is used as a raw
+ * index into our RMB by the urgent path; bound it to the RMB. The
+ * consumer cursor below indexes the peer's RMB and is left unbounded.
+ */
+ if (temp.count > conn->rmb_desc->len)
+ temp.count = conn->rmb_desc->len;
smc_curs_copy(&local->prod, &temp, conn);
temp.wrap = peer->cons.wrap;
--
2.55.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH net v5 1/3] net/smc: bound the wire-controlled producer cursor to the RMB
2026-07-24 0:23 ` [PATCH net v5 1/3] net/smc: bound the wire-controlled producer cursor to the RMB Bryam Vargas via B4 Relay
@ 2026-07-28 13:50 ` Paolo Abeni
2026-07-28 17:25 ` Bryam Vargas
2026-08-14 6:03 ` Sidraya Jayagond
1 sibling, 1 reply; 9+ messages in thread
From: Paolo Abeni @ 2026-07-28 13:50 UTC (permalink / raw)
To: hexlabsecurity, Sidraya Jayagond, Jakub Kicinski, D. Wythe,
David S. Miller, Wen Gu, Wenjia Zhang, Eric Dumazet, Tony Lu,
Mahanta Jambigi, Dust Li
Cc: linux-s390, linux-rdma, Ursula Braun, netdev, linux-kernel,
Stefan Raspl, Simon Horman
On 7/24/26 2:23 AM, Bryam Vargas via B4 Relay wrote:
> @@ -246,8 +256,13 @@ static inline void smcr_cdc_msg_to_host(struct smc_host_cdc_msg *local,
> local->len = peer->len;
> local->seqno = ntohs(peer->seqno);
> local->token = ntohl(peer->token);
> - smc_cdc_cursor_to_host(&local->prod, &peer->prod, conn);
> - smc_cdc_cursor_to_host(&local->cons, &peer->cons, conn);
> + /* bound the wire-controlled producer cursor to our RMB (used as a raw
> + * index by the urgent path); leave the consumer cursor unbounded -- it
> + * indexes the peer's RMB and is bounded by peer_rmbe_size.
> + */
> + smc_cdc_cursor_to_host(&local->prod, &peer->prod, conn,
> + conn->rmb_desc->len);
Sashiko gemini suspects the above may cause a Null ptr dereference:
https://sashiko.dev/#/patchset/20260723-b4-disp-0d07164f-v5-0-6a9e235dbc4e%40proton.me
/P
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net v5 1/3] net/smc: bound the wire-controlled producer cursor to the RMB
2026-07-28 13:50 ` Paolo Abeni
@ 2026-07-28 17:25 ` Bryam Vargas
0 siblings, 0 replies; 9+ messages in thread
From: Bryam Vargas @ 2026-07-28 17:25 UTC (permalink / raw)
To: Paolo Abeni
Cc: Sidraya Jayagond, Jakub Kicinski, D . Wythe, David S . Miller,
Wen Gu, Wenjia Zhang, Eric Dumazet, Tony Lu, Mahanta Jambigi,
Dust Li, Ursula Braun, Stefan Raspl, Simon Horman, linux-s390,
linux-rdma, netdev, linux-kernel
On Tue, 28 Jul 2026 15:50:02 +0200, Paolo Abeni wrote:
> Sashiko gemini suspects the above may cause a Null ptr dereference:
>
> https://sashiko.dev/#/patchset/20260723-b4-disp-0d07164f-v5-0-6a9e235dbc4e%40proton.me
The window is real, but this patch doesn't open it: the same load is already
on that path.
smc_cdc_msg_recv_action() dereferences conn->rmb_desc->len unconditionally
at smc_cdc.c:376, and nothing between the conversion call at :339 and that
line can return early, so every CDC that reaches the conversion reaches the
existing dereference as well. The patch moves the load about 37 lines up
inside the same function; it doesn't add an execution that touches
conn->rmb_desc. On SMC-D the existing one comes first anyway --
smcd_cdc_rx_tsklet() reads rmb_desc->cpu_addr at :452 before it calls
smc_cdc_msg_recv() at all. Line numbers are against net/main at
e095f249e220.
What the bot is pointing at is a separate defect. smc_conn_create() puts the
connection in the link group's token tree before smc_buf_create() allocates
the RMB, so a CDC arriving in that window finds a connection whose buffer is
still unset -- with or without this series. That one is fixed by [PATCH net
v4] "net/smc: order the CDC receive path against buffer publication", which
publishes the buffers with smp_store_release() once the receive state is
initialised and makes the CDC entry points bail while they are unset:
https://lore.kernel.org/all/20260728-b4-disp-52ee4e7d-v4-1-0dda94b0f397@proton.me/
Thanks,
Bryam
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net v5 1/3] net/smc: bound the wire-controlled producer cursor to the RMB
2026-07-24 0:23 ` [PATCH net v5 1/3] net/smc: bound the wire-controlled producer cursor to the RMB Bryam Vargas via B4 Relay
2026-07-28 13:50 ` Paolo Abeni
@ 2026-08-14 6:03 ` Sidraya Jayagond
1 sibling, 0 replies; 9+ messages in thread
From: Sidraya Jayagond @ 2026-08-14 6:03 UTC (permalink / raw)
To: hexlabsecurity, Jakub Kicinski, D. Wythe, David S. Miller, Wen Gu,
Wenjia Zhang, Eric Dumazet, Tony Lu, Mahanta Jambigi, Dust Li,
Paolo Abeni
Cc: linux-s390, linux-rdma, Ursula Braun, netdev, linux-kernel,
Stefan Raspl, Simon Horman
On 24/07/26 5:53 am, Bryam Vargas via B4 Relay wrote:
> From: Bryam Vargas <hexlabsecurity@proton.me>
>
> smcr_cdc_msg_to_host() and smcd_cdc_msg_to_host() import a peer's
> producer cursor from the wire into conn->local_rx_ctrl.prod without
> bounding it against the receive buffer. The urgent-data path in
> smc_cdc_msg_recv_action() then uses that count as a raw index into the
> RMB, so a peer that advertises a producer cursor past rmb_desc->len
> reads out of bounds of the RMB allocation in the receive tasklet and
> can disclose adjacent kernel memory.
>
> Bound the producer cursor count to rmb_desc->len at the wire-to-host
> conversion, for both SMC-R and SMC-D. Bound only the producer cursor:
> the consumer cursor indexes the peer's RMB and is bounded by
> peer_rmbe_size, so clamping it to our rmb_desc->len would under-credit
> peer_rmbe_space and stall transmit to a peer with a larger RMB.
> Conforming peers are unaffected.
>
> Fixes: de8474eb9d50 ("net/smc: urgent data support")
> Cc: stable@vger.kernel.org
> Signed-off-by: Bryam Vargas <hexlabsecurity@proton.me>
> Reviewed-by: Dust Li <dust.li@linux.alibaba.com>
> ---
> net/smc/smc_cdc.h | 27 ++++++++++++++++++++++++---
> 1 file changed, 24 insertions(+), 3 deletions(-)
>
> diff --git a/net/smc/smc_cdc.h b/net/smc/smc_cdc.h
> index 696cc11f2303..ca76ef630356 100644
> --- a/net/smc/smc_cdc.h
> +++ b/net/smc/smc_cdc.h
> @@ -221,7 +221,8 @@ static inline void smc_host_msg_to_cdc(struct smc_cdc_msg *peer,
>
> static inline void smc_cdc_cursor_to_host(union smc_host_cursor *local,
> union smc_cdc_cursor *peer,
> - struct smc_connection *conn)
> + struct smc_connection *conn,
> + int max_count)
> {
> union smc_host_cursor temp, old;
> union smc_cdc_cursor net;
> @@ -235,6 +236,15 @@ static inline void smc_cdc_cursor_to_host(union smc_host_cursor *local,
> if ((old.wrap == temp.wrap) &&
> (old.count > temp.count))
> return;
> + /* The peer producer cursor is wire-controlled and is later used as a
> + * raw index into our RMB by the urgent path; bound its count to the
> + * RMB. max_count == 0 leaves the consumer cursor unbounded here: it
> + * indexes the peer's RMB (bounded by peer_rmbe_size, not our
> + * rmb_desc->len), so clamping it to rmb_desc->len would under-credit
> + * peer_rmbe_space and stall transmit to peers with a larger RMB.
> + */
> + if (max_count && temp.count > max_count)
> + temp.count = max_count;
> smc_curs_copy(local, &temp, conn);
> }
>
> @@ -246,8 +256,13 @@ static inline void smcr_cdc_msg_to_host(struct smc_host_cdc_msg *local,
> local->len = peer->len;
> local->seqno = ntohs(peer->seqno);
> local->token = ntohl(peer->token);
> - smc_cdc_cursor_to_host(&local->prod, &peer->prod, conn);
> - smc_cdc_cursor_to_host(&local->cons, &peer->cons, conn);
> + /* bound the wire-controlled producer cursor to our RMB (used as a raw
> + * index by the urgent path); leave the consumer cursor unbounded -- it
> + * indexes the peer's RMB and is bounded by peer_rmbe_size.
> + */
> + smc_cdc_cursor_to_host(&local->prod, &peer->prod, conn,
> + conn->rmb_desc->len);
> + smc_cdc_cursor_to_host(&local->cons, &peer->cons, conn, 0);
> local->prod_flags = peer->prod_flags;
> local->conn_state_flags = peer->conn_state_flags;
> }
> @@ -260,6 +275,12 @@ static inline void smcd_cdc_msg_to_host(struct smc_host_cdc_msg *local,
>
> temp.wrap = peer->prod.wrap;
> temp.count = peer->prod.count;
> + /* the peer producer cursor is wire-controlled and is used as a raw
> + * index into our RMB by the urgent path; bound it to the RMB. The
> + * consumer cursor below indexes the peer's RMB and is left unbounded.
> + */
> + if (temp.count > conn->rmb_desc->len)
> + temp.count = conn->rmb_desc->len;
> smc_curs_copy(&local->prod, &temp, conn);
>
> temp.wrap = peer->cons.wrap;
>
Reviewed-by: Sidraya Jayagond <sidraya@linux.ibm.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH net v5 2/3] net/smc: bound the receive length to the RMB in smc_rx_recvmsg()
2026-07-24 0:23 [PATCH net v5 0/3] net/smc: bound wire-controlled CDC cursors against the local buffers Bryam Vargas via B4 Relay
2026-07-24 0:23 ` [PATCH net v5 1/3] net/smc: bound the wire-controlled producer cursor to the RMB Bryam Vargas via B4 Relay
@ 2026-07-24 0:23 ` Bryam Vargas via B4 Relay
2026-08-14 6:03 ` Sidraya Jayagond
2026-07-24 0:23 ` [PATCH net v5 3/3] net/smc: bound the send length to the send buffer in smc_tx_sendmsg() Bryam Vargas via B4 Relay
2 siblings, 1 reply; 9+ messages in thread
From: Bryam Vargas via B4 Relay @ 2026-07-24 0:23 UTC (permalink / raw)
To: Sidraya Jayagond, Jakub Kicinski, D. Wythe, David S. Miller,
Wen Gu, Wenjia Zhang, Eric Dumazet, Tony Lu, Mahanta Jambigi,
Dust Li, Paolo Abeni
Cc: linux-s390, linux-rdma, Ursula Braun, netdev, linux-kernel,
Stefan Raspl, Simon Horman
From: Bryam Vargas <hexlabsecurity@proton.me>
conn->bytes_to_rcv is accumulated in the receive tasklet from the
peer's wire-controlled producer cursor via smc_curs_diff(), whose
differing-wrap branch can exceed rmb_desc->len; a forged cursor drives
bytes_to_rcv past the RMB, and over many CDC messages overflows the
signed counter negative. smc_rx_recvmsg() reads it as the readable
length and does a wrap-around copy whose second chunk is not re-bounded
to rmb_desc->len, reading past the RMB into adjacent kernel memory and
disclosing it to the peer. The nearby readable >= rmb_desc->len test
only feeds SMC_STAT_RMB_RX_FULL on a separate earlier read; it does not
bound the copy.
Bound the readable length to rmb_desc->len at the consumer, treating a
negative (sign-overflowed) value as out of range too, so the copy can
never exceed the ring. This enforces the documented
0 <= bytes_to_rcv <= rmb_desc->len invariant where it is race-free
against the producer update in the tasklet; conforming peers are
unaffected.
Fixes: 952310ccf2d8 ("smc: receive data from RMBE")
Cc: stable@vger.kernel.org
Signed-off-by: Bryam Vargas <hexlabsecurity@proton.me>
Reviewed-by: Dust Li <dust.li@linux.alibaba.com>
---
net/smc/smc_rx.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/net/smc/smc_rx.c b/net/smc/smc_rx.c
index c1d9b923938d..f461cf10b085 100644
--- a/net/smc/smc_rx.c
+++ b/net/smc/smc_rx.c
@@ -442,6 +442,18 @@ int smc_rx_recvmsg(struct smc_sock *smc, struct msghdr *msg,
/* initialize variables for 1st iteration of subsequent loop */
/* could be just 1 byte, even after waiting on data above */
readable = smc_rx_data_available(conn, peeked_bytes);
+ /* bytes_to_rcv is accumulated from the peer's wire-controlled
+ * producer cursor; a forged cursor can drive it past the RMB,
+ * or overflow the signed accumulator to a negative value across
+ * many CDC messages (which a plain "> len" check would miss
+ * before the size_t cast below turns it huge). Bound it to the
+ * RMB in either case so the wrap-around copy cannot run past
+ * rmb_desc->len. This enforces the documented
+ * 0 <= bytes_to_rcv <= rmb_desc->len invariant at the consumer,
+ * race-free against the producer update in the receive tasklet.
+ */
+ if (readable < 0 || readable > conn->rmb_desc->len)
+ readable = conn->rmb_desc->len;
splbytes = atomic_read(&conn->splice_pending);
if (!readable || (msg && splbytes)) {
if (splbytes)
--
2.55.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH net v5 2/3] net/smc: bound the receive length to the RMB in smc_rx_recvmsg()
2026-07-24 0:23 ` [PATCH net v5 2/3] net/smc: bound the receive length to the RMB in smc_rx_recvmsg() Bryam Vargas via B4 Relay
@ 2026-08-14 6:03 ` Sidraya Jayagond
0 siblings, 0 replies; 9+ messages in thread
From: Sidraya Jayagond @ 2026-08-14 6:03 UTC (permalink / raw)
To: hexlabsecurity, Jakub Kicinski, D. Wythe, David S. Miller, Wen Gu,
Wenjia Zhang, Eric Dumazet, Tony Lu, Mahanta Jambigi, Dust Li,
Paolo Abeni
Cc: linux-s390, linux-rdma, Ursula Braun, netdev, linux-kernel,
Stefan Raspl, Simon Horman
On 24/07/26 5:53 am, Bryam Vargas via B4 Relay wrote:
> From: Bryam Vargas <hexlabsecurity@proton.me>
>
> conn->bytes_to_rcv is accumulated in the receive tasklet from the
> peer's wire-controlled producer cursor via smc_curs_diff(), whose
> differing-wrap branch can exceed rmb_desc->len; a forged cursor drives
> bytes_to_rcv past the RMB, and over many CDC messages overflows the
> signed counter negative. smc_rx_recvmsg() reads it as the readable
> length and does a wrap-around copy whose second chunk is not re-bounded
> to rmb_desc->len, reading past the RMB into adjacent kernel memory and
> disclosing it to the peer. The nearby readable >= rmb_desc->len test
> only feeds SMC_STAT_RMB_RX_FULL on a separate earlier read; it does not
> bound the copy.
>
> Bound the readable length to rmb_desc->len at the consumer, treating a
> negative (sign-overflowed) value as out of range too, so the copy can
> never exceed the ring. This enforces the documented
> 0 <= bytes_to_rcv <= rmb_desc->len invariant where it is race-free
> against the producer update in the tasklet; conforming peers are
> unaffected.
>
> Fixes: 952310ccf2d8 ("smc: receive data from RMBE")
> Cc: stable@vger.kernel.org
> Signed-off-by: Bryam Vargas <hexlabsecurity@proton.me>
> Reviewed-by: Dust Li <dust.li@linux.alibaba.com>
> ---
> net/smc/smc_rx.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/net/smc/smc_rx.c b/net/smc/smc_rx.c
> index c1d9b923938d..f461cf10b085 100644
> --- a/net/smc/smc_rx.c
> +++ b/net/smc/smc_rx.c
> @@ -442,6 +442,18 @@ int smc_rx_recvmsg(struct smc_sock *smc, struct msghdr *msg,
> /* initialize variables for 1st iteration of subsequent loop */
> /* could be just 1 byte, even after waiting on data above */
> readable = smc_rx_data_available(conn, peeked_bytes);
> + /* bytes_to_rcv is accumulated from the peer's wire-controlled
> + * producer cursor; a forged cursor can drive it past the RMB,
> + * or overflow the signed accumulator to a negative value across
> + * many CDC messages (which a plain "> len" check would miss
> + * before the size_t cast below turns it huge). Bound it to the
> + * RMB in either case so the wrap-around copy cannot run past
> + * rmb_desc->len. This enforces the documented
> + * 0 <= bytes_to_rcv <= rmb_desc->len invariant at the consumer,
> + * race-free against the producer update in the receive tasklet.
> + */
> + if (readable < 0 || readable > conn->rmb_desc->len)
> + readable = conn->rmb_desc->len;
> splbytes = atomic_read(&conn->splice_pending);
> if (!readable || (msg && splbytes)) {
> if (splbytes)
>
Reviewed-by: Sidraya Jayagond <sidraya@linux.ibm.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH net v5 3/3] net/smc: bound the send length to the send buffer in smc_tx_sendmsg()
2026-07-24 0:23 [PATCH net v5 0/3] net/smc: bound wire-controlled CDC cursors against the local buffers Bryam Vargas via B4 Relay
2026-07-24 0:23 ` [PATCH net v5 1/3] net/smc: bound the wire-controlled producer cursor to the RMB Bryam Vargas via B4 Relay
2026-07-24 0:23 ` [PATCH net v5 2/3] net/smc: bound the receive length to the RMB in smc_rx_recvmsg() Bryam Vargas via B4 Relay
@ 2026-07-24 0:23 ` Bryam Vargas via B4 Relay
2026-08-14 6:04 ` Sidraya Jayagond
2 siblings, 1 reply; 9+ messages in thread
From: Bryam Vargas via B4 Relay @ 2026-07-24 0:23 UTC (permalink / raw)
To: Sidraya Jayagond, Jakub Kicinski, D. Wythe, David S. Miller,
Wen Gu, Wenjia Zhang, Eric Dumazet, Tony Lu, Mahanta Jambigi,
Dust Li, Paolo Abeni
Cc: linux-s390, linux-rdma, Ursula Braun, netdev, linux-kernel,
Stefan Raspl, Simon Horman
From: Bryam Vargas <hexlabsecurity@proton.me>
On the SMC-D DMB-merge (nocopy) path, smc_cdc_msg_recv_action()
advances conn->sndbuf_space from the peer's wire-controlled consumer
cursor via smc_curs_diff(), which can return more than sndbuf_desc->len;
a forged cursor drives sndbuf_space past the send buffer, and over many
CDC messages overflows the signed counter negative. smc_tx_sendmsg()
reads it as the write space and does a wrap-around copy whose second
chunk is not re-bounded to sndbuf_desc->len, spilling the local
sender's outbound data past the send buffer at a peer-controlled
length: a heap out-of-bounds write. The nearby len > sndbuf_desc->len
test only feeds SMC_STAT_RMB_TX_SIZE_SMALL on the user length; it does
not bound the copy.
Bound the write space to sndbuf_desc->len at the consumer, treating a
negative (sign-overflowed) value as out of range too, so the copy can
never exceed the ring. This enforces the documented
0 <= sndbuf_space <= sndbuf_desc->len invariant where it is race-free
against the CDC tasklet; conforming peers are unaffected.
Fixes: cc0ab806fc52 ("net/smc: adapt cursor update when sndbuf and peer DMB are merged")
Cc: stable@vger.kernel.org
Signed-off-by: Bryam Vargas <hexlabsecurity@proton.me>
Reviewed-by: Dust Li <dust.li@linux.alibaba.com>
---
net/smc/smc_tx.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/net/smc/smc_tx.c b/net/smc/smc_tx.c
index 3144b4b1fe29..5916f02060fb 100644
--- a/net/smc/smc_tx.c
+++ b/net/smc/smc_tx.c
@@ -233,6 +233,19 @@ int smc_tx_sendmsg(struct smc_sock *smc, struct msghdr *msg, size_t len)
/* initialize variables for 1st iteration of subsequent loop */
/* could be just 1 byte, even after smc_tx_wait above */
writespace = atomic_read(&conn->sndbuf_space);
+ /* sndbuf_space is advanced from the peer's wire-controlled
+ * consumer cursor on the SMC-D DMB-merge path; a forged cursor
+ * can inflate it past the send buffer, or overflow the signed
+ * accumulator to a negative value across many CDC messages
+ * (which a plain "> len" check would miss before the size_t
+ * cast below turns it huge). Bound it to the send buffer in
+ * either case so the wrap-around write cannot run past
+ * sndbuf_desc->len. This enforces the documented
+ * 0 <= sndbuf_space <= sndbuf_desc->len invariant at the
+ * producer, race-free against the CDC tasklet.
+ */
+ if (writespace < 0 || writespace > conn->sndbuf_desc->len)
+ writespace = conn->sndbuf_desc->len;
/* not more than what user space asked for */
copylen = min_t(size_t, send_remaining, writespace);
/* determine start of sndbuf */
--
2.55.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH net v5 3/3] net/smc: bound the send length to the send buffer in smc_tx_sendmsg()
2026-07-24 0:23 ` [PATCH net v5 3/3] net/smc: bound the send length to the send buffer in smc_tx_sendmsg() Bryam Vargas via B4 Relay
@ 2026-08-14 6:04 ` Sidraya Jayagond
0 siblings, 0 replies; 9+ messages in thread
From: Sidraya Jayagond @ 2026-08-14 6:04 UTC (permalink / raw)
To: hexlabsecurity, Jakub Kicinski, D. Wythe, David S. Miller, Wen Gu,
Wenjia Zhang, Eric Dumazet, Tony Lu, Mahanta Jambigi, Dust Li,
Paolo Abeni
Cc: linux-s390, linux-rdma, Ursula Braun, netdev, linux-kernel,
Stefan Raspl, Simon Horman
On 24/07/26 5:53 am, Bryam Vargas via B4 Relay wrote:
> From: Bryam Vargas <hexlabsecurity@proton.me>
>
> On the SMC-D DMB-merge (nocopy) path, smc_cdc_msg_recv_action()
> advances conn->sndbuf_space from the peer's wire-controlled consumer
> cursor via smc_curs_diff(), which can return more than sndbuf_desc->len;
> a forged cursor drives sndbuf_space past the send buffer, and over many
> CDC messages overflows the signed counter negative. smc_tx_sendmsg()
> reads it as the write space and does a wrap-around copy whose second
> chunk is not re-bounded to sndbuf_desc->len, spilling the local
> sender's outbound data past the send buffer at a peer-controlled
> length: a heap out-of-bounds write. The nearby len > sndbuf_desc->len
> test only feeds SMC_STAT_RMB_TX_SIZE_SMALL on the user length; it does
> not bound the copy.
>
> Bound the write space to sndbuf_desc->len at the consumer, treating a
> negative (sign-overflowed) value as out of range too, so the copy can
> never exceed the ring. This enforces the documented
> 0 <= sndbuf_space <= sndbuf_desc->len invariant where it is race-free
> against the CDC tasklet; conforming peers are unaffected.
>
> Fixes: cc0ab806fc52 ("net/smc: adapt cursor update when sndbuf and peer DMB are merged")
> Cc: stable@vger.kernel.org
> Signed-off-by: Bryam Vargas <hexlabsecurity@proton.me>
> Reviewed-by: Dust Li <dust.li@linux.alibaba.com>
> ---
> net/smc/smc_tx.c | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
>
> diff --git a/net/smc/smc_tx.c b/net/smc/smc_tx.c
> index 3144b4b1fe29..5916f02060fb 100644
> --- a/net/smc/smc_tx.c
> +++ b/net/smc/smc_tx.c
> @@ -233,6 +233,19 @@ int smc_tx_sendmsg(struct smc_sock *smc, struct msghdr *msg, size_t len)
> /* initialize variables for 1st iteration of subsequent loop */
> /* could be just 1 byte, even after smc_tx_wait above */
> writespace = atomic_read(&conn->sndbuf_space);
> + /* sndbuf_space is advanced from the peer's wire-controlled
> + * consumer cursor on the SMC-D DMB-merge path; a forged cursor
> + * can inflate it past the send buffer, or overflow the signed
> + * accumulator to a negative value across many CDC messages
> + * (which a plain "> len" check would miss before the size_t
> + * cast below turns it huge). Bound it to the send buffer in
> + * either case so the wrap-around write cannot run past
> + * sndbuf_desc->len. This enforces the documented
> + * 0 <= sndbuf_space <= sndbuf_desc->len invariant at the
> + * producer, race-free against the CDC tasklet.
> + */
> + if (writespace < 0 || writespace > conn->sndbuf_desc->len)
> + writespace = conn->sndbuf_desc->len;
> /* not more than what user space asked for */
> copylen = min_t(size_t, send_remaining, writespace);
> /* determine start of sndbuf */
>
Reviewed-by: Sidraya Jayagond <sidraya@linux.ibm.com>
^ permalink raw reply [flat|nested] 9+ messages in thread