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