summaryrefslogtreecommitdiff
path: root/core/jni
diff options
context:
space:
mode:
authorMitch Phillips <mitchp@google.com>2021-02-04 09:38:40 -0800
committerMitch Phillips <mitchp@google.com>2021-02-04 15:28:07 -0800
commitb8d053a81567d431c192f030a9acc45b581cd1f5 (patch)
tree3b2cf1f52b35d573d63e48c7757c1fe07c0a245b /core/jni
parent0db5d441ad620d1a1f53b16c2cd0f462fe600827 (diff)
[MTE] Parse MTE sysprop in system_server
The system server inherits the ELF note from the Zygote, but should also be able to be overwritten by the system property. This needs to be manually parsed. Bug: 172365548 Test: 'adb shell setprop arm64.memtag.process.system_server 123' \ Test: ... kill the system_server, and and look in logcat for Test ... "Unknown memory tag level for the system server". Test: 'adb shell setprop arm64.memtag.process.system_server sync' \ Test: ... kill the system_server, and look in logcat for Test: ... "SetHeapTaggingLevel: tag level set to 3". Change-Id: Icda4ff141646086ae85d751b8af9b1fe94bfd7b5
Diffstat (limited to 'core/jni')
-rw-r--r--core/jni/com_android_internal_os_Zygote.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/core/jni/com_android_internal_os_Zygote.cpp b/core/jni/com_android_internal_os_Zygote.cpp
index d7001d8d36ea..903ecaef4938 100644
--- a/core/jni/com_android_internal_os_Zygote.cpp
+++ b/core/jni/com_android_internal_os_Zygote.cpp
@@ -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/"
@@ -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) {