Skip to main content
Be Bitwise

Pointer Authentication & Memory Tagging

Processor Security Features · CPU Architectures track

7 min read

In this module

Protecting Pointers in Hardware

Buffer overflows and use-after-free bugs corrupt memory, but the actual security damage almost always traces back to corrupting pointers — return addresses, function pointers, vtable pointers. If the hardware could spot pointer corruption, a huge swathe of exploits would die in their tracks. ARM's Pointer Authentication Codes (PAC) and Memory Tagging Extension (MTE) take a swing at exactly that, in silicon.

ARM Pointer Authentication (PAC)

ARMv8.3 brought PAC. The CPU signs a pointer with a cryptographic key, tucking the signature into the unused upper bits of the 64-bit pointer. Before the pointer is used, the CPU verifies the signature. If the pointer has been mangled — by a buffer overflow, say — the check fails.

Signing uses a tweakable MAC (message authentication code) with three inputs:

  1. The pointer value itself
  2. A secret key (stored in a system register, not accessible to user-mode software)
  3. A context value (typically the stack pointer or a diversifier)
text
Original pointer: 0x0000_7fff_dead_beef
PAC bits: 0x3A7F_0000_0000_0000 (computed from key + value + context)
Signed pointer: 0x3A7F_7fff_dead_beef

The values are illustrative: exactly which upper bits hold the PAC, and how many there are, depends on the virtual address size and on whether the top byte is reserved for other uses (more on that below).

ARM provides dedicated instructions for common use cases:

  • PACIASP / AUTIASP: sign/verify return address using instruction key A and the stack pointer as context. Used in function prologues and epilogues.
  • PACIBSP / AUTIBSP: same but using instruction key B. Allows different signing domains.
  • PACDA / AUTDA: sign/verify data pointers.
