From 2659d7b6c221402b9fc58709fdab4d0790c47b4f Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Fri, 5 Mar 2021 13:31:41 -0800 Subject: 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 --- tests/malloc_test.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'tests/malloc_test.cpp') 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(131072); + volatile char *vp = p.get(); + volatile char oob ATTRIBUTE_UNUSED = vp[131072]; +#else + GTEST_SKIP() << "bionic extension"; +#endif +} -- cgit v1.2.3