fchownat ignores AT_SYMLINK_NOFOLLOW flag

Bug #59083 reported by Jim Meyering
10
Affects Status Importance Assigned to Milestone
glibc (Ubuntu)
Confirmed
Undecided
Unassigned
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

Revision history for this message
Paul Dufresne (paulduf) wrote :

Thank you for taking the time to report this bug and helping to make Ubuntu better. You reported this bug a while ago and there hasn't been any activity in it recently. We were wondering is this still an issue for you? Can you try with latest Ubuntu release? Thanks in advance.

Changed in glibc:
assignee: nobody → dufresnep
status: New → Incomplete
Revision history for this message
Paul Dufresne (paulduf) wrote :

No response...
Well, I will confirm anyway, as the bug description contains a nice test program.

Paul Dufresne (paulduf)
Changed in glibc:
assignee: dufresnep → nobody
status: Incomplete → Confirmed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.