]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
nfsd4: fix NULL dereference in nfsd/clients display code
authorJ. Bruce Fields <bfields@redhat.com>
Wed, 15 Jul 2020 17:31:36 +0000 (13:31 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 29 Jul 2020 08:18:34 +0000 (10:18 +0200)
[ Upstream commit 9affa435817711861d774f5626c393c80f16d044 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/nfsd/nfs4state.c

index 9af9b673f2923d54cb1cf7466bf55cd740df6569..68cf116607645603b5b7f9c53de440b8f630a034 100644 (file)
@@ -506,6 +506,17 @@ find_any_file(struct nfs4_file *f)
        return ret;
 }
 
+static struct nfsd_file *find_deleg_file(struct nfs4_file *f)
+{
+       struct nfsd_file *ret = NULL;
+
+       spin_lock(&f->fi_lock);
+       if (f->fi_deleg_file)
+               ret = nfsd_file_get(f->fi_deleg_file);
+       spin_unlock(&f->fi_lock);
+       return ret;
+}
+
 static atomic_long_t num_delegations;
 unsigned long max_delegations;
 
@@ -2378,6 +2389,8 @@ static int nfs4_show_open(struct seq_file *s, struct nfs4_stid *st)
        oo = ols->st_stateowner;
        nf = st->sc_file;
        file = find_any_file(nf);
+       if (!file)
+               return 0;
 
        seq_printf(s, "- 0x%16phN: { type: open, ", &st->sc_stateid);
 
@@ -2411,6 +2424,8 @@ static int nfs4_show_lock(struct seq_file *s, struct nfs4_stid *st)
        oo = ols->st_stateowner;
        nf = st->sc_file;
        file = find_any_file(nf);
+       if (!file)
+               return 0;
 
        seq_printf(s, "- 0x%16phN: { type: lock, ", &st->sc_stateid);
 
@@ -2439,7 +2454,9 @@ static int nfs4_show_deleg(struct seq_file *s, struct nfs4_stid *st)
 
        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);
 
@@ -2451,6 +2468,7 @@ static int nfs4_show_deleg(struct seq_file *s, struct nfs4_stid *st)
 
        nfs4_show_superblock(s, file);
        seq_printf(s, " }\n");
+       nfsd_file_put(file);
 
        return 0;
 }