From: Linus Torvalds <torvalds@linux-foundation.org>
To: Omar Sandoval <osandov@osandov.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>,
linux-fsdevel <linux-fsdevel@vger.kernel.org>,
Linux API <linux-api@vger.kernel.org>,
kernel-team <kernel-team@fb.com>, Xi Wang <xi@cs.washington.edu>,
Omar Sandoval <osandov@fb.com>
Subject: Re: [RFC PATCH v2 1/2] fs: add AT_REPLACE flag for linkat() which replaces the target
Date: Tue, 21 Mar 2017 09:30:30 -0700 [thread overview]
Message-ID: <CA+55aFxpzYqt3MYe8Yd7PVVQoPkVpae5diYYBJXh0zu4JCJrYA@mail.gmail.com> (raw)
In-Reply-To: <c823982d5b46ea888dc1fdf26c067a7aa0f3585f.1490103963.git.osandov@fb.com>
On Tue, Mar 21, 2017 at 7:51 AM, Omar Sandoval <osandov@osandov.com> wrote:
> */
> -int vfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_dentry, struct inode **delegated_inode)
> +int vfs_link(struct dentry *old_dentry, struct inode *dir,
> + struct dentry *new_dentry, struct inode **delegated_inode,
> + unsigned int flags)
> {
> struct inode *inode = old_dentry->d_inode;
> + struct inode *target = new_dentry->d_inode;
> unsigned max_links = dir->i_sb->s_max_links;
> int error;
>
> if (!inode)
> return -ENOENT;
>
> - error = may_create(dir, new_dentry);
> + if (target) {
> + if (flags & AT_REPLACE)
> + error = may_delete(dir, new_dentry, d_is_dir(old_dentry));
> + else
> + error = -EEXIST;
> + } else {
> + error = may_create(dir, new_dentry);
> + }
This looks bogus.
In particular, that "may_delete()" cannot be right. It should still
*also* have the right to create something in that directory.
But even if you replace it with checks for both deletion _and_
creation, it won't be right, since the test for d_is_negative() on the
target in may_delete() looks wrong for this situation.
Normally, you cannot delete a negative entry (think of what that would
do in a overlay situation), but it should still be ok to link a
positive entry on top of a negative one.
Also, I think the above is incorrect for yet another case: moving
somethign on top of a directory should be disallowed. We do later on
check that the *source* isn't a directory (since you can't link
directories), but I'm not seeing where you'd be checking that you
don't move over a directory either.
So I don't think this patch is acceptable as such. I also suspect that
it should be done in multiple phases.
Linus
next prev parent reply other threads:[~2017-03-21 16:30 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-21 14:51 [RFC PATCH v2 0/2] fs: add AT_REPLACE flag for linkat() Omar Sandoval
2017-03-21 14:51 ` [RFC PATCH v2 1/2] fs: add AT_REPLACE flag for linkat() which replaces the target Omar Sandoval
2017-03-21 16:30 ` Linus Torvalds [this message]
2017-03-21 18:44 ` Omar Sandoval
2017-03-21 19:02 ` Linus Torvalds
2017-03-21 20:37 ` Miklos Szeredi
2017-03-21 21:06 ` Linus Torvalds
2017-03-21 14:51 ` [RFC PATCH v2 2/2] Btrfs: add support for linkat() AT_REPLACE Omar Sandoval
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=CA+55aFxpzYqt3MYe8Yd7PVVQoPkVpae5diYYBJXh0zu4JCJrYA@mail.gmail.com \
--to=torvalds@linux-foundation.org \
--cc=kernel-team@fb.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=osandov@fb.com \
--cc=osandov@osandov.com \
--cc=viro@zeniv.linux.org.uk \
--cc=xi@cs.washington.edu \
/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).