* commit 'e93bc6bbe8ce180187e3914d0a7494cfe84f6255': Fix "faccessat ignores flags"
This commit is contained in:
		@@ -116,6 +116,7 @@ libc_bionic_ndk_src_files := \
 | 
				
			|||||||
    bionic/error.cpp \
 | 
					    bionic/error.cpp \
 | 
				
			||||||
    bionic/eventfd_read.cpp \
 | 
					    bionic/eventfd_read.cpp \
 | 
				
			||||||
    bionic/eventfd_write.cpp \
 | 
					    bionic/eventfd_write.cpp \
 | 
				
			||||||
 | 
					    bionic/faccessat.cpp \
 | 
				
			||||||
    bionic/fchmod.cpp \
 | 
					    bionic/fchmod.cpp \
 | 
				
			||||||
    bionic/fchmodat.cpp \
 | 
					    bionic/fchmodat.cpp \
 | 
				
			||||||
    bionic/ffs.cpp \
 | 
					    bionic/ffs.cpp \
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -130,7 +130,7 @@ int         fremovexattr(int, const char*) all
 | 
				
			|||||||
int __getdents64:getdents64(unsigned int, struct dirent*, unsigned int)   arm,arm64,mips,mips64,x86,x86_64
 | 
					int __getdents64:getdents64(unsigned int, struct dirent*, unsigned int)   arm,arm64,mips,mips64,x86,x86_64
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int __openat:openat(int, const char*, int, mode_t) all
 | 
					int __openat:openat(int, const char*, int, mode_t) all
 | 
				
			||||||
int faccessat(int, const char*, int, int)  all
 | 
					int ___faccessat:faccessat(int, const char*, int)  all
 | 
				
			||||||
int ___fchmodat:fchmodat(int, const char*, mode_t)  all
 | 
					int ___fchmodat:fchmodat(int, const char*, mode_t)  all
 | 
				
			||||||
int fchownat(int, const char*, uid_t, gid_t, int)  all
 | 
					int fchownat(int, const char*, uid_t, gid_t, int)  all
 | 
				
			||||||
int fstatat64|fstatat:fstatat64(int, const char*, struct stat*, int)   arm,mips,x86
 | 
					int fstatat64|fstatat:fstatat64(int, const char*, struct stat*, int)   arm,mips,x86
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,7 +2,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include <private/bionic_asm.h>
 | 
					#include <private/bionic_asm.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ENTRY(faccessat)
 | 
					ENTRY(___faccessat)
 | 
				
			||||||
    mov     ip, r7
 | 
					    mov     ip, r7
 | 
				
			||||||
    ldr     r7, =__NR_faccessat
 | 
					    ldr     r7, =__NR_faccessat
 | 
				
			||||||
    swi     #0
 | 
					    swi     #0
 | 
				
			||||||
@@ -11,4 +11,5 @@ ENTRY(faccessat)
 | 
				
			|||||||
    bxls    lr
 | 
					    bxls    lr
 | 
				
			||||||
    neg     r0, r0
 | 
					    neg     r0, r0
 | 
				
			||||||
    b       __set_errno_internal
 | 
					    b       __set_errno_internal
 | 
				
			||||||
END(faccessat)
 | 
					END(___faccessat)
 | 
				
			||||||
 | 
					.hidden ___faccessat
 | 
				
			||||||
@@ -2,7 +2,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include <private/bionic_asm.h>
 | 
					#include <private/bionic_asm.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ENTRY(faccessat)
 | 
					ENTRY(___faccessat)
 | 
				
			||||||
    mov     x8, __NR_faccessat
 | 
					    mov     x8, __NR_faccessat
 | 
				
			||||||
    svc     #0
 | 
					    svc     #0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -11,4 +11,5 @@ ENTRY(faccessat)
 | 
				
			|||||||
    b.hi    __set_errno_internal
 | 
					    b.hi    __set_errno_internal
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ret
 | 
					    ret
 | 
				
			||||||
END(faccessat)
 | 
					END(___faccessat)
 | 
				
			||||||
 | 
					.hidden ___faccessat
 | 
				
			||||||
@@ -2,7 +2,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include <private/bionic_asm.h>
 | 
					#include <private/bionic_asm.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ENTRY(faccessat)
 | 
					ENTRY(___faccessat)
 | 
				
			||||||
    .set noreorder
 | 
					    .set noreorder
 | 
				
			||||||
    .cpload t9
 | 
					    .cpload t9
 | 
				
			||||||
    li v0, __NR_faccessat
 | 
					    li v0, __NR_faccessat
 | 
				
			||||||
@@ -16,4 +16,5 @@ ENTRY(faccessat)
 | 
				
			|||||||
    j t9
 | 
					    j t9
 | 
				
			||||||
    nop
 | 
					    nop
 | 
				
			||||||
    .set reorder
 | 
					    .set reorder
 | 
				
			||||||
END(faccessat)
 | 
					END(___faccessat)
 | 
				
			||||||
 | 
					.hidden ___faccessat
 | 
				
			||||||
@@ -2,7 +2,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include <private/bionic_asm.h>
 | 
					#include <private/bionic_asm.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ENTRY(faccessat)
 | 
					ENTRY(___faccessat)
 | 
				
			||||||
    .set push
 | 
					    .set push
 | 
				
			||||||
    .set noreorder
 | 
					    .set noreorder
 | 
				
			||||||
    li v0, __NR_faccessat
 | 
					    li v0, __NR_faccessat
 | 
				
			||||||
@@ -22,4 +22,5 @@ ENTRY(faccessat)
 | 
				
			|||||||
    j t9
 | 
					    j t9
 | 
				
			||||||
    move ra, t0
 | 
					    move ra, t0
 | 
				
			||||||
    .set pop
 | 
					    .set pop
 | 
				
			||||||
END(faccessat)
 | 
					END(___faccessat)
 | 
				
			||||||
 | 
					.hidden ___faccessat
 | 
				
			||||||
@@ -2,7 +2,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include <private/bionic_asm.h>
 | 
					#include <private/bionic_asm.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ENTRY(faccessat)
 | 
					ENTRY(___faccessat)
 | 
				
			||||||
    pushl   %ebx
 | 
					    pushl   %ebx
 | 
				
			||||||
    .cfi_def_cfa_offset 8
 | 
					    .cfi_def_cfa_offset 8
 | 
				
			||||||
    .cfi_rel_offset ebx, 0
 | 
					    .cfi_rel_offset ebx, 0
 | 
				
			||||||
@@ -12,13 +12,9 @@ ENTRY(faccessat)
 | 
				
			|||||||
    pushl   %edx
 | 
					    pushl   %edx
 | 
				
			||||||
    .cfi_adjust_cfa_offset 4
 | 
					    .cfi_adjust_cfa_offset 4
 | 
				
			||||||
    .cfi_rel_offset edx, 0
 | 
					    .cfi_rel_offset edx, 0
 | 
				
			||||||
    pushl   %esi
 | 
					    mov     16(%esp), %ebx
 | 
				
			||||||
    .cfi_adjust_cfa_offset 4
 | 
					    mov     20(%esp), %ecx
 | 
				
			||||||
    .cfi_rel_offset esi, 0
 | 
					    mov     24(%esp), %edx
 | 
				
			||||||
    mov     20(%esp), %ebx
 | 
					 | 
				
			||||||
    mov     24(%esp), %ecx
 | 
					 | 
				
			||||||
    mov     28(%esp), %edx
 | 
					 | 
				
			||||||
    mov     32(%esp), %esi
 | 
					 | 
				
			||||||
    movl    $__NR_faccessat, %eax
 | 
					    movl    $__NR_faccessat, %eax
 | 
				
			||||||
    int     $0x80
 | 
					    int     $0x80
 | 
				
			||||||
    cmpl    $-MAX_ERRNO, %eax
 | 
					    cmpl    $-MAX_ERRNO, %eax
 | 
				
			||||||
@@ -28,9 +24,9 @@ ENTRY(faccessat)
 | 
				
			|||||||
    call    __set_errno_internal
 | 
					    call    __set_errno_internal
 | 
				
			||||||
    addl    $4, %esp
 | 
					    addl    $4, %esp
 | 
				
			||||||
