Skip to content

Add bounds validation for LinearClassifier coefficients#27989

Merged
vraspar merged 1 commit intomainfrom
vraspar/fix-linearclassifier-oob-read
Apr 9, 2026
Merged

Add bounds validation for LinearClassifier coefficients#27989
vraspar merged 1 commit intomainfrom
vraspar/fix-linearclassifier-oob-read

Conversation

@vraspar
Copy link
Copy Markdown
Contributor

@vraspar vraspar commented Apr 6, 2026

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

  • Constructor: Validate class_count_ > 0 and coefficients_.size() % class_count_ == 0
  • Compute(): Validate coefficients_.size() == class_count * num_features before GEMM call
  • Tests: Two regression tests for invalid coefficient sizes

Motivation 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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_ > 0 and coefficients_.size() divisibility by class_count_.
  • Add runtime validation in Compute() that coefficients_.size() == class_count * num_features before 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.

@vraspar vraspar requested a review from edgchen1 April 6, 2026 17:36
@vraspar vraspar force-pushed the vraspar/fix-linearclassifier-oob-read branch from 69ed9f4 to b6773d9 Compare April 6, 2026 18:43
@vraspar vraspar merged commit 9c90e79 into main Apr 9, 2026
104 of 107 checks passed
@vraspar vraspar deleted the vraspar/fix-linearclassifier-oob-read branch April 9, 2026 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants