From: Bryam Vargas recv(MSG_OOB) returns the urgent byte and relies on smc_rx_update_consumer() to skip the byte's place in the RMB. recv(MSG_OOB) asks for that skip by setting urg_rx_skip_pend, but only when there is unread data in front of the byte. When the urgent byte is the next unread byte, e.g. after a one-byte send(MSG_OOB) to a reader that has read everything else, no skip is pending and urg_state is SMC_URG_READ: the byte is never skipped, and the sender, which waits for its urgent data to be consumed, stalls on its next send(). A zero-length recv(MSG_OOB) consumes the byte as well, but neither sets urg_rx_skip_pend nor calls smc_rx_update_consumer(). Set urg_rx_skip_pend whenever the reader has not passed the urgent byte, and call smc_rx_update_consumer() for any length. Fixes: de8474eb9d50 ("net/smc: urgent data support") Suggested-by: Sidraya Jayagond Cc: stable@vger.kernel.org Signed-off-by: Bryam Vargas --- net/smc/smc_rx.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/net/smc/smc_rx.c b/net/smc/smc_rx.c index 2680b91e882b..579ee008900c 100644 --- a/net/smc/smc_rx.c +++ b/net/smc/smc_rx.c @@ -342,12 +342,14 @@ static int smc_rx_recv_urg(struct smc_sock *smc, struct msghdr *msg, int len, valid = conn->urg_state == SMC_URG_VALID; if (valid) { byte = conn->urg_rx_byte; - if (len > 0) { - smc_curs_copy(&cons, &conn->local_tx_ctrl.cons, conn); - if (smc_curs_sdiff(conn->rmb_desc->len, &cons, - &conn->urg_curs) > 1) - conn->urg_rx_skip_pend = true; - } + /* The reader has not passed the urgent byte: have + * smc_rx_update_consumer() skip it once it is the next + * unread byte. + */ + smc_curs_copy(&cons, &conn->local_tx_ctrl.cons, conn); + if (smc_curs_sdiff(conn->rmb_desc->len, &cons, + &conn->urg_curs) > 0) + conn->urg_rx_skip_pend = true; if (!(flags & MSG_PEEK)) conn->urg_state = SMC_URG_READ; } @@ -362,14 +364,14 @@ static int smc_rx_recv_urg(struct smc_sock *smc, struct msghdr *msg, int len, if (!(flags & MSG_TRUNC)) rc = memcpy_to_msg(msg, &byte, 1); len = 1; - /* Urgent Byte was already accounted for, but trigger - * skipping the urgent byte in non-inline case - */ - if (!(flags & MSG_PEEK)) - smc_rx_update_consumer(smc, cons, 0); } else { msg->msg_flags |= MSG_TRUNC; } + /* Urgent Byte was already accounted for, but trigger + * skipping the urgent byte in non-inline case + */ + if (!(flags & MSG_PEEK)) + smc_rx_update_consumer(smc, cons, 0); return rc ? -EFAULT : len; } -- 2.56.1