]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
nfsd: allow fh_want_write to be called twice
authorJ. Bruce Fields <bfields@redhat.com>
Fri, 12 Apr 2019 20:37:30 +0000 (16:37 -0400)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Wed, 14 Aug 2019 09:18:49 +0000 (11:18 +0200)
BugLink: https://bugs.launchpad.net/bugs/1838824
[ Upstream commit 0b8f62625dc309651d0efcb6a6247c933acd8b45 ]

A fuzzer recently triggered lockdep warnings about potential sb_writers
deadlocks caused by fh_want_write().

Looks like we aren't careful to pair each fh_want_write() with an
fh_drop_write().

It's not normally a problem since fh_put() will call fh_drop_write() for
us.  And was OK for NFSv3 where we'd do one operation that might call
fh_want_write(), and then put the filehandle.

But an NFSv4 protocol fuzzer can do weird things like call unlink twice
in a compound, and then we get into trouble.

I'm a little worried about this approach of just leaving everything to
fh_put().  But I think there are probably a lot of
fh_want_write()/fh_drop_write() imbalances so for now I think we need it
to be more forgiving.

Signed-off-by: J. Bruce Fields <bfields@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
fs/nfsd/vfs.h

index be6d8e00453f7e598a699f7c6401be37dc1a7867..85f544007311d5bf687b5e9be7c0cb6928f598e3 100644 (file)
@@ -117,8 +117,11 @@ void               nfsd_put_raparams(struct file *file, struct raparms *ra);
 
 static inline int fh_want_write(struct svc_fh *fh)
 {
-       int ret = mnt_want_write(fh->fh_export->ex_path.mnt);
+       int ret;
 
+       if (fh->fh_want_write)
+               return 0;
+       ret = mnt_want_write(fh->fh_export->ex_path.mnt);
        if (!ret)
                fh->fh_want_write = true;
        return ret;