Skip to content

Commit

Permalink
net/tls: fix no wakeup on partial reads
Browse files Browse the repository at this point in the history
When tls_sw_recvmsg() partially copies a record it pops that
record from ctx->recv_pkt and places it on rx_list.

Next iteration of tls_sw_recvmsg() reads from rx_list via
process_rx_list() before it enters the decryption loop.
If there is no more records to be read tls_wait_data()
will put the process on the wait queue and got to sleep.
This is incorrect, because some data was already copied
in process_rx_list().

In case of RPC connections process may never get woken up,
because peer also simply blocks in read().

I think this may also fix a similar issue when BPF is at
play, because after __tcp_bpf_recvmsg() returns some data
we subtract it from len and use continue to restart the
loop, but len could have just reached 0, so again we'd
sleep unnecessarily. That's added by:
commit d3b18ad ("tls: add bpf support to sk_msg handling")

Fixes: 692d7b5 ("tls: Fix recvmsg() to be able to peek across multiple records")
Reported-by: David Beckett <[email protected]>
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 7718a85 commit 04b25a5
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions net/tls/tls_sw.c
Original file line number Diff line number Diff line change
Expand Up @@ -1719,7 +1719,7 @@ int tls_sw_recvmsg(struct sock *sk,
len = len - copied;
timeo = sock_rcvtimeo(sk, flags & MSG_DONTWAIT);

do {
while (len && (decrypted + copied < target || ctx->recv_pkt)) {
bool retain_skb = false;
bool zc = false;
int to_decrypt;
Expand Down Expand Up @@ -1850,11 +1850,7 @@ int tls_sw_recvmsg(struct sock *sk,
} else {
break;
}

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

recv_end:
if (num_async) {
Expand Down

0 comments on commit 04b25a5

Please sign in to comment.