Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp532099yba; Mon, 1 Apr 2019 11:12:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqxSrJuWAb+KX3xhAXSv9v59QDb4mQQS0RiJmr7tQ9qlFk8aohejnhi1AF2YEsYuKSX6YDrQ X-Received: by 2002:a62:6985:: with SMTP id e127mr29546539pfc.188.1554142320729; Mon, 01 Apr 2019 11:12:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554142320; cv=none; d=google.com; s=arc-20160816; b=W82Z0sy/b3cUVVgCzGA/ET6aX7es29xg0JyNuIO7+18F5xtqqD1GsgzxBXdup4CtI/ xiEmnK7ixTmJYr8i08BMzCFEpMNIIBnLoOhfwosnY6e0hamuD8GECBtDdfDd+zbE7WLJ ZJNkie8kphyVfwoQK2qqjin3pjSmKUJVN3CIVtl7sxQzC1Z3g9y5Cj6Dw2T5HuiEZE/M DDlo+g+GIa5y5VpO10zorHKYpHUGuty3VTZ4ywkRyPz0d/CWAdTcPxBqHIEc1/zzl1QP VwwXtOHb0IYDyqopZ9HSOEpJW4k3aFez9WzKJki1KoQa1Da2NW5nwVNE0YMc/C4oWvUI XVJA== 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=yk8aiJ0mPrYu6OaePbZiGQN1RyOtyXHWVmV8+ph0X60=; b=MzH9tygCPLiG4acA6yixbD73R4DPYYMfGSTMA5/Kcfp6zyBSmLzDuR9AZAq/n+OIIW QBSvjm+N4m9KJSpQw1fEIJMYWHmAPdP0YHqVj/JIvkeQqxGfyHbUiDM8Nk+QW2P2LANr BnjrX3eky92Rifht1vx2tsJnMVEyCJPtpNAG0qt+fHIPCs+9Ql2k3CeADMJIM/PFqjKI pfrQGhucxfOGakFwRw+scheOMzqnMJmbc8gBEB+I3z+4LDjdcaA9XcTsTUSfeedCgPLm 87WTprqVahw9GzYmqa1bp6wyUJrtfhuRQ+2EM/j++jG9EkcHsZJmjwQx14eXE3kkrHP1 CouQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JT3TDGA4; 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 p10si8989759plr.137.2019.04.01.11.11.43; Mon, 01 Apr 2019 11:12:00 -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; dkim=pass header.i=@kernel.org header.s=default header.b=JT3TDGA4; 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 S1729278AbfDASJ5 (ORCPT + 99 others); Mon, 1 Apr 2019 14:09:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:55264 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728737AbfDARIf (ORCPT ); Mon, 1 Apr 2019 13:08:35 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 B195821939; Mon, 1 Apr 2019 17:08:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554138514; bh=KcSvhUOi1ztF/T2HVgbaRdwp+C5E4bjdZRuEATjt2nY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JT3TDGA4m/6t4SS46jceCVtMtnJ3l1edidw7Vvj+b/pEbgF9S+5s5xVg1GyHQM8nD m8ZB451Lfm+jM6izijyUiO1rQWb9U/9ggUwYbnSNpn5K1j+39PUjm5rmf80FzmpUYo ECJ+HOIgSOoSnhd8R550OIkAavwRQtMaHc4Xxx1A= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, NeilBrown , Trond Myklebust Subject: [PATCH 5.0 051/146] NFS: fix mount/umount race in nlmclnt. Date: Mon, 1 Apr 2019 19:01:03 +0200 Message-Id: <20190401170052.932349769@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190401170048.449559024@linuxfoundation.org> References: <20190401170048.449559024@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 5.0-stable review patch. If anyone has any objections, please let me know. ------------------ From: NeilBrown commit 4a9be28c45bf02fa0436808bb6c0baeba30e120e upstream. If the last NFSv3 unmount from a given host races with a mount from the same host, we can destroy an nlm_host that is still in use. Specifically nlmclnt_lookup_host() can increment h_count on an nlm_host that nlmclnt_release_host() has just successfully called refcount_dec_and_test() on. Once nlmclnt_lookup_host() drops the mutex, nlm_destroy_host_lock() will be called to destroy the nlmclnt which is now in use again. The cause of the problem is that the dec_and_test happens outside the locked region. This is easily fixed by using refcount_dec_and_mutex_lock(). Fixes: 8ea6ecc8b075 ("lockd: Create client-side nlm_host cache") Cc: stable@vger.kernel.org (v2.6.38+) Signed-off-by: NeilBrown Signed-off-by: Trond Myklebust Signed-off-by: Greg Kroah-Hartman --- fs/lockd/host.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) --- a/fs/lockd/host.c +++ b/fs/lockd/host.c @@ -290,12 +290,11 @@ void nlmclnt_release_host(struct nlm_hos WARN_ON_ONCE(host->h_server); - if (refcount_dec_and_test(&host->h_count)) { + if (refcount_dec_and_mutex_lock(&host->h_count, &nlm_host_mutex)) { WARN_ON_ONCE(!list_empty(&host->h_lockowners)); WARN_ON_ONCE(!list_empty(&host->h_granted)); WARN_ON_ONCE(!list_empty(&host->h_reclaim)); - mutex_lock(&nlm_host_mutex); nlm_destroy_host_locked(host); mutex_unlock(&nlm_host_mutex); }