Manuscript Offprint
arXiv:2611.06138KVGuard: A KV Cache Safety Checker for LLM Serving Systems
Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.
Jonguk Cheong
Seoul National University
Seoul, Korea
Eulgyu Kim
Seoul National University
Seoul, Korea
Myungbin Hwang
Seoul National University
Seoul, Korea
Byoungyoung Lee
Seoul National University
Seoul, Korea
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.
PagedAttention [9] is a widely used technique for managing the KV cache. It introduces a paging mechanism that maps each request's logical blocks to physical KV blocks in the GPU buffer, and is widely adopted by state-of-the-art LLM serving systems such as vLLM, SGLang, and TensorRT-LLM [9, 15, 31].
Figure 1 shows the overall workflow of PagedAttention. Initially, the serving system allocates a GPU buffer for the

Figure 1. Workflow of PagedAttention. LB denotes a logical block of a request, and PB denotes a physical KV cache block in the GPU buffer. Ref. denotes the reference count of each PB.
KV cache via cudaMalloc (①). The buffer is divided into KV cache blocks (e.g., from PB0 to PB3), where each block holds a specific number of KV cache entries (e.g., two entries in Figure 1). Serving systems allocate this large buffer once and keep reusing blocks to avoid repeatedly allocating and freeing GPU memory per request.
The serving system manages this buffer with a block pool, which records the reference count of each KV cache block (②). When a request arrives, the serving system divides the request's input context into logical blocks, and allocates the required number of KV cache blocks from the block pool. For instance, when Req0 arrives, the serving system allocates two logical blocks LB0 and LB1 for the request, and assigns them to two physical KV cache blocks PB0 and PB1. Thus, the block pool is initially updated as (1, 1, 0, 0), meaning that the first two PB0 and PB1 blocks are referenced by Req0. Then when Req1 arrives, two logical blocks LB0 and LB1 are allocated, each of which is assigned to PB0 and PB2. Thus, the block pool is updated to (2, 1, 1, 0), since PB0 is now shared by both requests and PB2 is referenced by Req1.
Such request-to-block assignments are written into a CPU block table (③), which maintains per-request mapping from logical block indices to physical block indices. Before launching each kernel, the serving system copies the relevant CPU block table rows (i.e., the mappings relevant to the requests) to GPU memory as a GPU block table (④).
After this copy, the GPU access path depends on the GPU block table rather than the CPU block table. During attention computation, the GPU attention kernel (denoted as Attn.) reads a GPU block table entry (⑤), obtains the physical block index, computes the physical location of the KV cache entries, and accesses them (⑥). Finally, the cache write kernel (denoted as CW) writes the newly computed key and value vectors into the KV cache buffer (⑦), using the same GPU-side mapping information to locate the destination KV cache entry.
Block Sharing and Permissions. Prefix caching [31], also called prefix sharing, is a mechanism that allows the serving system to reuse and share KV cache blocks across requests, demanding read/write permissions for the blocks. Specifically, when a prefix has already been computed, the same physical KV block is mapped by logical blocks of multiple requests, allowing those requests to share the same KV cache entries. These shared blocks are read-only: later requests may read them during attention, but they must not overwrite them. Thus, a request's CPU block table may contain both read-only blocks (i.e., shared prefix blocks) and allocated blocks that can be written by that request (i.e., private non-prefix blocks).
3 Motivation
KV cache memory safety matters because LLM serving systems keep per-request model state for concurrent requests inside a shared GPU allocation. A wrong KV cache access can corrupt future outputs, or break request isolation by letting one request read from or write into another request's KV cache state. Critically, these failures are hard to notice early because the wrong KV cache accesses still belong to the allocated KV cache buffer, so the system may simply produce degraded outputs instead of crashing or exposing explicit symptoms. This makes the root cause difficult to identify and fix, and motivates a memory safety mechanism for the KV cache.
3.1 Case Studies of Real-world KV Cache Safety Bugs
The KV cache management layer is structurally a custom memory allocator. The serving system partitions one cudaMalloc region into software-defined KV cache blocks. Then it manages those KV cache blocks with allocator primitives, where its interfaces are similar to malloc and free but with different semantics.
Thus, KV cache bugs exhibit a variety of allocator-style bugs, similar to those in traditional allocators yet with different root causes and consequences. Popular open-source LLM serving systems, such as vLLM [9] and SGLang [31], have experienced many KV cache safety bugs, which are summarized in Table 1. To showcase how these bugs violate KV cache safety, this section presents three case studies.
Case 1. Write to a Read-Only Block (B3). Figure 2a illustrates a bug where a request writes its new KV vectors into a shared, read-only block. In the example, Req0 and Req1 share the prefix It is, so both requests map their LB0 to PB0, and the reference count of PB0 is two. Thus, PB0 is read-only, and Req1 should write its next token job into the second entry of its private block PB2 (mapped by LB1). However, the bug is that the scheduler moves the write position of Req1 back into a block that is already read-only. Specifically, the scheduler moves the write position of Req1 back by two entries, from LB1 into LB0 (①). Following this position, the cache write
Table 1. Real-world KV cache safety bugs in vLLM and SGLang, each reproduced end to end and detected by KVGUARD. IDs starting with N are newly found by KVGUARD, and Fix PR is the pull request submitted after the finding.
| ID | System | Fix PR | Type | Check | Model Family | Workload | Newly Found by KVGUARD |
|---|---|---|---|---|---|---|---|
| B0 | vLLM | #47728 | Use-after-free | C1/C5 | Phi-3 | Async scheduling, SWA block pruning | - |
| B1 | vLLM | #48085 | Wrong block mapping | C3 | Qwen3.5 | Async scheduling, MTP, CUDA graphs | - |
| B2 | vLLM | #36580 | Permission violation | C3/C5 | Llama 3.2 | Chunked prefill, full CUDA graphs | - |
| B3 | vLLM | #58259 | Permission violation | C5 | Llama 3.2 | EAGLE3, async scheduling, streaming input | - |
| B4 | vLLM | #49146 | Block table OOB | C2 | Phi-3 | CPU KV offload, streaming input | - |
| B5 | vLLM | #51900 | Block table OOB | C2/C3 | Llama 3.2 | Streaming input, retained outputs | - |
| B6 | vLLM | #56709 | Uninitialized read | C5 | Step-3.5 | Multi-module MTP, CPU offload restore | - |
| B7 | SGLang | #24743 | Permission violation | C3/C5 | Gemma 4 | Hybrid SWA, decode CUDA-graph padding | - |
| B8 | SGLang | #1712 | Wrong block mapping | C3 | Qwen2.5 | Overlap scheduling | - |
| B9 | SGLang | #2051 | Use-after-free | C1/C3 | Qwen2.5 | Overlap scheduling | - |
| B10 | SGLang | #32555 | Use-after-free | C5 | Falcon-H1 | CUDA-graph decode after abort | - |
| B11 | SGLang | #40775 | Use-after-free | C1 | Qwen3 | C++ radix tree, shared prefix | - |
| B12 | SGLang | #39040 | Wrong block mapping | C3 | Millama | Paged cross-attention decode | - |
| B13 | SGLang | #32759 | Uninitialized read | C5 | DeepSeek-V4 | Radix prefix hit, SWA ring | - |
| B14 | SGLang | #38577 | Wrong block mapping | C2 | Llama 3.2 | Multi-LoRA, file-backed HiCache | - |
| B15 | SGLang | #45435 | Uninitialized read | C5 | Qwen3.5 | Mixed chunked prefill, overlap scheduling | - |
| B16 | SGLang | #32701 | Double free | C1/C2 | Qwen3.5 | Mixed chunks, parallel sampling | - |
| B17 | SGLang | #39283 | Use-after-free | C1 | Qwen3.5 | HiCache load, priority scheduling | - |
| B18 | SGLang | #36507 | Uninitialized read | C5 | Qwen3.5 | HiCache load, state copy-on-write | - |
| B19 | SGLang | #38187 | Wrong block mapping | C4 | Llama 4 | Local attention, FA3, CUDA-graph decode | - |
| B20 | SGLang | #42005 | Wrong block mapping | C3 | DeepSeek-V4 | P/D (NIXL), HiSparse | - |
| B21 | SGLang | #44081 | Uninitialized read | C5 | Llama 3.2 | EAGLE3, P/D (Mooncake), HiCache load | - |
| B22 | SGLang | #33477 | Uninitialized read | C5 | Falcon-H1 | Overlap, mixed chunk, parallel sampling | - |
| B23 | SGLang | #42072 | Out-of-bounds access | C1 | Falcon-H1 | Streaming session close | - |
| B24 | SGLang | #40223 | Uninitialized read | C5 | DeepSeek-V4 | EAGLE, persistent HiCache hit | - |
| B25 | SGLang | #46990 | Stale block mapping | C3 | Step-3.5 | SWA, EAGLE target verification | - |
| B26 | SGLang | #46986 | Stale block mapping | C3 | Step-3.5 | SWA, EAGLE draft-extend CUDA graphs | - |
| B27 | SGLang | #46990 | Stale block mapping | C3 | Gemma 3 | SWA, NGRAM verification | - |
| B28 | SGLang | #42509 | Uninitialized read | C5 | Llama 3.2 | PDMUX split prefill, EAGLE3 | - |
| N0 | vLLM | #42276 | Stale block mapping | C2 | Phi-3 | Chunked prefill, SWA eviction | ✓ |
| N1 | vLLM | #62871 | Wrong block reuse | C1 | Llama 3.2 | Async scheduling, rejected stream chunk | ✓ |
| N2 | vLLM | #64649 | Admission stall | C1 | Qwen3 | Async P2P KV load, speculative decoding | ✓ |
| N3 | SGLang | #45604 | Uninitialized read | C5 | Qwen3.5 | int8 state checkpoint, short request | ✓ |
| N4 | SGLang | #45605 | Permission violation | C3 | Llama 4 | P/D (NIXL), parallel sampling | ✓ |
| N5 | SGLang | #47390 | Use-after-free | C5 | Llama 3.2 | Speculative grammar decoding, overlap scheduling | ✓ |
| N6 | SGLang | #47392 | Stale block mapping | C2 | Qwen3.5 | NGRAM, streaming session | ✓ |
| N7 | SGLang | #47250 | Use-after-free | C1 | Llama 3.2 | P/D, EAGLE3, prefill cancellation | ✓ |
kernel translates LB0 through the GPU block table row of Req1 and obtains PB0 (②). It then writes the KV vectors of job into the second entry of PB0, overwriting those of is (③). As a result, Req1 violates the read-only permission of PB0, and both Req0 and every later request that reuses the prefix read job in place of is.
Case 2. Use-After-Free of a Cached Block (B11). Figure 2b illustrates a bug where the serving system frees a block that the prefix cache still holds. In the example, Req0 has finished, and the serving system keeps the KV vectors of the prefix "It is" in PB0 so that later requests can reuse them. Thus, when Req0 finishes, the serving system should drop only the reference of Req0 to PB0, decreasing its reference count from two to one, and only free the private block PB1. However, the bug is that the serving system misses that PB0 has been cached for future reuse. It frees PB0 as if it were another private block of Req0, setting its reference count to zero (①). When Req1 arrives, the block pool hands the freed PB0 to Req1, although the prefix "It is" is still mapped to PB0 (②). The cache write kernel then writes the KV vectors of "I see" for Req1 into PB0, overwriting the cached KV vectors of "It is" (③). As a result, any later request that reuses the cached prefix "It is" reads the KV vectors of Req1. For example, when Req2 arrives with the prefix "It is", it reuses PB0 due to the prefix match, and its attention kernel reads
the KV vectors of "I see" in place of those of "It is" (④), which is a use-after-free of a KV cache block. Here, the mapping from "It is" to PB0 acts like a dangling pointer in a conventional use-after-free bug, since it still points to PB0 after the block is freed and reused.
Case 3. Uninitialized Read of a Block (B6). Figure 2c illustrates a bug where a request reads a block that has never been written. When GPU memory runs short, serving systems can offload the KV cache blocks of earlier prompts to CPU memory and load them back into GPU memory when a later request shares the same prefix. In the example, the KV cache blocks of the prompt of Req1, "I see my dog", are found in CPU memory. Thus, the serving system assigns PB2 and PB3 to LB0 and LB1 of Req1, counts both blocks as computed, and should load both blocks from CPU memory. However, the bug is that the serving system loads only PB3 but still counts PB2 as computed (①). It decides which blocks to load by the attention window of the model, and misses PB2, an older block that Req1 still reads. Thus, the load fills PB3 with the KV vectors of "my dog", while PB2 keeps whatever it held before (②). When the attention kernel later runs for Req1, it reads PB2 as if it held the KV vectors of "I see" (③). As a result, Req1 reads uninitialized KV vectors. Worse, the serving system may later share PB2 through the prefix cache

