1 From e9d71f0e30c4151c0b77d4750c9287a5ecd4ebfb Mon Sep 17 00:00:00 2001
2 From: "J. Bruce Fields" <bfields@redhat.com>
3 Date: Fri, 12 Apr 2019 16:37:30 -0400
4 Subject: nfsd: allow fh_want_write to be called twice
6 [ Upstream commit 0b8f62625dc309651d0efcb6a6247c933acd8b45 ]
8 A fuzzer recently triggered lockdep warnings about potential sb_writers
9 deadlocks caused by fh_want_write().
11 Looks like we aren't careful to pair each fh_want_write() with an
14 It's not normally a problem since fh_put() will call fh_drop_write() for
15 us. And was OK for NFSv3 where we'd do one operation that might call
16 fh_want_write(), and then put the filehandle.
18 But an NFSv4 protocol fuzzer can do weird things like call unlink twice
19 in a compound, and then we get into trouble.
21 I'm a little worried about this approach of just leaving everything to
22 fh_put(). But I think there are probably a lot of
23 fh_want_write()/fh_drop_write() imbalances so for now I think we need it
26 Signed-off-by: J. Bruce Fields <bfields@redhat.com>
27 Signed-off-by: Sasha Levin <sashal@kernel.org>
29 fs/nfsd/vfs.h | 5 ++++-
30 1 file changed, 4 insertions(+), 1 deletion(-)
32 diff --git a/fs/nfsd/vfs.h b/fs/nfsd/vfs.h
33 index fcfc48cbe136..128d6e216fd7 100644
36 @@ -109,8 +109,11 @@ void nfsd_put_raparams(struct file *file, struct raparms *ra);
38 static inline int fh_want_write(struct svc_fh *fh)
40 - int ret = mnt_want_write(fh->fh_export->ex_path.mnt);
43 + if (fh->fh_want_write)
45 + ret = mnt_want_write(fh->fh_export->ex_path.mnt);
47 fh->fh_want_write = true;