Skip to content

Commit 9affa43

Browse files
author
J. Bruce Fields
committed
nfsd4: fix NULL dereference in nfsd/clients display code
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 <[email protected]> Fixes: 78599c4 ("nfsd4: add file to display list of client's opens") Reviewed-by: NeilBrown <[email protected]> Signed-off-by: J. Bruce Fields <[email protected]>
1 parent becd201 commit 9affa43

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

fs/nfsd/nfs4state.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,17 @@ find_any_file(struct nfs4_file *f)
507507
return ret;
508508
}
509509

510+
static struct nfsd_file *find_deleg_file(struct nfs4_file *f)
511+
{
512+
struct nfsd_file *ret = NULL;
513+
514+
spin_lock(&f->fi_lock);
515+
if (f->fi_deleg_file)
516+
ret = nfsd_file_get(f->fi_deleg_file);
517+
spin_unlock(&f->fi_lock);
518+
return ret;
519+
}
520+
510521
static atomic_long_t num_delegations;
511522
unsigned long max_delegations;
512523

@@ -2444,6 +2455,8 @@ static int nfs4_show_open(struct seq_file *s, struct nfs4_stid *st)
24442455
oo = ols->st_stateowner;
24452456
nf = st->sc_file;
24462457
file = find_any_file(nf);
2458+
if (!file)
2459+
return 0;
24472460

24482461
seq_printf(s, "- ");
24492462
nfs4_show_stateid(s, &st->sc_stateid);
@@ -2481,6 +2494,8 @@ static int nfs4_show_lock(struct seq_file *s, struct nfs4_stid *st)
24812494
oo = ols->st_stateowner;
24822495
nf = st->sc_file;
24832496
file = find_any_file(nf);
2497+
if (!file)
2498+
return 0;
24842499

24852500
seq_printf(s, "- ");
24862501
nfs4_show_stateid(s, &st->sc_stateid);
@@ -2513,7 +2528,9 @@ static int nfs4_show_deleg(struct seq_file *s, struct nfs4_stid *st)
25132528

25142529
ds = delegstateid(st);
25152530
nf = st->sc_file;
2516-
file = nf->fi_deleg_file;
2531+
file = find_deleg_file(nf);
2532+
if (!file)
2533+
return 0;
25172534

25182535
seq_printf(s, "- ");
25192536
nfs4_show_stateid(s, &st->sc_stateid);
@@ -2529,6 +2546,7 @@ static int nfs4_show_deleg(struct seq_file *s, struct nfs4_stid *st)
25292546
seq_printf(s, ", ");
25302547
nfs4_show_fname(s, file);
25312548
seq_printf(s, " }\n");
2549+
nfsd_file_put(file);
25322550

25332551
return 0;
25342552
}

0 commit comments

Comments
 (0)