]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.19.33/nfs-fix-mount-umount-race-in-nlmclnt.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.19.33 / nfs-fix-mount-umount-race-in-nlmclnt.patch
CommitLineData
9329f6f7
GKH
1From 4a9be28c45bf02fa0436808bb6c0baeba30e120e Mon Sep 17 00:00:00 2001
2From: NeilBrown <neilb@suse.com>
3Date: Tue, 19 Mar 2019 11:33:24 +1100
4Subject: NFS: fix mount/umount race in nlmclnt.
5
6From: NeilBrown <neilb@suse.com>
7
8commit 4a9be28c45bf02fa0436808bb6c0baeba30e120e upstream.
9
10If the last NFSv3 unmount from a given host races with a mount from the
11same host, we can destroy an nlm_host that is still in use.
12
13Specifically nlmclnt_lookup_host() can increment h_count on
14an nlm_host that nlmclnt_release_host() has just successfully called
15refcount_dec_and_test() on.
16Once nlmclnt_lookup_host() drops the mutex, nlm_destroy_host_lock()
17will be called to destroy the nlmclnt which is now in use again.
18
19The cause of the problem is that the dec_and_test happens outside the
20locked region. This is easily fixed by using
21refcount_dec_and_mutex_lock().
22
23Fixes: 8ea6ecc8b075 ("lockd: Create client-side nlm_host cache")
24Cc: stable@vger.kernel.org (v2.6.38+)
25Signed-off-by: NeilBrown <neilb@suse.com>
26Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
27Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
28
29---
30 fs/lockd/host.c | 3 +--
31 1 file changed, 1 insertion(+), 2 deletions(-)
32
33--- a/fs/lockd/host.c
34+++ b/fs/lockd/host.c
35@@ -290,12 +290,11 @@ void nlmclnt_release_host(struct nlm_hos
36
37 WARN_ON_ONCE(host->h_server);
38
39- if (refcount_dec_and_test(&host->h_count)) {
40+ if (refcount_dec_and_mutex_lock(&host->h_count, &nlm_host_mutex)) {
41 WARN_ON_ONCE(!list_empty(&host->h_lockowners));
42 WARN_ON_ONCE(!list_empty(&host->h_granted));
43 WARN_ON_ONCE(!list_empty(&host->h_reclaim));
44
45- mutex_lock(&nlm_host_mutex);
46 nlm_destroy_host_locked(host);
47 mutex_unlock(&nlm_host_mutex);
48 }