Commit ccda03a0 authored by Vlad Tsyrklevich's avatar Vlad Tsyrklevich Committed by Commit Bot

GWP-ASan: Try harder to allocate in high memory

GWP-ASan tries to allocate its memory region in upper memory (e.g. above
the first 32-bits on 64-bit platforms) to limit false positive reports
that can result when randomly overwritten pointer values point into the
GWP-ASan region. Since introducing the mechanism to hint that the region
should be allocated in high memory, these inactionable reports have
decreased, but still occasionally occur on Windows. Try to map the region
in high memory multiple times to account for the unlikely probability
that the memory is already reserved.

Bug: 969146
Change-Id: Ide3ae093debcf4a3eee758dbe526ae6c1a66f7d5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1876754
Auto-Submit: Vlad Tsyrklevich <vtsyrklevich@chromium.org>
Commit-Queue: Vitaly Buka <vitalybuka@chromium.org>
Reviewed-by: default avatarVitaly Buka <vitalybuka@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709188}
parent 18b72c26
......@@ -13,10 +13,13 @@ namespace gwp_asan {
namespace internal {
void* GuardedPageAllocator::MapRegion() {
if (void* hint = MapRegionHint())
if (void* ptr =
VirtualAlloc(hint, RegionSize(), MEM_RESERVE, PAGE_NOACCESS))
// Number of times to try to map the region in high memory before giving up.
constexpr size_t kHintTries = 5;
for (size_t i = 0; i < kHintTries; i++) {
if (void* ptr = VirtualAlloc(MapRegionHint(), RegionSize(), MEM_RESERVE,
PAGE_NOACCESS))
return ptr;
}
return VirtualAlloc(nullptr, RegionSize(), MEM_RESERVE, PAGE_NOACCESS);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment