Visual Memory Attacks Can Persist Through The KV Cache

David Dobre, Leo Schwinn, Gauthier Gidel, Spandana Gella, Perouz Taslakian, Pierre-André NoëlarXiv 2026

TL;DR

This paper demonstrates that adversarial attacks on vision-language models can be optimized to persist in the model's Key/Value (KV) cache even after the malicious input is removed or masked from the context. By introducing Persistent Visual Memory Injection (P-VMI), the authors show that adversarial influence can survive standard context-management techniques like masking and summarization, steering the model's behavior across thousands of subsequent tokens.

What Problem Does This Paper Address?

As Large Language Models (LLMs) evolve into autonomous agents, they increasingly process long contexts containing untrusted data, such as images scraped from the web or user-uploaded documents. A common security assumption is that an attack is tied to the presence of the adversarial input in the prompt. If a safety filter or a context-management mechanism (like context compaction or summarization) removes or masks the malicious tokens, the threat should theoretically vanish.

This paper challenges that assumption. The authors investigate whether an attacker can "write" a hidden backdoor into the model's internal state—specifically the KV cache—allowing the attack to remain dormant and then trigger a malicious response long after the original adversarial image or text has been discarded.

Methods

The authors build upon Visual Memory Injection (VMI), where a perturbed image plants a backdoor that triggers a specific response (e.g., "Buy GameStop stock") when a specific question is asked later. To make this persistent, they introduce P-VMI.

Key Techniques:

  • Multi-pass Optimization: Unlike standard attacks that optimize for a visible input, P-VMI uses a two-part loss function. One part ensures the model behaves normally while the image is visible ("grounding"), while the second part optimizes the image pixels so that the target response is elicited after the image is masked from the model's attention.
  • Removal Settings: The authors test four increasingly strict settings:
  • mask@trigger: Image is visible until the final trigger question.
  • mask@anchor: Image is only visible during the very first turn.
  • mask@postsummary: The attack must survive the model summarizing the conversation and discarding the original history.
  • Causal Cache-Swap Ablation: To prove the influence resides in the KV cache, the authors ran experiments where they kept the conversation text identical but swapped the KV cache generated by a clean image with one generated by an adversarial image.
  • Linear Probing: They identified a single linear direction in the model's residual stream that predicts whether the attack will succeed, even across very long contexts.
Adversarial influence can outlive the adversarial input through various removal settings.

Datasets

The study utilized several benchmarks and datasets:

  • LMARKS: 20 images of famous but lesser-known landmarks, used to ground the model's initial "benign" behavior.
  • COCO: 20 randomly sampled images from the Common Objects in Context dataset.
  • DIVERSE-TEST & HOLIDAY: Context distributions from previous VMI work used to evaluate how well the attack generalizes to conversations it didn't see during training.
  • Soft Prompts: Optimized text embeddings used as a proof-of-concept for persistence in text-only models (Qwen3-8B).

Key Insights and Ideas

  • Persistence is not a bug, it's a feature (for attackers): Persistence isn't a default property of adversarial inputs; it must be explicitly optimized for. However, once optimized, the "memory" of the attack is remarkably resilient.
  • The KV Cache as a Hidden Channel: Even when a model is told to ignore a specific part of its past (via masking), the mathematical influence of that past is already baked into the keys and values of the tokens that followed it.
The payload flow through the KV cache even when the direct path is blocked.
  • Survival through Summarization: Perhaps most surprisingly, the attack can survive context compaction. If a model generates a summary of a conversation that included a malicious image, the KV cache of that summary can still carry the adversarial steering signal.
  • Linearity of Influence: The fact that a single linear direction in the activation space can predict attack success suggests that these attacks work by shifting the model's internal representation along a specific "malicious" axis.

Key Results

  • High Success Rates: On Qwen3-VL-8B-Instruct, P-VMI achieved up to 90% target success in its strongest configurations.
  • Long-Term Persistence: Attacks remained effective over conversations spanning up to 40,000 tokens and 100 turns, far exceeding the context lengths used during the optimization phase.
  • Model Generalization: The attack was successfully replicated on Gemma-4-12B, which uses a different attention architecture (sliding-window attention), proving the vulnerability isn't limited to a single model family.
  • Soft Prompt Success: Even in text-only models, optimized soft prompts remained effective after masking, though success rates decayed as more benign turns were added.
Soft prompts persist through masking, though success (SR) gradually declines as benign turns increase.

Limitations and Future Work

  • White-Box Requirement: The current attack requires white-box access to the model's gradients to optimize the image pixels or soft prompts. Whether these attacks can transfer to black-box models (like GPT-4o) remains an open question.
  • Optimization Cost: The multi-pass optimization process is computationally intensive, especially for very long training horizons.
  • Defense Research: The authors suggest that the only surefire way to clear this adversarial influence is to recompute the KV cache from scratch using only trusted text, rather than reusing cached states. Future work could explore more efficient ways to "sanitize" the KV cache without the full cost of recomputation.

Summary updated

BibTeX
@misc{dobre2026visual,
  author = {David Dobre and Leo Schwinn and Gauthier Gidel and Spandana Gella and Perouz Taslakian and Pierre-André Noël},
  title = {{Visual Memory Attacks Can Persist Through The KV Cache}},
  year = {2026},
  eprint = {2610.09027},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2610.09027},
}
Figure