Memory Tagging: A Memory Efficient Design

Aditi Partap, Dan BoneharXiv 2022 · DOI

Introduction

Memory corruption vulnerabilities, such as buffer overflows and use-after-free errors, remain a significant threat to software security, accounting for approximately 70% of critical vulnerabilities in major projects like Google Chrome. ARM’s Memory Tagging Extension (MTE) was introduced to mitigate these risks by "coloring" memory granules (16-byte blocks) with 4-bit tags. When a pointer attempts to access memory, the hardware verifies that the pointer's tag matches the memory's tag, throwing an exception on a mismatch.

However, the current MTE implementation faces two primary hurdles: low entropy and high storage overhead. A 4-bit tag offers only a 1-in-16 chance of detecting a mismatch, which is insufficient against sophisticated attackers. Furthermore, even these small tags require reserving 3% of system RAM. Quadrupling the tag size to 16 bits would increase overhead to over 12%, a cost prohibitive for production environments. This paper proposes a compressed, BTree-based data structure to support larger tags (up to 32 bits) while maintaining a minimal memory footprint.

Methodology: Compressed Tag Storage

The core insight of this research is that memory allocations are typically much larger than the 16-byte MTE granules. Analysis of common workloads reveals that most allocations span multiple granules, all of which share the same tag.

Figure 1: Average allocation sizes across various real-world workloads, demonstrating that most allocations are significantly larger than the 16-byte MTE granule.

By leveraging this redundancy, the authors move away from a "flat array" of tags toward a compressed storage model using Run-Length Encoding (RLE). Instead of storing a tag for every individual granule, the system stores the starting address and the associated tag for each contiguous "run" of memory.

Per-Page Adaptive BTree

To manage these RLE runs efficiently, the design implements a 4,5-BTree for every 4KB memory page. This structure allows for fast lookups and updates while significantly reducing the space required for tag storage.

Figure 3: The proposed BTree structure for managing compressed tags, where nodes store starting addresses and corresponding tags.

To ensure robustness, the system is adaptive: if a page becomes highly fragmented due to many small, differently-tagged allocations, it can revert to a standard flat tag array to bound memory usage. Additionally, the authors propose integrating Pointer Authentication Codes (PAC) with MTE using a cryptographic block cipher (QARMA) to provide both memory safety and pointer integrity within a 16-bit tag.

Evaluation and Results

The design was evaluated using memory allocation traces from five real-world workloads: apache2, axel, ffmpeg, md5sum, and pbzip2.

Key findings include:

  • Storage Efficiency: The BTree design fits within the existing 128-byte metadata budget for 57.9% to 99.9% of pages across all workloads, even when supporting 32-bit tags. Compared to a standard 4-bit flat array, the BTree uses 0.1x to 0.61x less space.
  • Security Enhancement: By increasing tag entropy to 16 or 32 bits, the probability of an attacker successfully guessing a tag drops from 6.25% to 0.0015% or lower.
  • Performance: Software emulation shows a modest 3% increase in lookup overhead (LDG) and a 12% increase in update overhead (STG). These figures are expected to decrease with dedicated hardware implementation in the Memory Management Unit (MMU).

Conclusion

This research demonstrates that hardware-software co-design can significantly enhance memory safety without the prohibitive costs of traditional tagging schemes. By utilizing compressed BTree structures, systems can achieve high-entropy protection against memory corruption while maintaining the efficiency required for production deployment. Future work will focus on hardware-level optimizations and exploring "Invalid Tags" to provide even stronger protection for freed memory.

Summary updated

BibTeX
@misc{partap2022memory,
  author = {Aditi Partap and Dan Boneh},
  title = {{Memory Tagging: A Memory Efficient Design}},
  year = {2022},
  eprint = {2209.00307},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2209.00307},
}
Figure