Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

13.6 MTE in a system

MTE is not only a CPU feature. Tags need physical storage that a memory controller manages, firmware has to reserve and protect that storage, hypervisors have to decide what guests may tag, and devices that write memory know nothing about tags. This section covers what each layer of the platform must do, the 2022 MTE extensions, how Linux uses MTE, where MTE’s guarantees end, and how to validate it before silicon.

The enable chain: SCR_EL3.ATA and HCR_EL2.ATA

Allocation tag access is gated top-down, in the pattern described in 17.3:

ControlWhen 0
SCR_EL3.ATA [26]Allocation tag access is disabled at EL2, EL1 and EL0. MSR/MRS of GCR_EL1, RGSR_EL1, TFSR_EL1, TFSR_EL2 and TFSRE0_EL1 from those ELs traps to EL3 (EC 0x18)
HCR_EL2.ATA [56]The same for EL1 and EL0, trapping to EL2
SCTLR_ELx.ATA/ATA0Tag access disabled for that EL, with no trap (13.4)

HCR_EL2.DCT [57] covers the case where HCR_EL2.DC = 1 forces a guest’s stage 1 to Normal Write-Back while its MMU is off: DCT makes that default attribute Tagged.

TF-A sets SCR_EL3.ATA in both the Secure and Non-secure contexts whenever FEAT_MTE2 is present (context_mgmt.c), and ENABLE_FEAT_MTE2 makes it context-switch the MTE system registers. If both worlds use MTE, the per-world GCR_EL1, RGSR_EL1, TFSR_EL1 and TFSRE0_EL1 must be saved and restored on every world switch, exactly as for any other EL1 state. A missing SCR_EL3.ATA typically shows up as Linux dying in mte_cpu_setup() on the GCR_EL1 write, with BL31 reporting an unhandled EC 0x18.

Tag storage: carve-outs and the memory controller

The architecture says only that each Tagged granule has an allocation tag. It says nothing about where the tag lives. In real systems:

  • The memory controller (or the interconnect’s home node) implements tag storage, usually as a dedicated region of DRAM holding 4 bits per 16 bytes, 1/32 of the covered range. On each Tagged access it fetches or updates the tag alongside the data, and it may cache tags. The PA-to-tag-address mapping, the tag cache and the tag error-handling behaviour are all IMPLEMENTATION DEFINED.
  • Firmware reserves the carve-out, normally in the stage that trains DRAM (TF-A BL2 or a platform-specific DDR initialisation). It programs the memory controller’s tag-region base and size registers, and it removes the carve-out from the memory map it hands on (the device tree /memory and /reserved-memory, or the UEFI memory map). Some products make this a boot-time choice: the bootloader reserves tag storage only when MTE is requested, which is why some phones need a reboot to turn MTE on.
  • The OS has no standard way to learn which ranges are taggable. Linux assumes that if every CPU supports MTE then all memory that it maps as Normal is taggable. A Linux RFC (2023–2024) proposed a device-tree description of tag storage so that the kernel could reuse unused tag memory for data. It was not merged. Consequently, firmware must not report DRAM that lacks tag storage as ordinary memory on an MTE-enabled system. What a Tagged access to tag-less memory does is IMPLEMENTATION DEFINED, and on some systems it can be an external abort.

Security note: The tag carve-out is a security asset. If the Normal world can write it through a PA alias or a DMA master, it can recolour Secure or Realm memory, which defeats MTE in that world. If it can read it, it learns another world’s tags. The carve-out must be covered by the same TZASC or GPT protection as the memory it describes (12.1, 12.4), and it should not be reachable by ordinary PA accesses at all.

Stage 2: what a guest may tag

A guest’s Tagged stage 1 mapping yields Tagged memory only if stage 2 allows it. Stage 2 must not degrade the memory below Normal Inner and Outer Write-Back, and DDI0487’s attribute-combining rules decide the final result (11.3, including the FEAT_S2FWB encodings). If stage 2 makes the page Non-cacheable or Device, the guest’s tags silently vanish: tag reads return zero, and nothing is checked.

Before FEAT_MTE_PERM, a hypervisor had no way to allow Normal WB access to a page while denying tag access to it. That matters because the hypervisor must be able to back the tags, by saving them on swap and copying them on migration. KVM therefore requires a VMM to opt in (KVM_CAP_ARM_MTE), and it refuses to map memory into an MTE guest unless the host VMA is VM_MTE_ALLOWED, which means anonymous or shmem memory. File-backed and device-backed memory is excluded.

FEAT_MTE_PERM (ID_AA64PFR2_EL1.MTEPERM [3:0]) adds a stage 2 NoTagAccess attribute. Linux’s stage 2 AT emulation treats MemAttr[3] in the FWB encoding as selecting the NoTagAccess variants; take the exact encodings, including the non-FWB case, from DDI0487. A guest access to the allocation tags of such a page (LDG/STG, or a checked access) takes a stage 2 permission fault to EL2, with ISS2.TagAccess (bit 9 of ISS2) set. The hypervisor can then allow ordinary data access to memory it cannot tag and either emulate or refuse the tag access.

