[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:25:06 PST 2018
eugenis created this revision.
eugenis added reviewers: rprichard, vitalybuka.
Herald added subscribers: kubamracek, srhines.
Add a check that TLS_SLOT_TSAN / TLS_SLOT_SANITIZER, whichever
android_get_tls_slot is using, is not conflicting with
TLS_SLOT_DLERROR.
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().");
+ 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.177800.patch
Type: text/x-patch
Size: 1687 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181212/2533f4d6/attachment.bin>
More information about the llvm-commits
mailing list