diff --git a/compiler-rt/lib/msan/lit_tests/initgroups.cc b/compiler-rt/lib/msan/lit_tests/initgroups.cc new file mode 100644 index 000000000000..adba5369579a --- /dev/null +++ b/compiler-rt/lib/msan/lit_tests/initgroups.cc @@ -0,0 +1,11 @@ +// RUN: %clangxx_msan -m64 -O0 %s -o %t && %t + +#include +#include + +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/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc index d8d21b4ee3f4..1b736ade694d 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc +++ b/compiler-rt/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/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h index 312b073b8b81..01bddd2c6c87 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h +++ b/compiler-rt/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/compiler-rt/lib/tsan/rtl/tsan_stat.cc b/compiler-rt/lib/tsan/rtl/tsan_stat.cc index bc1ce9d034f2..971e739ce2dd 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_stat.cc +++ b/compiler-rt/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/compiler-rt/lib/tsan/rtl/tsan_stat.h b/compiler-rt/lib/tsan/rtl/tsan_stat.h index a3deef85b6ff..237a8921e4d6 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_stat.h +++ b/compiler-rt/lib/tsan/rtl/tsan_stat.h @@ -379,6 +379,7 @@ enum StatType { StatInt_statvfs64, StatInt_fstatvfs, StatInt_fstatvfs64, + StatInt_initgroups, // Dynamic annotations. StatAnnotation,