[scudo][standalone] Fix a race in the secondary release
authorKostya Kortchinsky <kostyak@google.com>
Wed, 5 Feb 2020 17:58:52 +0000 (09:58 -0800)
committerKostya Kortchinsky <kostyak@google.com>
Wed, 5 Feb 2020 19:02:51 +0000 (11:02 -0800)
commita9d5f8989d83dee1ed01b7f8eaaab89ad190116a
tree726159d76a31c608875fda04cfbd6d7b070729f8
parentce9633633c07045068d202cc225dbf2deb7e4e8b
[scudo][standalone] Fix a race in the secondary release

Summary:
I tried to move the `madvise` calls outside of one of the secondary
mutexes, but this backfired. There is situation when a low release
interval is set combined with secondary pressure that leads to a race:
a thread can get a block from the cache, while another thread is
`madvise`'ing that block, resulting in a null header.

I changed the secondary race test so that this situation would be
triggered, and moved the release into the cache mutex scope.

Reviewers: cferris, pcc, eugenis, hctim, morehouse

Subscribers: jfb, #sanitizers, llvm-commits

Tags: #sanitizers, #llvm

Differential Revision: https://reviews.llvm.org/D74072
compiler-rt/lib/scudo/standalone/secondary.h
compiler-rt/lib/scudo/standalone/tests/secondary_test.cpp