Received: by 10.223.185.116 with SMTP id b49csp1075960wrg; Sat, 3 Mar 2018 14:53:38 -0800 (PST) X-Google-Smtp-Source: AG47ELsGjY6y0WuVnh3CX3g3HGCBpLfZsHVk/QJ6XdXms+E83jmMljseb36Fs426RyagWwyZaLXq X-Received: by 10.98.163.67 with SMTP id s64mr10357666pfe.67.1520117618075; Sat, 03 Mar 2018 14:53:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520117618; cv=none; d=google.com; s=arc-20160816; b=zMaTxVV+3PoMdz9jQhupv9ZA1fX+68OEBBJYhYkYlzTvdaW7ZHI2+7dcOn3xs2SmzU lqDkF3y8NTTbSB9eQeoouJJtyeoBT1ZpBjUaWsAnQo8b704Uwgk7l5A0//GsJRtoGdR1 GkkYJEl9JV4I44XE1XWP8Z+aFcDcXwdg8GEft2AqBQyyglvLbgaHPycHlTRpNpvk3wbo ZYxzwNI1vTtY2Ft0o0xgi6EzRZFOLhCyXV6wr1lRqXpeG+jeWwC0sWO8j+tl1wt7RrSV Y2XYro+TtmO2UmUJnhvl6IxdYvLSFYiENUhYBVwPcIaLtq9qktwJI4wuXJglZWLbCBkt h3Ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=oxsPYLtjgQaWz6WlJDUFCald2kfER7NQc7YBl5BTljc=; b=sG7PSvzL2/4/ZxEIXByfdPIzIzn4rb/xyJqgY0s703HCFCfDbS7fgowvkKcUyVY2Oc jd4C5s0d7FmZI5QCkewJpek71oZb5/zKb8RxsH8IwNdBp34Tbb/6CkcQ3BXNUuoK959z 3/a/TzcikVo7jtc0aYbtt+EzkUoSqKq2ME+YIZv/3W0FGn/vKgPwRONY3QQdTQADjgS6 0oatPqFa+UN2LVYLMALPlTeYfpDpIIhXgZy0z249aa1iPAFs57j4gRHYdpiyJKa8+anZ PXkcRZS717zUEp2/tE/ND0wVH8ECGmN4OxsoG58wYVtep7lcm5Jbj9ygBHBPCusvSl/E 3DZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=ZaflzbqO; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w3si6093406pgb.258.2018.03.03.14.53.23; Sat, 03 Mar 2018 14:53:38 -0800 (PST) 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; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=ZaflzbqO; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935435AbeCCWw0 (ORCPT + 99 others); Sat, 3 Mar 2018 17:52:26 -0500 Received: from mail-by2nam01on0095.outbound.protection.outlook.com ([104.47.34.95]:48488 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S935328AbeCCWlJ (ORCPT ); Sat, 3 Mar 2018 17:41:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=oxsPYLtjgQaWz6WlJDUFCald2kfER7NQc7YBl5BTljc=; b=ZaflzbqOsrojweUwlBCt0wxK+rzVsd/rk3uNDYhn99k+iy77ZHrSJ2BW0bL4nfVyyNKVZhOOmCWB9W8p/G2RzIBX+8c9yL9qWxSHJg874V3tlVANOV0xWTOZcRzI4k4Vvzruaiz4U3eYmxcB44mfGybzy25PNQxhQUUqzHlkkJ4= Received: from MW2PR2101MB1034.namprd21.prod.outlook.com (52.132.149.10) by MW2PR2101MB0940.namprd21.prod.outlook.com (52.132.146.13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.567.5; Sat, 3 Mar 2018 22:41:05 +0000 Received: from MW2PR2101MB1034.namprd21.prod.outlook.com ([fe80::1d56:338f:e2b:cec0]) by MW2PR2101MB1034.namprd21.prod.outlook.com ([fe80::1d56:338f:e2b:cec0%3]) with mapi id 15.20.0567.006; Sat, 3 Mar 2018 22:41:05 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Gao Feng , "David S . Miller" , Sasha Levin Subject: [PATCH AUTOSEL for 3.18 20/63] tcp: sysctl: Fix a race to avoid unexpected 0 window from space Thread-Topic: [PATCH AUTOSEL for 3.18 20/63] tcp: sysctl: Fix a race to avoid unexpected 0 window from space Thread-Index: AQHTsz+i3XyVBFXhD0yxqb9fQ/A46Q== Date: Sat, 3 Mar 2018 22:33:21 +0000 Message-ID: <20180303223228.27323-20-alexander.levin@microsoft.com> References: <20180303223228.27323-1-alexander.levin@microsoft.com> In-Reply-To: <20180303223228.27323-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;MW2PR2101MB0940;7:Qd3MsE6vnqL6bvUUPmDwouuxevTnPPwqeeF10rCx8e4eLmf4KLjs/BP4vzhYuz/pqqUTYTaS8OhFPv8RHk7KOCq7yjoFAXV57YPOHFyB/mykpNa0ZF/T1af/5JGnKC5n4A8SmnXXfCC9Mzv9XLkqwlTI9XVI1W2EimSxWyu+dxzserP/LifC7+78suHQGYbwazJfgw/2CY7E7isa9h/6QiIP+rfw/3/qfKUX1Ec63U8FenkfZyDPJeJzmkODaAAo x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 39701eaf-c35b-41a0-e353-08d58157d9d0 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603307)(7193020);SRVR:MW2PR2101MB0940; x-ms-traffictypediagnostic: MW2PR2101MB0940: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040501)(2401047)(5005006)(8121501046)(93006095)(93001095)(3002001)(10201501046)(3231220)(944501244)(52105095)(6055026)(61426038)(61427038)(6041288)(20161123558120)(20161123564045)(20161123560045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:MW2PR2101MB0940;BCL:0;PCL:0;RULEID:;SRVR:MW2PR2101MB0940; x-forefront-prvs: 0600F93FE1 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(376002)(39380400002)(346002)(366004)(39860400002)(396003)(199004)(189003)(106356001)(68736007)(6486002)(25786009)(22452003)(6436002)(186003)(2906002)(81156014)(81166006)(10090500001)(66066001)(8676002)(36756003)(6512007)(2900100001)(316002)(97736004)(102836004)(53936002)(6506007)(3280700002)(26005)(4326008)(5250100002)(305945005)(2501003)(76176011)(2950100002)(86362001)(99286004)(3846002)(72206003)(14454004)(3660700001)(478600001)(1076002)(5660300001)(10290500003)(6666003)(6116002)(7736002)(86612001)(107886003)(110136005)(54906003)(105586002)(8936002)(575784001)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:MW2PR2101MB0940;H:MW2PR2101MB1034.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: hQbxiHsGQA1+acH6jqlxFKZ0jdJFSd5lUz49xDDUkxwlfz+FQE9hZQR7eDxTGwqfhECuaPyrN/V8IIDtRtjiBCWIIWtGl3EClD9h1LXLaI7hVsekSWaPLuVBS1Jf0h+2FvwPCt7EwHWxv/CccUVhFcywoz8J/5wPkJSn0ipC6gw= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 39701eaf-c35b-41a0-e353-08d58157d9d0 X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Mar 2018 22:33:21.2785 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2PR2101MB0940 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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<=3D0 (sysctl_tcp_adv_win_scale is negative now) 2.space>>(-sysctl_tcp_adv_win_scale) (sysctl_tcp_adv_win_scale is postive n= ow) 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 --- include/net/tcp.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index 2cd7003a8a19..15564a2cc28c 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -1099,9 +1099,11 @@ void tcp_select_initial_window(int __space, __u32 ms= s, __u32 *rcv_wnd, =20 static inline int tcp_win_from_space(int space) { - return sysctl_tcp_adv_win_scale<=3D0 ? - (space>>(-sysctl_tcp_adv_win_scale)) : - space - (space>>sysctl_tcp_adv_win_scale); + int tcp_adv_win_scale =3D sysctl_tcp_adv_win_scale; + + return tcp_adv_win_scale <=3D 0 ? + (space>>(-tcp_adv_win_scale)) : + space - (space>>tcp_adv_win_scale); } =20 /* Note: caller must be prepared to deal with negative returns */=20 --=20 2.14.1