Add bounds validation for LinearClassifier coefficients#27989
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds defensive validation to the CPU ML LinearClassifier operator to prevent crafted models from triggering an out-of-bounds read during the GEMM call by ensuring the coefficients vector size matches the expected [class_count, num_features] layout.
Changes:
- Add constructor-time validation for
class_count_ > 0andcoefficients_.size()divisibility byclass_count_. - Add runtime validation in
Compute()thatcoefficients_.size() == class_count * num_featuresbefore invoking GEMM. - Add two regression tests covering invalid coefficient sizing scenarios.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| onnxruntime/core/providers/cpu/ml/linearclassifier.cc | Adds attribute and runtime coefficient-size validation to prevent OOB reads in GEMM. |
| onnxruntime/test/providers/cpu/ml/linearclassifer_test.cc | Adds regression tests asserting failures for malformed coefficient sizes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
69ed9f4 to
b6773d9
Compare
edgchen1
approved these changes
Apr 7, 2026
tianleiwu
added a commit
that referenced
this pull request
Apr 13, 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
Add input validation to the LinearClassifier operator to prevent an out-of-bounds heap read in GEMM when a crafted model provides mismatched coefficients/intercepts sizes.
Fixes https://portal.microsofticm.com/imp/v5/incidents/details/31000000559851/summary
Changes
class_count_ > 0andcoefficients_.size() % class_count_ == 0coefficients_.size() == class_count * num_featuresbefore GEMM callMotivation and Context
MSRC case 109185 (VULN-176698): OOB read via GEMM from crafted model in LinearClassifier operator. Root cause is missing validation that the coefficients vector size matches
[class_count, num_features]before passing raw pointers to GEMM.