[PATCH] D55587: [hwasan] Verify Android TLS slot at startup.

Evgenii Stepanov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 11 16:42:49 PST 2018


eugenis updated this revision to Diff 177802.
eugenis added a comment.

Added newline at the end of the error message.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55587/new/

https://reviews.llvm.org/D55587

Files:
  compiler-rt/lib/hwasan/hwasan.cc
  compiler-rt/lib/hwasan/hwasan.h
  compiler-rt/lib/hwasan/hwasan_linux.cc


Index: compiler-rt/lib/hwasan/hwasan_linux.cc
===================================================================
--- compiler-rt/lib/hwasan/hwasan_linux.cc
+++ compiler-rt/lib/hwasan/hwasan_linux.cc
@@ -24,6 +24,7 @@
 #include "hwasan_thread.h"
 #include "hwasan_thread_list.h"
 
+#include <dlfcn.h>
 #include <elf.h>
 #include <link.h>
 #include <pthread.h>
@@ -283,6 +284,22 @@
 }
 #endif
 
+#if SANITIZER_ANDROID
+void AndroidTestTlsSlot() {
+  uptr kMagicValue = 0x010203040A0B0C0D;
+  *(uptr *)get_android_tls_ptr() = kMagicValue;
+  dlerror();
+  if (*(uptr *)get_android_tls_ptr() != kMagicValue) {
+    Printf(
+        "ERROR: Incompatible version of Android: TLS_SLOT_SANITIZER(6) is used "
+        "for dlerror().\n");
+    Die();
+  }
+}
+#else
+void AndroidTestTlsSlot() {}
+#endif
+
 Thread *GetCurrentThread() {
   auto *R = (StackAllocationsRingBuffer*)GetCurrentThreadLongPtr();
   return hwasanThreadList().GetThreadByBufferAddress((uptr)(R->Next()));
Index: compiler-rt/lib/hwasan/hwasan.h
===================================================================
--- compiler-rt/lib/hwasan/hwasan.h
+++ compiler-rt/lib/hwasan/hwasan.h
@@ -154,6 +154,8 @@
 
 void AppendToErrorMessageBuffer(const char *buffer);
 
+void AndroidTestTlsSlot();
+
 }  // namespace __hwasan
 
 #define HWASAN_MALLOC_HOOK(ptr, size)       \
Index: compiler-rt/lib/hwasan/hwasan.cc
===================================================================
--- compiler-rt/lib/hwasan/hwasan.cc
+++ compiler-rt/lib/hwasan/hwasan.cc
@@ -283,6 +283,8 @@
 
   __sanitizer_set_report_path(common_flags()->log_path);
 
+  AndroidTestTlsSlot();
+
   DisableCoreDumperIfNecessary();
 
   __hwasan_shadow_init();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55587.177802.patch
Type: text/x-patch
Size: 1689 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181212/a35397f7/attachment.bin>


More information about the llvm-commits mailing list