用推理路径检测提示注入攻击,防御时零开销复用缓存
RedVisor: Reasoning-Aware Prompt Injection Defense via Zero-Copy KV Cache Reuse
- 通过轻量适配器分析模型推理过程,定位攻击并引导安全响应
- 检测准确率高于现有方法,吞吐量提升且不损失正常任务性能
- 适合部署在大规模服务系统,尤其对延迟敏感的场景
大型语言模型越来越易受提示注入攻击,恶意指令藏于检索内容中可劫持模型执行流程。现有防御存在两难:基于预防的微调会因‘对齐代价’降低通用能力,基于检测的过滤则带来高昂延迟与内存开销。为此,我们提出 RedVisor,一个统一框架,融合检测系统的可解释性与预防策略的无缝集成。据我们所知,RedVisor 是首个利用细粒度推理路径实现攻击检测并指导模型安全响应的方法。通过部署在冻结主干上的轻量、可移除适配器实现,该适配器仅在推理分析阶段激活,用于生成可解释的攻击定位报告,并显式引导模型拒绝恶意指令;随后自动静默。该设计使主干模型在良性输入上保持原始性能,并支持新型 KV 缓存复用策略,消除解耦流水线中的冗余预填充计算。我们进一步将该防御集成至 vLLM 服务引擎,采用自定义内核优化。实验表明,RedVisor 在检测准确率和吞吐量上均优于当前最优防御,且对模型通用能力影响极小。
原文摘要 · Abstract (English)
Large Language Models (LLMs) are increasingly vulnerable to Prompt Injection (PI) attacks, where adversarial instructions hidden within retrieved contexts hijack the model's execution flow. Current defenses typically face a critical trade-off: prevention-based fine-tuning often degrades general utility via the "alignment tax", while detection-based filtering incurs prohibitive latency and memory costs. To bridge this gap, we propose RedVisor, a unified framework that synthesizes the explainability of detection systems with the seamless integration of prevention strategies. To the best of our knowledge, RedVisor is the first approach to leverage fine-grained reasoning paths to simultaneously detect attacks and guide the model's safe response. We implement this via a lightweight, removable adapter positioned atop the frozen backbone. This adapter serves a dual function: it first generates an explainable analysis that precisely localizes the injection and articulates the threat, which then explicitly conditions the model to reject the malicious command. Uniquely, the adapter is active only during this reasoning phase and is effectively muted during the subsequent response generation. This architecture yields two distinct advantages: (1) it mathematically preserves the backbone's original utility on benign inputs; and (2) it enables a novel KV Cache Reuse strategy, eliminating the redundant prefill computation inherent to decoupled pipelines. We further pioneer the integration of this defense into the vLLM serving engine with custom kernels. Experiments demonstrate that RedVisor outperforms state-of-the-art defenses in detection accuracy and throughput while incurring negligible utility loss.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。