linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Herrmann <dh.herrmann@gmail.com>
To: Pavel Machek <pavel@ucw.cz>
Cc: Andy Lutomirski <luto@amacapital.net>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	linux-fsdevel <linux-fsdevel@vger.kernel.org>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	"Theodore Ts'o" <tytso@mit.edu>
Subject: Re: [RFC 2/2] fs,proc: Respect FMODE_WRITE when opening /proc/pid/fd/N
Date: Tue, 22 Apr 2014 23:31:11 +0200	[thread overview]
Message-ID: <CANq1E4R4PSuDD599n=0Xff+rfH01CTRtzLSkFDWSdnXMggVKRA@mail.gmail.com> (raw)
In-Reply-To: <20140422185802.GA31201@amd.pavel.ucw.cz>

Hi

On Tue, Apr 22, 2014 at 8:58 PM, Pavel Machek <pavel@ucw.cz> wrote:
> I don't think openat helps you. This is what we are talking about, it
> is easy to reproduce. Can you reproduce it without /proc mounted?
>
> I think that chmod 700 . should stop you. Openat seems no worse than
> just placing cwd there...

Example1:
$ mkdir -p subdir/next
$ chmod 000 subdir
$ touch subdir/next/test
=> EACCES
$ cd subdir
=> EACCES

Example2:
$ mkdir -p subdir/next
$ cd subdir/next
$ chmod 000 ..
$ touch test
=> SUCCESS

This is the exact same situation. The filesystem tree is exactly the
same in both situations, but in the first example CWD is outside of
"subdir", in the second example CWD is inside of "subdir". Thus, they
can create files in that directory, even though they have no access to
_any_ absolute path to that directory.

This is the exact same race that you describe via /proc/self/fd/. But
instead of keeping a ref to the dir via CWD, in your example you keep
the ref via a FD in that exact same directory and access it via /proc.

(Hint: instead of using CWD, you can also keep an FD via open(O_PATH)
and pass it to openat())

Thanks
David

  reply	other threads:[~2014-04-22 21:31 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-21 16:22 [RFC 0/2] Fix permission checks on open("/proc/self/fd/N", O_RDWR) Andy Lutomirski
2014-04-21 16:22 ` [RFC 1/2] fs,proc: Pass nameidata to proc_get_link implementations Andy Lutomirski
2014-04-21 16:29   ` Al Viro
2014-04-21 16:22 ` [RFC 2/2] fs,proc: Respect FMODE_WRITE when opening /proc/pid/fd/N Andy Lutomirski
2014-04-21 16:30   ` Al Viro
2014-04-21 17:00     ` Andy Lutomirski
2014-04-21 17:04       ` Andy Lutomirski
2014-04-21 17:48         ` Andy Lutomirski
2014-04-22 12:44   ` David Herrmann
2014-04-22 13:49     ` Andy Lutomirski
2014-04-22 14:17       ` David Herrmann
2014-04-22 14:33         ` Andy Lutomirski
2014-04-22 15:03           ` David Herrmann
2014-04-22 15:20             ` Andy Lutomirski
2014-04-22 14:40         ` Pavel Machek
2014-04-22 14:31     ` Pavel Machek
2014-04-22 15:19       ` David Herrmann
2014-04-22 15:24         ` Andy Lutomirski
2014-04-22 16:44           ` David Herrmann
2014-04-22 17:05             ` Andy Lutomirski
2014-04-22 18:58         ` Pavel Machek
2014-04-22 21:31           ` David Herrmann [this message]
2014-04-22 21:34             ` Andy Lutomirski
2014-04-22 22:12             ` Pavel Machek

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='CANq1E4R4PSuDD599n=0Xff+rfH01CTRtzLSkFDWSdnXMggVKRA@mail.gmail.com' \
    --to=dh.herrmann@gmail.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=pavel@ucw.cz \
    --cc=tytso@mit.edu \
    --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).