(a) Write to a read-only block.
(b) Use-after-free of a cached block.
(c) Uninitialized read of a block.
Figure 2. Three real-world KV cache safety bugs in vLLM and SGLang. Each case shows a different way that a valid GPU address can still produce unsafe KV cache behavior.
as a complete block, spreading the uninitialized KV vectors to other requests.
3.2 Limitations: Using Existing Mechanisms for KV Cache Safety
A natural question is whether existing memory safety mechanisms can detect the KV cache bugs listed in Table 1. There are two classes of candidates: traditional memory corruption detectors and GPU memory debugging tools. However, neither captures the KV cache abstraction that the case studies violate. Both classes reason about addresses and CUDA-level allocations. They do not reason about KV cache-specific abstractions, such as KV cache blocks, requests, and block tables.
Limitations of Traditional Memory Corruption Detectors. Traditional detectors such as ASan [21], SoftBound [13], and tagged-memory systems [1, 14, 25] enforce memory safety using per-object or per-pointer metadata. However, this metadata is attached to addresses, pointers, or allocator-visible objects. It is not attached to the software-defined KV
cache blocks carved out of a single cudaMalloc region. Thus, the metadata cannot express whether Req0 is permitted to access PB1. It also cannot express whether a GPU block table entry maps the block that the CPU block table intended. As a result, the write to a read-only block in Case 1 and the use-after-free in Case 2 appear legal, because they stay inside one live allocation. The ASan-style sanitizers are not a good fit either. LLM serving treats GPU memory as a scarce resource, which directly impacts the batch size and context length managed by the KV cache. However, ASan-style sanitizers impose high memory overhead through redzones and quarantines.
Limitations of GPU Memory Debugging Tools. GPU memory debugging tools such as NVIDIA Compute Sanitizer [16] extend these checks to GPU kernels. Its memcheck tool reports out-of-bounds accesses, and its initcheck tool reports uninitialized reads at the CUDA allocation level. However, these tools share the same abstraction mismatch. They only see CUDA-visible allocations (i.e., an entire KV cache buffer), not the individual KV cache blocks. For example, memcheck treats the entire KV cache buffer as one valid region. Thus, a kernel that follows a stale or out-of-bounds KV block still appears to be following a valid address, so it passes the memcheck. initcheck has the same abstraction issue on the temporal side. Once any prior request has written a KV block, the underlying memory is considered initialized. An uninitialized read of the KV cache entry is therefore not reported by initcheck.
3.3 Design Requirements
The case studies ( ) and limitations ( ) together motivate three design requirements for a practical KV cache safety checker. A checker must reason about serving-level abstractions that traditional detectors cannot express ( ). Then it must catch various violations (Table 1) across the three boundaries that the case studies span: CPU allocation, CPU-to-GPU translation, and GPU access.
R1. Early Detection. A KV cache violation should be caught close to the operation that creates it, not after corrupted outputs appear. Case 2 and Case 3 both motivate this requirement. In Case 2, the wrong free of PB0 surfaces only when Req2, an unrelated later request, reads the overwritten KV vectors. In Case 3, Req1 reads uninitialized KV vectors from PB2 without any error, and the prefix cache may later spread them to other requests. In both cases, the corruption appears far from the operation that causes it. The checker should therefore validate each step: an allocation call when it is made, the CPU block table before it reaches the GPU, the GPU block table before a kernel consumes it, and a kernel access at the access point itself. Catching violations at the boundary that created them is significantly helpful for triaging and fixing, since it gives developers a precise failure site instead of a downstream symptom whose root cause may live many requests away.
R2. Low Memory and Runtime Overhead. KV cache checks must preserve GPU memory capacity, since KV cache size directly bounds batch size and context length. This rules out directly porting mechanisms that buy detection by reserving large extra memory, such as ASan-style redzones, shadow memory, and quarantines, as well as the allocation padding option provided by Compute Sanitizer [16] (§3.2).
This is not only a performance issue. When a checker consumes excessive device memory, the serving system has to shrink its KV cache, serve fewer concurrent requests, or may fail with CUDA out-of-memory before the workload runs. Compute Sanitizer documents that its tools can have a large memory footprint due to tracking data, and that memcheck padding increases device memory pressure and can cause additional CUDA out-of-memory errors [16]. Thus, a KV cache checker should be designed to add only the necessary amount of metadata and checks, and to avoid reserving large extra memory for redzones or quarantines.
R3. Seamless Integration. KV cache checks should fit the existing PagedAttention workflow without disturbing the single-buffer KV cache layout or the optimized GPU kernels. Cases 1 through 3 each manifest at a different boundary in this workflow, so the checker should attach to those same boundaries: the CPU allocator, the CPU-to-GPU block table commit, and the GPU access path.
4 Design
KVGUARD is a KV cache memory safety checker for LLM serving systems. The key mechanism of KVGUARD consists of two steps: maintaining shadow metadata for critical objects in KV cache management, and checking the serving system's behavior against the shadow metadata across the KV cache management workflow.
Figure 3 shows how KVGUARD realizes this mechanism across the PagedAttention workflow. KVGUARD first constructs and maintains shadow blocks that record the safety state of each physical KV block, by hooking CPU-side block allocation events ( ). KVGUARD then validates the CPU-side state that the serving system builds before each kernel launch, including allocation calls, the CPU block table, and the GPU block table, against the shadow blocks ( ). Finally, KVGUARD validates each KV cache access inside the kernel against the on-GPU shadow blocks ( ).
4.1 Shadow Block Construction
KVGUARD constructs and maintains a shadow block for each physical KV block to track its safety state. Each shadow block records two fields: permission and initialization. These two fields together capture the ownership and content-validity of a physical KV block along its lifetime, which are the properties required to decide whether any given KV cache access is safe. KVGUARD updates these fields by hooking CPU-side allocation-related events, and uses them to check the safety of operations related to KV cache accesses. This compact hook-based design satisfies R2 by avoiding redzones around KV blocks, and R3 by attaching to existing allocation events without changing the KV cache layout.
Permission. The permission field records whether the request can read or write a given physical block during the block's current lifetime. For each block, this permission field is per-request metadata, meaning that it tracks the permission of each request for the block. In effect, the request ID acts as a lifetime token, since the serving system never reuses an ID across requests. Hence, this per-request encoding inherently captures the lifetime of the block. Specifically, when a block is freed and later reallocated to a new request, the previous owner's permission is removed, and any new permission is recorded under a different request ID.
Using this permission field, KVGUARD detects three classes of unsafe accesses. In all three, the underlying check is the same: the permission field of the target block does not record

