All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nikolaus Rath <Nikolaus@rath.org>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: linux-fsdevel <linux-fsdevel@vger.kernel.org>,
	Al Viro <viro@zeniv.linux.org.uk>, Neil Brown <neil@brown.name>
Subject: Re: Behaviour of /proc/self/fd/NN
Date: Wed, 14 Nov 2018 12:10:20 +0000	[thread overview]
Message-ID: <87muqblv0z.fsf@thinkpad.rath.org> (raw)
In-Reply-To: <CAJfpegs6knndH=K85hHWABCd4XvKLV9X8DYJoFaqd56XArz6Ew@mail.gmail.com> (Miklos Szeredi's message of "Wed, 14 Nov 2018 12:57:20 +0100")

On Nov 14 2018, Miklos Szeredi <miklos@szeredi.hu> wrote:
> On Wed, Nov 14, 2018 at 11:45 AM, Nikolaus Rath <Nikolaus@rath.org> wrote:
>> Hi,
>>
>> If I understand Documentation/filesystems/path-lookup.md correctly, then
>> the "symlinks" in /proc/self/fd/NN are not true symlinks but just
>> presented as such to userspace. Does this mean that I can access (e.g.,
>> open(), setxattr(), or chmod()) these files without the possibility of
>> race conditions? I.e., there is no way for someone to rename the target
>> after the kernel has "looked up" the target but before the operation is
>> applied?
>
> Exactly.   The only limitation is that if the target is a symlink (fd
> opened with O_PATH) then the neither the symlink following, nor the
> non-following variants will do the right thing (see *xattr ops in
> passthrough_ll for example).

A workaround for that case would be to use readlink() and then act on
that without eg lgetxattr. That would introduce a race condition, but it
would work where that's not a concern, right?

That said, I also noticed the following code to handle utimens for symlinks:

res = utimensat(inode->fd, "", tv,
		AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW);
if (res == -1 && errno == EINVAL) {
	/* Sorry, no race free way to set times on symlink. */
	errno = EPERM;
}

So it looks as it at least utimensat() does the right thing under at
least some conditions...?


>> Secondly, under which conditions can I open the files in /proc? Does
>> this still work if the destination file has been unlinked?
>
> Yes.
>
>> Does it
>> always follow renames? What if I mounted something over the destination?
>
> It works in all those cases.

Did you mean it *always* works, or it works in the cases I listed but
there are other cases where it can fail?


Thanks!
-Nikolaus

-- 
GPG Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

             »Time flies like an arrow, fruit flies like a Banana.«

  reply	other threads:[~2018-11-14 22:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-14 10:45 Behaviour of /proc/self/fd/NN Nikolaus Rath
2018-11-14 11:57 ` Miklos Szeredi
2018-11-14 12:10   ` Nikolaus Rath [this message]
2018-11-14 12:20     ` Miklos Szeredi
2018-11-14 12:29       ` Nikolaus Rath
2018-11-14 12:33         ` Miklos Szeredi

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=87muqblv0z.fsf@thinkpad.rath.org \
    --to=nikolaus@rath.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=neil@brown.name \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.