[PATCH] D50574: [hwasan] Handle missing /proc/self/maps.

Evgenii Stepanov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 13 13:05:35 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rCRT339607: [hwasan] Handle missing /proc/self/maps. (authored by eugenis, committed by ).
Herald added a subscriber: Sanitizers.

Changed prior to commit:
  https://reviews.llvm.org/D50574?vs=160148&id=160431#toc

Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D50574

Files:
  lib/hwasan/hwasan_thread.cc


Index: lib/hwasan/hwasan_thread.cc
===================================================================
--- lib/hwasan/hwasan_thread.cc
+++ lib/hwasan/hwasan_thread.cc
@@ -5,6 +5,7 @@
 #include "hwasan_poisoning.h"
 #include "hwasan_interface_internal.h"
 
+#include "sanitizer_common/sanitizer_file.h"
 #include "sanitizer_common/sanitizer_tls_get_addr.h"
 
 namespace __hwasan {
@@ -36,30 +37,42 @@
 }
 
 void HwasanThread::SetThreadStackAndTls() {
-  uptr tls_size = 0;
-  uptr stack_size = 0;
-  GetThreadStackAndTls(IsMainThread(), &stack_bottom_, &stack_size,
-                       &tls_begin_, &tls_size);
+  // If this process is "init" (pid 1), /proc may not be mounted yet.
+  if (IsMainThread() && !FileExists("/proc/self/maps")) {
+    stack_top_ = stack_bottom_ = 0;
+    tls_begin_ = tls_end_ = 0;
+    return;
+  }
+
+  uptr tls_size;
+  uptr stack_size;
+  GetThreadStackAndTls(IsMainThread(), &stack_bottom_, &stack_size, &tls_begin_,
+                       &tls_size);
   stack_top_ = stack_bottom_ + stack_size;
   tls_end_ = tls_begin_ + tls_size;
 
   int local;
   CHECK(AddrIsInStack((uptr)&local));
+  CHECK(MEM_IS_APP(stack_bottom_));
+  CHECK(MEM_IS_APP(stack_top_ - 1));
 }
 
 void HwasanThread::Init() {
   SetThreadStackAndTls();
-  CHECK(MEM_IS_APP(stack_bottom_));
-  CHECK(MEM_IS_APP(stack_top_ - 1));
+  if (stack_bottom_) {
+    CHECK(MEM_IS_APP(stack_bottom_));
+    CHECK(MEM_IS_APP(stack_top_ - 1));
+  }
 }
 
 void HwasanThread::TSDDtor(void *tsd) {
   HwasanThread *t = (HwasanThread*)tsd;
   t->Destroy();
 }
 
 void HwasanThread::ClearShadowForThreadStackAndTLS() {
-  TagMemory(stack_bottom_, stack_top_ - stack_bottom_, 0);
+  if (stack_top_ != stack_bottom_)
+    TagMemory(stack_bottom_, stack_top_ - stack_bottom_, 0);
   if (tls_begin_ != tls_end_)
     TagMemory(tls_begin_, tls_end_ - tls_begin_, 0);
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50574.160431.patch
Type: text/x-patch
Size: 1855 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180813/5cdb7569/attachment.bin>


More information about the llvm-commits mailing list