Figure 3. Overview of KVGUARD.
the required access for the requesting request. However, the three classes differ in why the record is missing.
First, the requesting request writes to a block that it should only read. Because the block is shared, the permission field records only read permission for the requesting request, so the check for the write fails. Taking Case 1 in §3.1 as an example, Req1 holds only read permission on the shared PB0, but its cache write kernel still writes the KV vectors of "job" into PB0. Second, the target block is not allocated to the requesting request. The permission field records only the actual owners of the block, if any, so the check fails for the requesting request. For example, in B2 (Table 1), padding rows of a CUDA graph write into blocks that belong to live requests. Third, the target block has been freed and reused after the requesting request acquired it. The entry of the requesting request was removed on free, so the permission field no longer records it, and the check fails. B0 and B10 in Table 1 fall into this class.
Figure 4 shows how KVGUARD updates the permission of PB0 across requests. Initially, PB0 is free and thus its permission is -, meaning that no permission is granted to any request. On Req0's allocation of PB0, KVGUARD grants write permission to Req0, making PB0 writable only by Req0. On prefix sharing, KVGUARD downgrades Req0's permission to read and also grants read permission to Req1, making PB0 read-only for both requests. As PB0 is freed per request, KVGUARD accordingly removes their permissions one by one. On Req2's later allocation of the same PB0, KVGUARD grants write permission to Req2; any later kernel that still refers to Req0 or Req1 finds no permission on PB0 and is rejected as a stale access.
Initialization. The initialization field tells whether each KV entry inside the block is properly initialized. It is worth noting that, while the permission field is per-block metadata, the initialization field is per-entry metadata. This per-entry
granularity for initialization is needed because a block can be partially written, and thus the remaining unwritten entries hold stale data, which can be NaN, garbage, or values written by a previous request (e.g., B13 and B24 in Table 1). To track the initialization state, KVGUARD sets the initialization bit on each write, and clears the bits in a block when the block is (re)allocated to a request. This allows KVGUARD to detect a read of an uninitialized entry that has not been written, which is described later (§4.3).
4.2 CPU-Side Checks
KVGUARD performs three CPU-side safety checks that validate the construction of CPU-side state. The serving system builds this state in three sequential steps: (i) allocation-related calls update the block pool, (ii) a CPU block table is assembled from the allocated blocks, and (iii) a GPU block table is derived from the CPU block table. Following the same order, KVGUARD places an individual check at each step, as detailed below. This step-by-step placement realizes R1 on the CPU side, since a wrong allocation, CPU block table, or GPU block table is rejected at the step that produced it, before the kernel ever launches.
C1. Checking Alloc/Share/Free Calls. KVGUARD checks the validity of the CPU-side block allocation-related calls using shadow blocks. Specifically, KVGUARD validates three allocation events: allocation, sharing, and free. For allocation, KVGUARD checks if the block is currently free, i.e., no request has permission in the corresponding shadow block. Otherwise, the allocation call is a bug because the block is still in use by another request (e.g., B11 in Table 1). For sharing, KVGUARD checks that the block is currently allocated, i.e., at least one request has permission. Otherwise, the sharing call is a bug because the block should be allocated before sharing. For free, KVGUARD checks that the block is currently referenced by a single request, i.e., only the freeing request has

