9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Alexander Viro <viro@math.psu.edu>
To: 9fans@cse.psu.edu
Subject: Re: [9fans] correcting old failures, and NJ vs MA
Date: Thu, 11 Oct 2001 00:27:00 -0400	[thread overview]
Message-ID: <Pine.GSO.4.21.0110102333260.21168-100000@weyl.math.psu.edu> (raw)
In-Reply-To: <87het8uxcl.fsf@becket.becket.net>



On Wed, 10 Oct 2001, Thomas Bushnell, BSG wrote:

> That's an important point that I think got lost.  For example, someone
> asks "what about find?  won't it miss stuff if you move a directory?"
> And the answer is "yes, it will--and it will miss stuff whether you
> move things with a quick syscall or with a long tedious file-by-file
> copy-and-delete."  

I don't recall anybody complaining about the stuff find _misses_. It's
stuff that it finds in places where it shouldn't have looked that is
a problem.

Let me try again: full-blow rename() makes several userland programs
simpler at the cost of many userland programs becoming much more complex
or outright broken.  It's not just the kernel complexity that goes up -
that can be done, even though result will not be nice.  It's userland
that really pays a lot and that's much harder to handle.

Symlinks are actually a nice example of the same effect.  Resulting kernel
complexity is nothing compared to complexity added to userland to prevent
symlink attacks.  Notice that correct tree-walker must reimplement a large
chunk of VFS if it's ever going to be used in the area writable to attacker.
Every time when tar(1) does open() it has to do very ugly stuff.  Example:
tar in Solaris 2.6 and GNU tar earlier than 1.12 [1] do stat() followed by
open().  Then they proceed to write the metadata from stat and data read from
file into the archive.  Think what will happen if file gets replaced with
symlink to /var/spool/mail/boss between the stat() and open() during the system
backup.  Yes, missing fstat().  But even putting fstat() there doesn't solve
the problem - we have to deal with the fact that open() on some devices
may have nontrivial side effects.  O_NDELAY removes most of them, but not
all.

Worse yet, _anything_ that does unlink("foo/bar") is open to an attack -
all "when should I follow the symlinks" logics applies only to the last
component.  And there's nothing kernel could do about that.  As the result,
anything that may be used in hostile environment has to reimplement
namei(9), doing the series of open()/fstat()/fchdir() just to walk the
friggin' path.  And you'd better have a working O_NOFOLLOW or do lstat()
first; otherwise things will get very ugly.

I wouldn't describe reimplementing namei() in a lot of basic utilities
as making the life easier for userland. YMMV.

[1] BTW, it's not just GNU or Sun being sloppy - that would be business
as usual, sad as it is.  OpenBSD pax(1) is vulnerable to exactly that
attack - there is a window between stat() and open() that can be used
to replace the file you own with a symlink to a file you should be
unable to read.  And yes, it _is_ exploitable.  Attack would take a
while, but potential results of getting a look at the contents of
right mailbox may be more than worth attacker's time and efforts.



  parent reply	other threads:[~2001-10-11  4:27 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-10-09 17:43 anothy
2001-10-10  8:56 ` Thomas Bushnell, BSG
2001-10-10  9:16   ` Boyd Roberts
2001-10-11  4:27   ` Alexander Viro [this message]
2001-10-11  9:11     ` Thomas Bushnell, BSG
2001-10-09 21:44 forsyth
2001-10-09 21:51 bwc
2001-10-10 13:04 presotto
2001-10-11  9:10 ` Thomas Bushnell, BSG
2001-10-11 14:29   ` david presotto
2001-10-11 15:26     ` Boyd Roberts
2001-10-11 15:54       ` andrey mirtchovski
2001-10-11 11:39 forsyth

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=Pine.GSO.4.21.0110102333260.21168-100000@weyl.math.psu.edu \
    --to=viro@math.psu.edu \
    --cc=9fans@cse.psu.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).