arXiv:2611.06138cs.CRNov 2026

Manuscript Offprint

arXiv:2611.06138

KVGuard: A KV Cache Safety Checker for LLM Serving Systems

Jonguk Cheong, Myungbin Hwang, Eulgyu Kim, Byoungyoung Lee

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Jonguk Cheong

Seoul National University

Seoul, Korea

jdal3031@snu.ac.kr

Eulgyu Kim

Seoul National University

Seoul, Korea

eulgyukim@snu.ac.kr

Myungbin Hwang

Seoul National University

Seoul, Korea

auddl1020@snu.ac.kr

Byoungyoung Lee

Seoul National University

Seoul, Korea

byoungyoung@snu.ac.kr

Abstract

Modern LLM serving systems manage the KV cache through PagedAttention, a custom GPU allocator that partitions a single CUDA-allocated region into fixed-size physical blocks and maps each request to those blocks through a CPU-built block table. This block-based design exposes a previously unstudied class of memory safety bugs in the KV cache, including double-free, use-after-free, out-of-bounds access, uninitialized read, and permission violation, which silently corrupt outputs or break request isolation without ever crashing the system. Existing memory sanitizers cannot detect them, because they reason about CUDA-level addresses rather than KV cache blocks, requests, and block tables, and their redzone- and quarantine-based designs do not fit the scarce GPU memory budget of LLM serving.

This paper presents KVGUARD, the first systematic memory-safety abstraction for KV cache management in LLM serving systems. KVGUARD maintains a compact shadow block for each physical KV block, recording per-request permission and per-entry initialization, and uses this metadata to perform five safety checks across the PagedAttention workflow, spanning CPU allocation, block table construction and translation, and GPU-side block table lookup and KV entry access. Each check fires at the boundary that introduced the violation, enabling early detection during development rather than reporting downstream output corruption many requests later. A prototype of KVGUARD on vLLM and SGLang covers all 29 historical real-world KV cache safety bugs collected from the two systems' patch histories. KVGUARD further found 8 previously unknown safety violations while reporting no false positives. It adds 3.0% and 7.4% geomean TPOT overhead on Qwen 2.5 14B on vLLM and SGLang and at most 0.11% of the KV cache in memory overhead, two orders of magnitude below NVIDIA Compute Sanitizer on the same workloads.

1 Introduction

Modern LLM serving systems treat the KV cache as a first-class GPU resource, since throughput is dominated

by how efficiently per-request key and value vectors are allocated, tracked, and reused [9, 12, 18, 23, 29]. To manage this resource at scale, state-of-the-art systems such as vLLM, SGLang, and TensorRT-LLM adopt PagedAttention [9, 15, 31]. PagedAttention reserves one large GPU buffer via cudaMalloc, partitions it into fixed-size physical KV cache blocks, and assigns these blocks to requests through a CPU-side allocator and a CPU-to-GPU block table that GPU kernels consume at runtime.

This block-based design, however, exposes LLM serving systems to a class of memory safety bugs that has not been studied for the KV cache. The KV cache management layer is structurally a custom allocator built on top of a single cudaMalloc region, and is therefore vulnerable to the same bug families as heap allocators: double-free, use-after-free, out-of-bounds access, uninitialized read, and permission violation. For example, one recent vLLM bug leaves stale slot-mapping entries for the padding rows of a CUDA graph, so the padding rows write into blocks that belong to live requests, which read the overwritten values back as their own KV vectors and silently produce corrupted outputs. Table 1 lists similar real-world bugs across allocation, block table construction, and GPU kernel access, all of which corrupt outputs, break request isolation, or leak KV state without ever crashing the system.

Existing memory safety mechanisms cannot detect these bugs. The two natural candidates are traditional memory corruption detectors such as ASan [21], SoftBound [13], and tagged-memory systems [1, 14, 25], and GPU memory debugging tools such as NVIDIA Compute Sanitizer [16]. Both reason about addresses and CUDA-level allocations, not about KV cache blocks, requests, and block tables. A wrong access that follows a stale or out-of-bounds block table entry therefore still produces an in-range address and passes the check. Their redzone- and quarantine-based designs are also poorly matched to LLM serving, where GPU memory is scarce and KV cache capacity directly limits batch size and context length.

