diff mbox

Can ovl_drop_write() be called earlier in ovl_dentry_open()

Message ID 21902.1433166736@warthog.procyon.org.uk (mailing list archive)
State New, archived
Headers show

Commit Message

David Howells June 1, 2015, 1:52 p.m. UTC
In ovl_dentry_open(), ovl_drop_write() is called after vfs_open() - but is
this actually necessary?  Can't we just drop it post-copyup?  After all,
that's all we wanted the write lock for, right?

David
---
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Miklos Szeredi June 1, 2015, 2:22 p.m. UTC | #1
On Mon, Jun 1, 2015 at 3:52 PM, David Howells <dhowells@redhat.com> wrote:
> In ovl_dentry_open(), ovl_drop_write() is called after vfs_open() - but is
> this actually necessary?  Can't we just drop it post-copyup?  After all,
> that's all we wanted the write lock for, right?

Hmm,  that could result in a race where remount r/o of upper fs comes
in between copy-up and vfs_open() so copy-up succeeds but the actual
open fails.  It's harmless, though, and not  very likely.  So I guess
your patch is OK.

Thanks,
Miklos




>
> David
> ---
> --- a/fs/overlayfs/inode.c
> +++ b/fs/overlayfs/inode.c
> @@ -356,16 +356,14 @@ static int ovl_dentry_open(struct dentry *dentry, struct inode *inode,
>                         err = ovl_copy_up_last(dentry, NULL, true);
>                 else
>                         err = ovl_copy_up(dentry);
> +               ovl_drop_write(dentry);
>                 if (err)
> -                       goto out_drop_write;
> +                       goto out;
>
>                 ovl_path_upper(dentry, &realpath);
>         }
>
>         err = vfs_open(&realpath, d_backing_inode(realpath.dentry), file, cred);
> -out_drop_write:
> -       if (want_write)
> -               ovl_drop_write(dentry);
>  out:
>         return err;
>  }
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Howells June 1, 2015, 3:45 p.m. UTC | #2
Miklos Szeredi <miklos@szeredi.hu> wrote:

> > In ovl_dentry_open(), ovl_drop_write() is called after vfs_open() - but is
> > this actually necessary?  Can't we just drop it post-copyup?  After all,
> > that's all we wanted the write lock for, right?
> 
> Hmm,  that could result in a race where remount r/o of upper fs comes
> in between copy-up and vfs_open() so copy-up succeeds but the actual
> open fails.  It's harmless, though, and not  very likely.  So I guess
> your patch is OK.

That race is there anyway if there's no copy up, right?

David
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Miklos Szeredi June 1, 2015, 3:51 p.m. UTC | #3
On Mon, Jun 1, 2015 at 5:45 PM, David Howells <dhowells@redhat.com> wrote:
> Miklos Szeredi <miklos@szeredi.hu> wrote:
>
>> > In ovl_dentry_open(), ovl_drop_write() is called after vfs_open() - but is
>> > this actually necessary?  Can't we just drop it post-copyup?  After all,
>> > that's all we wanted the write lock for, right?
>>
>> Hmm,  that could result in a race where remount r/o of upper fs comes
>> in between copy-up and vfs_open() so copy-up succeeds but the actual
>> open fails.  It's harmless, though, and not  very likely.  So I guess
>> your patch is OK.
>
> That race is there anyway if there's no copy up, right?

No.  The race I'm talking about is that with your patch it's possible
that the file will be copied up, but open will return -EROFS.

Without your patch, that is not possible since holding write counter
for the mnt over both the copy-up and the open ensures that the
filesystem cannot become read-only in the middle.

So your patch changes behavior, but the new behavior is acceptable,
because there's no major change in semantics (it should only be
detectable by the increased disk usage in the rare case of the failed
open).

Thanks,
Miklos
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Howells June 1, 2015, 3:53 p.m. UTC | #4
Miklos Szeredi <miklos@szeredi.hu> wrote:

> >> Hmm,  that could result in a race where remount r/o of upper fs comes
> >> in between copy-up and vfs_open() so copy-up succeeds but the actual
> >> open fails.  It's harmless, though, and not  very likely.  So I guess
> >> your patch is OK.
> >
> > That race is there anyway if there's no copy up, right?
> 
> No.  The race I'm talking about is that with your patch it's possible
> that the file will be copied up, but open will return -EROFS.

Ah, I see what you're getting at.

> Without your patch, that is not possible since holding write counter
> for the mnt over both the copy-up and the open ensures that the
> filesystem cannot become read-only in the middle.
> 
> So your patch changes behavior, but the new behavior is acceptable,
> because there's no major change in semantics (it should only be
> detectable by the increased disk usage in the rare case of the failed
> open).

Okay.

David
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

--- a/fs/overlayfs/inode.c
+++ b/fs/overlayfs/inode.c
@@ -356,16 +356,14 @@  static int ovl_dentry_open(struct dentry *dentry, struct inode *inode,
 			err = ovl_copy_up_last(dentry, NULL, true);
 		else
 			err = ovl_copy_up(dentry);
+		ovl_drop_write(dentry);
 		if (err)
-			goto out_drop_write;
+			goto out;
 
 		ovl_path_upper(dentry, &realpath);
 	}
 
 	err = vfs_open(&realpath, d_backing_inode(realpath.dentry), file, cred);
-out_drop_write:
-	if (want_write)
-		ovl_drop_write(dentry);
 out:
 	return err;
 }