summaryrefslogtreecommitdiff
path: root/tests/malloc_test.cpp
diff options
context:
space:
mode:
authorPeter Collingbourne <pcc@google.com>2021-03-05 13:31:41 -0800
committerPeter Collingbourne <pcc@google.com>2021-03-05 14:29:17 -0800
commit2659d7b6c221402b9fc58709fdab4d0790c47b4f (patch)
tree35a268ac00847c20d5f109a10f75a44703dfe695 /tests/malloc_test.cpp
parent15ade069b10f7f5291e48c01db2da4852dae04b7 (diff)
Add some slack at the end of large allocations when target SDK level < S.
This works around buggy applications that read a few bytes past the end of their allocation, which would otherwise cause a segfault with the concurrent Scudo change that aligns large allocations to the right. Because the implementation of android_set_application_target_sdk_version() lives in the linker, we need to introduce a hook so that libc is notified when the target SDK version changes. Bug: 181344545 Change-Id: Id4be6645b94fad3f64ae48afd16c0154f1de448f
Diffstat (limited to 'tests/malloc_test.cpp')
-rw-r--r--tests/malloc_test.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/malloc_test.cpp b/tests/malloc_test.cpp
index 3a09258f7..d73f2436d 100644
--- a/tests/malloc_test.cpp
+++ b/tests/malloc_test.cpp
@@ -46,6 +46,7 @@
#if defined(__BIONIC__)
#include "SignalUtils.h"
+#include "dlext_private.h"
#include "platform/bionic/malloc.h"
#include "platform/bionic/mte.h"
@@ -1351,3 +1352,22 @@ TEST(malloc, disable_mte) {
GTEST_SKIP() << "bionic extension";
#endif
}
+
+TEST(malloc, allocation_slack) {
+#if defined(__BIONIC__)
+ bool allocator_scudo;
+ GetAllocatorVersion(&allocator_scudo);
+ if (!allocator_scudo) {
+ GTEST_SKIP() << "scudo allocator only test";
+ }
+
+ // Test that older target SDK levels let you access a few bytes off the end of
+ // a large allocation.
+ android_set_application_target_sdk_version(29);
+ auto p = std::make_unique<char[]>(131072);
+ volatile char *vp = p.get();
+ volatile char oob ATTRIBUTE_UNUSED = vp[131072];
+#else
+ GTEST_SKIP() << "bionic extension";
+#endif
+}