Message ID | 1605748432-19416-1-git-send-email-vfedorenko@novek.ru (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | [net,v2] net/tls: missing received data after fast remote close | expand |
Context | Check | Description |
---|---|---|
netdev/cover_letter | success | Link |
netdev/fixes_present | fail | Series targets non-next tree, but doesn't contain any Fixes tags |
netdev/patch_count | success | Link |
netdev/tree_selection | success | Clearly marked for net |
netdev/subject_prefix | success | Link |
netdev/source_inline | success | Was 0 now: 0 |
netdev/verify_signedoff | success | Link |
netdev/module_param | success | Was 0 now: 0 |
netdev/build_32bit | success | Errors and warnings before: 0 this patch: 0 |
netdev/kdoc | success | Errors and warnings before: 0 this patch: 0 |
netdev/verify_fixes | success | Link |
netdev/checkpatch | success | total: 0 errors, 0 warnings, 0 checks, 12 lines checked |
netdev/build_allmodconfig_warn | success | Errors and warnings before: 0 this patch: 0 |
netdev/header_inline | success | Link |
netdev/stable | success | Stable not CCed |
On 19.11.2020 01:13, 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. > > Please ignore this one, it hase typo mistake.
diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c index 2fe9e2c..97c5f6e 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;
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(+)