[PATCH] D19499: [MSan] Use COMMON_INTERCEPTOR_ENTER in libdl interceptors.

Marcin Koƛcielnicki via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 25 14:50:39 PDT 2016


koriakin created this revision.
koriakin added reviewers: eugenis, samsonov, kcc.
koriakin added a subscriber: llvm-commits.
koriakin set the repository for this revision to rL LLVM.
koriakin added a project: Sanitizers.

This fixes fails in test/msan/dlerror.cc - when real dlerror calls strcmp,
our strcmp interceptor now skips poison checking, since it's called in
interceptor context.  Strictly speaking, only the dlerror change is
necessary to fix the fail, but let's also change the other two just in case.

This fixes the bug XFAILed in D19205 (obsoleting it) and D17503.

Repository:
  rL LLVM

http://reviews.llvm.org/D19499

Files:
  lib/msan/msan_interceptors.cc
  test/msan/dlerror.cc

Index: test/msan/dlerror.cc
===================================================================
--- test/msan/dlerror.cc
+++ test/msan/dlerror.cc
@@ -1,9 +1,4 @@
 // RUN: %clangxx_msan -O0 %s -o %t && %run %t
-//
-// AArch64, MIPS64 shows fails with uninitialized bytes in __interceptor_strcmp from
-// dlfcn/dlerror.c:107 (glibc).
-// XFAIL: aarch64
-// XFAIL: mips64
 
 #include <assert.h>
 #include <dlfcn.h>
Index: lib/msan/msan_interceptors.cc
===================================================================
--- lib/msan/msan_interceptors.cc
+++ lib/msan/msan_interceptors.cc
@@ -104,6 +104,19 @@
 #define CHECK_UNPOISONED_STRING(x, n)                           \
     CHECK_UNPOISONED_STRING_OF_LEN((x), internal_strlen(x), (n))
 
+struct MSanInterceptorContext {
+  bool in_interceptor_scope;
+};
+
+#define COMMON_INTERCEPTOR_ENTER(ctx, func, ...)                  \
+  if (msan_init_is_running) return REAL(func)(__VA_ARGS__);       \
+  ENSURE_MSAN_INITED();                                           \
+  MSanInterceptorContext msan_ctx = {IsInInterceptorScope()};     \
+  ctx = (void *)&msan_ctx;                                        \
+  (void)ctx;                                                      \
+  InterceptorScope interceptor_scope;                             \
+  __msan_unpoison(__errno_location(), sizeof(int)); /* NOLINT */
+
 INTERCEPTOR(SIZE_T, fread, void *ptr, SIZE_T size, SIZE_T nmemb, void *file) {
   ENSURE_MSAN_INITED();
   SIZE_T res = REAL(fread)(ptr, size, nmemb, file);
@@ -1060,7 +1073,8 @@
 };
 
 INTERCEPTOR(int, dladdr, void *addr, dlinfo *info) {
-  ENSURE_MSAN_INITED();
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, dladdr, addr, info);
   int res = REAL(dladdr)(addr, info);
   if (res != 0) {
     __msan_unpoison(info, sizeof(*info));
@@ -1073,7 +1087,8 @@
 }
 
 INTERCEPTOR(char *, dlerror, int fake) {
-  ENSURE_MSAN_INITED();
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, dlerror, fake);
   char *res = REAL(dlerror)(fake);
   if (res) __msan_unpoison(res, REAL(strlen)(res) + 1);
   return res;
@@ -1101,7 +1116,8 @@
 }
 
 INTERCEPTOR(int, dl_iterate_phdr, dl_iterate_phdr_cb callback, void *data) {
-  ENSURE_MSAN_INITED();
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, dl_iterate_phdr, callback, data);
   dl_iterate_phdr_data cbdata;
   cbdata.callback = callback;
   cbdata.data = data;
@@ -1357,10 +1373,6 @@
   return res;
 }
 
-struct MSanInterceptorContext {
-  bool in_interceptor_scope;
-};
-
 namespace __msan {
 
 int OnExit() {
@@ -1393,14 +1405,6 @@
   CHECK_UNPOISONED_CTX(ctx, ptr, size)
 #define COMMON_INTERCEPTOR_INITIALIZE_RANGE(ptr, size) \
   __msan_unpoison(ptr, size)
-#define COMMON_INTERCEPTOR_ENTER(ctx, func, ...)                  \
-  if (msan_init_is_running) return REAL(func)(__VA_ARGS__);       \
-  ENSURE_MSAN_INITED();                                           \
-  MSanInterceptorContext msan_ctx = {IsInInterceptorScope()};     \
-  ctx = (void *)&msan_ctx;                                        \
-  (void)ctx;                                                      \
-  InterceptorScope interceptor_scope;                             \
-  __msan_unpoison(__errno_location(), sizeof(int)); /* NOLINT */
 #define COMMON_INTERCEPTOR_DIR_ACQUIRE(ctx, path) \
   do {                                            \
   } while (false)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19499.54912.patch
Type: text/x-patch
Size: 3332 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160425/fbfd7275/attachment.bin>


More information about the llvm-commits mailing list