Fix integer truncation in deconvolution kernel_size computation#9876
Open
mohammadmseet-hue wants to merge 2 commits intogoogle:masterfrom
Open
Fix integer truncation in deconvolution kernel_size computation#9876mohammadmseet-hue wants to merge 2 commits intogoogle:masterfrom
mohammadmseet-hue wants to merge 2 commits intogoogle:masterfrom
Conversation
Use size_t instead of uint32_t for kernel_size, n_stride, and k_stride in create_deconvolution2d_nhwc() to prevent integer truncation when kernel_height * kernel_width exceeds 2^32. The truncated kernel_size was used to compute packed_group_weights_size (the allocation size), while pack_deconv_goki_w() received kernel_height and kernel_width as separate size_t parameters and iterated the true product, causing a heap buffer overflow.
Apply the same uint32_t → size_t/uint64_t promotion to prevent integer truncation in: - convolution-nchw.c: kernel_height * kernel_width in packed weights allocation (heap overflow, same class as deconvolution bug) - average-pooling-nhwc.c: pooling_size computation (3 sites) - max-pooling-nhwc.c: pooling_size and effective kernel computation - argmax-pooling-nhwc.c: pooling_size computation
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
Systemic
uint32_tinteger truncation across 6 operator files. Whenuint32_tmultiplications overflow, allocation sizes are undersized while write loops use the true (non-truncated) product, causing heap buffer overflows.Bug 1: deconvolution-nhwc.c:286 — heap buffer overflow (ASAN confirmed)
kernel_sizecomputed asuint32_t:Truncated
kernel_sizeused for packed weights allocation (line 288-291), butpack_deconv_goki_w()receiveskernel_heightandkernel_widthas separatesize_tparameters and iterates the true product. With kh=kw=65536,kernel_sizewraps to 0, allocation is 256 bytes, packing writes past it.Same truncation on lines 284-285 (
n_stride,k_stride).ASAN output (operator API):
ASAN output (subgraph API — same path as TFLite XNNPACK delegate):
Reachable from all
xnn_create_deconvolution2d_nhwc_*APIs and from TFLite XNNPACK delegate viaVisitTransposeConvNode→xnn_define_deconvolution_2d→xnn_create_runtime.Bug 2: convolution-nchw.c:287 — heap buffer overflow
kernel_height * kernel_widthcomputed inuint32_tarithmetic (both fields areuint32_t), then used to computepacked_weights_size. Packing functions iterate the true product.Bug 3-7: pooling operators — validation bypass and wrong computation
pooling_sizetruncation bypasses zero-check and produces wrong 1/pooling_size scale factorpooling_sizeandeffective_kerneltruncation produces wrong paddingpooling_sizetruncation bypasses zero-checkAttack vector
Crafted .tflite model → TFLite → XNNPACK delegate → TransposeConv delegated to
xnn_define_deconvolution_2d()→xnn_create_runtime()triggers weight packing → uint32_t truncation → heap buffer overflow with attacker-controlled weight data.XNNPACK is used by TensorFlow Lite (Android/iOS), MediaPipe, PyTorch, ONNX Runtime, and Chrome (WebNN).
Fix
kernel_size,n_stride,k_stridefromuint32_ttosize_t, cast tosize_tbefore multiplicationsize_tbefore multiplication in allocation computationpooling_sizefromuint32_ttouint64_t, cast before multiplicationeffective_kernelfromuint32_ttosize_t, cast before multiplication