operators: guard unpooling indirection buffer size against overflow#10782
Open
destro4evr-rgb wants to merge 1 commit into
Open
operators: guard unpooling indirection buffer size against overflow#10782destro4evr-rgb wants to merge 1 commit into
destro4evr-rgb wants to merge 1 commit into
Conversation
xnn_reshape_unpooling2d_nhwc_x32 computed the indirection buffer size with a raw four-factor multiplication (batch_size * input_height * input_width * pooling_size * sizeof(void*)) with no overflow check. Large caller-supplied dimensions silently wrap the product to a value far smaller than required. xnn_reallocate_memory then returns a valid pointer to an undersized buffer, and xnn_indirection_init_unpool2d subsequently writes the full (attacker-sized) number of pointer entries out of bounds. Replace the raw multiplication with chained xnn_safe_mul calls, matching the pattern already used in argmax-pooling-nhwc.c and average-pooling-nhwc.c after PR google#10646.
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.
xnn_reshape_unpooling2d_nhwc_x32computed the indirection buffer size as a raw four-factor product with no overflow guard:On 32-bit targets (WebAssembly, ARM32) where
size_tis 32 bits andsizeof(void*) = 4, the product overflows when its true value exceeds 2²⁸. The wrapped result causesxnn_reallocate_memoryto return an undersized allocation;xnn_indirection_init_unpool2dthen writes the full intended extent of pointer entries out of bounds - a heap out-of-bounds write.This fix replaces the raw product with a
xnn_safe_mulchain that returnsxnn_status_out_of_memoryon overflow, consistent with the pattern used inaverage-pooling-nhwc.candargmax-pooling-nhwc.c.