Memory Sanitization Techniques
- Memory sanitization is a set of techniques that enforce spatial and temporal safety, secure erasure, and protection against data poisoning in systems, storage, and AI models.
- It employs diverse methods including tag-based sanitizers, hybrid metadata schemes, and hardware-assisted pointer authentication, achieving metrics such as <1.2% false negatives in some implementations.
- Ongoing research addresses challenges like scalable tag-space management, adaptive thresholding, and holistic erasure protocols to balance precision, coverage, and performance.
Memory sanitization refers to a class of techniques and mechanisms for enforcing, verifying, or restoring desired invariants over memory contents or metadata—whether for spatial/temporal safety, privacy, poisoning resistance, erasure, or semantic trust. Approaches span systems-level allocation and pointer tracking, binary rewriting, hardware-specific tagging, persistent storage, runtime metadata, and even model-level interventions in machine learning, with the common aim of mitigating disclosure, corruption, or misuse risk.
1. Core Principles and Taxonomy
Memory sanitization encompasses a spectrum of enforcement domains:
- Spatial and Temporal Memory Safety: Preventing spatial violations (out-of-bounds, cross-object access) and temporal violations (use-after-free, double free) through dynamic checking and metadata.
- Persistent/Permanent Erasure: Guaranteeing the removal of all sensitive content from storage or memory, usually for security or regulatory compliance.
- Sanitization of Semantic or Knowledge State: In LLMs or data-driven systems, restricting or erasing learned or persisted (possibly poisoned or confidential) facts.
- Trust and Pattern-based Filtering: Restricting the propagation or retrieval of data items based on composite trust scores, decay, and rule-based patterns.
This holds across low-level systems (C/C++/Rust, allocators, kernels), binaries, hardware, persistent storage (SSD, flash), and AI models.
2. Systems-Level Memory Sanitizers: Design and Methodologies
Contemporary systems-level sanitizers rely on various mechanisms:
- Tag-based and Identity-based Sanitizers: Approaches such as HWASan, ClusterTag, and IdSan (Xie et al., 11 Sep 2025, Craaijo, 2020) attach per-pointer tags or object-identity metadata, with runtime checks at dereference points. Tags capture associations between pointers and intended objects; mismatches denote spatial/temporal violations.
- Tag collisions (spatial or temporal) arise with small tag spaces, requiring careful assignment and reuse strategies.
- Cluster-based allocators (e.g., ClusterTag) partition memory into clusters to maximize minimum/average/entropy of tag collision distances, minimizing probabilistic false negatives (Xie et al., 11 Sep 2025).
- Hybrid Metadata Schemes and Capability-Based Approaches: CUP (Burow et al., 2017) and SafeFFI (Braunsdorf et al., 23 Oct 2025) re-interpret pointer bits to encode capability IDs and offsets. These build global metadata tables, allowing precise bounds and liveness checks. CUP and SafeFFI also showcase instrumentation and optimization strategies, including heavy static analysis and boundary-based check elision.
- Hardware-Assisted Sanitizers: PACSan (Li et al., 2022) leverages ARM Pointer Authentication Codes (PACs) to seal metadata directly into pointers. Seals are authenticated at use sites, enforcing spatial and temporal safety by cryptographically binding pointer values to object identities and liveness. This approach offers low overhead, no false positives, and negligible false negatives.
- Allocator-Assisted and Combined Compiler-Allocator Systems: CAMP (Lin et al., 2024) enhances the heap allocator and compiler in lockstep. O(1) runtime metadata lookups and aggressive static elimination of checks are coordinated through compile-time analysis and runtime pointer neutralization, yielding both high detection capability and low overhead.
- Run-Time Partitioning and Selective Sanitization: PartiSan (Lettner et al., 2017) probabilistically partitions execution into sanitized and unsanitized slices, managing performance budgets while still covering code areas with high expected bug density.
- Binary-Only and Dynamic Sanitizers: IdSan (Craaijo, 2020) enables identity-based sanitization through dynamic binary instrumentation, supporting binaries without available source code but with higher runtime cost.
The table below synthesizes system sanitizer characteristics:
| Approach | Pointer/Obj. Tracking | Spatial/Temporal Coverage | Notable Optimizations |
|---|---|---|---|
| Tag-based | Per-pointer tag/key | Both if tag assignment | Clustered assignment, rotate |
| CUP | Capability ID/offset | Probabilistic temporal | Hybrid metadata, full libc |
| PACSan | PAC in ptr (HW) | Both, strong | Pointer auth, no FP/FN |
| CAMP | Range + escape table | Heap-only, strong | Static check elision, O(1) |
| SafeFFI | Safe/Raw ptr classes | Both (Rust/FFI) | Check hoisting at boundaries |
| PartiSan | Sanitization partition | Configurable via policy | Function-level switching |
| IdSan | Identity tags, binary | Stack/global/heap (not temp) | Per-bit meta, dynamic instr |
3. Persistent Storage and Flash Sanitization
Flash memory sanitization focuses on the irreversible removal of user data from storage devices, as required when re-provisioning or discarding media. Comprehensive analysis of USB drives shows that up to 12.2% of "new" low-cost USB sticks contain recoverable user data, with a 95% CI of (9.6%, 14.8%). Analytical findings demonstrate no reliable correlation of data persistence to NAND technology, chip manufacturer, or visible reuse marks; rather, batch effects and price orientation are predictive (Schneider et al., 20 May 2025).
Key techniques include:
- Physical or Logical Overwrite: Firmware-level "Secure Erase" commands for ATA, eMMC, NVMe, and explicit "Sanitize" or TRIM commands.
- Cryptographic Erasure: Sanitize by destroying device-level encryption keys, rendering all data unreadable even if blocks persist.
- Verification and Auditing: Read-back and logging protocols to validate the effectiveness of erasure.
Best practice mandates always using the highest-level erase primitive, supplemented by cryptographic key revocation where feasible, and anchoring results in auditable logs to support chain-of-custody analyses.
4. Memory Sanitization Beyond Systems: LLMs and Trust Enforcement
Memory sanitization principles apply in the domain of persistent or learned agent memory, especially in LLM-augmented agents vulnerable to poisoning attacks (Sunil et al., 9 Jan 2026). Here, sanitization is implemented as a runtime, trust-aware system supporting:
- Composite Trust Scoring: Each memory item is assigned a base trust score at append time, reflecting orthogonal safety signals. Scores decay exponentially over time: .
- Pattern-based Filtering: Regex and LLM-template detectors reject entries matching known poisoning templates.
- Threshold Calibration: Append- and retrieval-time checks enforce , with tuned to trade off FPs and FNs as per utility-security requirements.
Experimental results reveal that improper thresholding can lead to over-conservatism (all memory blocked) or overconfidence (poisoned items stored). Future work contemplates adaptive thresholds, real-effect verification, and ensemble guard agents for consensus-based memory acceptance.
In LLM knowledge sanitization, parametric model fine-tuning can be used to "erase" specific facts, substituting a harmless fixed phrase for forbidden knowledge (Ishibashi et al., 2023). The approach relies on LoRA adapters injected at MLP layers, trained only on a mix of (sanitization, retention) QA pairs. It achieves marked reductions in leakage (e.g., forget accuracy drops from 74% to 7%), robustness to extraction attacks, and maintains overall performance across unrelated tasks.
5. Quantitative Evaluation and Limitations
Systematic evaluation of memory sanitizers utilizes suites such as Juliet (CWE-122…CWE-416), SPEC CPU, and real-world CVEs. Key quantitative findings include:
- ClusterTag: 100% deterministic detection of covered faults, zero probabilistic misses (vs. up to 13.6% for alternative tag assignments), and minimum spatial collision distances vs. $1$ for random tags (Xie et al., 11 Sep 2025).
- PACSan: No false positives, negligible false negatives (), and average runtime overhead , with lower memory overhead than ASan (Li et al., 2022).
- CAMP: Heap-only, but 100% detection on all Juliet heap cases, real-world coverage of all 32 tested CVEs, and lowest overhead among strong heap sanitizers (Lin et al., 2024).
- SafeFFI: Reduces sanitizer dynamic check overhead by up to 98% in Rust/mixed language settings, with only 10–21% of original checks retained and up to 30% runtime overhead reduction relative to vanilla HWASan (Braunsdorf et al., 23 Oct 2025).
Well-understood structural limitations persist: incomplete stack/global/struct field coverage (ClusterTag, PACSan), high instrumentation or binary rewriting cost (IdSan), inherent reliance on per-pointer state or pointer-carrying ABIs (CUP, PACSan, SafeFFI), and gaps in concurrent or cross-module memory invalidation.
6. Theoretical Foundations: Symbolic Models and Formal Erasure
In security-oriented protocol work, memory sanitization (specifically erasure) is defined via formal symbolic models, for instance employing Dolev–Yao-style term algebra with distance constraints on attackers (Trujillo-Rasua, 2019). Under such models:
- Secure erasure is realized only if the adversary is -distant (i.e., not co-located with the prover), where for channel speed, round-trip threshold.
- Erasure protocols combine MAC authentication, nonce exchange, and n-round fast-phase responses, ensuring only the device in physical possession can produce required outputs.
- Trade-offs in communication complexity, adversarial model, and erasure proof come to the fore; increase in number of challenge rounds exponentially drives down the probability of a successful attack by an under-provisioned or distant adversary.
This formal foundation is critical for attestation, secure provisioning, and forensic soundness in hardware and embedded systems.
7. Open Problems and Research Directions
Memory sanitization research highlights several enduring and emerging directions:
- Tag-space and Metadata Scalability: As in ClusterTag and PACSan, optimizing assignment, management, and orthogonal usage of tags or IDs remains crucial, especially under hardware-imposed constraints.
- Boundary and Invariant Safety: Approaches like SafeFFI illustrate the benefits of tight integration between sanitizer instrumentation and language type systems, but further refinement for intra- and inter-procedural analysis (e.g., in concurrent or mixed-mode code) is needed.
- Adaptive and Composable Sanitization: Whether in LLM agents (memory trust thresholds, pattern coverage) or system sanitizers (dynamic partitioning), adaptivity, compositionality, and consensus-based mechanisms are active fields of exploration.
- Holistic and Auditable Erasure: For storage, melding protocol-level, cryptographic, and device-specific erasure into verifiable, certifiable flows is essential for privacy guarantees and legal clarity.
- Cross-Domain Synthesis: The structural analogs between runtime memory sanitization and knowledge sanitization in model-centric AI/ML systems invite further transfers—both in metrication (e.g., trust, collision distance) and in real-time risk management mechanisms.
Continued research aims to close precision-coverage-overhead tradeoffs and to extend formal and empirical guarantees across new hardware, language, and application domains.