Repository navigation
Closed
Labels
bugSomething isn't working
Description
Summary
Several native ops index memory using integer tensors loaded from the checkpoint, with no bounds checks. A crafted quantized checkpoint can therefore cause host heap corruption or out-of-bounds GPU reads and writes. These are separate sinks from #2949 (Triton g_idx), #3922 (NF12 embedding token IDs) and #3919 (ParoQuant shapes). Audited at a16977e by reading the source; nothing was built or reproduced on hardware.
Findings
1. ExLlamaV2 make_q_matrix: host heap OOB write from g_idx (High)
- Entry:
gptqmodel_ext/exllamav2/ext_gptq.cpp:10checks only thatg_idxis int32. It does not check values, length, or that the tensor is on CPU. - Path:
cuda/q_matrix.cu:131→make_sequential. - Sinks:
:553cpu_g_idx_map = calloc(groups, 4), then:559cpu_g_idx_map[cpu_g_idx[i]]++. Theuint32index comes from the checkpoint with no bound, giving a heap write at a chosen offset.:575-576and:582cpu_x_map[cpu_x_map_inv[row]] = rowwrite further out of bounds.
- Reached at load time:
ExllamaV2Linear.post_init→_ensure_q_handle→exllamav2_make_q_matrix(..., w["g_idx"].cpu())(nn_modules/qlinear/exllamav2.py:~341). No forward pass is needed. ExLlamaV2 is selected when Marlin is unavailable (e.g. sm75) or chosen explicitly. - Gap:
validate_g_idx_bounds(nn_modules/qlinear/_g_idx.py, the Out-of-bounds read in the Triton dequant kernel via an unchecked checkpointg_idx(CWE-125) #2949 fix) is not called fromexllamav2.py. - 1b:
shorttruncation survives even validg_idx::565short tmp = cpu_g_idx_map[i]truncates the per-group count.- With
in_features≥ 32768 and one group holding ≥ 32768 rows, the prefix sum goes negative and:582writes at aboutcpu_x_map[0xFFFF8000]. - A range check alone does not fix this.
- Fix:
TORCH_CHECK(g_idx.is_cpu() && g_idx.numel() == height).- Check
0 <= g_idx < groups. - Use
uint32_tfortmp. - Assert
target_row < heightbefore writing.
2. NF12 linear/decode: escape index g.lo0 has no bound (High/Med; CUDA and HIP)
- Entry:
gptqmodel_ext/nf12/csrc/torch/ops.cpp:110-135weight_view, used bydecode,decode_fp32,sub_fp32,linearandlinear_staged_b1.- It checks shapes, dtype and alignment, but never checks escape indices against
escapes.size(0). - When
escapesis empty,w.escapesisnullptr.
- It checks shapes, dtype and alignment, but never checks escape indices against
- Sinks:
include/nf12/format.cuh:78and:107(__ldg(escapes + g.lo0)).linear/gemv.cu:159.linear/mma.cuh:523/720/868/1034.linear/sm100/large_m_tc_kernel.cuh:670.- HIP:
nf12_hip/nf12_format_hip.cuh:134-145.
- The bound was intended:
codec/embedding.cu:57and the sm90/sm120 kernels already checkg.lo0 < num_escapes. - Reached from: the checkpoint's
nf12_packed/nf12_escapes(resized to the checkpoint's shape atutils/model.py:2815-2839) →NF12Linear._native_forward/dequantize_weight, andgptqmodel_nf12.NF12Weight.from_state_dict. Post-init checks only the packed shape. - Impact: GPU OOB reads of up to about 64 GiB past the buffer. These crash, or decode other tensors' bytes into the weights.
- Fix:
- Pass
num_escapesto the kernels and use the same guard as the embedding kernel. - Add a one-time load check that
max(lo0 | meta==0) < escapes.size(0).
- Pass
3. NF12 MoE: escape_offsets unchecked (Med, library API)
- Entry:
nf12/csrc/torch/ops.cpp:484-517moe_weight_viewchecks only thatescape_offsetsis contiguous int64 with E+1 entries. It does not check that offsets are ≥ 0, monotone, or end at ≤escapes.size(0). - Sinks:
moe/common.cuh:59-61codec/decode.cu:155- sm80, sm90 and sm120 large kernels
nf12_moe.hip:287nf12_wmma.hip:185
- Reached from:
NF12MoEWeight.from_state_dict.
4. ParoQuant CUDA rotation: pairs index shared memory (Med)
- Entry:
gptqmodel_ext/paroquant/rotation.cu:1003-1030checks device, dtype and rank only. It does not check pair values,idx.size(1) == h,thetashape, orscalesnumel. - Sink:
rotation.cuh:73-81(float) and:148-160(half) read and writex_grp[i*ROW_STRIDE+m]/x_grp[j*...]. Herei/jare signed int16 values from the checkpoint, while valid values are in[0, 128). - Reached from: a ParoQuant checkpoint with non-zero
theta→ParoLinear._rotate_inputs→apply_paroquant_rotation→ fused kernel._rotation_kernel_readydoes not check values. - Impact: OOB shared-memory writes, typically an illegal-address fault that kills the CUDA context.
- Fix: validate
0 <= pairs < group_sizeonce at load.
5. VPTQ CUDA: outlier_indices used as a codebook index (Med)
- Entries:
gptqmodel_ext/vptq/vptq_kernel.cu:428and:491. - Sink:
:73-74load_float(outlier_centroids, code * outlier_vector_len + component), wherecodeis any int32. - Gap: the bound is enforced only at quantize time (
vptq_torch.py:395). The load-time_validate_loaded_state(vptq_torch.py:327) checks only the shape ofindices. - Fix: check
0 <= outlier_indices < outlier_num_centroidsin_validate_loaded_state.
6. ExLlamaV3 reconstruct: trellis K indexes a 24-entry kernel table (Med-High)
- Entry:
gptqmodel_ext/exllamav3/bindings.cpp:59→quant/reconstruct.cu:100. Onlypacked.size(2) == 256*K/16is checked. - Sink:
:124-130cbi = K-1 (+8 mcg / +16 mul1), thenreconstruct_kernel_instances[cbi](an uncheckedstd::array), then the launch.- K = 0, or K large enough that
cbi ≥ 24, calls through a garbage function pointer. - K = 9..16 runs the wrong kernel.
- K = 0, or K large enough that
- Source of K:
trellis.shape[-1] // 16, fromquantization_config.tensor_storage. Any forward with more than 32 rows takes this path. - The GEMM path already checks:
exl3_kernel_map.cu:207enforces1 <= K <= 8. - Same pattern elsewhere:
pack.cu:92,175(quantize-time only). - Fix:
TORCH_CHECK(1 <= K && K <= 8 && !(mcg && mul1)).
7. Low
- FloatX CPU dequant divides by zero:
gptqmodel_ext/floatx_cpu.cpp:205and:237/244/261take% countwithcount == 0for an empty scale tensor. This raises SIGFPE and kills the process._fast_scale_argexplicitly allowsnumel() == 0; the path is reachable from NVFP4 dequant. - EXL3 per-device arrays have no bound:
exllamav3/quant/exl3_devctx.cuh:13,24-27,exl3_devctx.cu:25-68andexl3_gemm.cu:37,129-143indexMAX_DEVICES = 16arrays without checking. Device ordinal ≥ 16 gives a host OOB write.
General suggestion
- Add one load-time "index tensor validation" pass for every format:
g_idx, NF12 escapes and offsets, ParoQuant pairs, VPTQ outlier indices, and EXL3 K. - Add matching
TORCH_CHECKs at each C++ op entry, so that direct API callers are protected too.
Metadata
Metadata
Assignees
Labels
bugSomething isn't working
Activity
fix(security): validate checkpoint index tensors before native indexi…