summaryrefslogtreecommitdiff
path: root/mtectrl
diff options
context:
space:
mode:
authorFlorian Mayer <fmayer@google.com>2022-01-19 14:03:44 -0800
committerFlorian Mayer <fmayer@google.com>2022-01-19 16:35:40 -0800
commit6e129a45bc8e0ddca3f29cd07e8dabcd1b3fec6e (patch)
treed69e7264f4b56c6877f184dc7ac303bff8e8a1cd /mtectrl
parent2f5dc1b054f03c9a54fa3de59f7a282993040e85 (diff)
downloadextras-6e129a45bc8e0ddca3f29cd07e8dabcd1b3fec6e.tar.gz
Add command line tool to control MTE boot state.
Change-Id: I24271eb642a2a908fe6053a14b48d0780d5ad3a0
Diffstat (limited to 'mtectrl')
-rw-r--r--mtectrl/Android.bp23
-rw-r--r--mtectrl/OWNERS5
-rw-r--r--mtectrl/mtectrl.cc56
-rw-r--r--mtectrl/mtectrl.rc16
4 files changed, 100 insertions, 0 deletions
diff --git a/mtectrl/Android.bp b/mtectrl/Android.bp
new file mode 100644
index 00000000..642f9f4a
--- /dev/null
+++ b/mtectrl/Android.bp
@@ -0,0 +1,23 @@
+// Copyright (C) 2022 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+cc_binary {
+ name: "mtectrl",
+ srcs: ["mtectrl.cc"],
+ shared_libs: [
+ "libbootloader_message",
+ "libbase",
+ ],
+ init_rc: ["mtectrl.rc"],
+}
diff --git a/mtectrl/OWNERS b/mtectrl/OWNERS
new file mode 100644
index 00000000..79625dfb
--- /dev/null
+++ b/mtectrl/OWNERS
@@ -0,0 +1,5 @@
+fmayer@google.com
+
+eugenis@google.com
+mitchp@google.com
+pcc@google.com
diff --git a/mtectrl/mtectrl.cc b/mtectrl/mtectrl.cc
new file mode 100644
index 00000000..0738f9ec
--- /dev/null
+++ b/mtectrl/mtectrl.cc
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <android-base/logging.h>
+#include <android-base/strings.h>
+#include <bootloader_message/bootloader_message.h>
+
+#include <iostream>
+
+int main(int argc, char** argv) {
+ if (argc != 2) {
+ std::cerr
+ << "Usage: " << argv[0]
+ << " [none|memtag|memtag_once|memtag_kernel|memtag_kernel_once]\n";
+ return 1;
+ }
+ std::string value = argv[1];
+ misc_memtag_message m = {.version = MISC_MEMTAG_MESSAGE_VERSION,
+ .magic = MISC_MEMTAG_MAGIC_HEADER};
+ for (const auto& field : android::base::Split(value, ",")) {
+ if (field == "memtag") {
+ m.memtag_mode |= MISC_MEMTAG_MODE_MEMTAG;
+ } else if (field == "memtag-once") {
+ m.memtag_mode |= MISC_MEMTAG_MODE_MEMTAG_ONCE;
+ } else if (field == "memtag-kernel") {
+ m.memtag_mode |= MISC_MEMTAG_MODE_MEMTAG_KERNEL;
+ } else if (field == "memtag-kernel-once") {
+ m.memtag_mode |= MISC_MEMTAG_MODE_MEMTAG_KERNEL_ONCE;
+ } else if (field != "none") {
+ LOG(ERROR) << "Unknown value for arm64.memtag.bootctl: " << field;
+ return 1;
+ }
+ }
+ std::string err;
+ if (!WriteMiscMemtagMessage(m, &err)) {
+ LOG(ERROR) << "Failed to apply arm64.memtag.bootctl: " << value << ". "
+ << err;
+ return 1;
+ } else {
+ LOG(INFO) << "Applied arm64.memtag.bootctl: " << value;
+ return 0;
+ }
+}
diff --git a/mtectrl/mtectrl.rc b/mtectrl/mtectrl.rc
new file mode 100644
index 00000000..de042376
--- /dev/null
+++ b/mtectrl/mtectrl.rc
@@ -0,0 +1,16 @@
+# Copyright (C) 2022 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+on property:arm64.memtag.bootctl=*
+ exec -- /system/bin/mtectrl ${arm64.memtag.bootctl}