[compiler-rt] r366253 - [GWP-ASan] Add thread ID to PRNG seed.

Mitch Phillips via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 16 13:06:17 PDT 2019


Author: hctim
Date: Tue Jul 16 13:06:17 2019
New Revision: 366253

URL: http://llvm.org/viewvc/llvm-project?rev=366253&view=rev
Log:
[GWP-ASan] Add thread ID to PRNG seed.

Summary:
Adds thread ID to PRNG seed for increased entropy. In particular, this allows
multiple runs in quick succession that will have different PRNG seeds, allowing
for better demos/testing.

Reviewers: kcc

Reviewed By: kcc

Subscribers: kubamracek, #sanitizers, llvm-commits

Tags: #sanitizers, #llvm

Differential Revision: https://reviews.llvm.org/D64453

Modified:
    compiler-rt/trunk/lib/gwp_asan/guarded_pool_allocator.h
    compiler-rt/trunk/lib/gwp_asan/random.cpp

Modified: compiler-rt/trunk/lib/gwp_asan/guarded_pool_allocator.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/gwp_asan/guarded_pool_allocator.h?rev=366253&r1=366252&r2=366253&view=diff
==============================================================================
--- compiler-rt/trunk/lib/gwp_asan/guarded_pool_allocator.h (original)
+++ compiler-rt/trunk/lib/gwp_asan/guarded_pool_allocator.h Tue Jul 16 13:06:17 2019
@@ -132,6 +132,10 @@ public:
   // occur.
   static void reportError(uintptr_t AccessPtr, Error E = Error::UNKNOWN);
 
+  // Get the current thread ID, or kInvalidThreadID if failure. Note: This
+  // implementation is platform-specific.
+  static uint64_t getThreadID();
+
 private:
   static constexpr size_t kInvalidSlotID = SIZE_MAX;
 
@@ -146,10 +150,6 @@ private:
   void markReadWrite(void *Ptr, size_t Size) const;
   void markInaccessible(void *Ptr, size_t Size) const;
 
-  // Get the current thread ID, or kInvalidThreadID if failure. Note: This
-  // implementation is platform-specific.
-  static uint64_t getThreadID();
-
   // Get the page size from the platform-specific implementation. Only needs to
   // be called once, and the result should be cached in PageSize in this class.
   static size_t getPlatformPageSize();

Modified: compiler-rt/trunk/lib/gwp_asan/random.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/gwp_asan/random.cpp?rev=366253&r1=366252&r2=366253&view=diff
==============================================================================
--- compiler-rt/trunk/lib/gwp_asan/random.cpp (original)
+++ compiler-rt/trunk/lib/gwp_asan/random.cpp Tue Jul 16 13:06:17 2019
@@ -7,12 +7,14 @@
 //===----------------------------------------------------------------------===//
 
 #include "gwp_asan/random.h"
+#include "gwp_asan/guarded_pool_allocator.h"
 
 #include <time.h>
 
 namespace gwp_asan {
 uint32_t getRandomUnsigned32() {
-  thread_local uint32_t RandomState = static_cast<uint64_t>(time(nullptr));
+  thread_local uint32_t RandomState =
+      time(nullptr) + GuardedPoolAllocator::getThreadID();
   RandomState ^= RandomState << 13;
   RandomState ^= RandomState >> 17;
   RandomState ^= RandomState << 5;




More information about the llvm-commits mailing list