[PATCH] D50574: [hwasan] Handle missing /proc/self/maps.
Evgenii Stepanov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 10 11:04:55 PDT 2018
eugenis created this revision.
eugenis added reviewers: vitalybuka, kcc.
Herald added a subscriber: kubamracek.
Don't crash when /proc/self/maps is inaccessible from main thread.
It's not a big deal, really.
https://reviews.llvm.org/D50574
Files:
compiler-rt/lib/hwasan/hwasan_thread.cc
Index: compiler-rt/lib/hwasan/hwasan_thread.cc
===================================================================
--- compiler-rt/lib/hwasan/hwasan_thread.cc
+++ compiler-rt/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.160148.patch
Type: text/x-patch
Size: 1891 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180810/f4515990/attachment.bin>
More information about the llvm-commits
mailing list