Skip to content

Commit 176ee7d

Browse files
vvfedorenkogregkh
authored andcommitted
net/tls: missing received data after fast remote close
[ Upstream commit 20ffc7a ] In case when tcp socket received FIN after some data and the parser haven't started before reading data caller will receive an empty buffer. This behavior differs from plain TCP socket and leads to special treating in user-space. The flow that triggers the race is simple. Server sends small amount of data right after the connection is configured to use TLS and closes the connection. In this case receiver sees TLS Handshake data, configures TLS socket right after Change Cipher Spec record. While the configuration is in process, TCP socket receives small Application Data record, Encrypted Alert record and FIN packet. So the TCP socket changes sk_shutdown to RCV_SHUTDOWN and sk_flag with SK_DONE bit set. The received data is not parsed upon arrival and is never sent to user-space. Patch unpauses parser directly if we have unparsed data in tcp receive queue. Fixes: fcf4793 ("tls: check RCV_SHUTDOWN in tls_wait_data") Signed-off-by: Vadim Fedorenko <vfedorenko@novek.ru> Link: https://lore.kernel.org/r/1605801588-12236-1-git-send-email-vfedorenko@novek.ru Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent ff764c1 commit 176ee7d

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

‎net/tls/tls_sw.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,12 @@ static struct sk_buff *tls_wait_data(struct sock *sk, struct sk_psock *psock,
12951295
return NULL;
12961296
}
12971297

1298+
if (!skb_queue_empty(&sk->sk_receive_queue)) {
1299+
__strp_unpause(&ctx->strp);
1300+
if (ctx->recv_pkt)
1301+
return ctx->recv_pkt;
1302+
}
1303+
12981304
if (sk->sk_shutdown & RCV_SHUTDOWN)
12991305
return NULL;
13001306

0 commit comments

Comments
 (0)