From 15bdfea2165b0b384521182063c6018a1228c51a Mon Sep 17 00:00:00 2001 From: Ivan Lozano Date: Fri, 14 Feb 2020 11:56:31 -0500 Subject: [PATCH] Remove execute-only memory related code. The kernel no longer enforces XOM layouts, and the build system no longer generates XOM binaries. As a result, the zygote code to mark XOM sections of memory readable for apps with targetSdkVersion #include #include -#include #include #include #include @@ -59,7 +58,6 @@ #include #include #include -#include #include #include #include @@ -76,10 +74,8 @@ #include #include #include -#include #include #include -#include #include #include #include @@ -1905,25 +1901,6 @@ static void UnmountStorageOnInit(JNIEnv* env) { UnmountTree("/storage"); } -static int DisableExecuteOnly(struct dl_phdr_info* info, - size_t size [[maybe_unused]], - void* data [[maybe_unused]]) { - // Search for any execute-only segments and mark them read+execute. - for (int i = 0; i < info->dlpi_phnum; i++) { - const auto& phdr = info->dlpi_phdr[i]; - if ((phdr.p_type == PT_LOAD) && (phdr.p_flags == PF_X)) { - auto addr = reinterpret_cast(info->dlpi_addr + PAGE_START(phdr.p_vaddr)); - size_t len = PAGE_OFFSET(phdr.p_vaddr) + phdr.p_memsz; - if (mprotect(addr, len, PROT_READ | PROT_EXEC) == -1) { - ALOGE("mprotect(%p, %zu, PROT_READ | PROT_EXEC) failed: %m", addr, len); - return -1; - } - } - } - // Return non-zero to exit dl_iterate_phdr. - return 0; -} - } // anonymous namespace namespace android { @@ -2286,14 +2263,6 @@ static void com_android_internal_os_Zygote_nativeEmptyUsapPool(JNIEnv* env, jcla } } -/** - * @param env Managed runtime environment - * @return True if disable was successful. - */ -static jboolean com_android_internal_os_Zygote_nativeDisableExecuteOnly(JNIEnv* env, jclass) { - return dl_iterate_phdr(DisableExecuteOnly, nullptr) == 0; -} - static void com_android_internal_os_Zygote_nativeBlockSigTerm(JNIEnv* env, jclass) { auto fail_fn = std::bind(ZygoteFailure, env, "usap", nullptr, _1); BlockSignal(SIGTERM, fail_fn); @@ -2375,8 +2344,6 @@ static const JNINativeMethod gMethods[] = { {"nativeGetUsapPoolCount", "()I", (void*)com_android_internal_os_Zygote_nativeGetUsapPoolCount}, {"nativeEmptyUsapPool", "()V", (void*)com_android_internal_os_Zygote_nativeEmptyUsapPool}, - {"nativeDisableExecuteOnly", "()Z", - (void*)com_android_internal_os_Zygote_nativeDisableExecuteOnly}, {"nativeBlockSigTerm", "()V", (void*)com_android_internal_os_Zygote_nativeBlockSigTerm}, {"nativeUnblockSigTerm", "()V", (void*)com_android_internal_os_Zygote_nativeUnblockSigTerm}, {"nativeBoostUsapPriority", "()V",