Subject: Re: bug#18280: chmod: race condition

From: Tobias Stoeckmann <[email-masked]>
Date: Sun, 17 Aug 2014 13:46:13 +0200

On Sat, Aug 16, 2014 at 01:53:07PM -0700, Paul Eggert wrote:
> Tobias Stoeckmann wrote:
> >But I will recommend to look into
> >the use of fchmodat() instead, supplying the argument
> >AT_SYMLINK_NOFOLLOW.
> 
> Sorry, that won't work, and this is a known bug.  Please see:
> 
> http://bugs.gnu.org/11108

I investigated into this and installed the mentioned Fedora 17
distribution on a virtual machine.  The bug report is correct, chmod
fails to adjust the permission of files and directories with fchmodat
and AT_SYMLINK_NOFOLLOW in place.

Opening the manual page helped me though:

$ man fchmodat
[...]
AT_SYMLINK_NOFOLLOW
    If pathname is a symbolic link, do not dereference it: instead operate
    on the link itself. This flag is not currently implemented.
[...]
ENOTSUP
    flags specified AT_SYMLINK_NOFOLLOW, which is not supported.

So in short, Fedora 17 and even later versions simply don't support the
flag.  I'm not convinced that due to the lack of implementation of some
systems, everyone should suffer.

For me, it sounds like configure should run a functionality test, calling
fchmodat with AT_SYMLINK_NOFOLLOW and see if it fails and ENOTSUP is set
in errno.  In that case, don't call fchmodat or force 0 for flags,
otherwise use AT_SYMLINK_NOFOLLOW.

Tobias