Merge "Remove execute-only memory related code."

This commit is contained in:
Ivan Lozano
2020-02-14 18:39:51 +00:00
committed by Android (Google) Code Review
3 changed files with 3 additions and 52 deletions

View File

@@ -24,7 +24,6 @@ import android.content.pm.ApplicationInfo;
import android.net.Credentials;
import android.net.LocalServerSocket;
import android.net.LocalSocket;
import android.os.Build;
import android.os.FactoryTest;
import android.os.IVold;
import android.os.Process;
@@ -291,7 +290,7 @@ public final class Zygote {
static int forkAndSpecialize(int uid, int gid, int[] gids, int runtimeFlags,
int[][] rlimits, int mountExternal, String seInfo, String niceName, int[] fdsToClose,
int[] fdsToIgnore, boolean startChildZygote, String instructionSet, String appDataDir,
int targetSdkVersion, boolean isTopApp, String[] pkgDataInfoList) {
boolean isTopApp, String[] pkgDataInfoList) {
ZygoteHooks.preFork();
int pid = nativeForkAndSpecialize(
@@ -299,8 +298,6 @@ public final class Zygote {
fdsToIgnore, startChildZygote, instructionSet, appDataDir, isTopApp,
pkgDataInfoList);
if (pid == 0) {
Zygote.disableExecuteOnly(targetSdkVersion);
// Note that this event ends at the end of handleChildProc,
Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "PostFork");
}
@@ -696,8 +693,6 @@ public final class Zygote {
args.mInstructionSet, args.mAppDataDir, args.mIsTopApp,
args.mPkgDataInfoList);
disableExecuteOnly(args.mTargetSdkVersion);
Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
return ZygoteInit.zygoteInit(args.mTargetSdkVersion,
@@ -776,17 +771,6 @@ public final class Zygote {
}
}
/**
* Mark execute-only segments of libraries read+execute for apps with targetSdkVersion<Q.
*/
private static void disableExecuteOnly(int targetSdkVersion) {
if ((targetSdkVersion < Build.VERSION_CODES.Q) && !nativeDisableExecuteOnly()) {
Log.e("Zygote", "Failed to set libraries to read+execute.");
}
}
private static native boolean nativeDisableExecuteOnly();
/**
* @return Raw file descriptors for the read-end of USAP reporting pipes.
*/

View File

@@ -257,8 +257,8 @@ class ZygoteConnection {
pid = Zygote.forkAndSpecialize(parsedArgs.mUid, parsedArgs.mGid, parsedArgs.mGids,
parsedArgs.mRuntimeFlags, rlimits, parsedArgs.mMountExternal, parsedArgs.mSeInfo,
parsedArgs.mNiceName, fdsToClose, fdsToIgnore, parsedArgs.mStartChildZygote,
parsedArgs.mInstructionSet, parsedArgs.mAppDataDir, parsedArgs.mTargetSdkVersion,
parsedArgs.mIsTopApp, parsedArgs.mPkgDataInfoList);
parsedArgs.mInstructionSet, parsedArgs.mAppDataDir, parsedArgs.mIsTopApp,
parsedArgs.mPkgDataInfoList);
try {
if (pid == 0) {

View File

@@ -49,7 +49,6 @@
#include <fcntl.h>
#include <grp.h>
#include <inttypes.h>
#include <link.h>
#include <malloc.h>
#include <mntent.h>
#include <paths.h>
@@ -59,7 +58,6 @@
#include <sys/capability.h>
#include <sys/cdefs.h>
#include <sys/eventfd.h>
#include <sys/mman.h>
#include <sys/personality.h>
#include <sys/prctl.h>
#include <sys/resource.h>
@@ -76,10 +74,8 @@
#include <android-base/properties.h>
#include <android-base/file.h>
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
#include <android-base/unique_fd.h>
#include <bionic/malloc.h>
#include <bionic/page.h>
#include <cutils/fs.h>
#include <cutils/multiuser.h>
#include <cutils/sockets.h>
@@ -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<void*>(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",