summaryrefslogtreecommitdiff
path: root/lib/sanitizer_common/sanitizer_allocator_checks.h
diff options
context:
space:
mode:
authorKostya Kortchinsky <kostyak@google.com>2017-07-25 21:18:02 +0000
committerKostya Kortchinsky <kostyak@google.com>2017-07-25 21:18:02 +0000
commit77afdbc0a07be926ec41110be6937aba4019165d (patch)
tree693ae8dd78b5612e4f8907667bee86fac33092d1 /lib/sanitizer_common/sanitizer_allocator_checks.h
parent2295a0eb5848c8fbdef829a1fb3fd4895aa5010f (diff)
[scudo] Check for pvalloc overflow
Summary: Previously we were rounding up the size passed to `pvalloc` to the next multiple of page size no matter what. There is an overflow possibility that wasn't accounted for. So now, return null in the event of an overflow. The man page doesn't seem to indicate the errno to set in this particular situation, but the glibc unit tests go for ENOMEM (https://code.woboq.org/userspace/glibc/malloc/tst-pvalloc.c.html#54) so we'll do the same. Update the aligned allocation funtions tests to check for properly aligned returned pointers, and the `pvalloc` corner cases. @alekseyshl: do you want me to do the same in the other Sanitizers? Reviewers: alekseyshl Reviewed By: alekseyshl Subscribers: kubamracek, alekseyshl, llvm-commits Differential Revision: https://reviews.llvm.org/D35818 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@309033 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/sanitizer_common/sanitizer_allocator_checks.h')
-rw-r--r--lib/sanitizer_common/sanitizer_allocator_checks.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/sanitizer_common/sanitizer_allocator_checks.h b/lib/sanitizer_common/sanitizer_allocator_checks.h
index 202916eae..b72f541a4 100644
--- a/lib/sanitizer_common/sanitizer_allocator_checks.h
+++ b/lib/sanitizer_common/sanitizer_allocator_checks.h
@@ -59,6 +59,12 @@ INLINE bool CheckForCallocOverflow(uptr size, uptr n) {
return (max / size) < n;
}
+// Returns true if the size passed to pvalloc overflows when rounded to the next
+// multiple of page_size.
+INLINE bool CheckForPvallocOverflow(uptr size, uptr page_size) {
+ return RoundUpTo(size, page_size) < size;
+}
+
} // namespace __sanitizer
#endif // SANITIZER_ALLOCATOR_CHECKS_H