Skip to content

Commit

Permalink
net/tls: fix lowat calculation if some data came from previous record
Browse files Browse the repository at this point in the history
If some of the data came from the previous record, i.e. from
the rx_list it had already been decrypted, so it's not counted
towards the "decrypted" variable, but the "copied" variable.
Take that into account when checking lowat.

When calculating lowat target we need to pass the original len.
E.g. if lowat is at 80, len is 100 and we had 30 bytes on rx_list
target would currently be incorrectly calculated as 70, even though
we only need 50 more bytes to make up the 80.

Fixes: 692d7b5 ("tls: Fix recvmsg() to be able to peek across multiple records")
Signed-off-by: Jakub Kicinski <[email protected]>
Reviewed-by: Dirk van der Merwe <[email protected]>
Tested-by: David Beckett <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Jakub Kicinski authored and davem330 committed May 27, 2019
1 parent 66a04ab commit 46a1695
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions net/tls/tls_sw.c
Original file line number Diff line number Diff line change
Expand Up @@ -1712,13 +1712,12 @@ int tls_sw_recvmsg(struct sock *sk,
copied = err;
}

len = len - copied;
if (len) {
target = sock_rcvlowat(sk, flags & MSG_WAITALL, len);
timeo = sock_rcvtimeo(sk, flags & MSG_DONTWAIT);
} else {
if (len <= copied)
goto recv_end;
}

target = sock_rcvlowat(sk, flags & MSG_WAITALL, len);
len = len - copied;
timeo = sock_rcvtimeo(sk, flags & MSG_DONTWAIT);

do {
bool retain_skb = false;
Expand Down Expand Up @@ -1853,7 +1852,7 @@ int tls_sw_recvmsg(struct sock *sk,
}

/* If we have a new message from strparser, continue now. */
if (decrypted >= target && !ctx->recv_pkt)
if (decrypted + copied >= target && !ctx->recv_pkt)
break;
} while (len);

Expand Down

0 comments on commit 46a1695

Please sign in to comment.