[compiler-rt] r339607 - [hwasan] Handle missing /proc/self/maps.
Evgeniy Stepanov via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 13 13:04:48 PDT 2018
Author: eugenis
Date: Mon Aug 13 13:04:48 2018
New Revision: 339607
URL: http://llvm.org/viewvc/llvm-project?rev=339607&view=rev
Log:
[hwasan] Handle missing /proc/self/maps.
Summary:
Don't crash when /proc/self/maps is inaccessible from main thread.
It's not a big deal, really.
Reviewers: vitalybuka, kcc
Subscribers: kubamracek, llvm-commits
Differential Revision: https://reviews.llvm.org/D50574
Modified:
compiler-rt/trunk/lib/hwasan/hwasan_thread.cc
Modified: compiler-rt/trunk/lib/hwasan/hwasan_thread.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/hwasan/hwasan_thread.cc?rev=339607&r1=339606&r2=339607&view=diff
==============================================================================
--- compiler-rt/trunk/lib/hwasan/hwasan_thread.cc (original)
+++ compiler-rt/trunk/lib/hwasan/hwasan_thread.cc Mon Aug 13 13:04:48 2018
@@ -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,21 +37,32 @@ HwasanThread *HwasanThread::Create(threa
}
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) {
@@ -59,7 +71,8 @@ void HwasanThread::TSDDtor(void *tsd) {
}
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);
}
More information about the llvm-commits
mailing list