Skip to content

Commit 9d0c75b

Browse files
Doron Roberts-Kedesdavem330
authored andcommitted
strparser: Fix incorrect strp->need_bytes value.
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: 43a0c67 ("strparser: Stream parser for messages") Signed-off-by: Doron Roberts-Kedes <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 5ff9c1a commit 9d0c75b

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

net/strparser/strparser.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,9 @@ static int __strp_recv(read_descriptor_t *desc, struct sk_buff *orig_skb,
296296
strp_start_timer(strp, timeo);
297297
}
298298

299+
stm->accum_len += cand_len;
299300
strp->need_bytes = stm->strp.full_len -
300301
stm->accum_len;
301-
stm->accum_len += cand_len;
302302
stm->early_eaten = cand_len;
303303
STRP_STATS_ADD(strp->stats.bytes, cand_len);
304304
desc->count = 0; /* Stop reading socket */
@@ -321,6 +321,7 @@ static int __strp_recv(read_descriptor_t *desc, struct sk_buff *orig_skb,
321321
/* Hurray, we have a new message! */
322322
cancel_delayed_work(&strp->msg_timer_work);
323323
strp->skb_head = NULL;
324+
strp->need_bytes = 0;
324325
STRP_STATS_INCR(strp->stats.msgs);
325326

326327
/* Give skb to upper layer */
@@ -410,9 +411,7 @@ void strp_data_ready(struct strparser *strp)
410411
return;
411412

412413
if (strp->need_bytes) {
413-
if (strp_peek_len(strp) >= strp->need_bytes)
414-
strp->need_bytes = 0;
415-
else
414+
if (strp_peek_len(strp) < strp->need_bytes)
416415
return;
417416
}
418417

0 commit comments

Comments
 (0)