From 739c0b5193345abfce0373502c795448cc94a3ab Mon Sep 17 00:00:00 2001 From: Jeff Vander Stoep Date: Mon, 25 Mar 2019 20:27:52 -0700 Subject: [PATCH] Disable XOM on libraries for apps with targetSdkVerison #include #include +#include #include #include #include @@ -54,6 +55,7 @@ #include #include #include +#include #include #include #include @@ -69,6 +71,7 @@ #include #include #include +#include #include #include #include @@ -1975,6 +1978,26 @@ static void com_android_internal_os_Zygote_nativeEmptyUsapPool(JNIEnv* env, jcla } } +static int disable_execute_only(struct dl_phdr_info *info, size_t size, void *data) { + // Search for any execute-only segments and mark them read+execute. + for (int i = 0; i < info->dlpi_phnum; i++) { + if ((info->dlpi_phdr[i].p_type == PT_LOAD) && (info->dlpi_phdr[i].p_flags == PF_X)) { + mprotect(reinterpret_cast(info->dlpi_addr + info->dlpi_phdr[i].p_vaddr), + info->dlpi_phdr[i].p_memsz, PROT_READ | PROT_EXEC); + } + } + // Return non-zero to exit dl_iterate_phdr. + return 0; +} + +/** + * @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(disable_execute_only, nullptr) == 0; +} + static const JNINativeMethod gMethods[] = { { "nativeSecurityInit", "()V", (void *) com_android_internal_os_Zygote_nativeSecurityInit }, @@ -2007,7 +2030,9 @@ static const JNINativeMethod gMethods[] = { { "nativeGetUsapPoolCount", "()I", (void *) com_android_internal_os_Zygote_nativeGetUsapPoolCount }, { "nativeEmptyUsapPool", "()V", - (void *) com_android_internal_os_Zygote_nativeEmptyUsapPool } + (void *) com_android_internal_os_Zygote_nativeEmptyUsapPool }, + { "nativeDisableExecuteOnly", "()Z", + (void *) com_android_internal_os_Zygote_nativeDisableExecuteOnly } }; int register_com_android_internal_os_Zygote(JNIEnv* env) {