diff options
| author | NeilBrown <neilb@suse.com> | 2019-03-19 11:33:24 +1100 |
|---|---|---|
| committer | Moyster <oysterized@gmail.com> | 2019-09-11 14:26:37 +0200 |
| commit | 674fda09638452b55d18a727deb33841bd3307d4 (patch) | |
| tree | 1991b3a725136b26d7cd789a0aa17947febc2d9a /fs | |
| parent | 8da16c8e6e19f84f6a60a661f1508876df6cc148 (diff) | |
NFS: fix mount/umount race in nlmclnt.
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")
Change-Id: I37405cb4379c96c2ca9780beaa916067e6aab7b3
Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
[bwh: Backported to 3.16: use atomic instead of refcount API]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Diffstat (limited to 'fs')
| -rw-r--r-- | fs/lockd/host.c | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/fs/lockd/host.c b/fs/lockd/host.c index b5f3c3ab0..857ac4f3e 100644 --- a/fs/lockd/host.c +++ b/fs/lockd/host.c @@ -288,12 +288,11 @@ void nlmclnt_release_host(struct nlm_host *host) WARN_ON_ONCE(host->h_server); - if (atomic_dec_and_test(&host->h_count)) { + if (atomic_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); } |
