Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 16 Jan 2007 21:43:58 +1100 (EST)
From:      Bruce Evans <bde@zeta.org.au>
To:        Pawel Jakub Dawidek <pjd@FreeBSD.org>
Cc:        freebsd-security@FreeBSD.org, Dirk Engling <erdgeist@erdgeist.org>, Colin Percival <cperciva@FreeBSD.org>
Subject:   Re: HEADS UP: Re: FreeBSD Security Advisory FreeBSD-SA-07:01.jail
Message-ID:  <20070116211016.T6114@delplex.bde.org>
In-Reply-To: <20070116084243.GA1117@garage.freebsd.pl>
References:  <45A6DB76.40800@freebsd.org> <20070113112937.GI90718@garage.freebsd.pl> <45ABDC7C.6060407@erdgeist.org> <20070115210826.GA2839@garage.freebsd.pl> <45ABEEEE.4030609@erdgeist.org> <20070115220039.GB2839@garage.freebsd.pl> <45AC29EA.70009@erdgeist.org> <45AC2E9F.20901@freebsd.org> <45AC35A6.7090103@erdgeist.org> <20070116133259.N5056@delplex.bde.org> <20070116084243.GA1117@garage.freebsd.pl>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 16 Jan 2007, Pawel Jakub Dawidek wrote:

> On Tue, Jan 16, 2007 at 02:42:17PM +1100, Bruce Evans wrote:
>> install -S ...
>> ... can easily
>> be made both safer (actually no-clobber) and securer by opening the file
>> with O_EXCL and exiting if the file exists at the time of the open.
>> Perhaps cp -f should do the same.  (Both have paths where they do a
>> forced unlink() followed by an open().  This open() can easily use O_EXCL).
>
> Interesting. I was sure it won't work as you described, because the
> target file can be a symlink and open(2) by default follows symlinks.
> I thought that you just forget about O_NOFOLLOW flag, but it seems, that
> with O_EXCL open(2) doesn't follow symlinks so it will work.

I did forget it.  I just assumed that doing the same thing as mkstemp()
is as secure as possible, and it is.  Old versions of mkstemp() couldn't
use O_NOFOLLOW since O_NOFOLLOW has only existed since Y2K.  New
versions don't use it because it is unnecessary.  Exclusive access
isn't enough for security since if open() followed a dangling link it
would create a security hole with (O_CREAT | O_EXCL).  But there is
no problem since O_EXCL implies not following symlinks even if O_NOFOLLOW
is not supported.  This is documented in open(2) and better documented
in POSIX.

Bruce



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20070116211016.T6114>