linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Miklos Szeredi <miklos@szeredi.hu>
To: NeilBrown <neilb@suse.de>
Cc: Al Viro <viro@zeniv.linux.org.uk>,
	Miklos Szeredi <mszeredi@redhat.com>,
	Xavier Roche <xavier.roche@algolia.com>,
	linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH RFC] VFS: lock source directory for link to avoid rename race.
Date: Fri, 16 Sep 2022 08:28:06 +0200	[thread overview]
Message-ID: <CAJfpeguwtADz8D1eUp4JVY-7-WKcf8giiiyvvdv4jccGtxcJKw@mail.gmail.com> (raw)
In-Reply-To: <166330881189.15759.13499931397891560275@noble.neil.brown.name>

On Fri, 16 Sept 2022 at 08:13, NeilBrown <neilb@suse.de> wrote:

> @@ -4554,44 +4590,83 @@ int do_linkat(int olddfd, struct filename *old, int newdfd,
>         if (flags & AT_SYMLINK_FOLLOW)
>                 how |= LOOKUP_FOLLOW;
>  retry:
> -       error = filename_lookup(olddfd, old, how, &old_path, NULL);
> +       err2 = 0;
> +       error = filename_parentat(olddfd, old, how, &old_path,
> +                                 &old_last, &old_type);
>         if (error)
>                 goto out_putnames;
> +       error = -EISDIR;
> +       if (old_type != LAST_NORM && !(flags & AT_EMPTY_PATH))
> +               goto out_putnames;
> +       error = filename_parentat(newdfd, new, (how & LOOKUP_REVAL), &new_path,
> +                                 &new_last, &new_type);
> +       if (error)
> +               goto out_putoldpath;
>
> -       new_dentry = filename_create(newdfd, new, &new_path,
> -                                       (how & LOOKUP_REVAL));
> -       error = PTR_ERR(new_dentry);
> -       if (IS_ERR(new_dentry))
> -               goto out_putpath;
> +       err2 = mnt_want_write(new_path.mnt);
>
>         error = -EXDEV;
>         if (old_path.mnt != new_path.mnt)
> -               goto out_dput;
> +               goto out_putnewpath;
> +       lock_link(new_path.dentry, old_path.dentry, flags);
> +
> +       new_dentry = __lookup_hash(&new_last, new_path.dentry, how & LOOKUP_REVAL);
> +       error = PTR_ERR(new_dentry);
> +       if (IS_ERR(new_dentry))
> +               goto out_unlock;
> +       error = -EEXIST;
> +       if (d_is_positive(new_dentry))
> +               goto out_dput_new;
> +       if (new_type != LAST_NORM)
> +               goto out_dput_new;
> +
> +       error = err2;
> +       if (error)
> +               goto out_dput_new;
> +
> +       if (flags & AT_EMPTY_PATH)
> +               old_dentry = dget(old_path.dentry);
> +       else
> +               old_dentry = __lookup_hash(&old_last, old_path.dentry, how);

This will break AT_SYMLINK_FOLLOW.

And yes, we can add all the lookup logic to do_linkat() at which point
it will about 10x more complex than it was.

Thanks,
Miklos

  reply	other threads:[~2022-09-16  6:28 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-21  8:20 [PATCH v2] vfs: fix link vs. rename race Miklos Szeredi
2022-02-21  8:56 ` Xavier Roche
2022-09-13  2:04 ` Al Viro
2022-09-13  4:29   ` Al Viro
2022-09-13  8:02     ` Amir Goldstein
2022-09-13 10:03       ` Miklos Szeredi
2022-09-13  4:41 ` NeilBrown
2022-09-13  5:20   ` Al Viro
2022-09-13  5:40     ` Al Viro
2022-09-14  0:14       ` NeilBrown
2022-09-14  1:30         ` Al Viro
2022-09-13 23:52     ` NeilBrown
2022-09-14  0:13       ` Al Viro
2022-09-16  6:13         ` [PATCH RFC] VFS: lock source directory for link to avoid " NeilBrown
2022-09-16  6:28           ` Miklos Szeredi [this message]
2022-09-16  6:45             ` NeilBrown
2022-09-16  6:49             ` Al Viro
2022-09-16 14:32           ` Amir Goldstein
2022-09-19  8:28             ` Christian Brauner
2022-09-19 22:56               ` NeilBrown
2022-09-23  3:02           ` [VFS] 3fb4ec6faa: ltp.linkat02.fail kernel test robot

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=CAJfpeguwtADz8D1eUp4JVY-7-WKcf8giiiyvvdv4jccGtxcJKw@mail.gmail.com \
    --to=miklos@szeredi.hu \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=mszeredi@redhat.com \
    --cc=neilb@suse.de \
    --cc=viro@zeniv.linux.org.uk \
    --cc=xavier.roche@algolia.com \
    /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).