Figure 4. Shadow block updates across CPU allocation events. Each panel shows the shadow block state of PB0.
permission. Otherwise, the free call is a bug, leading to either double-free (if no request has permission, e.g., B16) or use-after-free (if multiple requests have permission, e.g., B17). It is worth noting that, while KVGUARD uses shadow blocks to check the allocation decisions, those checks can also be performed using the block pool's reference counts, because the two are updated in the same way on the same events. This means that this check can be seamlessly integrated into the serving system.
C2. Checking CPU Block Table. KVGUARD checks the safety of the CPU block table using shadow blocks. Before launching a kernel, the serving system builds a CPU block table, mapping logical block indices to physical block indices for each request. To ensure the safety of this mapping construction, KVGUARD iterates over every entry in the request's CPU block table. For each entry, KVGUARD first obtains the mapped physical block index. Then KVGUARD obtains the shadow block's permission field corresponding to the physical block index, and checks if the permission grants the required access to the request.
For instance, as shown in Figure 3, if Req0's CPU block table maps LB0 to PB0, then KVGUARD checks whether the shadow block of PB0 grants read or write permission to Req0. On the other hand, if Req0's CPU block table maps LB1 to PB1, which is a stale mapping, then KVGUARD checks the shadow block of PB1 and detects that it does not grant permission to Req0.
C3. Checking GPU Block Table. KVGUARD checks if the GPU block table (to be transferred to GPU memory) is correctly built from the CPU block table. To this end, for every request row in the GPU block table, KVGUARD checks the following constraints: GPUBlockTable[req] [LB] is the same as CPUBlockTable[req] [LB]. This comparison catches a wrong or stale mapping that reaches the GPU block table under asynchronous or overlap scheduling (e.g., B1 and B8 in Table 1), as well as failures in the copy from CPU state to GPU state.
4.3 GPU-Side Checks
After CPU-side checks, KVGUARD further checks the safety of the KV cache access inside GPU kernels. To support these GPU-side checks, KVGUARD first copies the shadow blocks to GPU memory before kernel launch. Then it performs two different checks using the shadow blocks: GPU block table lookups (C4) and KV cache entry accesses (C5). These
in-kernel checks complete R1 by reporting a violation at the access point itself, rather than as a downstream output corruption many requests later.
C4. Checking the GPU Block Table Lookup. When the kernel looks up a GPU block table to locate the physical block for a logical block, KVGUARD checks if the GPU block table entry is a valid one for the current request. A valid lookup must satisfy two conditions: the entry must belong to the current request's block table row, and the logical block index must be within the entries that the request is allowed to use. To achieve this, KVGUARD reuses the block table bounds checked before launch. At runtime, when a kernel reads a GPU block table entry, KVGUARD checks that the lookup is within the valid entries of the current request's row. This catches real-world bugs such as B19 (Table 1).
C5. Checking the KV Cache Entry Access. Lastly, to ensure the safety of the actual KV cache access, KVGUARD checks if the current request is allowed to access the target physical block (and its entry) using the shadow blocks. Specifically, KVGUARD first locates the shadow block corresponding to the target physical block index, and then performs two checks against it: permission and initialization. For permission, KVGUARD checks that the permission field of the shadow block grants the required access to the current request, where a read access requires the read permission and a write access requires the write permission. This check catches three classes of bugs: (i) writes to a shared, read-only block (e.g., B3 in Table 1), (ii) accesses to a block that belongs to another request (e.g., B2 and B7), and (iii) stale accesses to a block that has been freed and reused after the request acquired it (e.g., B0, B10, and N5), because the previous owner's permission is removed once the block is reallocated to another request. For initialization, KVGUARD checks that the initialization field of the target entry is set before a read, and sets the initialization field on a write. This check ensures that a read never observes an uninitialized entry that has not been written within the current block lifetime (e.g., B6, B15, and N3).
Figure 5 shows the KVGUARD-instrumented CUDA cache access path. KVGUARD checks the GPU block table entry, validates the physical block's permission through the shadow block, and checks or stamps the entry initialization around the KV cache access.
void kv_cache_kernel(...) {
int token = blockIdx.x;
int req = current_request();
int row = current_batch_row();
int lb = token_to_logical_block[token];
int entry = token_to_entry[token];
/* C4: check GPU block table lookup */
check(allowed_block_table_entry(req, row, lb));
int pb = gpu_block_table[row][lb];
/* C5: check KV cache entry access */
check(0 <= pb && pb < num_blocks);
check(0 <= entry && entry < block_size);
ShadowBlock sb = shadow_blocks[pb];
check(sb.has_permission(req, mode));
if (mode == READ) {
check(is_initialized(pb, entry));
out[token] = kv_cache[pb][entry];
} else {
kv_cache[pb][entry] = in[token];
mark_initialized(pb, entry);
}
}
Figure 5. KVGUARD instrumentation of GPU KV cache access.
4.4 KV Transfer Checks
KV offloading [5, 19] and P/D disaggregation [32] move KV blocks through DMA and the network. KVGUARD handles such cases by treating each transfer as an access by the request on whose behalf it runs. On the sender, a transfer is a read: its source entries must be initialized (C5), and its source blocks stay held by the request until the transfer completes, so a free before completion is a use-after-free (C1). On the receiver, a transfer is a write: its destination blocks must be those of the receiving request (C3), they stay held until completion (C1), and an entry becomes initialized only when the transfer actually writes it (C5).
A transfer may also deliver fewer entries than the receiver reserved. KVGUARD marks only the entries delivered as initialized, so a later read access to an entry that was not delivered is caught as an uninitialized read (C5). Here, the receiver cannot tell a short delivery from a full one by itself, because both complete the same way. The sender therefore reports the count of entries it wrote. This count is the only metadata KVGUARD adds to a transfer, and each node still checks against its own shadow blocks. B17, B21, N4, and N7 in Table 1 are caught this way.
5 Implementation
KVGUARD is implemented on vLLM [9] and SGLang [31], two popular open-source LLM serving systems that use PagedAttention for KV cache management. The implementation has three parts for each system: (i) a Python package that manages the shadow blocks, CPU-side bridge, and Triton check helpers, (ii) CUDA check kernels and helpers that are included from the system's cache and attention kernels, and (iii) hook insertions across the system's block manager,
Table 2. Implementation size in lines of code.
| Component | vLLM | SGLang |
| Shadow blocks and checks (Python) | 5,730 | 18,419 |
| GPU check kernels and helpers (CUDA, C++) | 385 | 3,285 |
| Hook insertions in the system and its kernels | 1,663 (180 sites) | 1,535 (177 sites) |
block table, attention backends, and kernels. Table 2 lists their sizes: lines exclude blanks, comments, and tests.
Shadow Block Construction. KVGUARD maintains one shadow record per physical block, carrying the two fields described in §4.1. The permission field is stored as a per-request permission list, recording which requests currently hold the block and whether each holds it for reading or writing. The initialization field is stored as a per-entry bit, set when a kernel writes the entry and cleared in bulk when the block is (re)allocated to a request.
To keep the shadow records consistent with vLLM's block lifecycle, KVGUARD intercepts five state transitions in vLLM's block pool and KV cache manager: allocation, touch, cache promotion, free, and cached eviction. These cover both block-commit paths in vLLM v1, explicit allocation and prefix-cache promotion, without duplicating bookkeeping.
CPU-Side Checks. CPU-side checks are fused with the hook points that manage the relevant state. C1 runs inside the allocation hooks themselves, so an allocator event raises immediately on a wrong precondition and adds at most one integer test per event. C2 and C3 share a single entry point invoked once before every kernel launch, operating on a per-request block table snapshot captured when the block table manager commits the block table. C2 first checks that the kernel's effective row length does not exceed the committed row length in the snapshot. For each cell within that bound, C2 then verifies that the cell's physical block is held by the request, and rejects the launch on a mismatch. C3 then compares the snapshot against the GPU block-table tensor cell by cell.
GPU-Side Checks. GPU-side checks are realized as kernel instrumentation. KVGUARD exposes a KV read check helper and a KV write check helper, inlined into every GPU kernel that reads or writes the KV cache, including attention, cache copy, cache write, gather, and SSM kernels. The instrumented kernel accesses the shadow metadata on KV access paths during runtime. Before each scheduling step, KVGUARD packs the host shadow blocks into fixed-shape tensors, including a row-to-request map, a host-visible violation counter, and a violation ring buffer. Each instrumented kernel reads the row-to-request map to find the owning request of its batch row. It then invokes the check helper with the request ID and the looked-up physical block to realize C4 and C5. A cache write sets the initialization bit of the accessed entry, and a cache read accepts the entry only when its bit is set. KVGUARD reports device-side violations in two modes. The aborting mode stops on the first violation and prints a decoded report,
Table 3. Evaluation workloads.
| Model | Size | Role | Dataset |
|---|---|---|---|
| Llama 3.2 | 1B | Smallest (worst case) | ShareGPT V3, LongBench, MMLU |
| Llama 3.1 | 8B | Mid-size | ShareGPT V3 |
| Qwen 2.5 | 14B | Largest (compute-bound) | ShareGPT V3 |
| Qwen 3.5 | 4B | Hybrid (recurrent state) | ShareGPT V3 |
keeping it close to the root cause. The logging mode records violations in a ring buffer drained periodically by the host, letting one run collect multiple reports for debugging.
KV Transfers Without a Kernel. As described in §4.4, KV transfers are checked on the host: KVGUARD hooks the submission of each offload copy and P/D transfer in the systems' connectors and its completion event, and checks the source or destination blocks against the shadow blocks. For a cross-node P/D transfer, the sender records the number of entries it wrote and passes that count to the receiver, which initializes only that many destination entries, so a short delivery leaves the rest uninitialized.
6 Evaluation
This section evaluates whether KVGUARD can check KV cache safety at acceptable serving cost. The evaluation answers three questions: (i) how much runtime overhead KVGUARD adds to serving systems, (ii) how much memory KVGUARD uses for shadow metadata, and (iii) whether the checks detect real and injected KV cache safety bugs.
6.1 Experimental Setup
Platform. All experiments run on a server with one NVIDIA H100 80 GB GPU and an Intel Xeon Platinum 8468 processor (16 vCPUs). The software stack uses Ubuntu 24.04, CUDA 13.0, vLLM v0.32.0 with FlashAttention 3 [22], and SGLang v0.5.22 with FlashInfer 0.7.1. KVGUARD attaches through each engine's plugin mechanism without patching either.
Workloads. Table 3 lists the evaluated models. Llama 3.2 1B [6] stresses sanitizer overhead because each decode step has little model compute, while Qwen 2.5 14B [28] represents a larger model where KV and attention work dominate each step. The serving workload uses ShareGPT V3 prompts [20] on every model. Llama 3.2 1B runs two more datasets: (1) LongBench [2] prompts of 2K to 8K tokens, to evaluate long inference sequences, and (2) five-shot MMLU [7] over eight subjects to exercise prefix publication and sharing.
Configurations. The evaluation uses two configurations. Baseline runs the serving systems with KVGUARD disabled, and KVGuard runs them with KVGUARD attached and every check (C1 to C5) enabled. KVGuard is evaluated in the aborting mode described in §5.
6.2 Performance Overhead
KVGUARD's overhead is largest on the smallest model and shrinks as the model's size grows. Figure 6 shows the median
TPOT and TTFT across request rates on the four models and both serving systems. On Llama 3.2 1B, the TPOT slowdown grows from at 2 req/s to at 24 req/s on vLLM and from to on SGLang. This is the worst case in the evaluated matrix: the model's baseline TPOT is only 1.6 to 1.7 ms, where the per-step host work for the shadow is as large as the execution time of the step itself. On Llama 3.1 8B, the slowdown is to on vLLM and to on SGLang, and on Qwen 2.5 14B to and to , because each step already spends 6 to 17 ms in model execution. The hybrid Qwen 3.5 4B sits between, at to and to , because its recurrent-state pool adds a state dispatch to every step besides the attention ones. TTFT follows the same order, from to on Llama 3.2 1B down to to on Qwen 2.5 14B, and stays below the TPOT slowdown because much of the time to first token is spent outside the checked step. SGLang shows the larger slowdown on the two larger models because its overlap scheduler hides its own per-step host work behind the GPU, so the attachment's host work is exposed in full.
KVGUARD has moderate user-visible latency impact on the larger evaluated model. Figure 7 shows the end-to-end latency for Qwen 2.5 14B. At 16 req/s, KVGUARD increases median end-to-end latency from 2.04 s to 2.13 s on vLLM and from 2.60 s to 3.04 s on SGLang, and the p99 from 10.6 s to 11.1 s and from 12.7 s to 13.8 s. This result shows that KVGUARD remains feasible on the larger model even under high request pressure. The tail cost falls on the small model instead: on Llama 3.2 1B at 24 req/s, the p99 TPOT rises from 2.4 ms to 17.3 ms on vLLM and from 4.0 ms to 17.4 ms on SGLang.
The overhead also depends on the prompt structure of the workload. Figure 8 shows the TPOT and TTFT slowdown of KVGUARD per workload on Llama 3.2 1B. LongBench prompts of 2K to 8K tokens raise the TPOT slowdown to on vLLM and on SGLang at 16 req/s, because the dispatch check covers every position a step consumes and a long context multiplies them. Five-shot MMLU, whose prompts share a prefix of 0.7K to 2.4K tokens per subject, costs to on vLLM and to on SGLang, close to ShareGPT, because the shared prefix is published once and then only referenced. On vLLM the MMLU slowdown even falls with the rate, because the detached engine's own decode step slows down on the 2K-token contexts while KVGUARD's cost per step grows little.
Comparison with Compute Sanitizer. KVGUARD's overhead is much lower than that of NVIDIA Compute Sanitizer [16] (Figure 9). The comparison uses Compute Sanitizer memcheck, which is the closest available GPU-side baseline for out-of-bounds, misaligned, and use-after-free checks on CUDA allocations, in two forms. memcheck as shipped instruments every kernel of the serving process. memcheck-kv restricts the instrumentation to the KV cache kernels, i.e.,

