Received: by 10.223.185.116 with SMTP id b49csp1089402wrg; Sat, 3 Mar 2018 15:16:00 -0800 (PST) X-Google-Smtp-Source: AG47ELsmYmbklD/NhGL1PL/yVAUQ3iEdW3KNP+ymc1Xc3ctJBCeQCH5Si3UOzN6aMUvQWbdWTphO X-Received: by 2002:a17:902:506:: with SMTP id 6-v6mr9103890plf.365.1520118959981; Sat, 03 Mar 2018 15:15:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520118959; cv=none; d=google.com; s=arc-20160816; b=uYc4oCBXs2QLzCVU5pKYZS+5IwMtDMmaGZIjK/MuLBonmeNLkndrPrj0EtDi9Hjntq bGqtuYbGYw+CqlMpMq5AE/3oIaLxdAAn8HiH0IUarKhIhfvz/lH5RTUSew8SqHDiFh7S yJKnijGIlxFtaBo8972T4rLtZCz6J6lF7Ot68k8XBjrkl+qG/UO17j+VpORCHOWj4orZ /RWhyDybQO4+NXhQ8xvSbL9O5MMscm3VDtl2nVqQX18okg+1KD76DnRBNDTyQezoOyWr xVwEoFSL7BESHEI4s083qTxobCsddeTJFYobPXfSPgixrgf0zBRgfjEjm2FdupSLO60M fNKA== 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=REvJAzP49oTfbF478u3iJHcX3LNWO/Qbjq/EYSM12pg=; b=Rcsx4riyN+OvOc0ke811DJYGGqtcRH7MPS5l4InGqM9H3rr6vq3MpLFycKawOgzJpP qg0PqLw1WvVfryLzcOkHXPMT4/wHyR4P7gczQQLeR5o7qQUdsTL0owTvnneW4VaPZjnH xx0PmnnHyG4WPgDJxseRVctepNnLHvG2QrPNHKSXKTejwz6GilwzNLWTWK4ISFAx7SUW ku2UUhDVHmpduWD008nAKr/IAfEqAFAhJQT+RgyiUuDZpj90huNJMyS664qhNAbnsdGx 7Cik1w4uYIP8LvLfOg7hV0x0C6bPyiX5AfBHEa3akkR/7Wf0+El/jgZIH9QUzEPGTujN fL0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=jL16WkSG; 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 g72si7468581pfd.2.2018.03.03.15.15.45; Sat, 03 Mar 2018 15:15:59 -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=jL16WkSG; 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 S934981AbeCCWjB (ORCPT + 99 others); Sat, 3 Mar 2018 17:39:01 -0500 Received: from mail-cys01nam02on0109.outbound.protection.outlook.com ([104.47.37.109]:20871 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934395AbeCCWip (ORCPT ); Sat, 3 Mar 2018 17:38:45 -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=REvJAzP49oTfbF478u3iJHcX3LNWO/Qbjq/EYSM12pg=; b=jL16WkSGhGxuFNnekl0KpujjZQl5gi4644oyr919oh4+5rJ8HUH8YtGMb1xxIWxAaPakcBfBvEMR1PmWhj99iGOD2/ZT7a/lRskoHYMQ1BbglsMzf+1hzr0oescgWUm6f8lIMooeoiNgI84RiIEqaC+fdxv0Lv4B3NHtEoFbkQ0= Received: from MW2PR2101MB1034.namprd21.prod.outlook.com (52.132.149.10) by MW2PR2101MB1067.namprd21.prod.outlook.com (52.132.149.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.567.2; Sat, 3 Mar 2018 22:38:42 +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:38:42 +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 4.4 033/115] tcp: sysctl: Fix a race to avoid unexpected 0 window from space Thread-Topic: [PATCH AUTOSEL for 4.4 033/115] tcp: sysctl: Fix a race to avoid unexpected 0 window from space Thread-Index: AQHTsz9Sg+6vIWnvyk2UbPEvPhCLLQ== Date: Sat, 3 Mar 2018 22:31:07 +0000 Message-ID: <20180303223010.27106-33-alexander.levin@microsoft.com> References: <20180303223010.27106-1-alexander.levin@microsoft.com> In-Reply-To: <20180303223010.27106-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;MW2PR2101MB1067;7:Daea4I/85iME+/HVPJs8PiiYF2cVy40mMqdhdfDN+SMrRCeS4PHK1xGVN5+j+ki8MDn1vSWI8wf8IPHa+FjKpM7TSB59SSVtWkNdbG6TyCIZoVJ67pEhJB08Luokg2EYSg6qzkrwM/6qNmp48VTxaadaEjpM1F0jegKRoy7tZ94UoE4j841NvpbSxW31xXMfvdhiiW3OlIPi6XeRsgQV2lV9u9nsHqQoY6BOVOwIHHxQgU2krOYkXTwO1eOFnqFv x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: d010e4a5-8588-42ed-8985-08d581578462 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(5600026)(4604075)(3008032)(2017052603307)(7193020);SRVR:MW2PR2101MB1067; x-ms-traffictypediagnostic: MW2PR2101MB1067: 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)(3231220)(944501244)(52105095)(3002001)(10201501046)(93006095)(93001095)(6055026)(61426038)(61427038)(6041288)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(20161123560045)(20161123562045)(6072148)(201708071742011);SRVR:MW2PR2101MB1067;BCL:0;PCL:0;RULEID:;SRVR:MW2PR2101MB1067; x-forefront-prvs: 0600F93FE1 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(396003)(366004)(376002)(39860400002)(39380400002)(346002)(199004)(189003)(4326008)(5250100002)(86362001)(1076002)(2501003)(110136005)(6666003)(81156014)(2906002)(8936002)(305945005)(81166006)(2950100002)(7736002)(10290500003)(26005)(186003)(3660700001)(478600001)(72206003)(107886003)(8676002)(3280700002)(2900100001)(76176011)(6116002)(25786009)(3846002)(102836004)(575784001)(6506007)(5660300001)(97736004)(10090500001)(86612001)(106356001)(99286004)(6512007)(66066001)(316002)(53936002)(14454004)(105586002)(36756003)(6486002)(54906003)(6436002)(68736007)(22452003)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:MW2PR2101MB1067;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: 8d6vdu8+1lrqGudgROF+m7DuJ26P7yh+yyrLVY0+iCnv+qr15ToGsxID4OD6ijWzrBXqDgnH7Zh1JmqdrHMtjLv4FynBDp9LpZ+FAFuD7gzR3avdXKPWCo7b1OivaiZ/TKk0PrHa74xhbZaCwSBmqWnF95YmafxbIER9UiEzvio= 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: d010e4a5-8588-42ed-8985-08d581578462 X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Mar 2018 22:31:07.9946 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2PR2101MB1067 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 cecb0e0eff06..a3696b778757 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -1199,9 +1199,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 2.14.1