Comment 1 for bug 59083

Revision history for this message
Jeff Bailey (jbailey) wrote :

Thanks, Jim. I'm pasting the body here so that I have it when I'm offline:

The fchownat function is supposed to operate on the named
symlink argument when given the AT_SYMLINK_NOFOLLOW option.
Unfortunately, with Ubuntu unstable (updated an hour or two ago)
it mistakenly dereferences a symlink and chowns the file it points
to instead. You can see that from the strace output below,
as well as from the tests that demonstrate the GID of the link
remains unchanged, yet the GID of the referent is changed.

On 2.6.17-6-686 #2 SMP, with libc6 version 2.4-1ubuntu9, one
of the coreutils-6.2-cvs "make check" tests fails.
Here's a pared-down test case:

----------------------------
$ cat demo
#!/bin/sh
# Create a file, then a symlink to it.
# Call fchownat on the symlink, with AT_SYMLINK_NOFOLLOW, and
# ensure that only the group of the symlink has changed.

rm -rf f sl; touch f; ln -s f sl
f_grp=`stat --format=%g f`

cat <<EOF > k.c
# define _GNU_SOURCE 1
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
int
main (int argc, char **argv)
{
  return (fchownat (AT_FDCWD, argv[1], -1, atoi(argv[2]), AT_SYMLINK_NOFOLLOW));
}
EOF
gcc -O k.c

# Determine an alternate group.
alt_grp=`id -G|sed 's/.* //'`
test `stat --format=%g sl` = $alt_grp \
  && echo "$0: cannot run test: it requires an alternate group"

strace -e chown32 ./a.out sl $alt_grp || echo fail
test `stat --format=%g sl` = $alt_grp \
  || echo buggy fchownat did not change group of symlink
test `stat --format=%g f` = $f_grp \
  || echo buggy fchownat did change group of symlink referent
----------------------------

Running the above:

    $ bash demo
    k.c: In function 'main':
    chown32("sl", -1, 112) = 0
    Process 32054 detached
    buggy fchownat did not change group of symlink
    buggy fchownat did change group of symlink referent