[compiler-rt] r193158 - [sanitizer] Intercept initgroups.

Evgeniy Stepanov eugeni.stepanov at gmail.com
Tue Oct 22 05:24:48 PDT 2013


Author: eugenis
Date: Tue Oct 22 07:24:48 2013
New Revision: 193158

URL: http://llvm.org/viewvc/llvm-project?rev=193158&view=rev
Log:
[sanitizer] Intercept initgroups.

Added:
    compiler-rt/trunk/lib/msan/lit_tests/initgroups.cc   (with props)
Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
    compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h

Added: compiler-rt/trunk/lib/msan/lit_tests/initgroups.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/lit_tests/initgroups.cc?rev=193158&view=auto
==============================================================================
--- compiler-rt/trunk/lib/msan/lit_tests/initgroups.cc (added)
+++ compiler-rt/trunk/lib/msan/lit_tests/initgroups.cc Tue Oct 22 07:24:48 2013
@@ -0,0 +1,11 @@
+// RUN: %clangxx_msan -m64 -O0 %s -o %t && %t
+
+#include <sys/types.h>
+#include <grp.h>
+
+int main(void) {
+  initgroups("root", 0);
+  // The above fails unless you are root. Does not matter, MSan false positive
+  // (which we are testing for) happens anyway.
+  return 0;
+}

Propchange: compiler-rt/trunk/lib/msan/lit_tests/initgroups.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=193158&r1=193157&r2=193158&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Tue Oct 22 07:24:48 2013
@@ -2408,6 +2408,19 @@ INTERCEPTOR(int, fstatvfs64, int fd, voi
 #define INIT_STATVFS64
 #endif
 
+#if SANITIZER_INTERCEPT_INITGROUPS
+INTERCEPTOR(int, initgroups, char *user, u32 group) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, initgroups, user, group);
+  if (user) COMMON_INTERCEPTOR_READ_RANGE(ctx, user, REAL(strlen)(user) + 1);
+  int res = REAL(initgroups)(user, group);
+  return res;
+}
+#define INIT_INITGROUPS INTERCEPT_FUNCTION(initgroups);
+#else
+#define INIT_INITGROUPS
+#endif
+
 #define SANITIZER_COMMON_INTERCEPTORS_INIT \
   INIT_STRCMP;                             \
   INIT_STRNCMP;                            \
@@ -2498,4 +2511,5 @@ INTERCEPTOR(int, fstatvfs64, int fd, voi
   INIT_STATFS64;                           \
   INIT_STATVFS;                            \
   INIT_STATVFS64;                          \
+  INIT_INITGROUPS;                         \
 /**/

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=193158&r1=193157&r2=193158&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Tue Oct 22 07:24:48 2013
@@ -132,6 +132,7 @@
 # define SANITIZER_INTERCEPT_STATFS64 SI_MAC || SI_LINUX_NOT_ANDROID
 # define SANITIZER_INTERCEPT_STATVFS SI_LINUX_NOT_ANDROID
 # define SANITIZER_INTERCEPT_STATVFS64 SI_LINUX_NOT_ANDROID
+# define SANITIZER_INTERCEPT_INITGROUPS SI_NOT_WINDOWS
 
 # define SANITIZER_INTERCEPT__EXIT SI_LINUX
 

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc?rev=193158&r1=193157&r2=193158&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc Tue Oct 22 07:24:48 2013
@@ -384,6 +384,7 @@ void StatOutput(u64 *stat) {
   name[StatInt_statvfs64]                = "  statvfs64                       ";
   name[StatInt_fstatvfs]                 = "  fstatvfs                        ";
   name[StatInt_fstatvfs64]               = "  fstatvfs64                      ";
+  name[StatInt_initgroups]               = "  initgroups                      ";
 
   name[StatAnnotation]                   = "Dynamic annotations               ";
   name[StatAnnotateHappensBefore]        = "  HappensBefore                   ";

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h?rev=193158&r1=193157&r2=193158&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h Tue Oct 22 07:24:48 2013
@@ -379,6 +379,7 @@ enum StatType {
   StatInt_statvfs64,
   StatInt_fstatvfs,
   StatInt_fstatvfs64,
+  StatInt_initgroups,
 
   // Dynamic annotations.
   StatAnnotation,





More information about the llvm-commits mailing list