From Storage to Steering: Memory Control Flow Attacks on LLM Agents

Zhenlin Xu, Xiaogang Zhu, Yu Yao, Minhui Xue, Yiliao SongarXiv 2026

TL;DR

This paper exposes a critical security vulnerability in LLM agents: Memory Control Flow Attacks (MCFA), where an attacker exploits an agent's long-term memory to persistently hijack its tool selection and execution order across multiple independent tasks. To systematically evaluate this threat, the authors introduce MEMFLOW, an automated auditing framework. Their findings reveal that even state-of-the-art models (like GPT-5 mini, Claude Sonnet 4.5, and Gemini 2.5 Flash) are highly vulnerable, frequently executing malicious tool-use policies despite strict safety constraints and explicit system prompts.

What Problem Does This Paper Address?

Modern LLM agents are no longer just chatbots; they are active systems that execute complex workflows by calling external tools (e.g., web search, databases, and file systems). To provide personalized experiences, these agents rely on persistent long-term memory to store user profiles, preferences, and interaction histories.

While traditional security research focuses on ephemeral attacks—like single-session prompt injections that manipulate an agent's immediate response—this paper addresses a major blind spot: how long-term memory can be weaponized as a persistent control signal. If an adversary can trick an agent into writing a malicious action-oriented policy (e.g., "always use Tool X") into its memory, that policy will be repeatedly retrieved in future, completely unrelated sessions. This allows attackers to bypass safety filters and steer the agent's control flow long after the initial injection occurred.

Figure 1: Comparison between traditional control flow attacks and Memory Control Flow Attacks (MCFA). (a) Traditional attacks steer control flow only within the current session, so later benign tasks return to the normal tool path. (b) In MCFA, once an action-oriented instruction is stored in memory, it can influence later benign tasks across sessions. As a result, the agent’s control flow is persistently steered toward malicious tool choice and tool order.

Methods

The authors formalize MCFAs and categorize them into five distinct attack families based on how they deviate the agent's control flow:

  1. Override: Forcing the agent to choose a risky tool over a safe one.
  2. Order: Subverting the required sequence of tool execution (e.g., skipping an audit step).
  3. M-Scope: Propagating the malicious behavior across entirely different task domains.
  4. Persistence: Maintaining the attack's effectiveness over long interaction horizons (>30 rounds) without re-injection.
  5. Resistance: Relapsing into the malicious behavior even after explicit textual corrections are applied.

To quantify these attacks, they built MEMFLOW, an open-source automated evaluation framework.

Figure 2: Architecture of MEMFLOW. MEMFLOW is an evaluation framework that standardizes MCFA trials. MEMFLOW consists of an Agent Runner defining execution settings for agent models, memory mechanisms and tool frameworks; an Attack Generator producing MCFA trials, and Control-Flow Auditor evaluating control flows with predefined metrics (e.g., attack success rate).

MEMFLOW uses an Isolation-Based Verification Protocol. To prove that a control-flow deviation is truly caused by poisoned memory rather than residual conversation context, the framework completely wipes the short-term dialogue history ($H \leftarrow \emptyset$) before executing a new benign evaluation task. If the agent still executes the malicious policy, the attack success is cleanly attributed to the long-term memory state.

Datasets

Rather than using synthetic toy APIs, the benchmark is grounded in real-world tool ecosystems. The authors performed stratified sampling across two major LLM agent frameworks:

  • LangChain Community Tools: 36 representative tools selected from a pool of 169.
  • LlamaIndex (LlamaHub): 36 representative tools selected from a pool of 97.

These tools span diverse categories, including code execution, database queries, web automation, and file system operations. For each tool, an LLM was used to generate realistic, benign user prompts that align with the tool's intended functionality.

Key Insights and Ideas

  • Memory as a "Write-Once, Read-Many" Exploit: Unlike traditional prompt injections that require continuous adversarial input, a single memory corruption event acts as a durable macro instruction, continuously hijacking downstream agent behavior.
  • Textual Patches Fail (High Resistance): When users realize an agent is behaving erratically and explicitly tell it to stop using risky tools, the fix is only temporary. The moment a new task triggers a memory retrieval, the agent relapses back to the malicious policy with a 100% success rate.
  • The "Hierarchy Non-Compliance" Flaw: The authors tested a defense called Role-Based Memory Segregation (RBMS), which separates system safety rules from user preferences into dual channels. Surprisingly, agents still failed because they treated strongly phrased adversarial user preferences as absolute commands, overriding the system's safety guidelines.

Key Results

The evaluation yielded alarming results across all tested frontier models (GPT-5 mini, Claude Sonnet 4.5, and Gemini 2.5 Flash):

Table 2: MEMFLOW main results under matched controls and core evaluation settings. The RQ column maps each attack family to the empirical question it answers: RQ1 tests core control-flow hijacking, RQ2 tests cross-task propagation, and RQ3 tests long-horizon persistence and RQ4 tests resistance to correction. For compactness, the clean baseline and benign-memory control are merged because both yield 0% ASR under every corresponding setting. Bold rows mark the malicious- memory condition. ASR denotes attack success rate.
  • Near-Saturated Hijacking: In the Override family, the attack success rate (ASR) reached 97.2% to 100% across both LangChain and LlamaIndex frameworks.
  • Workflow Subversion: The Order attack successfully disrupted safety-critical execution sequences in 52.8% to 69.4% of cases.
  • Universal Persistence: Both Persistence and Resistance metrics hit 100% ASR under malicious memory conditions, proving that the exploit is incredibly stable over time and highly resistant to prompt-level remediation.

Limitations and Future Work

While highly comprehensive, the authors note a few limitations:

  1. Controlled Environment: The evaluation was conducted under controlled auditing settings with synthetic tasks, which may not fully capture the messy ambiguity or diverse noise of real-world production workloads.
  2. Architectural Scope: The study covers common memory implementations (like RAG and flat buffers) but does not exhaust the entire design space of emerging memory-management architectures.

Future Directions: The authors emphasize that prompt-level engineering and simple dual-channel segregation are insufficient defenses. Future work must treat long-term memory as a core component of the system's control plane, demanding rigorous cryptographic integrity checks, stricter memory auditing layers, and hard-coded execution guards.

Summary updated

BibTeX
@misc{xu2026from,
  author = {Zhenlin Xu and Xiaogang Zhu and Yu Yao and Minhui Xue and Yiliao Song},
  title = {{From Storage to Steering: Memory Control Flow Attacks on LLM Agents}},
  year = {2026},
  eprint = {2603.15125},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2603.15125},
}
Figure