Skip to content

Commit 4db6803

Browse files
committed
[lsan][fuchsia] Add extra check for allocator cache to avoid overflow
Prior to this, we would check if the end of the allocator cache was located before the end of the chunk passed to the tls check. However, if the actual allocator cache comes after the end of the chunk, then the sub in the `end - params->allocator_caches[i]` bit overflows. Since the resulting type is an unsigned uptr, this is not UB, but if the signed result would be a negative value (ie. `end < params->allocator_caches[i]`) then this will actually result in a very large unsigned value much bigger than the compared `sizeof(AllocatorCache)` which will almost always be true. This can cause ScanRangeForPointers to accept incorrect values: a begin pointing to some address, and `params->allocator_caches[i]` pointing to some much larger address way past the end of the chunk which can result in a page fault/stack overflow. Differential Revision: https://reviews.llvm.org/D159518
1 parent 8998bcf commit 4db6803

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

compiler-rt/lib/lsan/lsan_common_fuchsia.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ void LockStuffAndStopTheWorld(StopTheWorldCallback callback,
119119
auto i = __sanitizer::InternalLowerBound(params->allocator_caches, begin);
120120
if (i < params->allocator_caches.size() &&
121121
params->allocator_caches[i] >= begin &&
122+
params->allocator_caches[i] <= end &&
122123
end - params->allocator_caches[i] >= sizeof(AllocatorCache)) {
123124
// Split the range in two and omit the allocator cache within.
124125
ScanRangeForPointers(begin, params->allocator_caches[i],

0 commit comments

Comments
 (0)