1:
 | 
					1:
 | 
				
			||||||
    popl    %esi
 | 
					 | 
				
			||||||
    popl    %edx
 | 
					    popl    %edx
 | 
				
			||||||
    popl    %ecx
 | 
					    popl    %ecx
 | 
				
			||||||
    popl    %ebx
 | 
					    popl    %ebx
 | 
				
			||||||
    ret
 | 
					    ret
 | 
				
			||||||
END(faccessat)
 | 
					END(___faccessat)
 | 
				
			||||||
 | 
					.hidden ___faccessat
 | 
				
			||||||
@@ -2,8 +2,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include <private/bionic_asm.h>
 | 
					#include <private/bionic_asm.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ENTRY(faccessat)
 | 
					ENTRY(___faccessat)
 | 
				
			||||||
    movq    %rcx, %r10
 | 
					 | 
				
			||||||
    movl    $__NR_faccessat, %eax
 | 
					    movl    $__NR_faccessat, %eax
 | 
				
			||||||
    syscall
 | 
					    syscall
 | 
				
			||||||
    cmpq    $-MAX_ERRNO, %rax
 | 
					    cmpq    $-MAX_ERRNO, %rax
 | 
				
			||||||
@@ -13,4 +12,5 @@ ENTRY(faccessat)
 | 
				
			|||||||
    call    __set_errno_internal
 | 
					    call    __set_errno_internal
 | 
				
			||||||
1:
 | 
					1:
 | 
				
			||||||
    ret
 | 
					    ret
 | 
				
			||||||