This paper presents KVGUARD, the first systematic memory-safety abstraction for KV cache management in LLM serving systems. The key idea of KVGUARD is to maintain a compact shadow block for each physical KV block, and to check the serving system's behavior against this metadata across the entire KV cache management workflow. Each shadow block records two fields: a per-request permission field that captures which requests hold the block and with what access mode, and a per-entry initialization field that records whether each KV entry has been written within the block's current lifetime. Because the serving system never reuses a request index, the per-request permission also inherently captures the block's current lifetime.

Using this shadow metadata, KVGUARD performs five safety checks at distinct points along the KV cache management workflow: CPU allocation events, CPU block table construction, CPU-to-GPU block table translation, GPU block table lookup inside a kernel, and KV cache entry access inside a kernel. Each check rejects a wrong allocator event, block table mapping, or kernel access at the first point where the required facts are available, pinpointing each violation at its origin rather than at a downstream symptom such as a corrupted output token. This design also avoids the redzones, padding, or delayed reuse that would consume scarce KV cache space.

The shadow block abstraction is not tied to any single serving system. It relies only on three properties shared by every PagedAttention-style system: a pool of fixed-size physical KV blocks, a CPU-built block table that maps logical to physical blocks per request, and GPU kernels that consume this block table. Systems such as vLLM, SGLang, and TensorRT-LLM all share these properties, so the same shadow block and the same five checks apply directly. KVGUARD is therefore positioned as a sanitizer in the style of ASan and NVIDIA Compute Sanitizer, targeting development-phase use cases such as continuous integration, pre-release validation of new kernels, and post-incident debugging, rather than always-on production.

KVGUARD is implemented on vLLM and SGLang, two popular open-source LLM serving systems. The evaluation shows that KVGUARD covers all 29 historical real-world bugs from the vLLM and SGLang patch histories listed in Table 1, and additionally found 8 previously unknown KV cache safety issues in current vLLM and SGLang execution paths during end-to-end serving. Across all evaluated workloads, KVGUARD reports no false positives, indicating that its checks fire only on genuine safety violations. KVGUARD adds 3.0% and 7.4% geomean TPOT overhead on Qwen 2.5 14B on vLLM and SGLang with all checks enabled and at most 0.11% of the KV cache in memory overhead, two orders of magnitude below NVIDIA Compute Sanitizer, which remains widely used during development despite its slowdown. The contribution of KVGUARD therefore lies not in production-grade performance, but in the KV cache safety

abstraction and the early detection it enables, which prevents KV cache bugs from remaining latent in the implementation and silently degrading model output across requests.

This paper makes the following contributions:

  • Bug class analysis. This paper analyzes KV cache memory safety as a new class of memory safety problem in LLM serving systems, characterized by 29 real-world bugs from the vLLM and SGLang patch histories.
  • Limitation analysis. This paper analyzes why traditional memory corruption detectors and GPU memory debugging tools cannot detect these bugs. The root cause is that they reason about addresses and CUDA-level allocations, not about KV cache abstractions.
  • KVGUARD design. This paper presents KVGUARD, the first systematic memory-safety abstraction for KV cache management. KVGUARD combines compact shadow blocks with five checks spanning the CPU allocator, the CPU and GPU block tables, and GPU memory accesses, catching each violation at the boundary that produced it rather than as downstream output corruption many requests later.
  • Implementation. This paper implements KVGUARD on vLLM and SGLang, covers all 29 historical bugs from the two systems' patch histories, and further uncovers 8 previously unknown safety violations in current vLLM and SGLang execution paths during end-to-end serving. KVGUARD reports no false positives and adds 3.0% and 7.4% geomean TPOT overhead on Qwen 2.5 14B on vLLM and SGLang with all checks enabled and at most 0.11% of the KV cache in memory overhead, two orders of magnitude below NVIDIA Compute Sanitizer.

References (27)