Commit 2f7be126 authored by Doron Roberts-Kedes's avatar Doron Roberts-Kedes Committed by Greg Kroah-Hartman

strparser: Fix incorrect strp->need_bytes value.


[ Upstream commit 9d0c75bf ]

strp_data_ready resets strp->need_bytes to 0 if strp_peek_len indicates
that the remainder of the message has been received. However,
do_strp_work does not reset strp->need_bytes to 0. If do_strp_work
completes a partial message, the value of strp->need_bytes will continue
to reflect the needed bytes of the previous message, causing
future invocations of strp_data_ready to return early if
strp->need_bytes is less than strp_peek_len. Resetting strp->need_bytes
to 0 in __strp_recv on handing a full message to the upper layer solves
this problem.

__strp_recv also calculates strp->need_bytes using stm->accum_len before
stm->accum_len has been incremented by cand_len. This can cause
strp->need_bytes to be equal to the full length of the message instead
of the full length minus the accumulated length. This, in turn, causes
strp_data_ready to return early, even when there is sufficient data to
complete the partial message. Incrementing stm->accum_len before using
it to calculate strp->need_bytes solves this problem.

Found while testing net/tls_sw recv path.

Fixes: 43a0c675 ("strparser: Stream parser for messages")
Signed-off-by: default avatarDoron Roberts-Kedes <doronrk@fb.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent e2956fc8
...@@ -285,9 +285,9 @@ static int strp_recv(read_descriptor_t *desc, struct sk_buff *orig_skb, ...@@ -285,9 +285,9 @@ static int strp_recv(read_descriptor_t *desc, struct sk_buff *orig_skb,
strp_start_rx_timer(strp); strp_start_rx_timer(strp);
} }
rxm->accum_len += cand_len;
strp->rx_need_bytes = rxm->strp.full_len - strp->rx_need_bytes = rxm->strp.full_len -
rxm->accum_len; rxm->accum_len;
rxm->accum_len += cand_len;
rxm->early_eaten = cand_len; rxm->early_eaten = cand_len;
STRP_STATS_ADD(strp->stats.rx_bytes, cand_len); STRP_STATS_ADD(strp->stats.rx_bytes, cand_len);
desc->count = 0; /* Stop reading socket */ desc->count = 0; /* Stop reading socket */
...@@ -310,6 +310,7 @@ static int strp_recv(read_descriptor_t *desc, struct sk_buff *orig_skb, ...@@ -310,6 +310,7 @@ static int strp_recv(read_descriptor_t *desc, struct sk_buff *orig_skb,
/* Hurray, we have a new message! */ /* Hurray, we have a new message! */
del_timer(&strp->rx_msg_timer); del_timer(&strp->rx_msg_timer);
strp->rx_skb_head = NULL; strp->rx_skb_head = NULL;
strp->rx_need_bytes = 0;
STRP_STATS_INCR(strp->stats.rx_msgs); STRP_STATS_INCR(strp->stats.rx_msgs);
/* Give skb to upper layer */ /* Give skb to upper layer */
...@@ -374,9 +375,7 @@ void strp_data_ready(struct strparser *strp) ...@@ -374,9 +375,7 @@ void strp_data_ready(struct strparser *strp)
return; return;
if (strp->rx_need_bytes) { if (strp->rx_need_bytes) {
if (strp_peek_len(strp) >= strp->rx_need_bytes) if (strp_peek_len(strp) < strp->rx_need_bytes)
strp->rx_need_bytes = 0;
else
return; return;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment