diff options
author | 2020-04-03 16:07:13 -0700 | |
---|---|---|
committer | 2020-04-07 15:44:00 +0000 | |
commit | 4d4347c257a3d88e60b3ece823afc04b584aea01 (patch) | |
tree | c7fa7c3a565e2b3ab4d476101b3dbcbead87162a | |
parent | 9e76544ceed5ad366a337e8a7acd607634d163b6 (diff) |
Don't ask libc for PT feature w/o kernel support.
Check that the kernel supports the Tagged Pointers feature before asking
libc to disable/enable pointer tagging.
Bug: 153114333
Test: Build coral, note no messages from SetHeapTaggingLevel.
Test: atest CtsTaggingHostTestCases
Change-Id: Id5fbd731aa70f7b0a75525387479f6123628a012
Merged-In: Id5fbd731aa70f7b0a75525387479f6123628a012
-rw-r--r-- | core/java/com/android/internal/os/Zygote.java | 7 | ||||
-rw-r--r-- | core/java/com/android/internal/os/ZygoteInit.java | 8 | ||||
-rw-r--r-- | core/jni/com_android_internal_os_Zygote.cpp | 11 | ||||
-rw-r--r-- | services/core/java/com/android/server/am/ProcessList.java | 12 |
4 files changed, 30 insertions, 8 deletions
diff --git a/core/java/com/android/internal/os/Zygote.java b/core/java/com/android/internal/os/Zygote.java index ff03f1a1a2ab..34f4957735fe 100644 --- a/core/java/com/android/internal/os/Zygote.java +++ b/core/java/com/android/internal/os/Zygote.java @@ -1060,4 +1060,11 @@ public final class Zygote { */ @FastNative public static native int nativeParseSigChld(byte[] in, int length, int[] out); + + /** + * Returns whether the kernel supports tagged pointers. Present in the + * Android Common Kernel from 4.14 and up. By default, you should prefer + * fully-feature Memory Tagging, rather than the static Tagged Pointers. + */ + public static native boolean nativeSupportsTaggedPointers(); } diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java index ec1f516df5f3..c2b13c971020 100644 --- a/core/java/com/android/internal/os/ZygoteInit.java +++ b/core/java/com/android/internal/os/ZygoteInit.java @@ -757,9 +757,11 @@ public class ZygoteInit { Zygote.applyDebuggerSystemProperty(parsedArgs); Zygote.applyInvokeWithSystemProperty(parsedArgs); - /* Enable pointer tagging in the system server unconditionally. Hardware support for - * this is present in all ARMv8 CPUs; this flag has no effect on other platforms. */ - parsedArgs.mRuntimeFlags |= Zygote.MEMORY_TAG_LEVEL_TBI; + if (Zygote.nativeSupportsTaggedPointers()) { + /* Enable pointer tagging in the system server. Hardware support for this is present + * in all ARMv8 CPUs. */ + parsedArgs.mRuntimeFlags |= Zygote.MEMORY_TAG_LEVEL_TBI; + } /* Enable gwp-asan on the system server with a small probability. This is the same * policy as applied to native processes and system apps. */ diff --git a/core/jni/com_android_internal_os_Zygote.cpp b/core/jni/com_android_internal_os_Zygote.cpp index ea3c0fa9fc3c..38b88ec4af45 100644 --- a/core/jni/com_android_internal_os_Zygote.cpp +++ b/core/jni/com_android_internal_os_Zygote.cpp @@ -2405,6 +2405,15 @@ static jint com_android_internal_os_Zygote_nativeParseSigChld(JNIEnv* env, jclas return -1; } +static jboolean com_android_internal_os_Zygote_nativeSupportsTaggedPointers(JNIEnv* env, jclass) { +#ifdef __aarch64__ + int res = prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0); + return res >= 0 && res & PR_TAGGED_ADDR_ENABLE; +#else + return false; +#endif +} + static const JNINativeMethod gMethods[] = { {"nativeForkAndSpecialize", "(II[II[[IILjava/lang/String;Ljava/lang/String;[I[IZLjava/lang/String;Ljava/lang/" @@ -2440,6 +2449,8 @@ static const JNINativeMethod gMethods[] = { (void*)com_android_internal_os_Zygote_nativeBoostUsapPriority}, {"nativeParseSigChld", "([BI[I)I", (void*)com_android_internal_os_Zygote_nativeParseSigChld}, + {"nativeSupportsTaggedPointers", "()Z", + (void*)com_android_internal_os_Zygote_nativeSupportsTaggedPointers}, }; int register_com_android_internal_os_Zygote(JNIEnv* env) { diff --git a/services/core/java/com/android/server/am/ProcessList.java b/services/core/java/com/android/server/am/ProcessList.java index 595275d20154..cb6990a82f00 100644 --- a/services/core/java/com/android/server/am/ProcessList.java +++ b/services/core/java/com/android/server/am/ProcessList.java @@ -1846,11 +1846,13 @@ public final class ProcessList { runtimeFlags |= Zygote.USE_APP_IMAGE_STARTUP_CACHE; } - // Enable heap pointer tagging, unless disabled by the app manifest, target sdk level, - // or the compat feature. - if (app.info.allowsNativeHeapPointerTagging() - && mPlatformCompat.isChangeEnabled(NATIVE_HEAP_POINTER_TAGGING, app.info)) { - runtimeFlags |= Zygote.MEMORY_TAG_LEVEL_TBI; + if (Zygote.nativeSupportsTaggedPointers()) { + // Enable heap pointer tagging if supported by the kernel, unless disabled by the + // app manifest, target sdk level, or compat feature. + if (app.info.allowsNativeHeapPointerTagging() + && mPlatformCompat.isChangeEnabled(NATIVE_HEAP_POINTER_TAGGING, app.info)) { + runtimeFlags |= Zygote.MEMORY_TAG_LEVEL_TBI; + } } runtimeFlags |= decideGwpAsanLevel(app); |