Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp564490imu; Thu, 20 Dec 2018 01:26:50 -0800 (PST) X-Google-Smtp-Source: AFSGD/XPINdbBD+UqzHj0pxrCyqeBEgomnVuwtgfS4l6Fnm/tV3j6TopYJ/exyjb1+6vdPH5aA++ X-Received: by 2002:a62:c683:: with SMTP id x3mr23156617pfk.10.1545298010872; Thu, 20 Dec 2018 01:26:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545298010; cv=none; d=google.com; s=arc-20160816; b=O+V73abfmGr0KL0PpqhhFwU9bBXGqSRoJsuDeC5QewzEpJJ4RmhFdIoEhRpYWkNMd4 fMbsiPbT76r1pZYkITJ64SEtMpmNkK5hExZe2YDvx1cwF2frU5Jd/JlgWeN4puI/+Adt Tlan01ELmKxJUvR6u1tB01zdNOqfSSunOuPTFs2p6ENyRELbtuQCq0M/L1TapI1gZzq4 I7JTwAJTv4WbLOVqE6sLf4zM9T1Vg3fPoEyGY17G+MhrxmdhbcLju6d1cMGoqNY8GZ2q oJ+Qy+8uhv8GuczN1ASuO5bsy/mLfyhzCcyFoXVljWe9nv/Wz/WdlRhU4WUyVW9ACGCl yobA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=j7AGq3FeUYwb7zWzu3tvcssQvLO1dGtoic8+OaLoqIg=; b=ePgC0y3YMid4LpFO+L81vbtvhPHz138UglknAaE4Nk78hhAYIUecxv7qCz7RBKB5wy IdvFnj3zSumhaKLQs3Z/Bpggh7BxbzK8LNcOIcq+LRLIAk3moTEifq2Vo5J5j0xiFqfr psEoqg9wq1qvowRULyVcuXuH4OSNLpKz5dy7UN3M7huL8HO7XQbQlGEjOnLUskNDKUix rpyhzwShQqe10Y++mNgdCP2vIgYO63MvXvKmotrSm3m6T9bzqpKhYZJWTRq1YooErM/w KqE2WwtgHMpm5E0qdNSWude7jzlb0X11WWUN+pPnayArOwRQYPP38ENgiT3Ymkd4zdxU XnVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="d5z/4snz"; 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 d34si15625640pla.80.2018.12.20.01.26.35; Thu, 20 Dec 2018 01:26:50 -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=@kernel.org header.s=default header.b="d5z/4snz"; 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 S1731772AbeLTJYL (ORCPT + 99 others); Thu, 20 Dec 2018 04:24:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:60538 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730167AbeLTJYI (ORCPT ); Thu, 20 Dec 2018 04:24:08 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 75A8B217D7; Thu, 20 Dec 2018 09:24:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1545297847; bh=cqiNFxuf1799ohMg7WhQQIjFVxM1Ktg2jgqP18gOtdY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d5z/4snzEJL1fJ7JUWz5gQQGRHsyEV3xOClQOaAc1T47M9eWZipgcmhlYhbdP+jJ+ Bkkto/HK+DBw3YBDtTgLneZfVZk0nKqFIgv3+gKr0ewCNqNfmbK3fs7X5O4haDA/mX qxl/0zMYTGQpa5s1COPNGP1Lx3fCVJw1067G76+U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Trond Myklebust , Sasha Levin Subject: [PATCH 4.9 39/61] SUNRPC: Fix a potential race in xprt_connect() Date: Thu, 20 Dec 2018 10:18:39 +0100 Message-Id: <20181220085845.342207898@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20181220085843.743900603@linuxfoundation.org> References: <20181220085843.743900603@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. ------------------ [ Upstream commit 0a9a4304f3614e25d9de9b63502ca633c01c0d70 ] If an asynchronous connection attempt completes while another task is in xprt_connect(), then the call to rpc_sleep_on() could end up racing with the call to xprt_wake_pending_tasks(). So add a second test of the connection state after we've put the task to sleep and set the XPRT_CONNECTING flag, when we know that there can be no asynchronous connection attempts still in progress. Fixes: 0b9e79431377d ("SUNRPC: Move the test for XPRT_CONNECTING into...") Signed-off-by: Trond Myklebust Signed-off-by: Sasha Levin --- net/sunrpc/xprt.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/net/sunrpc/xprt.c b/net/sunrpc/xprt.c index 685e6d225414..1a8df242d26a 100644 --- a/net/sunrpc/xprt.c +++ b/net/sunrpc/xprt.c @@ -778,8 +778,15 @@ void xprt_connect(struct rpc_task *task) return; if (xprt_test_and_set_connecting(xprt)) return; - xprt->stat.connect_start = jiffies; - xprt->ops->connect(xprt, task); + /* Race breaker */ + if (!xprt_connected(xprt)) { + xprt->stat.connect_start = jiffies; + xprt->ops->connect(xprt, task); + } else { + xprt_clear_connecting(xprt); + task->tk_status = 0; + rpc_wake_up_queued_task(&xprt->pending, task); + } } xprt_release_write(xprt, task); } -- 2.19.1