OOB read / SEGV via unvalidated gpu_bucket row index in auto-loaded .generated.gpuidx sidecar

Author: 3em0Created Sep 24, 2026Updated Sep 27, 2026
Labelsbug-unconfirmed

1. Prerequisites

  • I am running the latest version of PowerInfer. Development is rapid, and as of now, there are no tagged versions.
  • I have carefully read and followed the instructions in the README.md.
  • I searched using keywords relevant to my issue to make sure that I am creating a new issue that is not already open (or closed).

Note: this is a security-relevant memory-safety report. If a private channel (GitHub Private Vulnerability Reporting) is available, I am happy to move this discussion there.

2. Expected Behavior

The GPU-split sidecar file (<model>.generated.gpuidx) that PowerInfer automatically picks up from next to the model file should be treated as untrusted input: every int32 row index stored in the gpu_bucket tensors must be validated against the bounds of the corresponding host tensor (0 <= index < src->ne[1]) before it is used in pointer arithmetic.

3. Current Behavior

The sidecar is loaded merely because the file exists (access(F_OK)), and the only validations performed are: (1) split.vram_capacity (GGUF key) <= VRAM budget in the llama_gpu_split_loader constructor / check_vram_allocable(), and (2) n_tensors == n_layers * 2 in load_gpu_idx_for_model(). No per-entry validation of the int32 gpu_bucket indices happens anywhere. In create_striped_mat_to_gpu() each index is used directly as a row offset:

c
    for (int i = 0; i < gpu_rows; i++) {
        int32_t host_i = ((int32_t *)gpu_bucket->data)[i];
        host_mat_row->data = (char *)src->data + host_i * row_data_size;
        ggml_cuda_cpy_1d(device_mat_row, host_mat_row);   // -> cudaMemcpy, host source pointer
    }

An attacker-supplied index (e.g. 0x7FFFFFFF, or any negative value) is multiplied by row_data_size and added to src->data, so cudaMemcpy reads from an address up to INT32_MAX * row_data_size bytes away from the tensor buffer (observed: roughly 274 GB past the source buffer; the exact distance depends on row_data_size). Result: ASan heap-buffer-overflow READ / SEGV crash of ./main. Only the bucket length (gpu_rows <= src->ne[1]) is asserted; the index values are never checked.

4. Environment and Context

PowerInfer @ commit 8bd56d69906c9d2dba4d3bf6899763401e01a9a4 (main, 2026-05-11), built with CUDA support (GGML_USE_CUBLAS) on Linux x86_64 with an NVIDIA GPU (standard cmake build per README). No tagged releases exist, so the commit hash is the version anchor. The defect is in host-side index handling - plain C++ pointer arithmetic performed before the cudaMemcpy - so it does not depend on GPU model, driver version, or OS: every CUDA build of PowerInfer is affected, wherever a .generated.gpuidx file is honored.

5. Failure Information (for bugs)

Out-of-bounds READ (CWE-125). Attacker-controlled int32 values from the gpu_bucket tensors of the sidecar file are used unchecked as row offsets in host pointer arithmetic, then handed to cudaMemcpy as the source address.

Impact: Availability: process crash (SEGV) during model load - trivially triggered. Confidentiality: the out-of-bounds host memory is copied into device FFN weights (device_mat_row / gpu_dst); the copied bytes become part of the weights used by subsequent inference, so host memory adjacent to (or far from) the model buffer can in principle be leaked through the model's outputs.

Attack model: a distributed model package (model.gguf + model.gguf.generated.gpuidx, e.g. shared via a model hub) - the two files are byte-identical to a legitimate package except for one int32 bucket entry. Any user who runs PowerInfer on that directory with a GPU triggers the load; no flag is needed.

6. Steps to Reproduce

  1. Build PowerInfer (commit 8bd56d6) with CUDA.

  2. Produce a legitimate sidecar once: run ./main -m model.gguf on a GPU with GPU-index generation enabled, so that model.gguf.generated.gpuidx is created next to the model.

  3. Craft the evil package: keep model.gguf byte-identical; inside model.gguf.generated.gpuidx, locate the data of any layer's gpu_bucket tensor (layer il stores gpu_idx at slot il2 and gpu_bucket at il2+1) and overwrite one int32 entry with 0x7FFFFFFF. Nothing else changes - split.vram_capacity and the tensor count remain valid, so the existing checks pass.

  4. Run: ./main -m model.gguf --vram-budget 8 Note: the sidecar is auto-loaded whenever the file exists and --reset-gpu-index is not given; the default --vram-budget is -1 (use all available VRAM), so a plain ./main -m model.gguf with a GPU present reaches the same code path. The only opt-out is --disable-gpu-index.

  5. Negative control: repeat step 4 with the unmodified sidecar. The same striping loop completes and inference starts normally, which rules out an unrelated build/environment failure.

7. Failure Logs

$ ./main -m model.gguf --vram-budget 8
...
load_gpu_idx_for_model: applying gpu_idx adapter from 'model.gguf.generated.gpuidx' - please wait ...

Immediately after this line, the first striping iteration computes host_mat_row->data = (char *)src->data + (int32_t)0x7FFFFFFF * row_data_size, and ggml_cuda_cpy_1d() passes that pointer to cudaMemcpy as the source address. Under ASan this is a heap-buffer-overflow READ reported in the memcpy/cudaMemcpy issued by ggml_cuda_cpy_1d <- create_striped_mat_to_gpu <- slice_ffn_mat_to_gpu (model-load path); without ASan the process dies with SIGSEGV at the same point. Negative control: rerunning with the sidecar restored to its original (legitimate) index completes the very same loop and inference proceeds normally, which rules out an unrelated build/environment failure.

8. Suggested fix

In create_striped_mat_to_gpu(), validate every entry before use:

c
int32_t host_i = ((int32_t *)gpu_bucket->data)[i];
if (host_i < 0 || (int64_t)host_i >= src->ne[1]) {
    LLAMA_LOG_ERROR("%s: gpu_bucket[%d] index %d out of range [0, %lld)\n", ...);
    return nullptr;   // or fall back to CPU offload for this layer
}

More generally, treat .generated.gpuidx as untrusted input: also sanity-check gpu_rows against src->ne[1] per tensor (not only via the GGML_ASSERT), and consider binding the sidecar to the model file (e.g. hash check), since the file is silently auto-loaded when present.

link: https://github.com/3em0/cve_repo/blob/main/2026/PowerInfer-commit-8bd56d6-Out-of-bounds-Read(CWE-125)in-the-FFN-GPU-Split-Sidecar-Loader.md