Add validation for negative position_ids in EmbedLayerNorm#27573
Merged
Add validation for negative position_ids in EmbedLayerNorm#27573
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a missing lower-bound validation check for position_col_index (derived from position_ids input) in the EmbedLayerNormalization CPU contrib op, preventing an out-of-bounds heap read when a negative value is passed as a position ID. A regression test is also added to verify the fix.
Changes:
- Adds
position_col_index < 0guard inembed_layer_norm.cc(the non-quantized CPU path whereposition_idsis user-supplied data, fixing a real OOB read vulnerability) - Adds the same
position_col_index < 0guard inqembed_layer_norm.cc(the quantized CPU path, where this check is dead code sinceposition_col_index = index % sequence_lengthandindexis always non-negative) - Adds a regression test
EmbedLayerNormNegativePositionIdsin the test file
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
onnxruntime/contrib_ops/cpu/bert/embed_layer_norm.cc |
Adds < 0 lower-bound check to prevent OOB heap read on negative position_ids — this is the real fix |
onnxruntime/contrib_ops/cpu/quantization/qembed_layer_norm.cc |
Adds < 0 check to position_col_index, which is dead code since the value is always index % sequence_length (non-negative) |
onnxruntime/test/contrib_ops/embed_layer_norm_op_test.cc |
Regression test for the negative position_ids validation fix |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
yuslepukhin
previously approved these changes
Mar 6, 2026
Member
|
Make sure to comment on the Copilot comments and resolve them |
This was referenced Apr 25, 2026
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.
Description
Adds a missing lower-bound validation check for
position_col_index(derived fromposition_idsinput) in theEmbedLayerNormalizationcontrib operator. A negative value inposition_idscould bypass the existing upper-bound-only check and cause an out-of-bounds heap read before theposition_embeddingbuffer.Motivation and Context