Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1679138pxu; Sun, 6 Dec 2020 03:49:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJz6VSKZ0WIgy7lGpWUM4FdVRG3xmwt9xBaDVHzxOskSh7IHjpIQy4OAzRaPA/hhbi1CcTo7 X-Received: by 2002:a50:99c3:: with SMTP id n3mr15498199edb.213.1607255350034; Sun, 06 Dec 2020 03:49:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607255350; cv=none; d=google.com; s=arc-20160816; b=WTN94jSgR/oEUPtUP1GOmo739RoAdf8KJIRdUAjuNtpvNGo3PAq4U4p2fnZnu10vTO BQgNOXIEX4bZ6fYCwLFDCsIhMaJxKWDv0f+b57l9c2JvNvTuOTA3G+VE/t5RaSgXfjBb +id8YV1y9z3Rbahmkc9xldJBYDd9I43xOXzPOCkShodQ3JhtB5GgNsAVPbyYUqStA9pA lq+IMyOZ04VHUjpTEugjkhmvUboVAlhZGnvZFGyqFSGDZajUHU9MG2SDStrinwwHY7Al oVwv0yOC2A34CvCgIBrWOrVwRWwnL01L4EHfUD2VYNg5W0FZZcYUhIO5k2XZKTqnrkvW iC6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=Yz4InVYzTgU8/B+pjbgfLgiNWn6VvRi6UY0F8xnrhis=; b=rWLkFajVMCn5SrPSUlwb4UsPTyFj6AtnzVFETe4/2mk9XoaiSnDv0sqGA4y5/j4j56 mB9l7OECIUplMIDZWkpVBSe4SxEerprDbaGCLH0AHKUr5lEdpZwBoBh84VQQ4LPUMvu2 hzixHwYAFGSqOiig/UvZFlh5hSPdDQydWrWXoeSFws3apVLs82Tem51fKAxbLZqVbPY9 0qtEWKcJDU7JKvTi39+W4Pa92kjarxxO9TpZnoRX3MVfUes94G74B6diZrQZ5FyhYeRu AYqaC8Z/KQi5GwNrbMfPlF8pgaTqYkfULeJB4QAJRCnpGCWu3IKLg9ghx/Yl3GXE0yvs 5ztA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v21si577898ejg.492.2020.12.06.03.48.47; Sun, 06 Dec 2020 03:49:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729195AbgLFLrd (ORCPT + 99 others); Sun, 6 Dec 2020 06:47:33 -0500 Received: from mail.kernel.org ([198.145.29.99]:42414 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729089AbgLFLnG (ORCPT ); Sun, 6 Dec 2020 06:43:06 -0500 From: Greg Kroah-Hartman Authentication-Results: mail.kernel.org; dkim=permerror (bad message/signature format) To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vadim Fedorenko , Jakub Kicinski Subject: [PATCH 5.4 04/39] net/tls: missing received data after fast remote close Date: Sun, 6 Dec 2020 12:17:08 +0100 Message-Id: <20201206111554.881431827@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201206111554.677764505@linuxfoundation.org> References: <20201206111554.677764505@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vadim Fedorenko [ Upstream commit 20ffc7adf53a5fd3d19751fbff7895bcca66686e ] 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: fcf4793e278e ("tls: check RCV_SHUTDOWN in tls_wait_data") Signed-off-by: Vadim Fedorenko Link: https://lore.kernel.org/r/1605801588-12236-1-git-send-email-vfedorenko@novek.ru Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/tls/tls_sw.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/net/tls/tls_sw.c +++ b/net/tls/tls_sw.c @@ -1291,6 +1291,12 @@ static struct sk_buff *tls_wait_data(str 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;