[compiler-rt] r309883 - [msan] Check for pvalloc overflow
Kostya Kortchinsky via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 2 13:32:12 PDT 2017
Author: cryptoad
Date: Wed Aug 2 13:32:12 2017
New Revision: 309883
URL: http://llvm.org/viewvc/llvm-project?rev=309883&view=rev
Log:
[msan] Check for pvalloc overflow
Summary:
CheckForPvallocOverflow was introduced with D35818 to detect when pvalloc
would wrap when rounding up to the next multiple of the page size.
Add this check to MSan's pvalloc implementation.
This time I made sure I was actually running (and writing) the correct tests,
and that they are passing...
Reviewers: alekseyshl
Reviewed By: alekseyshl
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D36164
Modified:
compiler-rt/trunk/lib/msan/msan_allocator.cc
compiler-rt/trunk/lib/msan/tests/msan_test.cc
Modified: compiler-rt/trunk/lib/msan/msan_allocator.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_allocator.cc?rev=309883&r1=309882&r2=309883&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_allocator.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_allocator.cc Wed Aug 2 13:32:12 2017
@@ -255,6 +255,10 @@ void *msan_valloc(uptr size, StackTrace
void *msan_pvalloc(uptr size, StackTrace *stack) {
uptr PageSize = GetPageSizeCached();
+ if (UNLIKELY(CheckForPvallocOverflow(size, PageSize))) {
+ errno = errno_ENOMEM;
+ return Allocator::FailureHandler::OnBadRequest();
+ }
// pvalloc(0) should allocate one page.
size = size ? RoundUpTo(size, PageSize) : PageSize;
return SetErrnoOnNull(MsanAllocate(stack, size, PageSize, false));
Modified: compiler-rt/trunk/lib/msan/tests/msan_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/tests/msan_test.cc?rev=309883&r1=309882&r2=309883&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/tests/msan_test.cc (original)
+++ compiler-rt/trunk/lib/msan/tests/msan_test.cc Wed Aug 2 13:32:12 2017
@@ -3449,6 +3449,12 @@ TEST(MemorySanitizer, pvalloc) {
EXPECT_EQ(0U, (uintptr_t)p % PageSize);
EXPECT_EQ(PageSize, __sanitizer_get_allocated_size(p));
free(p);
+
+ // Overflows should be caught.
+ EXPECT_DEATH(p = pvalloc((uintptr_t)-1),
+ "allocator is terminating the process instead of returning 0");
+ EXPECT_DEATH(p = pvalloc((uintptr_t)-(PageSize - 1)),
+ "allocator is terminating the process instead of returning 0");
}
#endif
More information about the llvm-commits
mailing list