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
diff --git a/tests/malloc_test.cpp b/tests/malloc_test.cpp
index 3a09258..d73f243 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 @@
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
+}