Shadow in the Cache: Unveiling and Mitigating Privacy Risks of KV-cache in LLM Inference

Fuente: arXiv
Guardado en:
Detalles Bibliográficos
Autores principales: Luo, Zhifan, Shao, Shuo, Zhang, Su, Zhou, Lijing, Hu, Yuke, Zhao, Chenxu, Liu, Zhihao, Qin, Zhan
Formato: Preprint
Publicado: 2025
Materias:
Acceso en línea:
Etiquetas: Agregar Etiqueta
Sin Etiquetas, Sea el primero en etiquetar este registro!
_version_ 1866917358688272384
author Luo, Zhifan
Shao, Shuo
Zhang, Su
Zhou, Lijing
Hu, Yuke
Zhao, Chenxu
Liu, Zhihao
Qin, Zhan
author_facet Luo, Zhifan
Shao, Shuo
Zhang, Su
Zhou, Lijing
Hu, Yuke
Zhao, Chenxu
Liu, Zhihao
Qin, Zhan
contents The Key-Value (KV) cache, which stores intermediate attention computations (Key and Value pairs) to avoid redundant calculations, is a fundamental mechanism for accelerating Large Language Model (LLM) inference. However, this efficiency optimization introduces significant yet underexplored privacy risks. This paper provides the first comprehensive analysis of these vulnerabilities, demonstrating that an attacker can reconstruct sensitive user inputs directly from the KV-cache. We design and implement three distinct attack vectors: a direct Inversion Attack, a more broadly applicable and potent Collision Attack, and a semantic-based Injection Attack. These methods demonstrate the practicality and severity of KV-cache privacy leakage issues. To mitigate this, we propose KV-Cloak, a novel, lightweight, and efficient defense mechanism. KV-Cloak uses a reversible matrix-based obfuscation scheme, combined with operator fusion, to secure the KV-cache. Our extensive experiments show that KV-Cloak effectively thwarts all proposed attacks, reducing reconstruction quality to random noise. Crucially, it achieves this robust security with virtually no degradation in model accuracy and minimal performance overhead, offering a practical solution for trustworthy LLM deployment.
format Preprint
id arxiv_https___arxiv_org_abs_2508_09442
institution arXiv
publishDate 2025
record_format arxiv
spellingShingle Shadow in the Cache: Unveiling and Mitigating Privacy Risks of KV-cache in LLM Inference
Luo, Zhifan
Shao, Shuo
Zhang, Su
Zhou, Lijing
Hu, Yuke
Zhao, Chenxu
Liu, Zhihao
Qin, Zhan
Cryptography and Security
Artificial Intelligence
Computation and Language
The Key-Value (KV) cache, which stores intermediate attention computations (Key and Value pairs) to avoid redundant calculations, is a fundamental mechanism for accelerating Large Language Model (LLM) inference. However, this efficiency optimization introduces significant yet underexplored privacy risks. This paper provides the first comprehensive analysis of these vulnerabilities, demonstrating that an attacker can reconstruct sensitive user inputs directly from the KV-cache. We design and implement three distinct attack vectors: a direct Inversion Attack, a more broadly applicable and potent Collision Attack, and a semantic-based Injection Attack. These methods demonstrate the practicality and severity of KV-cache privacy leakage issues. To mitigate this, we propose KV-Cloak, a novel, lightweight, and efficient defense mechanism. KV-Cloak uses a reversible matrix-based obfuscation scheme, combined with operator fusion, to secure the KV-cache. Our extensive experiments show that KV-Cloak effectively thwarts all proposed attacks, reducing reconstruction quality to random noise. Crucially, it achieves this robust security with virtually no degradation in model accuracy and minimal performance overhead, offering a practical solution for trustworthy LLM deployment.
title Shadow in the Cache: Unveiling and Mitigating Privacy Risks of KV-cache in LLM Inference
topic Cryptography and Security
Artificial Intelligence
Computation and Language
url https://arxiv.org/abs/2508.09442