END(faccessat)
 | 
					END(___faccessat)
 | 
				
			||||||
 | 
					.hidden ___faccessat
 | 
				
			||||||
							
								
								
									
										59
									
								
								libc/bionic/faccessat.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										59
									
								
								libc/bionic/faccessat.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,59 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (C) 2015 The Android Open Source Project
 | 
				
			||||||
 | 
					 * All rights reserved.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Redistribution and use in source and binary forms, with or without
 | 
				
			||||||
 | 
					 * modification, are permitted provided that the following conditions
 | 
				
			||||||
 | 
					 * are met:
 | 
				
			||||||
 | 
					 *  * Redistributions of source code must retain the above copyright
 | 
				
			||||||
 | 
					 *    notice, this list of conditions and the following disclaimer.
 | 
				
			||||||
 | 
					 *  * Redistributions in binary form must reproduce the above copyright
 | 
				
			||||||
 | 
					 *    notice, this list of conditions and the following disclaimer in
 | 
				
			||||||
 | 
					 *    the documentation and/or other materials provided with the
 | 
				
			||||||
 | 
					 *    distribution.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 | 
				
			||||||
 | 
					 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 | 
				
			||||||
 | 
					 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 | 
				
			||||||
 | 
					 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 | 
				
			||||||
 | 
					 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 | 
				
			||||||
 | 
					 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 | 
				
			||||||
 | 
					 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 | 
				
			||||||
 | 
					 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 | 
				
			||||||
 | 
					 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 | 
				
			||||||
 | 
					 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 | 
				
			||||||
 | 
					 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 | 
				
			||||||
 | 
					 * SUCH DAMAGE.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <fcntl.h>
 | 
				
			||||||
 | 
					#include <unistd.h>
 | 
				
			||||||
 | 
					#include <errno.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern "C" int ___faccessat(int, const char*, int);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int faccessat(int dirfd, const char* pathname, int mode, int flags) {
 | 
				
			||||||
 | 
					  // "The mode specifies the accessibility check(s) to be performed,
 | 
				
			||||||
 | 
					  // and is either the value F_OK, or a mask consisting of the
 | 
				
			||||||
 | 
					  // bitwise OR of one or more of R_OK, W_OK, and X_OK."
 | 
				
			||||||
 | 
					  if ((mode != F_OK) && ((mode & ~(R_OK | W_OK | X_OK)) != 0) &&
 | 
				
			||||||
 | 
					      ((mode & (R_OK | W_OK | X_OK)) == 0)) {
 | 
				
			||||||
 | 
					    errno = EINVAL;
 | 
				
			||||||
 | 
					    return -1;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (flags != 0) {
 | 
				
			||||||
 | 
					    // We deliberately don't support AT_SYMLINK_NOFOLLOW, a glibc
 | 
				
			||||||
 | 
					    // only feature which is error prone and dangerous.
 | 
				
			||||||
 | 
					    //
 | 
				
			||||||
 | 
					    // AT_EACCESS isn't supported either. Android doesn't have setuid
 | 
				
			||||||
 | 
					    // programs, and never runs code with euid!=uid. It could be
 | 
				
			||||||
 | 
					    // implemented in an expensive way, following the model at
 | 
				
			||||||
 | 
					    // https://gitlab.com/bminor/musl/commit/0a05eace163cee9b08571d2ff9d90f5e82d9c228
 | 
				
			||||||
 | 
					    // but not worth it.
 | 
				
			||||||
 | 
					    errno = EINVAL;
 | 
				
			||||||
 | 
					    return -1;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return ___faccessat(dirfd, pathname, mode);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -219,3 +219,43 @@ TEST(sys_stat, fchmodat_AT_SYMLINK_NOFOLLOW_with_dangling_symlink) {
 | 
				
			|||||||
  ASSERT_EQ(ENOTSUP, errno);
 | 
					  ASSERT_EQ(ENOTSUP, errno);
 | 
				
			||||||
  unlink(linkname);
 | 
					  unlink(linkname);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					TEST(sys_stat, faccessat_EINVAL) {
 | 
				
			||||||
 | 
					  ASSERT_EQ(-1, faccessat(AT_FDCWD, "/dev/null", F_OK, ~AT_SYMLINK_NOFOLLOW));
 | 
				
			||||||
 | 
					  ASSERT_EQ(EINVAL, errno);
 | 
				
			||||||
 | 
					#if defined(__BIONIC__)
 | 
				
			||||||
 | 
					  ASSERT_EQ(-1, faccessat(AT_FDCWD, "/dev/null", ~(R_OK | W_OK | X_OK), 0));
 | 
				
			||||||
 | 
					  ASSERT_EQ(EINVAL, errno);
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					  ASSERT_EQ(0, faccessat(AT_FDCWD, "/dev/null", ~(R_OK | W_OK | X_OK), AT_SYMLINK_NOFOLLOW));
 | 
				
			||||||
 | 
					  ASSERT_EQ(-1, faccessat(AT_FDCWD, "/dev/null", ~(R_OK | W_OK | X_OK), 0));
 | 
				
			||||||
 | 
					  ASSERT_EQ(EINVAL, errno);
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					TEST(sys_stat, faccessat_AT_SYMLINK_NOFOLLOW_EINVAL) {
 | 
				
			||||||
 | 
					#if defined(__BIONIC__)
 | 
				
			||||||
 | 
					  // Android doesn't support AT_SYMLINK_NOFOLLOW
 | 
				
			||||||
 | 
					  ASSERT_EQ(-1, faccessat(AT_FDCWD, "/dev/null", F_OK, AT_SYMLINK_NOFOLLOW));
 | 
				
			||||||
 | 
					  ASSERT_EQ(EINVAL, errno);
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					  ASSERT_EQ(0, faccessat(AT_FDCWD, "/dev/null", F_OK, AT_SYMLINK_NOFOLLOW));
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					TEST(sys_stat, faccessat_dev_null) {
 | 
				
			||||||
 | 
					  ASSERT_EQ(0, faccessat(AT_FDCWD, "/dev/null", F_OK, 0));
 | 
				
			||||||
 | 
					  ASSERT_EQ(0, faccessat(AT_FDCWD, "/dev/null", R_OK, 0));
 | 
				
			||||||
 | 
					  ASSERT_EQ(0, faccessat(AT_FDCWD, "/dev/null", W_OK, 0));
 | 
				
			||||||
 | 
					  ASSERT_EQ(0, faccessat(AT_FDCWD, "/dev/null", R_OK|W_OK, 0));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					TEST(sys_stat, faccessat_nonexistant) {
 | 
				
			||||||
 | 
					  ASSERT_EQ(-1, faccessat(AT_FDCWD, "/blah", F_OK, AT_SYMLINK_NOFOLLOW));
 | 
				
			||||||
 | 
					#if defined(__BIONIC__)
 | 
				
			||||||
 | 
					  // Android doesn't support AT_SYMLINK_NOFOLLOW
 | 
				
			||||||
 | 
					  ASSERT_EQ(EINVAL, errno);
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					  ASSERT_EQ(ENOENT, errno);
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user