Validate STACKER init parameters against overflow and tensor sizes#3604
Open
adilburaksen wants to merge 1 commit into
Open
Validate STACKER init parameters against overflow and tensor sizes#3604adilburaksen wants to merge 1 commit into
adilburaksen wants to merge 1 commit into
Conversation
StackerInit reads num_channels, stacker_left_context, stacker_right_context and stacker_step from the init flexbuffer and computes buffer_size = num_channels * (left + right + 1) and step_size = num_channels * stacker_step. StackerPrepare validated only tensor ranks and types, never these parameters. Negative or overflowing values yield a zero/undersized circular buffer that StackerEval then writes and reads out of bounds via CircularBufferWrite/CircularBufferExtend (num_channels values are copied per frame and buffer_size values are read into the output). In release builds the bounds assert in CircularBufferWrite is compiled out, so this is an out-of-bounds access; confirmed with AddressSanitizer. Validate num_channels > 0, the contexts >= 0, stacker_step > 0, num_channels <= input size, that the buffer_size product does not overflow, and that the output is large enough, plus a regression test.
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.
BUG=out-of-bounds access in STACKER kernel from unvalidated init parameters
What
StackerInitreadsnum_channels,stacker_left_context,stacker_right_contextand
stacker_stepfrom the init flexbuffer and computes:buffer_size = num_channels * (stacker_left_context + stacker_right_context + 1); step_size = num_channels * stacker_step;StackerPreparevalidated only tensor ranks/types — never these parameters. Acrafted model (e.g.
stacker_right_context = -1, makingbuffer_size = 0, orvalues whose product overflows) produces a zero/undersized circular buffer.
StackerEvalthen callsCircularBufferWrite/CircularBufferExtend, copyingnum_channelsvalues per frame and readingbuffer_sizevalues into the output,out of bounds.
In release builds the
ASSERT(...)inCircularBufferWrite(#define ASSERT assert) is compiled out under-DNDEBUG, so this is an out-of-boundsread/write. Confirmed with AddressSanitizer (built with
-DNDEBUG):Change
stacker.cc:StackerPreparevalidatesnum_channels > 0, contexts>= 0,stacker_step > 0,num_channels <= input size, that thebuffer_sizeproductdoes not overflow, and that the output is large enough.
stacker_test.cc: regression test that the malformed parameters are rejected.No change for valid models.