Received: by 10.213.65.68 with SMTP id h4csp38057imn; Mon, 19 Mar 2018 18:47:12 -0700 (PDT) X-Google-Smtp-Source: AG47ELvTn/k4OXYtSy7cMe6PH+0Vrknrj+MOdwrgHAtPeF41n12FHeX2IOgfPH01iVRWhJknRbSK X-Received: by 2002:a17:902:47aa:: with SMTP id r39-v6mr3502458pld.59.1521510432655; Mon, 19 Mar 2018 18:47:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521510432; cv=none; d=google.com; s=arc-20160816; b=JChXbL77RouzbpEFMX4zsULP4FmCBsW/G1MzV8oP1N9KHKfCqcZy8WiVNQu1OP9CF/ 8WWOI0FhfwCGXOQ0Ix1aLJevEbo8bg6RSuxGIR5rAMmk20GRPtrV8FawXwIZUcXU8HyH CG58v9/xjajF82iWWxZgrJLxd6LAIyqc/Jw9CfI7+UH93N16XuaKrlE9vfzonFBRweuq VEDkU4fhd7KwhwW6ZUFU0dp2XgrSnlnZVazIwm7V1xHTY9cQecFtzKarUXLkl+kxwKG3 eS9nHza4OwIYEn/5S4vQFCDzXORQiZdCIbT1UM5tKgJ+cNqzU1sBCuLLBnx79p9SnS/v 8Dpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=AQzxnS9kCHI3++f5WE47+0ROa53f0L0ijgib99gUsoM=; b=RcI0KKOmBiXgm4vh+kKeN7ncJR4U6a9W1nJtmlIkobkApw3Vasn29FkZJcsIsTvfCC zHJWD+raJjvpIJ2Ix/qjZ6lFtxK1EtqFF6lVTci5GD+CojJrW9OkYQpuUBrIoDyzM3N7 ST+Dj0Py7Do0cnKjKnEocNDN/XUoreaSaaoenzvR3kEBJrcjkYlmsGVqoRpnU41ePMNU P4sIAmRUwg/EfArZcMvrR2nn7H8ZFrV89X0riyZCTNC4StAauG5akEiO6lEo0B76ndun eln43lEKss6tcwArDUnPkdygd9HMfRJELAfFhOesiEJBiikzsFP5TpQCCbvODxCtD9J5 v13w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 14si426124pfk.412.2018.03.19.18.46.59; Mon, 19 Mar 2018 18:47:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934373AbeCSTjA (ORCPT + 99 others); Mon, 19 Mar 2018 15:39:00 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:48330 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1031173AbeCSSV5 (ORCPT ); Mon, 19 Mar 2018 14:21:57 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 0519E1279; Mon, 19 Mar 2018 18:21:56 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Gao Feng , "David S. Miller" , Sasha Levin Subject: [PATCH 4.9 064/241] tcp: sysctl: Fix a race to avoid unexpected 0 window from space Date: Mon, 19 Mar 2018 19:05:29 +0100 Message-Id: <20180319180753.852247878@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319180751.172155436@linuxfoundation.org> References: <20180319180751.172155436@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Gao Feng [ Upstream commit c48367427a39ea0b85c7cf018fe4256627abfd9e ] Because sysctl_tcp_adv_win_scale could be changed any time, so there is one race in tcp_win_from_space. For example, 1.sysctl_tcp_adv_win_scale<=0 (sysctl_tcp_adv_win_scale is negative now) 2.space>>(-sysctl_tcp_adv_win_scale) (sysctl_tcp_adv_win_scale is postive now) As a result, tcp_win_from_space returns 0. It is unexpected. Certainly if the compiler put the sysctl_tcp_adv_win_scale into one register firstly, then use the register directly, it would be ok. But we could not depend on the compiler behavior. Signed-off-by: Gao Feng Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- include/net/tcp.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -1265,9 +1265,11 @@ void tcp_select_initial_window(int __spa static inline int tcp_win_from_space(int space) { - return sysctl_tcp_adv_win_scale<=0 ? - (space>>(-sysctl_tcp_adv_win_scale)) : - space - (space>>sysctl_tcp_adv_win_scale); + int tcp_adv_win_scale = sysctl_tcp_adv_win_scale; + + return tcp_adv_win_scale <= 0 ? + (space>>(-tcp_adv_win_scale)) : + space - (space>>tcp_adv_win_scale); } /* Note: caller must be prepared to deal with negative returns */