Figure 6. Median TPOT and TTFT of Baseline and KVGUARD across request rates.

Figure 7. End-to-end latency of Baseline and KVGUARD on Qwen 2.5 14B.
the attention and cache-write kernels that read or write the KV pool (FlashAttention and reshape_and_cache on vLLM, FlashInfer's paged kernels and the pool's index_put on SGLang), through the tool's kernel-name filter, with host stack traces off, so that the sanitizer checks the same kernels as KVGUARD at the least cost the tool allows. At 4 req/s on Llama 3.2 1B, KVGUARD raises the median TPOT of vLLM from 1.7 ms to 3.5 ms (2.1×), whereas memcheck raises it to 194 ms (115.7×) and memcheck-kv to 51 ms (30.6×). On SGLang the same points are 2.1×, 230.8×, and 46.0×. On Llama 3.1 8B, KVGUARD costs 1.1× on both systems, where memcheck costs 71.8× on vLLM and 129.7× on SGLang and memcheck-kv 19.6× and 22.4×.
Here, both memcheck and memcheck-kv still check the KV pool as one allocation, so an access to the wrong block inside the pool is invisible to them. Registering every KV block as a sub-allocation with the NVTX memory API [17] gives memcheck-kv block granularity, at 522× on Llama 3.2 1B and 368× on Llama 3.1 8B at 1 req/s on vLLM, and at 4 req/s the engine under the tool slows to about one step per second, so

