OSDN Git Service

Fix "faccessat ignores flags"
authorNick Kralevich <nnk@google.com>
Tue, 24 Feb 2015 21:40:43 +0000 (13:40 -0800)
committerNick Kralevich <nnk@google.com>
Tue, 24 Feb 2015 21:40:43 +0000 (13:40 -0800)
commit35778253a5ed71e87a608ca590b63729d9f88567
treed9e6112654bf2faa754abd9f28bc20c2ccccff57
parent2aef607b25c463baed5ae70d14212e24ea7bcf2b
Fix "faccessat ignores flags"

The kernel system call faccessat() does not have any flags arguments,
so passing flags to the kernel is currently ignored.

Fix the kernel system call so that no flags argument is passed in.

Ensure that we don't support AT_SYMLINK_NOFOLLOW. This non-POSIX
(http://pubs.opengroup.org/onlinepubs/9699919799/functions/access.html)
flag is a glibc extension, and has non-intuitive, error prone behavior.

For example, consider the following code:

  symlink("foo.is.dangling", "foo");
  if (faccessat(AT_FDCWD, "foo", R_OK, AT_SYMLINK_NOFOLLOW) == 0) {
    int fd = openat(AT_FDCWD, "foo", O_RDONLY | O_NOFOLLOW);
  }

The faccessat() call in glibc will return true, but an attempt to
open the dangling symlink will end up failing. GLIBC documents this
as returning the access mode of the symlink itself, which will
always return true for any symlink on Linux.

Some further discussions of this are at:

  * http://lists.landley.net/pipermail/toybox-landley.net/2014-September/003617.html
  * http://permalink.gmane.org/gmane.linux.lib.musl.general/6952

AT_SYMLINK_NOFOLLOW seems broken by design. I suspect this is why this
function was never added to POSIX. (note that "access" is pretty much
broken by design too, since it introduces a race condition between
check and action). We shouldn't support this until it's clearly
documented by POSIX or we can have it produce intuitive results.

Don't support AT_EACCESS for now. Implementing it is complicated, and
pretty much useless on Android, since we don't have setuid binaries.
See http://git.musl-libc.org/cgit/musl/commit/?id=0a05eace163cee9b08571d2ff9d90f5e82d9c228
for how an implementation might look.

Bug: 18867827
Change-Id: I25b86c5020f3152ffa3ac3047f6c4152908d0e04
libc/Android.mk
libc/SYSCALLS.TXT
libc/arch-arm/syscalls/___faccessat.S [moved from libc/arch-arm/syscalls/faccessat.S with 81% similarity]
libc/arch-arm64/syscalls/___faccessat.S [moved from libc/arch-arm64/syscalls/faccessat.S with 79% similarity]
libc/arch-mips/syscalls/___faccessat.S [moved from libc/arch-mips/syscalls/faccessat.S with 82% similarity]
libc/arch-mips64/syscalls/___faccessat.S [moved from libc/arch-mips64/syscalls/faccessat.S with 85% similarity]
libc/arch-x86/syscalls/___faccessat.S [moved from libc/arch-x86/syscalls/faccessat.S with 70% similarity]
libc/arch-x86_64/syscalls/___faccessat.S [moved from libc/arch-x86_64/syscalls/faccessat.S with 81% similarity]
libc/bionic/faccessat.cpp [new file with mode: 0644]
tests/sys_stat_test.cpp