Fix SIGSEGV in pack-weight unpack/GEMM on malformed blob#1928
Merged
Conversation
Add C++-level validation after BestLA blob deserialization to reject corrupted/metadata-tampered packed-weight blobs before they can cause out-of-bounds memory access. CPU (BestLA) path - cpu_wrapper.hpp: _validate_storage_weight() checks n, k, npad, kpad, block size, n_block consistency, NPack layout, and total buffer size against blob_count. Called in BTLAGemmUnpack, BTLAWOQGemmForwardWorkspace, and BTLAWOQGemmFp32Forward before set_buffers(). XPU path - xpu_wrapper.hpp: unpackq() and woq_gemm() validate blob_count against get_packw_size(). Binding layer - ark.cpp: Forward blob_numel from Python to native code. Python - __init__.py: _validate_packed_blob() validates parameter types at the Python layer. blob.numel() is passed to native calls for size validation.
for more information, see https://pre-commit.ci
Add forward declaration before the 3-arg compatibility wrapper to prevent recursive call when the 4-arg overload is defined later in the same translation unit.
for more information, see https://pre-commit.ci
Contributor
|
/azp run Unit-Test-CUDA-AutoRound |
|
Azure Pipelines could not run because the pipeline triggers exclude this branch/path. |
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
Add C++-level validation after BestLA blob deserialization to reject corrupted/metadata-tampered packed-weight blobs before they can cause out-of-bounds memory access (SIGSEGV).
Background
A vulnerability was reported where a malformed packed weight blob (e.g., one byte flipped at offset 64) causes a segmentation fault in
auto_round_kernel.unpack_weight(). The BestLA packed format embeds metadata (dimensions, block size, buffer offsets, etc.) in the blob itself. If those fields are corrupted, the deserialized pointers become invalid, leading to out-of-bounds reads.Changes
cpu_wrapper.hpp— CPU (BestLA) path_validate_storage_weight()that validates all deserialized metadata beforeset_buffers():n, k > 0and≤ 16Mnpad ≥ n, kpad ≥ kblock > 0andblock ≤ kn_blockconsistent withkpad / blockNPackmisc_size + buf_size ≤ blob_count(if available)BTLAGemmUnpack,BTLAWOQGemmForwardWorkspace,BTLAWOQGemmFp32Forward.xpu_wrapper.hpp— XPU pathunpackq()andwoq_gemm()validateblob_count ≥ get_packw_size().ark.cpp— Binding layerunpack_weight()andwoqgemm()accept and forwardblob_numel.__init__.py— Python API_validate_packed_blob()for parameter type validation._unpack_weight_core()andwoqgemm()passblob.numel()/B.numel()to native calls._repack_quantized_weight_core()validates input tensor shapes.