diff mbox series

[1/2] nfsd: allow fh_want_write to be called twice

Message ID 1557969619-17157-2-git-send-email-bfields@redhat.com (mailing list archive)
State New, archived
Headers show
Series exposing knfsd state to userspace | expand

Commit Message

Bruce Fields May 16, 2019, 1:20 a.m. UTC
From: "J. Bruce Fields" <bfields@redhat.com>

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>
---
 fs/nfsd/vfs.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

J. Bruce Fields May 18, 2019, 8:04 p.m. UTC | #1
Ugh, sorry, ignore the two old patches that got sent with the new
series.

--b.

On Wed, May 15, 2019 at 09:20:06PM -0400, J. Bruce Fields wrote:
> From: "J. Bruce Fields" <bfields@redhat.com>
> 
> 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>
> ---
>  fs/nfsd/vfs.h | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/nfsd/vfs.h b/fs/nfsd/vfs.h
> index a7e107309f76..db351247892d 100644
> --- a/fs/nfsd/vfs.h
> +++ b/fs/nfsd/vfs.h
> @@ -120,8 +120,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;
> -- 
> 2.21.0
diff mbox series

Patch

diff --git a/fs/nfsd/vfs.h b/fs/nfsd/vfs.h
index a7e107309f76..db351247892d 100644
--- a/fs/nfsd/vfs.h
+++ b/fs/nfsd/vfs.h
@@ -120,8 +120,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;