From: "J. Bruce Fields" <bfields@redhat.com>
Date: Wed, 15 Jul 2020 13:31:36 -0400
Subject: [PATCH] nfsd4: fix NULL dereference in nfsd/clients display code
Git-commit: 9affa435817711861d774f5626c393c80f16d044
Patch-mainline: v5.8-rc7
References: git-fixes
We hold the cl_lock here, and that's enough to keep stateid's from going
away, but it's not enough to prevent the files they point to from going
away. Take fi_lock and a reference and check for NULL, as we do in
other code.
Reported-by: NeilBrown <neilb@suse.de>
Fixes: 78599c42ae3c ("nfsd4: add file to display list of client's opens")
Reviewed-by: NeilBrown <neilb@suse.de>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
Acked-by: NeilBrown <neilb@suse.com>
---
fs/nfsd/nfs4state.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -506,6 +506,17 @@ find_any_file(struct nfs4_file *f)
return ret;
}
+static struct file *find_deleg_file(struct nfs4_file *f)
+{
+ struct file *ret = NULL;
+
+ spin_lock(&f->fi_lock);
+ if (f->fi_deleg_file)
+ ret = get_file(f->fi_deleg_file);
+ spin_unlock(&f->fi_lock);
+ return ret;
+}
+
static atomic_long_t num_delegations;
unsigned long max_delegations;
@@ -2429,7 +2440,9 @@ static int nfs4_show_deleg(struct seq_fi
ds = delegstateid(st);
nf = st->sc_file;
- file = nf->fi_deleg_file;
+ file = find_deleg_file(nf);
+ if (!file)
+ return 0;
seq_printf(s, "- 0x%16phN: { type: deleg, ", &st->sc_stateid);
@@ -2441,6 +2454,7 @@ static int nfs4_show_deleg(struct seq_fi
nfs4_show_superblock(s, file);
seq_printf(s, " }\n");
+ fput(file);
return 0;
}