Repository navigation
fix(triton): bound-check checkpoint g_idx to prevent OOB dequant read (#2949) - #2950
Merged
Merged
Conversation
…ModelCloud#2949) The Triton dequant kernel resolves each row's group as `where(g_idx < 0, g_idx + num_groups, g_idx)` and then indexes the scales/qzeros buffers with no upper-bound check, where `num_groups = scales.shape[0]`. Because the Triton QuantLinear leaves g_idx regeneration disabled in post_init, a crafted `desc_act=True` checkpoint whose g_idx exceeds num_groups reaches the kernel verbatim and reads out of bounds on the device (CWE-125: crash / possible adjacent-memory disclosure when loading an untrusted model). Validate g_idx once at load in TritonV2Linear.post_init, rejecting values outside `[-num_groups, num_groups)` — exactly the range the Torch backend's `scales[g_idx]` gather accepts, so this only rejects inputs that already fault safely there. The check is a one-time load-side guard, not per-forward overhead. Adds CPU-only unit tests for the pure validator (no GPU / Triton required).
Qubitium
approved these changes
Jul 14, 2026
Collaborator
|
@Anai-Guo Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2949 — an out-of-bounds device read (CWE-125) in the Triton dequant path when loading an untrusted GPTQ checkpoint.
The Triton dequant kernel (
gptqmodel/nn_modules/triton_utils/dequant.py) resolves each row's group asgroups = where(g_idx < 0, g_idx + num_groups, g_idx)and then indexesscales/qzeroswithgroupswith no upper-bound check, wherenum_groups = scales.shape[0]. BecauseTritonV2Linear.post_initleaves g_idx regeneration disabled, a crafteddesc_act=Truecheckpoint whoseg_idxexceedsnum_groupsreaches the kernel verbatim and reads past the buffer — crashing the CUDA context (DoS) and potentially pulling adjacent GPU memory into the dequantized weights. The Torch backend'sscales[g_idx]gather faults safely on the same input; only the Triton path reads raw.Fix
Validate
g_idxonce at load inTritonV2Linear.post_init, rejecting values outside[-num_groups, num_groups). That range is exactly what the kernel's negative-wrap can resolve safely and what the Torch backend'sscales[g_idx]gather accepts, so the guard only rejects inputs that already fault safely on the Torch path — no legitimate checkpoint is affected. It runs once at load, not on the per-forward hot path.I kept the change to the load-side guard alone (rather than also masking the load inside the kernel) because rejecting at load fully prevents the bad
g_idxfrom ever reaching the device; a kernel-sidegroups < num_groupsmask would be reasonable defense-in-depth if you prefer it.Tests
tests/test_triton_g_idx_bounds.py— CPU-only unit tests for the pure validator (no GPU / Triton needed): in-range and negative-wrap-in-range pass;g_idx >= num_groupsandg_idx < -num_groupsare rejected;None/empty buffers are no-ops. The accept/reject boundaries were cross-checked againsttorch.zeros((num_groups, n))[g_idx]— they match the Torch backend's safe-fault semantics exactly.🤖 Generated with Claude Code