From: Bryam Vargas smcr_cdc_msg_to_host() and smcd_cdc_msg_to_host() import the peer's producer cursor from the wire into conn->local_rx_ctrl.prod without bounding it to the RMB. smc_cdc_handle_urg_data_arrival() then uses its count as a raw index into the RMB, so a producer cursor past rmb_desc->len makes the receive tasklet read past the RMB, and recv(MSG_OOB) hands that byte to the application. Bound the producer cursor count to rmb_desc->len when it comes off the wire, for SMC-R and SMC-D. Leave the consumer cursor alone: it indexes the peer's RMB, which can be larger than ours, so clamping it to our RMB would under-credit peer_rmbe_space and could stall sending to that peer. Conforming peers are unaffected. Fixes: de8474eb9d50 ("net/smc: urgent data support") Cc: stable@vger.kernel.org Signed-off-by: Bryam Vargas Reviewed-by: Dust Li Reviewed-by: Sidraya Jayagond --- net/smc/smc_cdc.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/net/smc/smc_cdc.h b/net/smc/smc_cdc.h index 696cc11f2303..4d630a305118 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,12 @@ static inline void smc_cdc_cursor_to_host(union smc_host_cursor *local, if ((old.wrap == temp.wrap) && (old.count > temp.count)) return; + /* The urgent path uses the producer count as a raw index into our + * RMB, so bound it. max_count == 0 leaves the consumer cursor alone: + * it indexes the peer's RMB, which can be larger than ours. + */ + if (max_count && temp.count > max_count) + temp.count = max_count; smc_curs_copy(local, &temp, conn); } @@ -246,8 +253,9 @@ 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); + 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 +268,9 @@ static inline void smcd_cdc_msg_to_host(struct smc_host_cdc_msg *local, temp.wrap = peer->prod.wrap; temp.count = peer->prod.count; + /* as in smc_cdc_cursor_to_host(): bound prod, not cons */ + 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.56.0