Merge "[MTE] Parse MTE sysprop in system_server" am: 4d7b7a71d6
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1575891 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: I08b48cb584c9cd727a23457721a50ae4a8b1a2e6
This commit is contained in:
@@ -1096,4 +1096,11 @@ public final class Zygote {
|
|||||||
* fully-feature Memory Tagging, rather than the static Tagged Pointers.
|
* fully-feature Memory Tagging, rather than the static Tagged Pointers.
|
||||||
*/
|
*/
|
||||||
public static native boolean nativeSupportsTaggedPointers();
|
public static native boolean nativeSupportsTaggedPointers();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current native tagging level, as one of the
|
||||||
|
* MEMORY_TAG_LEVEL_* constants. Returns zero if no tagging is present, or
|
||||||
|
* we failed to determine the level.
|
||||||
|
*/
|
||||||
|
public static native int nativeCurrentTaggingLevel();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -791,9 +791,19 @@ public class ZygoteInit {
|
|||||||
Zygote.applyInvokeWithSystemProperty(parsedArgs);
|
Zygote.applyInvokeWithSystemProperty(parsedArgs);
|
||||||
|
|
||||||
if (Zygote.nativeSupportsMemoryTagging()) {
|
if (Zygote.nativeSupportsMemoryTagging()) {
|
||||||
/* The system server is more privileged than regular app processes, so it has async
|
/* The system server has ASYNC MTE by default, in order to allow
|
||||||
* tag checks enabled on hardware that supports memory tagging. */
|
* system services to specify their own MTE level later, as you
|
||||||
parsedArgs.mRuntimeFlags |= Zygote.MEMORY_TAG_LEVEL_ASYNC;
|
* can't re-enable MTE once it's disabled. */
|
||||||
|
String mode = SystemProperties.get("arm64.memtag.process.system_server", "async");
|
||||||
|
if (mode.equals("async")) {
|
||||||
|
parsedArgs.mRuntimeFlags |= Zygote.MEMORY_TAG_LEVEL_ASYNC;
|
||||||
|
} else if (mode.equals("sync")) {
|
||||||
|
parsedArgs.mRuntimeFlags |= Zygote.MEMORY_TAG_LEVEL_SYNC;
|
||||||
|
} else if (!mode.equals("off")) {
|
||||||
|
/* When we have an invalid memory tag level, keep the current level. */
|
||||||
|
parsedArgs.mRuntimeFlags |= Zygote.nativeCurrentTaggingLevel();
|
||||||
|
Slog.e(TAG, "Unknown memory tag level for the system server: \"" + mode + "\"");
|
||||||
|
}
|
||||||
} else if (Zygote.nativeSupportsTaggedPointers()) {
|
} else if (Zygote.nativeSupportsTaggedPointers()) {
|
||||||
/* Enable pointer tagging in the system server. Hardware support for this is present
|
/* Enable pointer tagging in the system server. Hardware support for this is present
|
||||||
* in all ARMv8 CPUs. */
|
* in all ARMv8 CPUs. */
|
||||||
|
|||||||
@@ -2526,6 +2526,36 @@ static jboolean com_android_internal_os_Zygote_nativeSupportsTaggedPointers(JNIE
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static jint com_android_internal_os_Zygote_nativeCurrentTaggingLevel(JNIEnv* env, jclass) {
|
||||||
|
#if defined(__aarch64__)
|
||||||
|
int level = prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0);
|
||||||
|
if (level < 0) {
|
||||||
|
ALOGE("Failed to get memory tag level: %s", strerror(errno));
|
||||||
|
return 0;
|
||||||
|
} else if (!(level & PR_TAGGED_ADDR_ENABLE)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// TBI is only possible on non-MTE hardware.
|
||||||
|
if (!mte_supported()) {
|
||||||
|
return MEMORY_TAG_LEVEL_TBI;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (level & PR_MTE_TCF_MASK) {
|
||||||
|
case PR_MTE_TCF_NONE:
|
||||||
|
return 0;
|
||||||
|
case PR_MTE_TCF_SYNC:
|
||||||
|
return MEMORY_TAG_LEVEL_SYNC;
|
||||||
|
case PR_MTE_TCF_ASYNC:
|
||||||
|
return MEMORY_TAG_LEVEL_ASYNC;
|
||||||
|
default:
|
||||||
|
ALOGE("Unknown memory tagging level: %i", level);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#else // defined(__aarch64__)
|
||||||
|
return 0;
|
||||||
|
#endif // defined(__aarch64__)
|
||||||
|
}
|
||||||
|
|
||||||
static const JNINativeMethod gMethods[] = {
|
static const JNINativeMethod gMethods[] = {
|
||||||
{"nativeForkAndSpecialize",
|
{"nativeForkAndSpecialize",
|
||||||
"(II[II[[IILjava/lang/String;Ljava/lang/String;[I[IZLjava/lang/String;Ljava/lang/"
|
"(II[II[[IILjava/lang/String;Ljava/lang/String;[I[IZLjava/lang/String;Ljava/lang/"
|
||||||
@@ -2565,6 +2595,8 @@ static const JNINativeMethod gMethods[] = {
|
|||||||
(void*)com_android_internal_os_Zygote_nativeSupportsMemoryTagging},
|
(void*)com_android_internal_os_Zygote_nativeSupportsMemoryTagging},
|
||||||
{"nativeSupportsTaggedPointers", "()Z",
|
{"nativeSupportsTaggedPointers", "()Z",
|
||||||
(void*)com_android_internal_os_Zygote_nativeSupportsTaggedPointers},
|
(void*)com_android_internal_os_Zygote_nativeSupportsTaggedPointers},
|
||||||
|
{"nativeCurrentTaggingLevel", "()I",
|
||||||
|
(void*)com_android_internal_os_Zygote_nativeCurrentTaggingLevel},
|
||||||
};
|
};
|
||||||
|
|
||||||
int register_com_android_internal_os_Zygote(JNIEnv* env) {
|
int register_com_android_internal_os_Zygote(JNIEnv* env) {
|
||||||
|
|||||||
Reference in New Issue
Block a user