summaryrefslogtreecommitdiff
path: root/lib/msan/msan_allocator.cc
diff options
context:
space:
mode:
authorKostya Kortchinsky <kostyak@google.com>2017-08-02 20:32:12 +0000
committerKostya Kortchinsky <kostyak@google.com>2017-08-02 20:32:12 +0000
commitd20ebd10fdafaae026ac550e17d17daff39608e7 (patch)
treebcae6cb7bae78926346fdbdae274a8f4d5e011d2 /lib/msan/msan_allocator.cc
parentf6f49c0e05d1847dfd55d87a683140d991c9c6c1 (diff)
[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 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@309883 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/msan/msan_allocator.cc')
-rw-r--r--lib/msan/msan_allocator.cc4
1 files changed, 4 insertions, 0 deletions
diff --git a/lib/msan/msan_allocator.cc b/lib/msan/msan_allocator.cc
index 8e9d4d397..1b134e15a 100644
--- a/lib/msan/msan_allocator.cc
+++ b/lib/msan/msan_allocator.cc
@@ -255,6 +255,10 @@ void *msan_valloc(uptr size, StackTrace *stack) {
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));