[compiler-rt] r201235 - [sanitizer] Fix wait4 interceptor on Android.

Evgeniy Stepanov eugeni.stepanov at gmail.com
Wed Feb 12 05:05:18 PST 2014


Author: eugenis
Date: Wed Feb 12 07:05:17 2014
New Revision: 201235

URL: http://llvm.org/viewvc/llvm-project?rev=201235&view=rev
Log:
[sanitizer] Fix wait4 interceptor on Android.

It's called __wait4 there.

Added:
    compiler-rt/trunk/lib/asan/lit_tests/TestCases/waitid.cc   (with props)
Modified:
    compiler-rt/trunk/lib/asan/lit_tests/TestCases/wait.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc

Modified: compiler-rt/trunk/lib/asan/lit_tests/TestCases/wait.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/TestCases/wait.cc?rev=201235&r1=201234&r2=201235&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/lit_tests/TestCases/wait.cc (original)
+++ compiler-rt/trunk/lib/asan/lit_tests/TestCases/wait.cc Wed Feb 12 07:05:17 2014
@@ -4,9 +4,6 @@
 // RUN: %clangxx_asan -DWAITPID -O0 %s -o %t && not %t 2>&1 | FileCheck %s
 // RUN: %clangxx_asan -DWAITPID -O3 %s -o %t && not %t 2>&1 | FileCheck %s
 
-// RUN: %clangxx_asan -DWAITID -O0 %s -o %t && not %t 2>&1 | FileCheck %s
-// RUN: %clangxx_asan -DWAITID -O3 %s -o %t && not %t 2>&1 | FileCheck %s
-
 // RUN: %clangxx_asan -DWAIT3 -O0 %s -o %t && not %t 2>&1 | FileCheck %s
 // RUN: %clangxx_asan -DWAIT3 -O3 %s -o %t && not %t 2>&1 | FileCheck %s
 
@@ -19,7 +16,6 @@
 // RUN: %clangxx_asan -DWAIT4_RUSAGE -O0 %s -o %t && not %t 2>&1 | FileCheck %s
 // RUN: %clangxx_asan -DWAIT4_RUSAGE -O3 %s -o %t && not %t 2>&1 | FileCheck %s
 
-
 #include <assert.h>
 #include <sys/wait.h>
 #include <unistd.h>
@@ -34,9 +30,6 @@ int main(int argc, char **argv) {
     res = wait(status);
 #elif defined(WAITPID)
     res = waitpid(pid, status, WNOHANG);
-#elif defined(WAITID)
-    siginfo_t *si = (siginfo_t*)(x + argc * 3);
-    res = waitid(P_ALL, 0, si, WEXITED | WNOHANG);
 #elif defined(WAIT3)
     res = wait3(status, WNOHANG, NULL);
 #elif defined(WAIT4)
@@ -56,7 +49,7 @@ int main(int argc, char **argv) {
     // CHECK: {{in main .*wait.cc:}}
     // CHECK: is located in stack of thread T0 at offset
     // CHECK: {{in main}}
-    return res != -1;
+    return res == -1 ? 1 : 0;
   }
   // child
   return 0;

Added: compiler-rt/trunk/lib/asan/lit_tests/TestCases/waitid.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/TestCases/waitid.cc?rev=201235&view=auto
==============================================================================
--- compiler-rt/trunk/lib/asan/lit_tests/TestCases/waitid.cc (added)
+++ compiler-rt/trunk/lib/asan/lit_tests/TestCases/waitid.cc Wed Feb 12 07:05:17 2014
@@ -0,0 +1,30 @@
+// RUN: %clangxx_asan -O0 %s -o %t && not %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O3 %s -o %t && not %t 2>&1 | FileCheck %s
+
+// No waitid on Android.
+// XFAIL: android
+
+#include <assert.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+int main(int argc, char **argv) {
+  pid_t pid = fork();
+  if (pid) { // parent
+    int x[3];
+    int *status = x + argc * 3;
+    int res;
+
+    siginfo_t *si = (siginfo_t*)(x + argc * 3);
+    res = waitid(P_ALL, 0, si, WEXITED | WNOHANG);
+    // CHECK: stack-buffer-overflow
+    // CHECK: {{WRITE of size .* at 0x.* thread T0}}
+    // CHECK: {{in .*waitid}}
+    // CHECK: {{in main .*waitid.cc:}}
+    // CHECK: is located in stack of thread T0 at offset
+    // CHECK: {{in main}}
+    return res != -1;
+  }
+  // child
+  return 0;
+}

Propchange: compiler-rt/trunk/lib/asan/lit_tests/TestCases/waitid.cc
------------------------------------------------------------------------------
    svn:eol-style = LF

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=201235&r1=201234&r2=201235&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Wed Feb 12 07:05:17 2014
@@ -1176,6 +1176,19 @@ INTERCEPTOR(int, wait3, int *status, int
   }
   return res;
 }
+#if SANITIZER_ANDROID
+INTERCEPTOR(int, __wait4, int pid, int *status, int options, void *rusage) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, __wait4, pid, status, options, rusage);
+  int res = REAL(__wait4)(pid, status, options, rusage);
+  if (res != -1) {
+    if (status) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, status, sizeof(*status));
+    if (rusage) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, rusage, struct_rusage_sz);
+  }
+  return res;
+}
+#define INIT_WAIT4 COMMON_INTERCEPT_FUNCTION(__wait4);
+#else
 INTERCEPTOR(int, wait4, int pid, int *status, int options, void *rusage) {
   void *ctx;
   COMMON_INTERCEPTOR_ENTER(ctx, wait4, pid, status, options, rusage);
@@ -1186,14 +1199,16 @@ INTERCEPTOR(int, wait4, int pid, int *st
   }
   return res;
 }
+#define INIT_WAIT4 COMMON_INTERCEPT_FUNCTION(wait4);
+#endif  // SANITIZER_ANDROID
 #define INIT_WAIT                     \
   COMMON_INTERCEPT_FUNCTION(wait);    \
   COMMON_INTERCEPT_FUNCTION(waitid);  \
   COMMON_INTERCEPT_FUNCTION(waitpid); \
-  COMMON_INTERCEPT_FUNCTION(wait3);   \
-  COMMON_INTERCEPT_FUNCTION(wait4);
+  COMMON_INTERCEPT_FUNCTION(wait3);
 #else
 #define INIT_WAIT
+#define INIT_WAIT4
 #endif
 
 #if SANITIZER_INTERCEPT_INET
@@ -3284,6 +3299,7 @@ INTERCEPTOR(unsigned int, if_nametoindex
   INIT_TIME;                               \
   INIT_GLOB;                               \
   INIT_WAIT;                               \
+  INIT_WAIT4;                              \
   INIT_INET;                               \
   INIT_PTHREAD_GETSCHEDPARAM;              \
   INIT_GETADDRINFO;                        \





More information about the llvm-commits mailing list