nasm
; Function prologue with PAC
paciasp ; sign return address (LR) with key A and SP
stp x29, x30, [sp, #-16]! ; save frame pointer and signed return address
; Function epilogue
ldp x29, x30, [sp], #16 ; restore signed return address
autiasp ; verify and strip PAC from return address
ret ; return (faults here if the PAC was invalid)

A failed AUT doesn't fault on the spot on most cores. It strips the PAC but flips bits in the result so the pointer is no longer a valid address, and the fault only arrives when the following ret or branch tries to use it. CPUs with the ARMv8.6 FPAC feature fault in the AUT instruction itself.

Apple Silicon (M1/M2/M3) turns PAC on by default for all system software. iOS and macOS system libraries sign return addresses, function pointers, and even some data pointers. Overhead is about 1% on Apple's hardware — almost nothing.

PAC Security Strength

How many PAC bits you get depends on the virtual address space. With a 48-bit virtual address space on ARM, up to 15 upper bits are available for the PAC, giving 2^15 = 32,768 possible values. If top-byte ignore (TBI) is on, which Linux enables for user-space data pointers so the top byte can carry tags, the PAC shrinks to about 7 bits for those pointers. A brute-forcer has to guess right; each wrong guess crashes the program. For remote attacks where each restart spins up new keys, that's a serious deterrent. For local attacks with cheap retries, 15 bits of entropy may not be enough on its own — but it still raises the bar a long way above no protection at all. The PACMAN attack (2022) showed another route on Apple's M1: use speculative execution to test PAC guesses without crashing at all.

ARM Memory Tagging Extension (MTE)

ARMv8.5 added MTE, which staples a 4-bit tag onto every 16-byte aligned memory granule and a matching 4-bit tag onto every pointer. On every memory access, the hardware checks pointer tag against memory tag. A mismatch is a memory safety violation, full stop.

How the allocator wires MTE in:

  1. malloc(64) allocates 64 bytes, picks a random tag (0-15), and uses STG (Store Tag) to write that tag onto all 4 granules of memory.
  2. The returned pointer carries the same tag in bits 59:56. That's inside the top byte, which Top Byte Ignore leaves out of address translation, so the tag doesn't change which byte gets accessed.
  3. The program uses the tagged pointer like any other; every load and store quietly verifies the tags.
  4. When free() runs, the allocator rewrites the memory's tag to a different random value. The caller's pointer still has the old tag.
  5. Use the pointer after free, and tags mismatch. Hardware fires.

Buffer overflows get caught because adjacent allocations end up with different tags. Stepping past the allocation boundary lands in a region with a different tag, and the access faults.

With only 16 possible tags, detection is probabilistic: a stale or wild pointer has a 1 in 16 chance of carrying the right tag by luck. Allocators close that gap for the most common bug by never giving neighbouring allocations the same tag, so a linear overflow into the next chunk is always caught. Like PAC, MTE has also been probed with speculative execution: the 2024 TikTag work leaked tags this way.

MTE has three modes:

  • Synchronous: tag mismatches fault immediately (precise detection, some overhead)
  • Asynchronous: tag mismatches are recorded and reported later (less overhead, less precise)
  • Asymmetric: synchronous for reads, asynchronous for writes (compromise)

The simulator below starts with three 32-byte chunks, A, B and C. Write past the end of A and see the fault, then free A and use the stale pointer. Call malloc(32) again to reuse A's slot and try the stale pointer once more: now it only gets caught if the new tag differs, so keep an eye on the missed counter. Flip to async mode and the same overflow goes through, with the report turning up at the next system call and no address attached.

Memory tagging: catch overflows and use-after-free

Every 16-byte granule has a 4-bit tag, and every pointer carries a 4-bit tag in bits 59:56. Each load and store compares the two. Allocate, write, free and reuse chunks, then watch which bugs the hardware sees.

Tag-check mode

Heap granules and their tags

  1. +0x00
    1
    A
  2. +0x10
    1
    A
  3. +0x20
    9
    B
  4. +0x30
    9
    B
  5. +0x40
    C
    C
  6. +0x50
    C
    C
  7. +0x60
    0
    unused
  8. +0x70
    0
    unused

Offsets from the heap base 0x0000721A403000 (illustrative). Each chunk is 32 bytes in 2 granules. Tag 0 marks memory that was never handed out.

Pointers

  • A0x010000721A403000live · tag 1
  • B0x090000721A403020live · tag 9
  • C0x0C0000721A403040live · tag C
Valid accesses
0
Bugs caught
0
Bugs missed
0

Note. malloc(32) returned C = 0x0C0000721A403040. Its 2 granules now carry tag C.

Event log
  1. Note: malloc(32) returned A = 0x010000721A403000. Its 2 granules now carry tag 1.
  2. Note: malloc(32) returned B = 0x090000721A403020. Its 2 granules now carry tag 9.
  3. Note: malloc(32) returned C = 0x0C0000721A403040. Its 2 granules now carry tag C.
Why 4 bits is enough, mostly

Top Byte Ignore means the CPU leaves bits 63:56 out of address translation, so the tag rides along for free. Four bits give 16 tags, and a stale or wild pointer whose tag is effectively random matches its target 6.3% of the time (1 in 16). Those bugs get through.

Adjacent overflows don't rely on luck. Like Android's Scudo allocator, this one never gives a chunk the same tag as the granules on either side, so running off the end of a chunk into the next granule always faults. It also retags freed memory with a different tag, so a use-after-free right after free() always faults. Once the slot is reused, the new tag is random again.

MTE can't see inside a granule. With a chunk size that isn't a multiple of 16, the bytes between the end of the chunk and the end of its last granule share its tag. Sync mode stops the bad access before it lands; async mode is cheaper but lets it land and reports later without an address. Asymmetric mode, not shown here, checks reads synchronously and writes asynchronously.

Intel CET: Control-flow Enforcement Technology

Intel CET ships two complementary mechanisms:

Shadow Stacks: a second, hardware-protected stack that holds only return addresses. Every CALL pushes the return address onto both the regular stack and the shadow stack. Every RET compares them. If they differ (because a buffer overflow trampled the regular stack's return address), the CPU faults.

The shadow stack lives in a special memory region that only call and return instructions can write to. Software can't poke at it directly, which stops attackers from rewriting the shadow stack to match their corrupted return address.

Indirect Branch Tracking (IBT): every valid indirect jump or call target has to be preceded by an ENDBRANCH (ENDBR32/ENDBR64) instruction. Land an indirect branch anywhere else and the CPU faults. ROP/JOP attacks lose most of their gadgets — only instructions marked as legitimate entry points are reachable.

Combining Protections

The four mechanisms cover different ground:

  • PAC stops tampering with individual pointer values
  • MTE catches spatial (overflow) and temporal (use-after-free) memory errors
  • CET Shadow Stacks lock down backward-edge control flow (returns)
  • CET IBT locks down forward-edge control flow (indirect calls and jumps)

Here's what that looks like from the attacker's side. The same overflow writes the same kind of chain twice. Step each one and see where it dies (addresses are illustrative).

x86-64 with CET shadow stacks

The overflow has written the chain. Press Step to let the function return.

Stack (SP →)
1.0x401233→pop rdi; ret
2.0x7FFFF7F7A698→pointer to the /bin/sh string
3.0x7FFFF7DF2D70→system
Code (Gadgets)
0x401233pop rdi; ret
pop rdi; ret
0x7FFFF7DF2D70system
libc system()
A shadow-stack check happens on every ret, so the chain fails at its first link.

AArch64 with PAC return signing

The overflow has written the chain. Press Step to let the function return.

Stack (SP →)
1.0x400A3C→gadget 1
2.0x400B10→gadget 2
Code (Gadgets)
0x400A3Cgadget 1
ldp x29, x30, [sp], #16
ret
0x400B10gadget 2
mov x0, x19
ret
Forging the signature needs the key, which user code can't read, or a signing gadget the attacker can reach.

Stack them with ASLR and NX and exploitation gets genuinely expensive. An attacker has to defeat multiple independent hardware checks simultaneously, each demanding a different technique or information leak. That's not impossible — but it's a different class of problem from the bugs these protections guard against.