]> git.baikalelectronics.ru Git - kernel.git/commit
strparser: Fix incorrect strp->need_bytes value.
authorDoron Roberts-Kedes <doronrk@fb.com>
Wed, 11 Apr 2018 22:05:16 +0000 (15:05 -0700)
committerDavid S. Miller <davem@davemloft.net>
Fri, 13 Apr 2018 01:54:59 +0000 (21:54 -0400)
commitcf705617adb36bbb4c2b96a589dfd4e44a8d071d
treebb0a065e70bb7331987e4759f216ba24db4949a0
parentbf606b2a0c279b56a64f30abebc60b65c4e13410
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: 0310cbc8394aebb1 ("strparser: Stream parser for messages")
Signed-off-by: Doron Roberts-Kedes <doronrk@fb.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/strparser/strparser.c