Devices, DMA and the SMMU

DMA masters do not perform tag checks. In general they also cannot write tags, unless the device and the memory system implement a tag-aware path, which is rare and IMPLEMENTATION DEFINED. Three consequences follow:

  1. A device write into Tagged memory is never checked. A buggy or malicious device, or a driver that hands the device a stale buffer, corrupts memory without detection, whatever TCF says. The SMMU (11.5) still provides the address protection; MTE adds nothing on the device side.
  2. A device write leaves the allocation tags unchanged, or, on some memory systems, sets them to a defined value. CPU code reading the buffer afterwards must use a pointer whose tag matches whatever tags are there. Kernels usually avoid the issue by mapping DMA buffers untagged, or by accessing them with match-all pointers (TCMA1).
  3. Non-coherent DMA of Tagged memory follows 8.7, and it needs the tag-and-data maintenance forms if anything beyond the PE consumes the tags (13.4).

The 2022 MTE extensions (FEAT_MTE4 and friends)

Arm added a group of MTE extensions in 2022 (the v8.9/v9.4 wave; see DDI0487 A2 for exactly which are mandatory with FEAT_MTE4). They are discovered individually:

FeatureDiscoveryWhat it does
FEAT_MTE_CANONICAL_TAGSID_AA64PFR1_EL1.MTEXWith TCR_ELx.MTX0/MTX1 [60]/[61] set (a single MTX bit in the one-range TCR_EL2/TCR_EL3), memory that is not Tagged is treated as canonically tagged: an access to it with a non-canonical logical tag (not 0b0000 for bit 55 = 0, not 0b1111 for bit 55 = 1) is a tag check fault. This catches a tagged heap pointer straying into untagged memory
FEAT_MTE_NO_ADDRESS_TAGSID_AA64PFR1_EL1.MTEXMakes tag checking under MTX independent of TBI, so a regime can use MTE without making the whole top byte ignored (13.3)
FEAT_MTE_STORE_ONLYID_AA64PFR2_EL1.MTESTOREONLY [7:4]SCTLR_ELx.TCSO [59] / TCSO0 [58]: check only stores. This is cheaper and keeps write-corruption detection. Linux exposes it as PR_MTE_STORE_ONLY
FEAT_MTE_TAGGED_FARID_AA64PFR2_EL1.MTEFAR [11:8]FAR[63:60] valid on a synchronous tag check fault (13.3)
FEAT_MTE_PERMID_AA64PFR2_EL1.MTEPERM [3:0]Stage 2 NoTagAccess (above)

Linux integration in brief

  • User space. mmap/mprotect with PROT_MTE (anonymous and shmem only) selects the Tagged MAIR index. prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE | PR_MTE_TCF_SYNC | PR_MTE_TCF_ASYNC | (incl_mask << PR_MTE_TAG_SHIFT)) selects the modes and the tag include set, which the kernel turns into GCR_EL1.Exclude on return to user. Page tags are zeroed lazily the first time a page is mapped PROT_MTE (PG_mte_tagged), saved on swap-out, and copied on CoW and migration. Allocators that use it include Scudo (Android) and glibc (GLIBC_TUNABLES=glibc.mem.tagging=1). The selftests are in tools/testing/selftests/arm64/mte/.
  • Kernel. KASAN HW_TAGS (kasan=on kasan.mode=sync|async|asymm) tags slab and page allocations with random top-byte tags from 0xF0 upward, uses 0xFE for freed memory, and uses 0xFF for native pointers, which stay valid because of TCMA1. In async mode it checks TFSR_EL1 on kernel exit (13.5).

Security limits

  • 4 bits. A random guess matches with probability 1/16, or 1/15 with one tag excluded. An attacker who can retry, or who can crash a worker process without consequence, will eventually win. Deterministic colouring (adjacent allocations always differ) guarantees detection of linear overflow into the neighbour but not of arbitrary writes.
  • Granularity. Tags are per 16 bytes, so an overflow within a granule (into allocator padding or into a neighbouring field of the same object) is invisible. Intra-object overflows are invisible as well.
  • Asynchronous mode is detection, not prevention. The corrupting store lands, and the report arrives at the next kernel entry or exit.
  • Unchecked paths. SP-relative accesses, TCO windows, match-all tags, DMA and untagged aliases of the same PA all bypass checking.
  • Speculative tag-check bypass. Tag checks gate architectural access, but a mismatched speculative load can still bring data into the cache, and whether a speculative access faulted can itself leak. The 2024 TikTag work (on Pixel 8 class devices and Linux) and StickyTags showed gadgets that leak tag-check outcomes through cache timing, which let an attacker discover the tags and then make a correctly tagged architectural access. Treat allocation tags as not secret in the speculation threat model, and keep the usual Spectre mitigations in place (14.1, 14.3).

Validation note: validating MTE on pre-silicon.

