Skip to content

Commit 6e129a4

Browse files
committed
Add command line tool to control MTE boot state.
Change-Id: I24271eb642a2a908fe6053a14b48d0780d5ad3a0
1 parent 2f5dc1b commit 6e129a4

File tree

4 files changed

+100
-0
lines changed

4 files changed

+100
-0
lines changed

mtectrl/Android.bp

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (C) 2022 The Android Open Source Project
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
cc_binary {
16+
name: "mtectrl",
17+
srcs: ["mtectrl.cc"],
18+
shared_libs: [
19+
"libbootloader_message",
20+
"libbase",
21+
],
22+
init_rc: ["mtectrl.rc"],
23+
}

mtectrl/OWNERS

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
3+
4+
5+

mtectrl/mtectrl.cc

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (C) 2022 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include <android-base/logging.h>
18+
#include <android-base/strings.h>
19+
#include <bootloader_message/bootloader_message.h>
20+
21+
#include <iostream>
22+
23+
int main(int argc, char** argv) {
24+
if (argc != 2) {
25+
std::cerr
26+
<< "Usage: " << argv[0]
27+
<< " [none|memtag|memtag_once|memtag_kernel|memtag_kernel_once]\n";
28+
return 1;
29+
}
30+
std::string value = argv[1];
31+
misc_memtag_message m = {.version = MISC_MEMTAG_MESSAGE_VERSION,
32+
.magic = MISC_MEMTAG_MAGIC_HEADER};
33+
for (const auto& field : android::base::Split(value, ",")) {
34+
if (field == "memtag") {
35+
m.memtag_mode |= MISC_MEMTAG_MODE_MEMTAG;
36+
} else if (field == "memtag-once") {
37+
m.memtag_mode |= MISC_MEMTAG_MODE_MEMTAG_ONCE;
38+
} else if (field == "memtag-kernel") {
39+
m.memtag_mode |= MISC_MEMTAG_MODE_MEMTAG_KERNEL;
40+
} else if (field == "memtag-kernel-once") {
41+
m.memtag_mode |= MISC_MEMTAG_MODE_MEMTAG_KERNEL_ONCE;
42+
} else if (field != "none") {
43+
LOG(ERROR) << "Unknown value for arm64.memtag.bootctl: " << field;
44+
return 1;
45+
}
46+
}
47+
std::string err;
48+
if (!WriteMiscMemtagMessage(m, &err)) {
49+
LOG(ERROR) << "Failed to apply arm64.memtag.bootctl: " << value << ". "
50+
<< err;
51+
return 1;
52+
} else {
53+
LOG(INFO) << "Applied arm64.memtag.bootctl: " << value;
54+
return 0;
55+
}
56+
}

mtectrl/mtectrl.rc

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright (C) 2022 The Android Open Source Project
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
on property:arm64.memtag.bootctl=*
16+
exec -- /system/bin/mtectrl ${arm64.memtag.bootctl}

0 commit comments

Comments
 (0)