Received: by 10.213.65.68 with SMTP id h4csp40233imn; Mon, 19 Mar 2018 18:52:15 -0700 (PDT) X-Google-Smtp-Source: AG47ELt/OskTkVh1nOGK9QXBYUPrTeCnthBNbbUoln6r8QWxUbfOiI10lR1bioc2pib3DZblbxYp X-Received: by 2002:a17:902:86:: with SMTP id a6-v6mr10088659pla.165.1521510735306; Mon, 19 Mar 2018 18:52:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521510735; cv=none; d=google.com; s=arc-20160816; b=TIFAI4L9Fo5mlH9h50fUHbCnopmYHlUXnjBUhp42WFq2TTlcz2n3psqU9+RIwXF8lp QGvRIwaH0J+bgS7so08eJu9B2uszoEah8gsS+I6/5A0tHAv2HPg5koIeyjzc1cbBHmGX sCUsZHUD5cEMbVGpeebjzMa5tXiThUHUkOz/F+3bdXmea3ETnWA/WEeJ0PARqJo8rsHa 6HCE2/+yDyG/e1xte8UhhP2ueTyqNfW+RFvWH5K9mPl9z3ZzUQnLtx0qzfE8g/X7LZQC iSKZEhUwHPI41i1IJKxZ/uDn9RqEikxI3KZ5tvqlRYlBHZURkPPEEhRsCSlE6yh5FE6+ u8VQ== 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=bRN7aDpzyLD1+MmCvmgLDWKsniBjzCq0d/Xm4QBm+Ug=; b=jzOLN9dVZAFLOKrbiJjDDGw6IwSBPAORGH6w/iD/y87ACBGDUjegUaKDivFwv5cmsH 1xgD5lB43DqlP+dW/OicIzVyAB0iRLqbd+rKocwM7S7IHx4Bcqz/RcRBFijRJUHysJDW pVDlun0KZkILIrgNy/rvlJjA4RhhtHPrhNk0N03qn7wx9PrphOtqS6Cc2qqAf8Ixy6wS L9TQpgYAlzH7wfKsIqvDpBAMRkJnE8epVUJ2GLL3PMXVrvPR/P0b0cZbZHZ9qSWfirqr fkYuJZjcjpoMNF2bVS1vNoQ2akfw2ewJAryQazXsXKZWUBPPdoG9fQ/eSJkOz9MyQ1XO tg7w== 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 z10si389138pgz.781.2018.03.19.18.52.01; Mon, 19 Mar 2018 18:52:15 -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 S970334AbeCSU2a (ORCPT + 99 others); Mon, 19 Mar 2018 16:28:30 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:43048 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030537AbeCSSNQ (ORCPT ); Mon, 19 Mar 2018 14:13:16 -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 9C18811D6; Mon, 19 Mar 2018 18:13:15 +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.4 033/134] tcp: sysctl: Fix a race to avoid unexpected 0 window from space Date: Mon, 19 Mar 2018 19:05:16 +0100 Message-Id: <20180319171854.104088447@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319171849.024066323@linuxfoundation.org> References: <20180319171849.024066323@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.4-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 @@ -1199,9 +1199,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 */