Model setup. On FVP Base RevC AEM, set -C cluster0.memory_tagging_support_level=2 (or 3 for MTE3), mirror it for every cluster, and set -C bp.dram_metadata.is_enabled=1. Without the last parameter the model has no tag storage, and it does not warn about it. The MTE ID fields still look right, so tests pass or fail for the wrong reason. Build TF-A with ENABLE_FEAT_MTE2=1. On QEMU, -M virt,mte=on -cpu max (TCG) models tag memory as a separate address space.

Directed tests (18.5):

  1. STG and LDG round trip through two VA aliases of one PA, which shows the tag follows the PA.
  2. A negative test: a deliberate mismatch must produce EC 0x25 with DFSC 0x11 and FAR[59:56] equal to the pointer tag.
  3. Async: a mismatch sets TFSR_EL1.TF1, and is visible after DSB or after exception entry with ITFSB.
  4. TCMA1 match-all, the SP-relative unchecked rule, and PSTATE.TCO being set on exception entry.
  5. IRG never returns an excluded tag over many iterations, and a non-zero RGSR_EL1.SEED gives a non-constant sequence.
  6. Tag coherency: PE0 does STG, then a release; PE1 does an acquire, then a checked load, which must see the new tag (7.10).
  7. Tags survive DC CIGDVAC, the caches-off transition, and a cluster power-down with retention.
  8. DMA into Tagged memory leaves the tags as the SoC specification promises.

Confirming that checks really ran. The PMU common events MEM_ACCESS_CHECKED (0x4024), MEM_ACCESS_CHECKED_RD (0x4025) and MEM_ACCESS_CHECKED_WR (0x4026) count tag-checked accesses. If they read zero during a “passing” run, nothing was checked, typically because of ATA, TCF, TBI, MAIR or the model parameter.

Silicon-level. In emulation or RTL, inspect the memory controller’s tag region through a backdoor to confirm the PA-to-tag mapping, and inject tag-storage ECC errors to check the RAS reporting path (16.8). Finally, run the Linux MTE kselftests under the real firmware, which exercises SCR_EL3.ATA and the context switching end to end.

Checkpoint

Q13.6.1 On an FVP with MTE2 and DRAM metadata enabled, a directed test colours a buffer with STG and reads the tags back correctly with LDG. Yet a deliberately mismatched load never faults, with TCF = sync, and MEM_ACCESS_CHECKED stays at zero. The test code sets sp to the buffer’s (tagged) address and loads with ldr x1, [sp, #48]. What is the cause?

  • A. bp.dram_metadata.is_enabled is not set, so no tags are stored
  • B. SCR_EL3.ATA = 0
  • C. Loads that use SP as the base register with an immediate offset are architecturally Unchecked, so no check runs
  • D. The MAIR attribute is not Tagged Normal (0xF0)
Answer

C. The correct LDG read-back proves that tag storage exists (ruling out A), that allocation tag access is enabled (ruling out B, because with ATA disabled LDG reads zero), and that the memory is Tagged (ruling out D, because tags of untagged memory read as zero). What remains is a reason why the load is not checked, and the zero PMU count confirms it was not. The SP-relative immediate form is Unchecked by definition.

Read more: Arm ARM (DDI0487), Tag Checked and Unchecked accesses; PMU common event MEM_ACCESS_CHECKED

Q13.6.2 A hypervisor wants to give a guest Normal Write-Back access to a region of memory that the host cannot back with tag storage, while preventing the guest from relying on tags there. Which mechanism does this architecturally?

  • A. Clear HCR_EL2.ATA for the guest
  • B. FEAT_MTE_PERM: map the region with the stage 2 NoTagAccess attribute, so guest tag accesses there take a stage 2 permission fault to EL2
  • C. Map the region at stage 2 as Normal Non-cacheable
  • D. Set TCR_EL1.TCMA0 on the guest’s behalf
Answer

B. NoTagAccess is a per-page stage 2 control that leaves data access as Normal WB. A turns off tag access for the whole guest. C changes the data memory type and can create attribute mismatches with the guest’s mappings. D is guest-controlled state and only affects match-all tags.

Read more: Arm ARM (DDI0487), FEAT_MTE_PERM; stage 2 memory attributes; ESR_ELx ISS2.TagAccess

Q13.6.3 Linux runs with MTE in sync mode for a user process. A peripheral, via the SMMU, writes past the end of a DMA buffer into a neighbouring Tagged object. What does MTE detect?

  • A. Nothing at the time of the write, because device accesses are not tag-checked. Only the SMMU’s address permissions limit the device
  • B. A synchronous tag check fault reported to the process
  • C. An asynchronous fault recorded in TFSRE0_EL1
  • D. An SMMU event, because the SMMU checks the stream’s tags
Answer

A. Tag checking is performed by the PE for its own checked accesses. DMA masters, including those behind an SMMU, do not check tags, and SMMUv3 has no MTE checking. A later CPU access to the corrupted object may still fault if the device changed the tags, but the overflow itself is not caught. B and C would require a PE access.

Read more: Arm ARM (DDI0487), Memory Tagging Extension; SMMUv3 (IHI0070)