Loading core/java/com/android/internal/os/Zygote.java +7 −0 Original line number Diff line number Diff line Loading @@ -1096,4 +1096,11 @@ public final class Zygote { * fully-feature Memory Tagging, rather than the static Tagged Pointers. */ 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(); } core/java/com/android/internal/os/ZygoteInit.java +13 −3 Original line number Diff line number Diff line Loading @@ -791,9 +791,19 @@ public class ZygoteInit { Zygote.applyInvokeWithSystemProperty(parsedArgs); if (Zygote.nativeSupportsMemoryTagging()) { /* The system server is more privileged than regular app processes, so it has async * tag checks enabled on hardware that supports memory tagging. */ /* The system server has ASYNC MTE by default, in order to allow * system services to specify their own MTE level later, as you * 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()) { /* Enable pointer tagging in the system server. Hardware support for this is present * in all ARMv8 CPUs. */ Loading core/jni/com_android_internal_os_Zygote.cpp +32 −0 Original line number Diff line number Diff line Loading @@ -2526,6 +2526,36 @@ static jboolean com_android_internal_os_Zygote_nativeSupportsTaggedPointers(JNIE #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[] = { {"nativeForkAndSpecialize", "(II[II[[IILjava/lang/String;Ljava/lang/String;[I[IZLjava/lang/String;Ljava/lang/" Loading Loading @@ -2565,6 +2595,8 @@ static const JNINativeMethod gMethods[] = { (void*)com_android_internal_os_Zygote_nativeSupportsMemoryTagging}, {"nativeSupportsTaggedPointers", "()Z", (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) { Loading Loading
core/java/com/android/internal/os/Zygote.java +7 −0 Original line number Diff line number Diff line Loading @@ -1096,4 +1096,11 @@ public final class Zygote { * fully-feature Memory Tagging, rather than the static Tagged Pointers. */ 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(); }
core/java/com/android/internal/os/ZygoteInit.java +13 −3 Original line number Diff line number Diff line Loading @@ -791,9 +791,19 @@ public class ZygoteInit { Zygote.applyInvokeWithSystemProperty(parsedArgs); if (Zygote.nativeSupportsMemoryTagging()) { /* The system server is more privileged than regular app processes, so it has async * tag checks enabled on hardware that supports memory tagging. */ /* The system server has ASYNC MTE by default, in order to allow * system services to specify their own MTE level later, as you * 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()) { /* Enable pointer tagging in the system server. Hardware support for this is present * in all ARMv8 CPUs. */ Loading
core/jni/com_android_internal_os_Zygote.cpp +32 −0 Original line number Diff line number Diff line Loading @@ -2526,6 +2526,36 @@ static jboolean com_android_internal_os_Zygote_nativeSupportsTaggedPointers(JNIE #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[] = { {"nativeForkAndSpecialize", "(II[II[[IILjava/lang/String;Ljava/lang/String;[I[IZLjava/lang/String;Ljava/lang/" Loading Loading @@ -2565,6 +2595,8 @@ static const JNINativeMethod gMethods[] = { (void*)com_android_internal_os_Zygote_nativeSupportsMemoryTagging}, {"nativeSupportsTaggedPointers", "()Z", (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) { Loading