Merge "Move zygote's seccomp setup to post-fork"
This commit is contained in:
@@ -20,5 +20,6 @@ package android.os;
|
|||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public final class Seccomp {
|
public final class Seccomp {
|
||||||
public static final native void setPolicy();
|
public static native void setSystemServerPolicy();
|
||||||
|
public static native void setAppPolicy();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package com.android.internal.os;
|
package com.android.internal.os;
|
||||||
|
|
||||||
|
|
||||||
|
import android.os.Seccomp;
|
||||||
import android.os.Trace;
|
import android.os.Trace;
|
||||||
import dalvik.system.ZygoteHooks;
|
import dalvik.system.ZygoteHooks;
|
||||||
import android.system.ErrnoException;
|
import android.system.ErrnoException;
|
||||||
@@ -155,6 +156,9 @@ public final class Zygote {
|
|||||||
*/
|
*/
|
||||||
public static int forkSystemServer(int uid, int gid, int[] gids, int runtimeFlags,
|
public static int forkSystemServer(int uid, int gid, int[] gids, int runtimeFlags,
|
||||||
int[][] rlimits, long permittedCapabilities, long effectiveCapabilities) {
|
int[][] rlimits, long permittedCapabilities, long effectiveCapabilities) {
|
||||||
|
// Set system server specific seccomp policy.
|
||||||
|
Seccomp.setSystemServerPolicy();
|
||||||
|
|
||||||
VM_HOOKS.preFork();
|
VM_HOOKS.preFork();
|
||||||
// Resets nice priority for zygote process.
|
// Resets nice priority for zygote process.
|
||||||
resetNicePriority();
|
resetNicePriority();
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import android.net.Credentials;
|
|||||||
import android.net.LocalSocket;
|
import android.net.LocalSocket;
|
||||||
import android.os.FactoryTest;
|
import android.os.FactoryTest;
|
||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
|
import android.os.Seccomp;
|
||||||
import android.os.SystemProperties;
|
import android.os.SystemProperties;
|
||||||
import android.os.Trace;
|
import android.os.Trace;
|
||||||
import android.system.ErrnoException;
|
import android.system.ErrnoException;
|
||||||
@@ -767,6 +768,9 @@ class ZygoteConnection {
|
|||||||
Process.setArgV0(parsedArgs.niceName);
|
Process.setArgV0(parsedArgs.niceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set app specific seccomp policy.
|
||||||
|
Seccomp.setAppPolicy();
|
||||||
|
|
||||||
// End of the postFork event.
|
// End of the postFork event.
|
||||||
Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
|
Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
|
||||||
if (parsedArgs.invokeWith != null) {
|
if (parsedArgs.invokeWith != null) {
|
||||||
|
|||||||
@@ -782,9 +782,6 @@ public class ZygoteInit {
|
|||||||
// Zygote process unmounts root storage spaces.
|
// Zygote process unmounts root storage spaces.
|
||||||
Zygote.nativeUnmountStorageOnInit();
|
Zygote.nativeUnmountStorageOnInit();
|
||||||
|
|
||||||
// Set seccomp policy
|
|
||||||
Seccomp.setPolicy();
|
|
||||||
|
|
||||||
ZygoteHooks.stopZygoteNoThreadCreation();
|
ZygoteHooks.stopZygoteNoThreadCreation();
|
||||||
|
|
||||||
if (startSystemServer) {
|
if (startSystemServer) {
|
||||||
|
|||||||
@@ -21,20 +21,33 @@
|
|||||||
|
|
||||||
#include "seccomp_policy.h"
|
#include "seccomp_policy.h"
|
||||||
|
|
||||||
static void Seccomp_setPolicy(JNIEnv* /*env*/) {
|
static void Seccomp_setSystemServerPolicy(JNIEnv* /*env*/) {
|
||||||
if (security_getenforce() == 0) {
|
if (security_getenforce() == 0) {
|
||||||
ALOGI("seccomp disabled by setenforce 0");
|
ALOGI("seccomp disabled by setenforce 0");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!set_seccomp_filter()) {
|
if (!set_system_seccomp_filter()) {
|
||||||
|
ALOGE("Failed to set seccomp policy - killing");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Seccomp_setAppPolicy(JNIEnv* /*env*/) {
|
||||||
|
if (security_getenforce() == 0) {
|
||||||
|
ALOGI("seccomp disabled by setenforce 0");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!set_app_seccomp_filter()) {
|
||||||
ALOGE("Failed to set seccomp policy - killing");
|
ALOGE("Failed to set seccomp policy - killing");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const JNINativeMethod method_table[] = {
|
static const JNINativeMethod method_table[] = {
|
||||||
NATIVE_METHOD(Seccomp, setPolicy, "()V"),
|
NATIVE_METHOD(Seccomp, setSystemServerPolicy, "()V"),
|
||||||
|
NATIVE_METHOD(Seccomp, setAppPolicy, "()V"),
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace android {
|
namespace android {
|
||||||
|
|||||||
Reference in New Issue
Block a user