This is an archive of the discontinued LLVM Phabricator instance.

[hwasan] Fix Thread reuse.
ClosedPublic

Authored by eugenis on Nov 10 2020, 2:19 PM.

Details

Summary

HwasanThreadList::DontNeedThread clobbers Thread::next_, breaking the
freelist. As a result, only the top of the freelist ever gets reused,
and the rest of it is lost.

Since the Thread object its associated ring buffer is only 8Kb, this is
typically only noticable in long running processes, such as fuzzers.

Fix the problem by switching from an intrusive linked list to a vector.

Diff Detail

Event Timeline

eugenis created this revision.Nov 10 2020, 2:19 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 10 2020, 2:19 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
eugenis requested review of this revision.Nov 10 2020, 2:19 PM
pcc accepted this revision.Nov 10 2020, 4:19 PM

LGTM

This revision is now accepted and ready to land.Nov 10 2020, 4:19 PM
This revision was landed with ongoing or failed builds.Nov 10 2020, 5:24 PM
This revision was automatically updated to reflect the committed changes.
thakis added a subscriber: thakis.Nov 11 2020, 6:39 AM

This test is failing on our clang packaging bots: https://logs.chromium.org/logs/chromium/buildbucket/cr-buildbucket.appspot.com/8863946222064502624/+/steps/package_clang/0/stdout?format=raw

Testing:  0.. 10.. 20.. 30.. 40.
 FAIL: HWAddressSanitizer-x86_64 :: TestCases/Linux/reuse-threads.cpp (36788 of 78839)
 ******************** TEST 'HWAddressSanitizer-x86_64 :: TestCases/Linux/reuse-threads.cpp' FAILED ********************
 Script:
 --
 : 'RUN: at line 2';      /b/s/w/ir/cache/builder/src/third_party/llvm-build/Release+Asserts/./bin/clang  --driver-mode=g++  -m64  -gline-tables-only -fsanitize=hwaddress -fuse-ld=lld -mcmodel=large -mllvm -hwasan-globals -mllvm -hwasan-use-short-granules -mllvm -hwasan-instrument-landing-pads=0 -mllvm -hwasan-instrument-personality-functions -mllvm -hwasan-instrument-stack=0 /b/s/w/ir/cache/builder/src/third_party/llvm/compiler-rt/test/hwasan/TestCases/Linux/reuse-threads.cpp -o /b/s/w/ir/cache/builder/src/third_party/llvm-build/Release+Asserts/projects/compiler-rt/test/hwasan/X86_64/TestCases/Linux/Output/reuse-threads.cpp.tmp && env HWASAN_OPTIONS=disable_allocator_tagging=1:random_tags=0:verbose_threads=1  /b/s/w/ir/cache/builder/src/third_party/llvm-build/Release+Asserts/projects/compiler-rt/test/hwasan/X86_64/TestCases/Linux/Output/reuse-threads.cpp.tmp 2>&1 | FileCheck /b/s/w/ir/cache/builder/src/third_party/llvm/compiler-rt/test/hwasan/TestCases/Linux/reuse-threads.cpp
 --
 Exit Code: 1
 
 Command Output (stderr):
 --
 /b/s/w/ir/cache/builder/src/third_party/llvm/compiler-rt/test/hwasan/TestCases/Linux/reuse-threads.cpp:49:16: error: CHECK-DAG: expected string not found in input
  // CHECK-DAG: Creating : T{{[0-9]+}} [[A]] stack:
                ^
 <stdin>:26:38: note: scanning from here
 Creating : T12 0x770000006000 stack: [0x7f017d89f000,0x7f017e09ef80) sz: 8388480 tls: [0x7f017e09ef80,0x7f017e0a0000)
                                      ^
 <stdin>:26:38: note: with "A" equal to "0x770000006000"
 Creating : T12 0x770000006000 stack: [0x7f017d89f000,0x7f017e09ef80) sz: 8388480 tls: [0x7f017e09ef80,0x7f017e0a0000)
                                      ^
 <stdin>:27:10: note: possible intended match here
 Destroying: T12 0x770000006000 stack: [0x7f017d89f000,0x7f017e09ef80) sz: 8388480 tls: [0x7f017e09ef80,0x7f017e0a0000)
          ^
 
 Input file: <stdin>
 Check file: /b/s/w/ir/cache/builder/src/third_party/llvm/compiler-rt/test/hwasan/TestCases/Linux/reuse-threads.cpp
 
 -dump-input=help explains the following input dump.
 
 Input was:
 <<<<<<
           .
           .
           .
          21: Destroying: T9 0x77000000a000 stack: [0x7f017f0a2000,0x7f017f8a1f80) sz: 8388480 tls: [0x7f017f8a1f80,0x7f017f8a3000)
          22: Creating : T10 0x770000012000 stack: [0x7f017e8a1000,0x7f017f0a0f80) sz: 8388480 tls: [0x7f017f0a0f80,0x7f017f0a2000)
          23: Destroying: T10 0x770000012000 stack: [0x7f017e8a1000,0x7f017f0a0f80) sz: 8388480 tls: [0x7f017f0a0f80,0x7f017f0a2000)
          24: Creating : T11 0x77000000e000 stack: [0x7f017e0a0000,0x7f017e89ff80) sz: 8388480 tls: [0x7f017e89ff80,0x7f017e8a1000)
          25: Destroying: T11 0x77000000e000 stack: [0x7f017e0a0000,0x7f017e89ff80) sz: 8388480 tls: [0x7f017e89ff80,0x7f017e8a1000)
          26: Creating : T12 0x770000006000 stack: [0x7f017d89f000,0x7f017e09ef80) sz: 8388480 tls: [0x7f017e09ef80,0x7f017e0a0000)
 dag:49'0                                          X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found
 dag:49'1                                                                                                                           with "A" equal to "0x770000006000"
          27: Destroying: T12 0x770000006000 stack: [0x7f017d89f000,0x7f017e09ef80) sz: 8388480 tls: [0x7f017e09ef80,0x7f017e0a0000)
 dag:49'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 dag:49'2              ?                                                                                                             possible intended match
 >>>>>>
 
 --
 
 ********************
 Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. 
 ********************
 Failed Tests (1):
   HWAddressSanitizer-x86_64 :: TestCases/Linux/reuse-threads.cpp

PTAL!

Also failing on other bots, but not all the time: http://45.33.8.238/linux/32598/step_10.txt