[compiler-rt] r193348 - [sanitizer] Intercept shmctl.

Evgeniy Stepanov eugeni.stepanov at gmail.com
Thu Oct 24 07:47:35 PDT 2013


Author: eugenis
Date: Thu Oct 24 09:47:34 2013
New Revision: 193348

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

Modified:
    compiler-rt/trunk/lib/msan/tests/msan_test.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h
    compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h

Modified: compiler-rt/trunk/lib/msan/tests/msan_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/tests/msan_test.cc?rev=193348&r1=193347&r2=193348&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/tests/msan_test.cc (original)
+++ compiler-rt/trunk/lib/msan/tests/msan_test.cc Thu Oct 24 09:47:34 2013
@@ -53,6 +53,8 @@
 #include <wordexp.h>
 #include <mntent.h>
 #include <netinet/ether.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
 
 #if defined(__i386__) || defined(__x86_64__)
 # include <emmintrin.h>
@@ -1121,6 +1123,30 @@ TEST(MemorySanitizer, get_current_dir_na
   free(res);
 }
 
+TEST(MemorySanitizer, shmctl) {
+  int id = shmget(IPC_PRIVATE, 4096, 0644 | IPC_CREAT);
+  ASSERT_GT(id, -1);
+
+  struct shmid_ds ds;
+  int res = shmctl(id, IPC_STAT, &ds);
+  ASSERT_GT(res, -1);
+  EXPECT_NOT_POISONED(ds);
+
+  struct shminfo si;
+  res = shmctl(id, IPC_INFO, (struct shmid_ds *)&si);
+  ASSERT_GT(res, -1);
+  EXPECT_NOT_POISONED(si);
+
+  struct shm_info s_i;
+  res = shmctl(id, SHM_INFO, (struct shmid_ds *)&s_i);
+  ASSERT_GT(res, -1);
+  EXPECT_NOT_POISONED(s_i);
+
+  res = shmctl(id, IPC_RMID, 0);
+  ASSERT_GT(res, -1);
+}
+
+
 TEST(MemorySanitizer, confstr) {
   char buf[3];
   size_t res = confstr(_CS_PATH, buf, sizeof(buf));

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=193348&r1=193347&r2=193348&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Thu Oct 24 09:47:34 2013
@@ -2504,6 +2504,28 @@ INTERCEPTOR(__sanitizer_ether_addr *, et
 #define INIT_ETHER_R
 #endif
 
+#if SANITIZER_INTERCEPT_SHMCTL
+INTERCEPTOR(int, shmctl, int shmid, int cmd, void *buf) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, shmctl, shmid, cmd, buf);
+  int res = REAL(shmctl)(shmid, cmd, buf);
+  if (res >= 0) {
+    unsigned sz = 0;
+    if (cmd == shmctl_ipc_stat || cmd == shmctl_shm_stat)
+      sz = struct_shmid_ds_sz;
+    else if (cmd == shmctl_ipc_info)
+      sz = struct_shminfo_sz;
+    else if (cmd == shmctl_shm_info)
+      sz = struct_shm_info_sz;
+    if (sz) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, sz);
+  }
+  return res;
+}
+#define INIT_SHMCTL INTERCEPT_FUNCTION(shmctl);
+#else
+#define INIT_SHMCTL
+#endif
+
 #define SANITIZER_COMMON_INTERCEPTORS_INIT \
   INIT_STRCMP;                             \
   INIT_STRNCMP;                            \
@@ -2597,4 +2619,5 @@ INTERCEPTOR(__sanitizer_ether_addr *, et
   INIT_INITGROUPS;                         \
   INIT_ETHER;                              \
   INIT_ETHER_R;                            \
+  INIT_SHMCTL;                             \
 /**/

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=193348&r1=193347&r2=193348&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Thu Oct 24 09:47:34 2013
@@ -135,6 +135,7 @@
 # define SANITIZER_INTERCEPT_INITGROUPS SI_NOT_WINDOWS
 # define SANITIZER_INTERCEPT_ETHER SI_NOT_WINDOWS
 # define SANITIZER_INTERCEPT_ETHER_R SI_LINUX_NOT_ANDROID
+# define SANITIZER_INTERCEPT_SHMCTL SI_LINUX_NOT_ANDROID
 
 # define SANITIZER_INTERCEPT__EXIT SI_LINUX
 

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc?rev=193348&r1=193347&r2=193348&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc Thu Oct 24 09:47:34 2013
@@ -92,6 +92,8 @@
 #include <linux/scc.h>
 #include <linux/serial.h>
 #include <sys/msg.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
 #endif // SANITIZER_LINUX && !SANITIZER_ANDROID
 
 #if SANITIZER_ANDROID
@@ -180,6 +182,16 @@ namespace __sanitizer {
   int e_tabsz = (int)E_TABSZ;
 #endif
 
+
+#if SANITIZER_LINUX && !SANITIZER_ANDROID
+  unsigned struct_shminfo_sz = sizeof(struct shminfo);
+  unsigned struct_shm_info_sz = sizeof(struct shm_info);
+  int shmctl_ipc_stat = (int)IPC_STAT;
+  int shmctl_ipc_info = (int)IPC_INFO;
+  int shmctl_shm_info = (int)SHM_INFO;
+  int shmctl_shm_stat = (int)SHM_INFO;
+#endif
+
   int af_inet = (int)AF_INET;
   int af_inet6 = (int)AF_INET6;
 

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h?rev=193348&r1=193347&r2=193348&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h Thu Oct 24 09:47:34 2013
@@ -356,6 +356,15 @@ namespace __sanitizer {
   extern int ptrace_setregset;
 #endif
 
+#if SANITIZER_LINUX && !SANITIZER_ANDROID
+  extern unsigned struct_shminfo_sz;
+  extern unsigned struct_shm_info_sz;
+  extern int shmctl_ipc_stat;
+  extern int shmctl_ipc_info;
+  extern int shmctl_shm_info;
+  extern int shmctl_shm_stat;
+#endif
+
   // ioctl arguments
   struct __sanitizer_ifconf {
     int ifc_len;

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=193348&r1=193347&r2=193348&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc Thu Oct 24 09:47:34 2013
@@ -392,6 +392,7 @@ void StatOutput(u64 *stat) {
   name[StatInt_ether_ntohost]            = "  ether_ntohost                   ";
   name[StatInt_ether_hostton]            = "  ether_hostton                   ";
   name[StatInt_ether_line]               = "  ether_line                      ";
+  name[StatInt_shmctl]                   = "  shmctl                          ";
 
   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=193348&r1=193347&r2=193348&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h Thu Oct 24 09:47:34 2013
@@ -387,6 +387,7 @@ enum StatType {
   StatInt_ether_ntohost,
   StatInt_ether_hostton,
   StatInt_ether_line,
+  StatInt_shmctl,
 
   // Dynamic annotations.
   StatAnnotation,





More information about the llvm-commits mailing list