Re: O_NOLINK for open()

H. Peter Anvin
2007-09-12T21:46:56Z

Brent Casavant wrote:
> On Wed, 12 Sep 2007, H. Peter Anvin wrote:
>
>> Brent Casavant wrote:
>
>>> http://marc.info/?l=linux-kernel&m=93032806224160&w=2
>> This link talks about file flags handling. I don't see the relevance to
>> this problem at all. However, this is a very long thread, so if there
>> is anything specific that you want to point to, then please elucidate.
>
> Oops, my mistake -- I pasted the wrong URL. I meant this thread, this
> post in particular:
>
> http://marc.info/?l=linux-kernel&m=88937224115435&w=2
>
> Still, O_NOLINK would seem to be a valuable addition, and greatly
> simplify secure temporary file creation.
>

Avoiding -- or at least detecting -- symlink racing with mkdir() is
relatively simple: run mkdir(), make sure you don't get EEXIST or
something like that, lstat() the resulting path -- it should be a
directory with all the right modes and ownerships.

I believe -- but I'm not certain -- that mkdtemp() in glibc will do all
this for you. If not, I would consider that a glibc bug.

-hpa