subgraph: harden qs8->qc8 convert channelwise-quantization size arithmetic against integer overflow - #11411
Open
VIRUSBABAA wants to merge 1 commit into
Open
subgraph: harden qs8->qc8 convert channelwise-quantization size arithmetic against integer overflow#11411VIRUSBABAA wants to merge 1 commit into
VIRUSBABAA wants to merge 1 commit into
Conversation
…metic against integer overflow
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
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.
num_channels and qc8_batch_size both come from model/subgraph tensor shapes
as size_t with no upper bound beyond the aggregate tensor-size check. When
num_channels * 4 * qc8_batch_size >= 2^64, bytes_needed wraps to a small
value, a small buffer is allocated, and the fill loop below writes the TRUE
qc8_batch_size * num_channels floats past the end:
This is the same bug class as the convolution hardening in 7ed6bfc, but in the
subgraph convert path, which that campaign missed.
Repro (AddressSanitizer)
Standalone harness replicating the size computation and fill loop verbatim,
input shape [2^52 + 1, 1, 1024] (num_channels = 1024, qc8_batch_size = 2^52 + 1).
True need: 2^64 + 4096 bytes; wrapped allocation: 4096 bytes.
Fix
Checked multiplication via xnn_safe_mul for both factors; reshape fails with
xnn_status_out_of_memory on overflow. Follows the existing hardening pattern
used throughout the recent integer-overflow campaign.
Threat model note
XNNPACK is a library: attacker input is a malicious model whose shapes flow
through the public subgraph API (xnn_define_convert). The library must reject
insane shapes rather than corrupt the heap during reshape, before inference.