From: Luis Henriques <lhenriques@suse.com>
To: Jeff Layton <jlayton@kernel.org>
Cc: Amir Goldstein <amir73il@gmail.com>,
Ilya Dryomov <idryomov@gmail.com>,
"Darrick J . Wong" <darrick.wong@oracle.com>,
Dave Chinner <david@fromorbit.com>,
Christoph Hellwig <hch@lst.de>,
linux-xfs@vger.kernel.org, Al Viro <viro@zeniv.linux.org.uk>,
linux-fsdevel@vger.kernel.org, ceph-devel@vger.kernel.org
Subject: Re: [PATCH] ceph: copy_file_range needs to strip setuid bits and update timestamps
Date: Fri, 14 Jun 2019 09:52:21 +0100 [thread overview]
Message-ID: <87v9x87dmi.fsf@suse.com> (raw)
In-Reply-To: <38f6f71f6be0b5baaea75417aa4bcf072e625567.camel@kernel.org> (Jeff Layton's message of "Thu, 13 Jun 2019 13:48:42 -0400")
Jeff Layton <jlayton@kernel.org> writes:
> On Thu, 2019-06-13 at 16:50 +0100, Luis Henriques wrote:
>> Jeff Layton <jlayton@kernel.org> writes:
>>
>> > On Mon, 2019-06-10 at 20:40 +0300, Amir Goldstein wrote:
>> > > Because ceph doesn't hold destination inode lock throughout the copy,
>> > > strip setuid bits before and after copy.
>> > >
>> > > The destination inode mtime is updated before and after the copy and the
>> > > source inode atime is updated after the copy, similar to the filesystem
>> > > ->read_iter() implementation.
>> > >
>> > > Signed-off-by: Amir Goldstein <amir73il@gmail.com>
>> > > ---
>> > >
>> > > Hi Ilya,
>> > >
>> > > Please consider applying this patch to ceph branch after merging
>> > > Darrick's copy-file-range-fixes branch from:
>> > > git://git.kernel.org/pub/scm/fs/xfs/xfs-linux.git
>> > >
>> > > The series (including this patch) was tested on ceph by
>> > > Luis Henriques using new copy_range xfstests.
>> > >
>> > > AFAIK, only fallback from ceph to generic_copy_file_range()
>> > > implementation was tested and not the actual ceph clustered
>> > > copy_file_range.
>> > >
>> > > Thanks,
>> > > Amir.
>> > >
>> > > fs/ceph/file.c | 17 +++++++++++++++++
>> > > 1 file changed, 17 insertions(+)
>> > >
>> > > diff --git a/fs/ceph/file.c b/fs/ceph/file.c
>> > > index c5517ffeb11c..b04c97c7d393 100644
>> > > --- a/fs/ceph/file.c
>> > > +++ b/fs/ceph/file.c
>> > > @@ -1949,6 +1949,15 @@ static ssize_t __ceph_copy_file_range(struct file *src_file, loff_t src_off,
>> > > goto out;
>> > > }
>> > >
>> > > + /* Should dst_inode lock be held throughout the copy operation? */
>> > > + inode_lock(dst_inode);
>> > > + ret = file_modified(dst_file);
>> > > + inode_unlock(dst_inode);
>> > > + if (ret < 0) {
>> > > + dout("failed to modify dst file before copy (%zd)\n", ret);
>> > > + goto out;
>> > > + }
>> > > +
>> >
>> > I don't see anything that guarantees that the mode of the destination
>> > file is up to date at this point. file_modified() just ends up checking
>> > the mode cached in the inode.
>> >
>> > I wonder if we ought to fix get_rd_wr_caps() to also acquire a reference
>> > to AUTH_SHARED caps on the destination inode, and then call
>> > file_modified() after we get those caps. That would also mean that we
>> > wouldn't need to do this a second time after the copy.
>> >
>> > The catch is that if we did need to issue a setattr, I'm not sure if
>> > we'd need to release those caps first.
>> >
>> > Luis, Zheng, thoughts?
>>
>> Hmm... I missed that. IIRC the FILE_WR caps allow to modify some
>> metadata (such as timestamps, and file size). I suppose it doesn't
>> allow to cache the mode, does it?
>
> No, W caps don't guarantee that the mode won't change. You need As or Ax
> caps for that.
>
>> If it does, fixing it would be a
>> matter of moving the code a bit further down. If it doesn't the
>> ceph_copy_file_range function already has this problem, as it calls
>> file_update_time. And I wonder if other code paths have this problem
>> too.
>>
>
> I think you mean file_remove_privs, but yes...the write codepath has a
> similar problem. file_remove_privs is called before acquiring any caps,
> so the same thing could happen there too.
>
> It'd be good to fix both places, but taking As cap references in the
> write codepath could have performance impact in some cases. OTOH, they
> don't change that much, so maybe that's OK.
>
>> Obviously, the chunk below will have the same problem.
>>
>
> Right. If however, we have this code take an As cap reference before
> doing the copy, then we can be sure that the mode can't change until we
> drop them. That way we wouldn't need the second call.
So, do you think the patch below would be enough? It's totally
untested, but I wanted to know if that would be acceptable before
running some tests on it.
Cheers,
--
Luis
diff --git a/fs/ceph/file.c b/fs/ceph/file.c
index c5517ffeb11c..f6b0683dd8dc 100644
--- a/fs/ceph/file.c
+++ b/fs/ceph/file.c
@@ -1949,6 +1949,21 @@ static ssize_t __ceph_copy_file_range(struct file *src_file, loff_t src_off,
goto out;
}
+ ret = ceph_do_getattr(dst_inode, CEPH_CAP_AUTH_SHARED, false);
+ if (ret < 0) {
+ dout("failed to get auth caps on dst file (%zd)\n", ret);
+ goto out;
+ }
+
+ /* Should dst_inode lock be held throughout the copy operation? */
+ inode_lock(dst_inode);
+ ret = file_modified(dst_file);
+ inode_unlock(dst_inode);
+ if (ret < 0) {
+ dout("failed to modify dst file before copy (%zd)\n", ret);
+ goto out;
+ }
+
/*
* We need FILE_WR caps for dst_ci and FILE_RD for src_ci as other
* clients may have dirty data in their caches. And OSDs know nothing
next prev parent reply other threads:[~2019-06-14 8:52 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-10 17:40 [PATCH] ceph: copy_file_range needs to strip setuid bits and update timestamps Amir Goldstein
2019-06-10 19:24 ` Ilya Dryomov
2019-06-11 8:39 ` Luis Henriques
2019-06-13 12:03 ` Jeff Layton
2019-06-13 15:50 ` Luis Henriques
2019-06-13 17:48 ` Jeff Layton
2019-06-14 8:52 ` Luis Henriques [this message]
2019-06-14 11:43 ` Jeff Layton
2019-06-14 17:38 ` Jeff Layton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87v9x87dmi.fsf@suse.com \
--to=lhenriques@suse.com \
--cc=amir73il@gmail.com \
--cc=ceph-devel@vger.kernel.org \
--cc=darrick.wong@oracle.com \
--cc=david@fromorbit.com \
--cc=hch@lst.de \
--cc=idryomov@gmail.com \
--cc=jlayton@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).