13.5 MTE tag checking
Storing tags (13.4) does nothing by itself. Protection comes from tag checking: on a checked load or store, the PE compares the pointer’s logical tag with the allocation tag of every granule the access touches. This section covers which accesses are checked, the three reporting modes, how random tags are generated, and the escape hatch PSTATE.TCO.
Is this access checked?
An access is Tag Checked only if every condition below holds. This is the order in which to debug “why didn’t it fault?”:
- FEAT_MTE2 or higher is implemented, and allocation tag access is enabled for the EL:
SCR_EL3.ATA,HCR_EL2.ATAwhere applicable, andSCTLR_ELx.ATA/ATA0(13.6). - The memory’s final attribute is Tagged Normal (MAIR 0xF0, not withdrawn by stage 2).
- TBI applies to the address (13.3). The MTE4
MTXcontrols relax this. - The tag check fault mode for the EL is not NONE:
SCTLR_ELx.TCF, orSCTLR_EL1.TCF0for EL0 and for unprivilegedLDTR/STTRat EL1. PSTATE.TCO= 0.- The logical tag is not a match-all value under
TCMA0/TCMA1. - The instruction form is a checked form. Loads and stores whose base register is SP with an immediate offset (or none) are Unchecked, because the compiler is assumed to be accessing its own frame safely. PC-relative literal loads, instruction fetches, translation table walks and the tag instructions themselves are also unchecked.
The SP rule is the one that surprises people. A stack buffer overflow through x0 = sp + 16 is checked, but str x1, [sp, #16] is not. This is how compilers keep tagged stack slots cheap.
Fault modes: TCF and TCF0
| Field | Bits | Controls |
|---|---|---|
SCTLR_EL1.TCF | [41:40] | Accesses at EL1 |
SCTLR_EL1.TCF0 | [39:38] | Accesses at EL0 |
SCTLR_EL2.TCF / SCTLR_EL3.TCF | — | EL2 and EL3 respectively (with E2H = 1, SCTLR_EL2.TCF0 covers EL0 of the EL2&0 regime) |
| Value | Mode | On mismatch |
|---|---|---|
| 0b00 | NONE | Nothing; not checked |
| 0b01 | Synchronous | Synchronous Data Abort, precise, access not performed |
| 0b10 | Asynchronous | The access is performed, and a flag is set in TFSR_ELx/TFSRE0_EL1 |
| 0b11 | Asymmetric (FEAT_MTE3) | Reads synchronous, writes asynchronous |
Synchronous
A synchronous tag check fault is a Data Abort (EC 0x24 from a lower EL, or 0x25 from the current EL) with DFSC = 0b010001 (0x11), “Synchronous Tag Check Fault”. It is taken before the access has any architectural effect, ELR_ELx points at the faulting instruction, and FAR_ELx holds the faulting address. That address includes the logical tag in [59:56], while bits [63:60] are UNKNOWN without FEAT_MTE_TAGGED_FAR (13.3). For a multi-granule access (an LDP crossing granules, a SIMD load), take the exact rule for which address within the access FAR reports from DDI0487 rather than assuming it is the first byte. Linux delivers SIGSEGV/SEGV_MTESERR, and KASAN HW_TAGS prints a report with the allocation and free stacks.
Synchronous mode is precise and debuggable but costs the most, because the load cannot retire until the tag compare is resolved.
Asynchronous
In asynchronous mode the faulting access completes: a store has written memory and a load has returned data. The PE then sets a sticky bit:
| Register | Records faults from |
|---|---|
TFSRE0_EL1 | EL0 accesses |
TFSR_EL1 | EL1 accesses |
TFSR_EL2, TFSR_EL3 | EL2 and EL3 accesses |
Each register has TF0 [0] and TF1 [1]. TF0 is set for an address with bit 55 = 0 (the TTBR0 range) and TF1 for bit 55 = 1. No address, no PC and no exception are recorded. Software must poll the register, so detection is coarse-grained: “something in this task, since the last check”.
Asynchronous faults reach TFSR with no defined latency, so software must synchronise before reading:
- With
SCTLR_ELx.ITFSB[37] = 1, exception entry to ELx implicitly synchronises outstanding asynchronous faults intoTFSR_ELx/TFSRE0_EL1. Linux sets this, and its kernel entry path can therefore readTFSRE0_EL1.TF0directly (check_mte_async_tcfin entry.S) and raiseSIGSEGV/SEGV_MTEAERRon the next return to the task. - Without an exception, a
DSBis required. Before readingTFSR_EL1on the way out of the kernel, Linux doesdsb(nsh); isb();. Before clearingTFSRE0_EL1when a task execs a new image (mte_thread_init_user), it doesdsb ish.
// kernel exit: catch async faults from this kernel section
dsb nsh // make prior async tag faults visible in TFSR_EL1
isb
mrs x0, tfsr_el1
tbnz x0, #1, report_kasan // TF1: fault on a TTBR1 (kernel) address
The asynchronous mode is cheap, with a cost close to running MTE off on most microarchitectures, which is why it is Linux’s default per-CPU preferred mode. Its security value is detection after the fact: the corrupting store has already landed.
Asymmetric (MTE3)
Asymmetric mode makes loads synchronous and stores asynchronous. Its rationale is that tag-mismatched reads are the information-disclosure path and are cheap to check precisely, while stores are where synchronous checking hurts the store buffer. ID_AA64PFR1_EL1.MTE = 0b0011 indicates support. Linux’s per-CPU mte_tcf_preferred sysfs knob accepts asymm. A task’s prctl may request several modes at once, and the kernel then picks the CPU’s preferred mode among them.
Bring-up note: Async faults from EL3 or a secure partition land in
TFSR_EL3orTFSR_EL1and are never examined by anyone unless the firmware is written to check. EnablingTCF= async in firmware without a polling point gives you the cost and none of the benefit. Conversely, Normal-worldTFSR_EL1andTFSRE0_EL1contents are per-world state that EL3 must context-switch if both worlds use MTE.
Generating tags: GCR_EL1 and RGSR_EL1
IRG is the only random-tag source, and it is controlled by two registers:
| Register | Field | Meaning |
|---|---|---|
GCR_EL1 | Exclude [15:0] | Bitmap of tags IRG (and ADDG/SUBG) must not produce |
RRND [16] | 0: use the architected pseudo-random generator seeded by RGSR_EL1. 1: use an IMPLEMENTATION DEFINED random source | |
RGSR_EL1 | SEED [23:8] | Generator state |
TAG [3:0] | Last tag generated |
GCR_EL1 is used for IRG at both EL1 and EL0, but the kernel and user space want different exclusion sets. When KASAN HW_TAGS is enabled, Linux therefore rewrites GCR_EL1 on every kernel entry (mte_set_kernel_gcr) and on return to user (mte_set_user_gcr, which takes the task’s include mask from prctl(PR_SET_TAGGED_ADDR_CTRL)). Without KASAN it simply loads the task’s user value on context switch. RRND = 1 in both cases. The kernel’s exclusion keeps 0xF (its match-all tag under TCMA1) out of the random set.
RGSR_EL1 is UNKNOWN out of reset. Linux seeds it from CNTVCT_EL0 and forces a non-zero seed, because an implementation may treat RRND = 1 like RRND = 0, and a zero seed would make IRG return a constant. If Exclude excludes every tag, IRG returns tag 0.
Security note: An LFSR seeded from a counter is not a CSPRNG, and 4 bits are 4 bits: a blind guess succeeds with probability 1/15 or 1/16. MTE’s random tagging is a probabilistic defence that is strong against bugs and fuzzers but weaker against a patient attacker who can retry. Deterministic schemes, such as alternating odd and even tags for adjacent allocations, give guaranteed detection of linear overflows into the neighbour, which is why allocators combine both (13.6).
PSTATE.TCO
PSTATE.TCO (Tag Check Override, FEAT_MTE) disables tag checking for all accesses at the current EL while leaving tag access and the instructions working. It is written with MSR TCO, #imm and read with MRS Xt, TCO, and it is saved in SPSR_ELx (2.4).
Two behaviours matter:
- Exception entry sets
PSTATE.TCOto 1. A handler therefore starts with checking off until it explicitly clears TCO. Linux re-enables checking early in C entry (mte_disable_tco_entry) only if the kernel or the task uses checking, because toggling TCO is expensive on some microarchitectures. - Typical users of TCO are code that legitimately touches memory with a “wrong” tag: Linux’s
uaccess_enable()path (exclusives on user memory execute at EL1 and would otherwise be checked againstTCFrather thanTCF0),load_unaligned_zeropad, stack unwinders, and allocators walking metadata.
msr tco, #1 // suspend checks
ldr x1, [x0] // may cross into a differently-coloured granule
msr tco, #0 // resume
TCO is a context-local override and needs no barrier: an MSR immediate to PSTATE takes effect for following instructions in program order.
Checkpoint
Q13.5.1 A user program has TCF0 = async. An out-of-bounds store with a mismatched tag executes, then the program issues a write() system call. On the SVC entry, Linux reads TFSRE0_EL1 without a DSB first. Why is that sufficient?
- A.
SCTLR_EL1.ITFSB= 1, so taking the exception implicitly synchronises pending asynchronous tag check faults intoTFSRE0_EL1 - B. Asynchronous faults are written to
TFSRE0_EL1before the faulting store retires - C.
SVCis a DSB-equivalent for all memory effects - D. It is not sufficient; Linux misses the fault until the next context switch
Answer
A. ITFSB makes exception entry a synchronisation point for asynchronous tag check faults. Without it, a DSB would be needed, which is what Linux does on kernel exit. B is wrong because asynchronous recording has no defined latency, which is the whole reason synchronisation exists. C is wrong because an exception entry is a context synchronization event, not a DSB.
Read more: Arm ARM (DDI0487), SCTLR_EL1.ITFSB; TFSRE0_EL1
Q13.5.2 With TCF = sync at EL1, Tagged memory, TBI1 = 1 and TCMA1 = 0, which of these kernel accesses can take a synchronous tag check fault?
- A.
ldr x1, [sp, #32], where the stack slot has a different tag from SP - B. An instruction fetch from a Tagged page
- C.
ldr x1, [x2, #32], wherex2 = spwith a different logical tag from the granule atsp + 32 - D.
stg x2, [x3], where the tags of x3 and the granule differ
Answer
C. Only C is a checked access. A uses SP as the base with an immediate offset, which is architecturally Unchecked even though the value is the same as in C. B is an instruction fetch, which is never tag-checked. D is a tag store, which writes the allocation tag and is not checked.
Read more: Arm ARM (DDI0487), Tag Checked and Unchecked accesses
Q13.5.3 A secure partition enables MTE with TCF = sync, but its IRQ handler never faults on an obvious use-after-free, while the same bug faults in thread context. What is the most likely explanation?
- A. Asynchronous faults are always used in exception handlers
- B. Exception entry set
PSTATE.TCO= 1, and the handler never cleared it, so its accesses are not checked - C.
GCR_EL1.Excludediffers between handler and thread - D.
SPSR_EL1.TCOmust be set to 0 before the handler runs
Answer
B. Taking an exception sets PSTATE.TCO, which suppresses checking until software clears it with MSR TCO, #0. A is wrong because the TCF mode does not change on exception entry. C affects only which tags IRG generates. D confuses the saved state of the interrupted context (restored on ERET) with the handler’s current PSTATE.
Read more: Arm ARM (DDI0487), PSTATE.TCO; exception entry