Skip to content

Fix integer overflow in qc2w/qc4w requantization scale allocation - #10934

Merged
copybara-service[bot] merged 2 commits into
google:masterfrom
prasanna8585:fix/fc-qc2w-requant-scale-overflow
Oct 6, 2026
Merged

copybara-service[bot] merged 2 commits into
google:masterfrom
prasanna8585:fix/fc-qc2w-requant-scale-overflow

Conversation

@prasanna8585

@prasanna8585 prasanna8585 commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

setup_scale_params_qx8_qcyw computed the requantization-scale buffer size as an unguarded context-> output_channels * sizeof(float), where output_channels is a direct parameter of the public API xnn_create_fully_connected_nc_qs8_qc2w (and its qc4w/qd8/qdu8 siblings sharing this scale-params setup function). A caller supplying a large output_channels value overflows size_t, causing the allocation to wrap to a small value; the subsequent per-channel scale computation loop then reads and writes using the real, unwrapped output_channels.\n\nConfirmed via ASan (heap-buffer-overflow read and write) with output_channels = (1 << 62) + 16, which wraps the allocation to exactly 64 bytes.\n\nApplies xnn_safe_mul to the computation, consistent with the pattern already used for the main packed-weights allocation in this same file (line 264) and in convolution-nhwc.c / deconvolution-nhwc.c.

@prasanna8585

Copy link
Copy Markdown
Contributor Author

Hi Team,

is there any update require from my side on this ?

@Aelphy

Aelphy commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Hi, we are waiting for internal approval. Nothing is required on your side.

@prasanna8585

Copy link
Copy Markdown
Contributor Author

Hi @Aelphy ,

Just following up to check if this is ready to be merged.

@Aelphy

Aelphy commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Hm, could you please try rebase and push?

setup_scale_params_qx8_qcyw computed the requantization-scale buffer
size as an unguarded context->output_channels * sizeof(float), where
output_channels is a direct parameter of the public API
xnn_create_fully_connected_nc_qs8_qc2w (and its qc4w/qd8/qdu8 siblings
that share this scale-params setup function). A caller supplying a
large output_channels value overflows size_t, causing the allocation
to wrap to a small value; the subsequent per-channel scale computation
loop then reads and writes using the real, unwrapped output_channels,
producing both a heap-buffer-overflow read (from the caller-supplied
kernel_scale array) and a heap-buffer-overflow write (into the
undersized requantization_scale allocation).

Confirmed via ASan with output_channels = (1 << 62) + 16, which wraps
the allocation to exactly 64 bytes.

Applies xnn_safe_mul to the computation, consistent with the pattern
already used for the main packed-weights allocation in this same file
(line 264) and in convolution-nhwc.c / deconvolution-nhwc.c.
@prasanna8585
prasanna8585 force-pushed the fix/fc-qc2w-requant-scale-overflow branch from b9315bc to e0a9a56 Compare September 9, 2026 17:50
@prasanna8585

Copy link
Copy Markdown
Contributor Author

Done rebased onto current master and pushed. Let me know if anything else needs adjusting.

@prasanna8585

Copy link
Copy Markdown
Contributor Author

Hi Team,
Let me know if anything else needs adjusting to merge this PR.

@prasanna8585

Copy link
Copy Markdown
Contributor Author

Hi @Aelphy ,

Just following up to check if this is ready to be merged.

@Aelphy

Aelphy commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

Hi, sorry for long wait. PR was garbage collected in our internal system, could you please rebase again.

@prasanna8585

Copy link
Copy Markdown
Contributor Author

Rebased onto master resolved the conflict, kept the overflow-checked version. Ready for another look.

@copybara-service
copybara-service Bot merged commit 798ab80 into google:master Oct 6, 2026
8 checks passed
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.

2 participants