Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1677048pxu; Sun, 6 Dec 2020 03:44:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJyALcLhjCLHdnKVj6QIdOnZY9DW91WrPrkdtxgL7taOYzGYjlnrv554nZRKD8rlkUwpFVe4 X-Received: by 2002:a17:907:6e9:: with SMTP id yh9mr14764678ejb.131.1607255042416; Sun, 06 Dec 2020 03:44:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607255042; cv=none; d=google.com; s=arc-20160816; b=NkSV19jrnVL+GoNRV+1OD/XSKvf9ljWhgzNWrUzME099ggTF8kIOcecQThYbGTjZga 1eVS8AG6ttPdxfHMIz9AVAYvuAaemgoitCHL0zyIusqMx5gtdotektmpslo5QUwYrpED GXjhSc8sHS8WsiLWFCxDPBvoadFXKdkf8iV/U2h61StL5SuYY+poPZt5Wyi7eMqGQUG8 VurdcVRPNCB64uCKwkYsJEa8AkTdM7uf3ImA/q7P+aUk/KJ4Tg7VLMKZmJiyncheybWW CSlFmWK4uz4ljykpRYP0A29prescrDvTh4ss3FYe8klpOvK+Qrc6zjbqJ7VhGtqj0YgK lx1Q== 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=ijvqjwwf4dwixUoZp7TaZfomu4+fXIWDwFM8O7lZFq4=; b=kCOHmxUXD1OVSX/9wChoOPzM4wLhzwrhDgl/r+bQEZdos8VHtgzJrSNPzpCCsInSz4 cBoD/PKuRvIU6QnA2r6Uz68iEfA8J0lETNevFHkkFoZtnfjgTnhbpodMhY7DBaKY+i8J fcwaZ45c66FU84gsOOKWR5E0PAnKuPfBCp6RoQ4dupAQ9YjUiLM6DtyTbIXclHrI/A9l QQ6mc/MokXI0BNhVrXg8A7FdOMefRvpHhyuwRB+cY3Bt+vOO928FqgE2qmqlakGhtmwr bkPimHlOpkMfSkWlXl7tY2KxirjRXrOYlwZXrE5JwXJnRA24Hq6JMxf9VLC8GkltzgLs 4rMQ== 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 x17si7272825edq.475.2020.12.06.03.43.38; Sun, 06 Dec 2020 03:44:02 -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 S1728632AbgLFLlG (ORCPT + 99 others); Sun, 6 Dec 2020 06:41:06 -0500 Received: from mail.kernel.org ([198.145.29.99]:35896 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728076AbgLFLjk (ORCPT ); Sun, 6 Dec 2020 06:39:40 -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 4.19 03/32] net/tls: missing received data after fast remote close Date: Sun, 6 Dec 2020 12:17:03 +0100 Message-Id: <20201206111555.945020205@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201206111555.787862631@linuxfoundation.org> References: <20201206111555.787862631@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 @@ -630,6 +630,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;