Figure 8. TPOT and TTFT slowdown of KVGUARD per workload on Llama 3.2 1B.
that point is not measured. Thus memcheck-kv remains 15× to 22× slower than KVGUARD on the very kernels KVGUARD checks, because it checks every memory access of those kernels, while KVGUARD checks each step's tables once before the kernels run.
Compute Sanitizer also required a more constrained setup than KVGUARD. The memcheck runs set the GPU memory utilization of both engines to 0.50 and the KV pool to a quarter of its size, because the sanitizer's internal shadow allocator runs out of memory at the ordinary settings, and they measure 40 prompts at 1 and 4 req/s.
In addition, Compute Sanitizer initcheck is excluded because the systems failed to run with initcheck enabled.

Figure 9. TPOT slowdown of KVGUARD and NVIDIA Compute Sanitizer, normalized to Baseline.
Table 4. Memory overhead of KVGUARD shadow metadata on H100.
| Model | KV Cache | GPU Shadow | Host Shadow | Shadow / KV | Shadow / Weights |
|---|---|---|---|---|---|
| Llama 3.2 1B | 32 GiB | 17.8 MiB | 17.2 MiB | 0.11% | 1.5% |
| Qwen 3.5 4B | 59 GiB | 23.2 MiB | 18 MiB | 0.07% | 0.46% |
| Llama 3.1 8B | 24 GiB | 9.6 MiB | 6.6 MiB | 0.07% | 0.11% |
| Qwen 2.5 14B | 24 GiB | 9.1 MiB | 4.4 MiB | 0.05% | 0.05% |
6.3 Memory Overhead
Table 4 shows the memory overhead of KVGUARD shadow metadata. KVGUARD keeps shadow metadata on both GPU and host, and the table reports its size relative to the two main memory consumers in serving: the KV cache and model weights. The main GPU component is the per-entry initialization record, whose size scales with the number of physical blocks, the block size, and the number of layers. Other GPU metadata, including per-block permission state, request-row mappings, the violation counter, and the violation ring buffer, is comparatively small. Host shadow memory is smaller still, because the host keeps one compact record per physical block.
Table 4 shows that the shadow is 0.11% of the KV cache for Llama 3.2 1B and 0.05% for Qwen 2.5 14B, and at most 1.5% of the model weights. The absolute KV cache sizes are set by the evaluation: both engines are given the same KV pool per model, 1,048,576 tokens on Llama 3.2 1B, 196,608 on Llama 3.1 8B, and 131,072 on Qwen 2.5 14B, within the memory left beside the weights, while the hybrid model's pool is sized by each engine. This makes Llama 3.2 1B's KV pool the largest in slots on the same 80 GB GPU, even though the model is the smallest. The shadow overhead therefore follows the actual KV pool geometry, not only the model parameter count. For example, Llama 3.2 1B carries the largest shadow of the four models because it has the most slots per gigabyte of KV cache.
6.4 Bug Detection Capability
KVGUARD detects every bug in Table 1: the 29 historical bugs from the vLLM and SGLang patch histories and the 8 newly discovered bugs, each reproduced end to end. The historical
Table 5. New KV cache safety issues found by KVGUARD.
| ID | Fix PR | KVGUARD Check | Finding |
|---|---|---|---|
| N0 | #42276 | C2 | Stale mapping after SWA eviction. |
| N1 | #62871 | C1 | Block reuse after a rejected stream chunk. |
| N2 | #64649 | C1 | Async KV load stalls with free blocks. |
| N3 | #45604 | C5 | Uninitialized state read at int8 checkpoint. |
| N4 | #45605 | C3 | Parallel samples share one P/D transfer. |
| N5 | #47390 | C5 | Finished request's freed row relaunched. |
| N6 | #47392 | C2 | Session state past its kept tokens. |
| N7 | #47250 | C1 | Aborted prefill freed during KV transfer. |
bugs test whether KVGUARD catches known failures whose fixes were written by other developers. The new findings test whether the same checks expose previously unknown unsafe KV cache behavior, and Table 5 lists them with the fix pull requests submitted upstream.
End-to-End Reproduction. Each historical bug is replayed on the exact buggy revision, i.e., the parent of its fix commit, and on the exact fix, with a serving workload that triggers the bug. KVGUARD reports the violation on every buggy run and reports nothing on the fixed run. For example, B2 is a stale slot-mapping tail that chunked prefill leaves behind for the padding rows of a full CUDA graph. On the buggy revision, KVGUARD reports 276 accesses to another request's block through the padding rows in each run (C3), and 30 of 64 outputs differ from the fixed revision. B8 is a sequence-length tensor that the overlap worker keeps sharing with later scheduling, so attention consumes block mappings under bounds changed for a different batch. KVGUARD reports the reuse of the in-flight tensor (C3), and the two buggy runs produce outputs that differ from the fixed runs on 8 and 6 of 8 requests and from each other on all 8, a silent corruption without any error. Most historical bugs show no symptom at all in the replay. B7 and B9, for instance, complete every request with the same output as the fix, and only the KVGUARD report shows that a padding row wrote a live sliding-window entry (B7) or that a batch launched before its block mappings were produced (B9). KVGUARD therefore reports each bug at the unsafe transition itself, before a silent output corruption happens.
New Findings. Table 5 lists the eight new bugs KVGUARD reported during end-to-end serving, three in vLLM and five in SGLang. Three are lifecycle bugs caught by C1. N1 admits the end-of-stream sentinel of a rejected streaming input as a new request while the first instance's blocks are still held by its outstanding dispatch. N2 rejects an asynchronous KV load whose admission margin for a speculative step exceeds what the request can still use near the context limit, so the request waits forever with free blocks available. N7 releases the KV of a cancelled prefill while the decode side's transfer still reads it. Three are block table bugs caught by C2 and C3. N0 leaves old physical block indices in the worker's block table after sliding-window eviction replaces the logical blocks. N4 gives every parallel sample of one request the same disaggregation transfer room, so the samples' KV transfers land in one another's blocks. N6 keeps a streaming session's recurrent state past the tokens the session keeps, after a speculative verify overshoots the limit or a finished turn runs once more. Two are entry access bugs caught by C5. N3 quantizes a short request's never-written state slot into its int8 checkpoint. N5 launches the freed row of a request that finished at the grammar synchronization of the previous step.
These bugs range from silent unsafe transitions to visible failures. N0 and N3 have no visible symptom on the current kernels, which mask the stale or unwritten entries before consuming them, whereas N2 leaves a request unanswered and N6 changes the next turn's output distribution. KVGUARD reports all of them at the unsafe transition, so a later kernel change cannot silently turn a masked one into output corruption. All eight are reported upstream with a fix pull request each, listed as Fix PR in Table 5.
7 Discussion
Generality Across Serving Systems. KVGUARD's abstractions are not tied to one serving system, and the evaluation on both vLLM and SGLang shows it. KVGUARD relies on three properties that any PagedAttention-style serving system exposes: a pool of fixed-size physical KV blocks carved out of a single GPU buffer, a serving-managed block table that maps each request's logical blocks to physical blocks, and GPU kernels that consume this block table to compute KV addresses. vLLM and SGLang realize these properties differently. vLLM allocates 16-token blocks from a block pool and shares prefixes through content hashes, while SGLang allocates tokens or pages from a token pool and shares prefixes through a radix tree, and the two run different attention kernels. The shadow block and the five checks (C1–C5) apply to both unchanged. Porting KVGUARD to a system consists of attaching C1 to its block manager, C2 and C3 to its block table, and C4 and C5 to its KV-access kernels. The per-request permission field covers prefix sharing and speculative decoding in both systems, since shared and draft requests still
allocate and access blocks through the same block table. Hybrid attention and SSM models add new KV-touching kernels, which KVGUARD instruments with the same helpers, and the evaluated hybrid model runs under both systems this way. Disaggregated serving extends block lifetime across nodes, but each node keeps its own shadow blocks and checks the transfer as a read or write (§4.4), so the abstraction itself does not change.
Out-of-Scope Bugs. KVGUARD targets KV cache allocation and access bugs, not all model-quality or serving-correctness bugs. Two classes of bugs fall outside this scope. The first class is hash-collision bugs in prefix caching [27], which are wrong-sharing bugs caused by non-collision-free content hashes rather than by violations of permission, translation, or access rules. The second class is bugs in auxiliary metadata that is not part of KV cache allocation or access, such as quantization scaling factors used by reduced-precision kernels, or coordination messages exchanged between distributed serving components. These bugs can corrupt serving behavior, but they do not violate the KV cache permission, translation, or access rules that KVGUARD checks.
Use Cases. KVGUARD is designed as a sanitizer rather than an always-on production guard, because its GPU-side checks add a shadow block lookup and an initialization check on the critical path of every KV cache access. This cost positions KVGUARD for the same usage pattern as ASan and Compute Sanitizer, both of which impose multi-fold slowdowns (roughly 2× for ASan and an order of magnitude for Compute Sanitizer on GPU kernels) yet remain widely used through four sanitizer-style use cases: continuous integration, pre-release validation, post-incident debugging, and sampled production.
The first use case is continuous integration, where KVGUARD catches silent KV cache corruptions or potential safety violations that current unit tests miss, such as the eight new issues reported in §6.4. The second use case is pre-release validation of new kernels or serving features, where a developer runs KVGUARD with every check enabled locally and verifies that no check fires before merging. The third use case is post-incident debugging of corrupted outputs, where KVGUARD reports a violation at the boundary that produced it rather than at a downstream output many requests later. The fourth use case is sampled production, where KVGUARD runs on a small fraction of machines or requests, following the same strategy that ASan and Compute Sanitizer use at fleet scale to amortize their cost; a single violation report on a sampled request is sufficient to surface a bug that would otherwise produce silent corruption across the fleet.
8 Related work
Bug Finding in LLM Serving Systems. GRIEF [30] fuzzes vLLM and SGLang with timed traces of concurrent requests, but its oracles see a KV cache bug only through its symptoms. GRIEF reports a bug when the engine crashes, hangs, or slows down, when an output changes under log-probability replay, or when KV block lifecycle events become inconsistent. A KV cache safety violation, however, often shows none of these symptoms. For example, N3 reads an uninitialized state slot that no request consumes, and N7 frees blocks that an in-flight KV transfer still reads, yet neither run crashes, hangs, or produces a wrong output. Moreover, 23 of the 37 bugs in Table 1 are caught only at the GPU block table, its lookup, or the KV entry access (C3 to C5), which allocation and free events do not observe. KVGUARD instead checks each violation at the step that introduces it and reports the check, block, and request involved. A fuzzer such as GRIEF can therefore use KVGUARD as its oracle to find a broader range of KV cache safety bugs and to triage each one from the involved check, block, and request.
Sanitizer for Custom Allocators. Custom allocators are common in high-performance CPU applications, and have therefore been a target of memory safety research for decades. ASan protects objects allocated through standard allocation APIs, but custom allocators often allocate a large region and carve software-defined objects from it. As a result, object boundaries and object lifetimes inside an allocator can be invisible to ASan. CMASan addresses this gap by identifying custom allocator APIs, instrumenting allocator operations, and maintaining object metadata and quarantine state for objects created by those allocators [8]. KVGUARD follows the same high-level observation that the protected object may be defined by software above the standard allocator. However, the KV cache setting requires different metadata and checks: the protected objects are GPU-resident KV cache blocks, and an access is safe only if the serving system grants the request the right permission, the GPU block table names the intended physical block, and the target KV entry has been initialized.
Memory Safety for GPU Applications. Prior GPU memory safety systems explore several points in detecting memory errors in CUDA and GPU programs, but they operate at a lower abstraction than KV cache blocks. Canary-based tools such as GMOD [3] and cArmor [4] detect some GPU buffer overflows with low overhead, but can miss non-contiguous or non-linear corruptions. Hardware-assisted systems such as GPUSHield and LMI provide fine-grained bounds metadata, but require hardware support or allocation constraints that limit deployment on existing systems [10, 11]. cuCatch instruments CUDA programs with pointer tags and bounds metadata, but targets generic CUDA memory safety rather than serving-level KV cache semantics [24]. These systems protect GPU buffers from generic spatial or temporal memory errors. KVGUARD is complementary and specialized: a KV cache bug can use an address that is inside the allocated
GPU buffer and still violate memory safety because the kernel follows the wrong GPU block table entry, accesses a block without the required permission, or reads an uninitialized KV entry.
KV Cache Security. Recent work on KV cache security shows that the KV cache opens a new attack surface in LLM serving systems. Cache Me, Catch You [27] studies prefix, multimodal, and semantic cache attacks, including collision-based prefix cache poisoning and cache-based bypasses of system checks. Other work studies side channels created by KV cache sharing in multi-tenant serving. I Know What You Asked [26] shows that an attacker can infer whether its requests share KV cache with another user's request and can use that signal to reconstruct prompts. Both directions show that the KV cache is a security-critical component, while KVGUARD targets memory safety violations on the GPU-resident KV cache rather than cache-key correctness, poisoning resistance, or side-channel leakage from cache reuse.
9 Conclusion
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 that records per-request permission and per-entry initialization, and uses this metadata to perform five checks along the PagedAttention workflow, catching each violation at the boundary that produced it rather than as downstream output corruption many requests later. A prototype of KVGUARD on vLLM and SGLang covers all 29 historical KV cache bugs from the two systems' patch histories, uncovers 8 previously unknown safety violations during end-to-end serving, and reports no false positives. KVGUARD 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, making KVGUARD a practical sanitizer for continuous integration, pre-release validation, and post-incident debugging of LLM serving systems.
References
[1] ARM Limited. Memory Tagging Extension, 2019. https://developer.arm.com/-/media/Arm%20Developer%20Community/PDF/Arm_Memory_Tagging_Extension_Whitepaper.pdf. [2] Yushi Bai, Xin Lv, Jiajie Zhang, Hongchang Lyu, Jiankai Tang, Zhidian Huang, Zhengxiao Du, Xiao Liu, Aohan Zeng, Lei Hou, et al. LongBench: A bilingual, multitask benchmark for long context understanding. In Proceedings of the 62nd annual meeting of the association for computational linguistics (volume 1: Long papers), pages 3119–3137, 2024. [3] Bang Di, Jianhua Sun, Dong Li, Hao Chen, and Zhe Quan. GMOD: A dynamic GPU memory overflow detector. In Proceedings of the 27th International Conference on Parallel Architectures and Compilation Techniques, pages 1–13, 2018. [4] Christopher Erb and Joseph L Greathouse. cArmor: A dynamic buffer overflow detector for OpenCL kernels. In Proceedings of the International Workshop on OpenCL, pages 1–2, 2018.
[5] Bin Gao, Zhuomin He, Puru Sharma, Qingxuan Kang, Djordje Jevdijic, Junbo Deng, Xingkun Yang, Zhou Yu, and Pengfei Zuo. Cost-Efficient large language model serving for multi-turn conversations with Cache-dAttention. In 2024 USENIX annual technical conference (USENIX ATC 24), pages 111–126, 2024.
[6] Aaron Grattaflori, Abhimanyu Dubey, Abhinav Jauhri, Abhinav Pandey, Abhishek Kadian, Ahmad Al-Dahle, Aiesha Letman, Akhil Mathur, Alan Schelten, Alex Vaughan, et al. The llama 3 herd of models. arXiv preprint arXiv:2407.21783, 2024.
[7] Dan Hendrycks, Collin Burns, Steven Basart, Andy Zou, Mantas Mazeika, Dawn Song, and Jacob Steinhardt. Measuring massive multi-task language understanding. In International Conference on Learning Representations, 2021.
[8] Junwha Hong, Wonil Jang, Mijung Kim, Lei Yu, Yonghwi Kwon, and Yuseok Jeon. Cmasan: Custom memory allocator-aware address sanitizer. In 2025 IEEE Symposium on Security and Privacy (SP), pages 740–757. IEEE, 2025.
[9] Woosuk Kwon, Zhuohan Li, Siyuan Zhuang, Ying Sheng, Lianmin Zheng, Cody Hao Yu, Joseph E. Gonzalez, Hao Zhang, and Ion Stoica. Efficient memory management for large language model serving with PagedAttention. In Proceedings of the 29th symposium on operating systems principles, pages 611–626, 2023.
[10] Jaewon Lee, Euijun Chung, Saurabh Singh, Seonjin Na, Yonghae Kim, Jaekyu Lee, and Hyesoon Kim. Let-Me-In: (Still) employing in-pointer bounds metadata for fine-grained GPU memory safety. In 2025 IEEE International Symposium on High Performance Computer Architecture (HPCA), pages 1648–1661. IEEE, 2025.
[11] Jaewon Lee, Yonghae Kim, Jiashen Cao, Euna Kim, Jaekyu Lee, and Hyesoon Kim. Securing GPU via region-based bounds checking. In Proceedings of the 49th Annual International Symposium on Computer Architecture, pages 27–41, 2022.
[12] Wonbeom Lee, Jungi Lee, Junghwan Seo, and Jaewoong Sim. InfiniGen: Efficient generative inference of large language models with dynamic KV cache management. In 18th USENIX Symposium on Operating Systems Design and Implementation (OSDI 24), pages 155–172, 2024.
[13] Santosh Nagarakatte, Jianzhou Zhao, Milo M. K. Martin, and Steve Zdancewic. SoftBound: Highly compatible and complete spatial memory safety for C. In Proceedings of the 30th ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI), pages 245–258, 2009.
[14] Santosh Nagarakatte, Jianzhou Zhao, Milo M. K. Martin, and Steve Zdancewic. CETS: Compiler-enforced temporal safety for C. In Proceedings of the 2010 International Symposium on Memory Management (ISMM), pages 31–40, 2010.
[15] NVIDIA Corporation. TensorRT-LLM, 2025. https://github.com/NVIDIA/TensorRT-LLM.
[16] NVIDIA Corporation. Compute Sanitizer Documentation, 2026. https://docs.nvidia.com/compute-sanitizer/ComputeSanitizer/index.html.
[17] NVIDIA Corporation. NVTX API for Compute Sanitizer Reference Manual, 2026. https://docs.nvidia.com/compute-sanitizer/SanitizerNvtxGuide/index.html.
[18] Reiner Pope, Sholto Douglas, Aakanksha Chowdhery, Jacob Devlin, James Bradbury, Anselm Levskaya, Jonathan Heek, Kefan Xiao, Shivani Agrawal, and Jeff Dean. Efficiently scaling transformer inference. Proceedings of machine learning and systems, 5:606–624, 2023.
[19] Ruoyu Qin, Zheming Li, Weiran He, Jialei Cui, Heyi Tang, Feng Ren, Teng Ma, Shangming Cai, Yineng Zhang, Mingxing Zhang, et al. Mooncake: A KVCache-centric disaggregated architecture for LLM serving. ACM Transactions on Storage, 22(4):1–38, 2026.
[20] RyokoAI. ShareGPT52K Dataset, 2023. https://huggingface.co/datasets/RyokoAI/ShareGPT52K.
[21] Konstantin Serebryany, Derek Bruening, Alexander Potapenko, and Dmitry Vyukov. AddressSanitizer: A fast address sanity checker. In 2012 USENIX Annual Technical Conference (USENIX ATC 12), pages
309–318, 2012.
[22] Jay Shah, Ganesh Bikshandi, Ying Zhang, Vijay Thakkar, Pradeep Ramani, and Tri Dao. Flashattention-3: Fast and accurate attention with asynchrony and low-precision. Advances in Neural Information Processing Systems, 37:68658–68685, 2024.
[23] Ying Sheng, Lianmin Zheng, Binhang Yuan, Zhuohan Li, Max Ryabinin, Beidi Chen, Percy Liang, Christopher Ré, Ion Stoica, and Ce Zhang. FlexGen: High-throughput generative inference of large language models with a single GPU. In International Conference on Machine Learning, pages 31094–31116. PMLR, 2023.
[24] Mohamed Tarek Ibn Ziad, Sana Damani, Aamer Jaleel, Stephen W Keckler, and Mark Stephenson. cuCatch: A debugging tool for efficiently catching memory safety violations in CUDA applications. Proceedings of the ACM on Programming Languages, 7(PLDI):124–147, 2023.
[25] Robert N. M. Watson, Jonathan Woodruff, Peter G. Neumann, Simon W. Moore, Jonathan Anderson, David Chisnall, Nirav Dave, Brooks Davis, Khilan Gudka, Ben Laurie, et al. CHERi: A hybrid capability-system architecture for scalable software compartmentalization. In 2015 IEEE Symposium on Security and Privacy (SP), pages 20–37. IEEE, 2015.
[26] Guanlong Wu, Zheng Zhang, Yao Zhang, Weili Wang, Jianyu Niu, Ye Wu, and Yinqian Zhang. I know what you asked: Prompt leakage via KV-cache sharing in multi-tenant LLM serving. In NDSS, 2025.
[27] XiangFan Wu, Lingyun Ying, Guoqiang Chen, Yacong Gu, and Haipeng Qu. Cache me, catch you: Cache related security threats in LLM serving frameworks. NDSS, 2026.
[28] An Yang, Baosong Yang, Beichen Zhang, Binyuan Hui, Bo Zheng, Bowen Yu, Chengyuan Li, Dayiheng Liu, Fei Huang, Haoran Wei, et al. Qwen2.5 technical report. arXiv preprint arXiv:2412.15115, 2024.
[29] Chen Zhang, Kuntai Du, Shu Liu, Woosuk Kwon, Xiangxi Mo, Yufeng Wang, Xiaoxuan Liu, Kaichao You, Zhuohan Li, Mingsheng Long, et al. Jenga: Effective memory management for serving LLM with heterogeneity. In Proceedings of the ACM SIGOPS 31st Symposium on Operating Systems Principles, pages 446–461, 2025.
[30] Yunze Zhao, Yibo Zhao, Yuchen Zhang, Zaoxing Liu, and Michelle L Mazurek. Continuous discovery of vulnerabilities in LLM serving systems with fuzzing. arXiv preprint arXiv:2605.11202, 2026.
[31] Lianmin Zheng, Liangsheng Yin, Zhiqiang Xie, Chuyue Sun, Jeff Huang, Cody Hao Yu, Shiyi Cao, Christos Kozyrakis, Ion Stoica, Joseph E Gonzalez, et al. SGLang: Efficient execution of structured language model programs. Advances in neural information processing systems, 37:62557–62583, 2024.
[32] Yinmin Zhong, Shengyu Liu, Junda Chen, Jianbo Hu, Yibo Zhu, Xu-anze Liu, Xin Jin, and Hao Zhang. DistServe: Disaggregating prefill and decoding for goodput-optimized large language model serving. In 18th USENIX Symposium on Operating Systems Design and Implementation (OSDI 24), pages 193–210, 2024.