自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
MTE 引导加载程序支持
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Android 13 引入了一个用户空间 ABI,用于将请求的 MTE 模式传达给引导加载程序。这可用于在具有硬件支持但未默认启用 MTE 的设备上启用 MTE,或在启用 MTE 的设备上停用 MTE。
引导加载程序支持
为了支持此 ABI,引导加载程序需要读取 misc
分区中的 misc_memtag_message
(在
bootloader_message.h 中定义)。
如果找到了有效的 misc_memtag_message
(MISC_VIRTUAL_AB_MAGIC_HEADER
匹配,并且版本号受支持),引导加载程序会计算
memtag = (default_memtag && !(misc.memtag_mode & MISC_MEMTAG_MODE_MEMTAG_OFF)) ||
misc.memtag_mode & MISC_MEMTAG_MODE_MEMTAG ||
misc.memtag_mode & MISC_MEMTAG_MODE_MEMTAG_ONCE
memtag_kernel = misc.memtag_mode & MISC_MEMTAG_MODE_MEMTAG_KERNEL ||
misc.memtag_mode & MISC_MEMTAG_MODE_MEMTAG_KERNEL_ONCE
default_memtag
是 SKU 的默认 memtag 开启/关闭设置。如果 memtag
为 true,引导加载程序会设置 MTE 标记预留,在较低的异常级别启用标记检查,并通过 DT 将标记预留区域传达给内核。如果 memtag
为 false,引导加载程序会将 arm64.nomte 附加到内核命令行。
如果 memtag_kernel
为 true,引导加载程序会将 kasan=on
附加到内核命令行。
引导加载程序必须在每次启动时清除 MISC_MEMTAG_MODE_MEMTAG_ONCE
和 MISC_MEMTAG_MODE_MEMTAG_KERNEL_ONCE
。
如果引导加载程序支持 fastboot oem mte
,则系统会将 MISC_MEMTAG_MODE_{MEMTAG, MEMTAG_ONLY, MEMTAG_OFF}
开启状态设置为 (1, 0, 0)
,并将其关闭状态设置为 (0, 0, 1)
,同时保留其他标志。
您应配置您的产品来构建 mtectrl
二进制文件,以支持 userspace。然后,设置 ro.arm64.memtag.bootctl_supported
系统属性,向系统表明您的引导加载程序支持 memtag 消息。
界面
设置
ro.arm64.memtag.bootctl_supported
属性后,您可以使用“开发者选项”菜单中的按钮,在启用 MTE 的情况下重新启动一次。其目标受众是希望使用 MTE 测试其应用的应用开发者。
系统属性
对于高级用途,系统属性 arm64.memtag.bootctl
可以接受以下值(采用逗号分隔列表形式):
-
memtag:持续启用 user-space MTE(设置
MISC_MEMTAG_MODE_MEMTAG
)
-
memtag-once:启用一次 user-space MTE(设置
MISC_MEMTAG_MODE_MEMTAG_ONCE
)
-
memtag-kernel:启用 kernel-space MTE(设置
MISC_MEMTAG_MODE_MEMTAG_KERNEL
)
-
memtag-kernel-once::启用 kernel-space MTE 一次 (
MISC_MEMTAG_MODE_MEMTAG_KERNEL_ONCE
)
-
memtag-off:停用 MTE(设置
MISC_MEMTAG_MODE_MEMTAG_OFF
)
必须重新启动系统,才能使新设置生效(由引导加载程序应用的设置)。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# MTE bootloader support\n\nAndroid 13 introduces an ABI for user-space to communicate the requested\nMTE mode to the bootloader. This can be used to enable MTE on devices that\nhave hardware support but do not ship with MTE enabled by default, or to\ndisable MTE on devices that do ship with it.\n\nBootloader support\n------------------\n\n\nTo support this ABI, your bootloader needs to read the\n`misc_memtag_message` (defined in\n[bootloader_message.h](https://android.googlesource.com/platform/bootable/recovery/+/android16-release/bootloader_message/include/bootloader_message/bootloader_message.h)) from the `misc` partition.\nIf a valid `misc_memtag_message` is found\n(`MISC_VIRTUAL_AB_MAGIC_HEADER` matches, and the version number is supported),\nthe bootloader computes \n\n```\nmemtag = (default_memtag && !(misc.memtag_mode & MISC_MEMTAG_MODE_MEMTAG_OFF)) ||\n misc.memtag_mode & MISC_MEMTAG_MODE_MEMTAG ||\n misc.memtag_mode & MISC_MEMTAG_MODE_MEMTAG_ONCE\n\nmemtag_kernel = misc.memtag_mode & MISC_MEMTAG_MODE_MEMTAG_KERNEL ||\n misc.memtag_mode & MISC_MEMTAG_MODE_MEMTAG_KERNEL_ONCE\n```\n\n\n`default_memtag` is the default memtag on/off setting for the\nSKU. If `memtag` is true, the bootloader sets up MTE tag\nreservation, enables tag checks in the lower exception levels, and\ncommunicates the tag reserved region to the kernel via DT. If\n`memtag` is false, the bootloader appends arm64.nomte to the\nkernel command line.\n\n\nIf `memtag_kernel` is true, the bootloader appends\n`kasan=on` to the kernel command line. Otherwise, it\nappends `kasan=off`.\n\n\nBootloader **MUST** clear `MISC_MEMTAG_MODE_MEMTAG_ONCE` and\n`MISC_MEMTAG_MODE_MEMTAG_KERNEL_ONCE` on every boot.\n\n\nIf the bootloader supports `fastboot oem mte`, then on sets\n`MISC_MEMTAG_MODE_{MEMTAG, MEMTAG_ONLY, MEMTAG_OFF}` to\n`(1, 0, 0)`, and off to `(0, 0, 1)`, while\npreserving the other flags.\n\n\nYou should configure your product to build the `mtectrl` binary\nfor userspace support. Then, set the\n`ro.arm64.memtag.bootctl_supported` system property to indicate\nto the system that your bootloader supports the memtag message.\n\nUser interface\n--------------\n\nWhen the `ro.arm64.memtag.bootctl_supported` property is set, a button in the Developer Options menu allows the user to reboot once with MTE enabled. The target audience for this is app developers that want to test their apps with MTE.\n\nSystem property\n---------------\n\n\nFor advanced use, the system property\n`arm64.memtag.bootctl` can take a comma-separated list of the\nfollowing values:\n\n- **memtag:** persistenly enable user-space MTE (set `MISC_MEMTAG_MODE_MEMTAG`)\n- **memtag-once:** enable user-space MTE once (set `MISC_MEMTAG_MODE_MEMTAG_ONCE`)\n- **memtag-kernel:** enable kernel-space MTE (set `MISC_MEMTAG_MODE_MEMTAG_KERNEL`)\n- **memtag-kernel-once:** enable kernel-space MTE once (`MISC_MEMTAG_MODE_MEMTAG_KERNEL_ONCE`)\n- **memtag-off:** disable MTE (set `MISC_MEMTAG_MODE_MEMTAG_OFF`)\n\n\nThe system has to be rebooted for the new setting to take effect (as it is\napplied by the bootloader)."]]