Skip to content

subgraph: harden qs8->qc8 convert channelwise-quantization size arithmetic against integer overflow - #11411

Open
VIRUSBABAA wants to merge 1 commit into
google:masterfrom
VIRUSBABAA:fix-qs8-qc8-convert-overflow
Open

VIRUSBABAA wants to merge 1 commit into
google:masterfrom
VIRUSBABAA:fix-qs8-qc8-convert-overflow

Conversation

@VIRUSBABAA

@VIRUSBABAA VIRUSBABAA commented Sep 26, 2026 •

Copy link
Copy Markdown

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.

@google-cla

google-cla Bot commented Sep 26, 2026

Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant