summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>2013-10-22 12:24:48 +0000
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>2013-10-22 12:24:48 +0000
commit285d458935bc2f9d8ec1109de01ed66185062349 (patch)
treeef66891f561b7bbc27119f0bffa58a5dd77971cb
parent137a9b84c25f1ad7d68a14f138cf270a03a738cb (diff)
downloadcompiler-rt-285d458935bc2f9d8ec1109de01ed66185062349.tar.gz
compiler-rt-285d458935bc2f9d8ec1109de01ed66185062349.tar.bz2
compiler-rt-285d458935bc2f9d8ec1109de01ed66185062349.tar.xz
[sanitizer] Intercept initgroups.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@193158 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/msan/lit_tests/initgroups.cc11
-rw-r--r--lib/sanitizer_common/sanitizer_common_interceptors.inc14
-rw-r--r--lib/sanitizer_common/sanitizer_platform_interceptors.h1
-rw-r--r--lib/tsan/rtl/tsan_stat.cc1
-rw-r--r--lib/tsan/rtl/tsan_stat.h1
5 files changed, 28 insertions, 0 deletions
diff --git a/lib/msan/lit_tests/initgroups.cc b/lib/msan/lit_tests/initgroups.cc
new file mode 100644
index 00000000..adba5369
--- /dev/null
+++ b/lib/msan/lit_tests/initgroups.cc
@@ -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;
+}
diff --git a/lib/sanitizer_common/sanitizer_common_interceptors.inc b/lib/sanitizer_common/sanitizer_common_interceptors.inc
index d8d21b4e..1b736ade 100644
--- a/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -2408,6 +2408,19 @@ INTERCEPTOR(int, fstatvfs64, int fd, void *buf) {
#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, void *buf) {
INIT_STATFS64; \
INIT_STATVFS; \
INIT_STATVFS64; \
+ INIT_INITGROUPS; \
/**/
diff --git a/lib/sanitizer_common/sanitizer_platform_interceptors.h b/lib/sanitizer_common/sanitizer_platform_interceptors.h
index 312b073b..01bddd2c 100644
--- a/lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ b/lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -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
diff --git a/lib/tsan/rtl/tsan_stat.cc b/lib/tsan/rtl/tsan_stat.cc
index bc1ce9d0..971e739c 100644
--- a/lib/tsan/rtl/tsan_stat.cc
+++ b/lib/tsan/rtl/tsan_stat.cc
@@ -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 ";
diff --git a/lib/tsan/rtl/tsan_stat.h b/lib/tsan/rtl/tsan_stat.h
index a3deef85..237a8921 100644
--- a/lib/tsan/rtl/tsan_stat.h
+++ b/lib/tsan/rtl/tsan_stat.h
@@ -379,6 +379,7 @@ enum StatType {
StatInt_statvfs64,
StatInt_fstatvfs,
StatInt_fstatvfs64,
+ StatInt_initgroups,
// Dynamic annotations.
StatAnnotation,