[compiler-rt] r322831 - Add new interceptors: access(2), faccessat(2)

Kamil Rytarowski via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 18 03:04:25 PST 2018


Author: kamil
Date: Thu Jan 18 03:04:25 2018
New Revision: 322831

URL: http://llvm.org/viewvc/llvm-project?rev=322831&view=rev
Log:
Add new interceptors: access(2), faccessat(2)

Summary:
access, faccessat - check access permissions of a file or pathname

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, vitalybuka

Reviewed By: vitalybuka

Subscribers: llvm-commits, kubamracek, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D42065

Added:
    compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/access.cc
    compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/faccessat.cc
Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc?rev=322831&r1=322830&r2=322831&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Thu Jan 18 03:04:25 2018
@@ -6540,6 +6540,32 @@ INTERCEPTOR(int, gid_from_group, const c
 #define INIT_GID_FROM_GROUP
 #endif
 
+#if SANITIZER_INTERCEPT_ACCESS
+INTERCEPTOR(int, access, const char *path, int mode) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, access, path, mode);
+  if (path)
+    COMMON_INTERCEPTOR_READ_RANGE(ctx, path, REAL(strlen)(path) + 1);
+  return REAL(access)(path, mode);
+}
+#define INIT_ACCESS COMMON_INTERCEPT_FUNCTION(access)
+#else
+#define INIT_ACCESS
+#endif
+
+#if SANITIZER_INTERCEPT_FACCESSAT
+INTERCEPTOR(int, faccessat, int fd, const char *path, int mode, int flags) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, faccessat, fd, path, mode, flags);
+  if (path)
+    COMMON_INTERCEPTOR_READ_RANGE(ctx, path, REAL(strlen)(path) + 1);
+  return REAL(faccessat)(fd, path, mode, flags);
+}
+#define INIT_FACCESSAT COMMON_INTERCEPT_FUNCTION(faccessat)
+#else
+#define INIT_FACCESSAT
+#endif
+
 static void InitializeCommonInterceptors() {
   static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1];
   interceptor_metadata_map = new((void *)&metadata_mem) MetadataHashMap();
@@ -6756,6 +6782,8 @@ static void InitializeCommonInterceptors
   INIT_UID_FROM_USER;
   INIT_GROUP_FROM_GID;
   INIT_GID_FROM_GROUP;
+  INIT_ACCESS;
+  INIT_FACCESSAT;
 
 #if SANITIZER_NETBSD
   COMMON_INTERCEPT_FUNCTION(__libc_mutex_lock);

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h?rev=322831&r1=322830&r2=322831&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Thu Jan 18 03:04:25 2018
@@ -437,5 +437,7 @@
 #define SANITIZER_INTERCEPT_UID_FROM_USER SI_NETBSD
 #define SANITIZER_INTERCEPT_GROUP_FROM_GID SI_NETBSD
 #define SANITIZER_INTERCEPT_GID_FROM_GROUP SI_NETBSD
+#define SANITIZER_INTERCEPT_ACCESS SI_NETBSD
+#define SANITIZER_INTERCEPT_FACCESSAT SI_NETBSD
 
 #endif  // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H

Added: compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/access.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/access.cc?rev=322831&view=auto
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/access.cc (added)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/access.cc Thu Jan 18 03:04:25 2018
@@ -0,0 +1,5 @@
+// RUN: %clangxx -O0 -g %s -o %t && %run %t
+
+#include <unistd.h>
+
+int main(void) { return access("/root", F_OK); }

Added: compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/faccessat.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/faccessat.cc?rev=322831&view=auto
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/faccessat.cc (added)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/faccessat.cc Thu Jan 18 03:04:25 2018
@@ -0,0 +1,6 @@
+// RUN: %clangxx -O0 -g %s -o %t && %run %t
+
+#include <fcntl.h>
+#include <unistd.h>
+
+int main(void) { return faccessat(AT_FDCWD, "/root", F_OK, 0); }




More information about the llvm-commits mailing list