[PATCH] D41882: [hwasan] An option to disable tag randomization.
Evgenii Stepanov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 10 11:37:35 PST 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL322214: [hwasan] An option to disable tag randomization. (authored by eugenis, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D41882?vs=129163&id=129316#toc
Repository:
rL LLVM
https://reviews.llvm.org/D41882
Files:
compiler-rt/trunk/lib/hwasan/hwasan_flags.inc
compiler-rt/trunk/lib/hwasan/hwasan_thread.cc
compiler-rt/trunk/test/hwasan/lit.cfg
Index: compiler-rt/trunk/test/hwasan/lit.cfg
===================================================================
--- compiler-rt/trunk/test/hwasan/lit.cfg
+++ compiler-rt/trunk/test/hwasan/lit.cfg
@@ -18,7 +18,7 @@
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 += ':'
Index: compiler-rt/trunk/lib/hwasan/hwasan_thread.cc
===================================================================
--- compiler-rt/trunk/lib/hwasan/hwasan_thread.cc
+++ compiler-rt/trunk/lib/hwasan/hwasan_thread.cc
@@ -29,7 +29,7 @@
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 @@
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;
}
Index: compiler-rt/trunk/lib/hwasan/hwasan_flags.inc
===================================================================
--- compiler-rt/trunk/lib/hwasan/hwasan_flags.inc
+++ compiler-rt/trunk/lib/hwasan/hwasan_flags.inc
@@ -27,3 +27,7 @@
// 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, "")
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41882.129316.patch
Type: text/x-patch
Size: 2434 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180110/02154cce/attachment.bin>
More information about the llvm-commits
mailing list