[compiler-rt] r322214 - [hwasan] An option to disable tag randomization.
Evgeniy Stepanov via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 10 11:36:10 PST 2018
Author: eugenis
Date: Wed Jan 10 11:36:10 2018
New Revision: 322214
URL: http://llvm.org/viewvc/llvm-project?rev=322214&view=rev
Log:
[hwasan] An option to disable tag randomization.
Summary:
Avoid flaky test failures by by using a monotonic number sequence of
heap tags.
Does not affect stack tags: the way we generate those guarantees
uniqueness for at least 30-something first allocas in any function,
as well as the UAR tag.
Reviewers: alekseyshl, kcc
Subscribers: llvm-commits, kubamracek
Differential Revision: https://reviews.llvm.org/D41882
Modified:
compiler-rt/trunk/lib/hwasan/hwasan_flags.inc
compiler-rt/trunk/lib/hwasan/hwasan_thread.cc
compiler-rt/trunk/test/hwasan/lit.cfg
Modified: compiler-rt/trunk/lib/hwasan/hwasan_flags.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/hwasan/hwasan_flags.inc?rev=322214&r1=322213&r2=322214&view=diff
==============================================================================
--- compiler-rt/trunk/lib/hwasan/hwasan_flags.inc (original)
+++ compiler-rt/trunk/lib/hwasan/hwasan_flags.inc Wed Jan 10 11:36:10 2018
@@ -27,3 +27,7 @@ HWASAN_FLAG(bool, atexit, false, "")
// Test only flag to disable malloc/realloc/free memory tagging on startup.
// Tagging can be reenabled with __hwasan_enable_allocator_tagging().
HWASAN_FLAG(bool, disable_allocator_tagging, false, "")
+
+// If false, use simple increment of a thread local counter to generate new
+// tags.
+HWASAN_FLAG(bool, random_tags, true, "")
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=322214&r1=322213&r2=322214&view=diff
==============================================================================
--- compiler-rt/trunk/lib/hwasan/hwasan_thread.cc (original)
+++ compiler-rt/trunk/lib/hwasan/hwasan_thread.cc Wed Jan 10 11:36:10 2018
@@ -29,7 +29,7 @@ HwasanThread *HwasanThread::Create(threa
thread->start_routine_ = start_routine;
thread->arg_ = arg;
thread->destructor_iterations_ = GetPthreadDestructorIterations();
- thread->random_state_ = RandomSeed();
+ thread->random_state_ = flags()->random_tags ? RandomSeed() : 0;
return thread;
}
@@ -97,11 +97,15 @@ static u32 xorshift(u32 state) {
tag_t HwasanThread::GenerateRandomTag() {
tag_t tag;
do {
- if (!random_buffer_)
- random_buffer_ = random_state_ = xorshift(random_state_);
- CHECK(random_buffer_);
- tag = random_buffer_ & 0xFF;
- random_buffer_ >>= 8;
+ if (flags()->random_tags) {
+ if (!random_buffer_)
+ random_buffer_ = random_state_ = xorshift(random_state_);
+ CHECK(random_buffer_);
+ tag = random_buffer_ & 0xFF;
+ random_buffer_ >>= 8;
+ } else {
+ tag = random_state_ = (random_state_ + 1) & 0xFF;
+ }
} while (!tag);
return tag;
}
Modified: compiler-rt/trunk/test/hwasan/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/hwasan/lit.cfg?rev=322214&r1=322213&r2=322214&view=diff
==============================================================================
--- compiler-rt/trunk/test/hwasan/lit.cfg (original)
+++ compiler-rt/trunk/test/hwasan/lit.cfg Wed Jan 10 11:36:10 2018
@@ -18,7 +18,7 @@ def build_invocation(compile_flags):
config.substitutions.append( ("%clang_hwasan ", build_invocation(clang_hwasan_cflags)) )
config.substitutions.append( ("%clangxx_hwasan ", build_invocation(clang_hwasan_cxxflags)) )
-default_hwasan_opts_str = ':'.join(['disable_allocator_tagging=1'] + config.default_sanitizer_opts)
+default_hwasan_opts_str = ':'.join(['disable_allocator_tagging=1', 'random_tags=0'] + config.default_sanitizer_opts)
if default_hwasan_opts_str:
config.environment['HWASAN_OPTIONS'] = default_hwasan_opts_str
default_hwasan_opts_str += ':'
More information about the llvm-commits
mailing list