netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [net v3] net/tls: missing received data after fast remote close
@ 2020-11-19 15:59 Vadim Fedorenko
  2020-11-20 18:26 ` Jakub Kicinski
  0 siblings, 1 reply; 4+ messages in thread
From: Vadim Fedorenko @ 2020-11-19 15:59 UTC (permalink / raw)
  To: Jakub Kicinski, Boris Pismenny, Aviad Yehezkel; +Cc: Vadim Fedorenko, netdev

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.

Signed-off-by: Vadim Fedorenko <vfedorenko@novek.ru>
---
 net/tls/tls_sw.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c
index 2fe9e2c..845c628 100644
--- a/net/tls/tls_sw.c
+++ b/net/tls/tls_sw.c
@@ -1295,6 +1295,12 @@ static struct sk_buff *tls_wait_data(struct sock *sk, struct sk_psock *psock,
 			return NULL;
 		}
 
+		if (!skb_queue_empty(&sk->sk_receive_queue)) {
+			__strp_unpause(&ctx->strp);
+			if (ctx->recv_pkt)
+				return ctx->recv_pkt;
+		}
+
 		if (sk->sk_shutdown & RCV_SHUTDOWN)
 			return NULL;
 
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [net v3] net/tls: missing received data after fast remote close
  2020-11-19 15:59 [net v3] net/tls: missing received data after fast remote close Vadim Fedorenko
@ 2020-11-20 18:26 ` Jakub Kicinski
  2020-11-23 13:40   ` Vadim Fedorenko
  0 siblings, 1 reply; 4+ messages in thread
From: Jakub Kicinski @ 2020-11-20 18:26 UTC (permalink / raw)
  To: Vadim Fedorenko; +Cc: Boris Pismenny, Aviad Yehezkel, netdev

On Thu, 19 Nov 2020 18:59:48 +0300 Vadim Fedorenko wrote:
> 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.
> 
> Signed-off-by: Vadim Fedorenko <vfedorenko@novek.ru>

Applied, thanks!

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [net v3] net/tls: missing received data after fast remote close
  2020-11-20 18:26 ` Jakub Kicinski
@ 2020-11-23 13:40   ` Vadim Fedorenko
  2020-11-23 16:34     ` Jakub Kicinski
  0 siblings, 1 reply; 4+ messages in thread
From: Vadim Fedorenko @ 2020-11-23 13:40 UTC (permalink / raw)
  To: Jakub Kicinski; +Cc: Boris Pismenny, Aviad Yehezkel, netdev

On 20.11.2020 18:26, Jakub Kicinski wrote:
> On Thu, 19 Nov 2020 18:59:48 +0300 Vadim Fedorenko wrote:
>> 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.
>>
>> Signed-off-by: Vadim Fedorenko <vfedorenko@novek.ru>
> Applied, thanks!
Looks like I missed fixes tag to queue this patch to -stable.

Fixes: c46234ebb4d1 ("tls: RX path for ktls")


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [net v3] net/tls: missing received data after fast remote close
  2020-11-23 13:40   ` Vadim Fedorenko
@ 2020-11-23 16:34     ` Jakub Kicinski
  0 siblings, 0 replies; 4+ messages in thread
From: Jakub Kicinski @ 2020-11-23 16:34 UTC (permalink / raw)
  To: Vadim Fedorenko; +Cc: Boris Pismenny, Aviad Yehezkel, netdev

On Mon, 23 Nov 2020 13:40:46 +0000 Vadim Fedorenko wrote:
> On 20.11.2020 18:26, Jakub Kicinski wrote:
> > On Thu, 19 Nov 2020 18:59:48 +0300 Vadim Fedorenko wrote:  
> >> 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.
> >>
> >> Signed-off-by: Vadim Fedorenko <vfedorenko@novek.ru>  
> > Applied, thanks!  
> Looks like I missed fixes tag to queue this patch to -stable.
> 
> Fixes: c46234ebb4d1 ("tls: RX path for ktls")

I put this on:

Fixes: fcf4793e278e ("tls: check RCV_SHUTDOWN in tls_wait_data")

It's queued for stable, but it needs to hit Linus' tree first, so it'll
take another week or so to show up in stable releases.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-11-23 16:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-19 15:59 [net v3] net/tls: missing received data after fast remote close Vadim Fedorenko
2020-11-20 18:26 ` Jakub Kicinski
2020-11-23 13:40   ` Vadim Fedorenko
2020-11-23 16:34     ` Jakub Kicinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).