-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Verify in-memory references when loading a model #26764
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
XXX: Problem, ModelEditor can create models with in-memory references, which causes issues when loading such models.
…ith 'import' and 'import from' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds a critical security fix to prevent arbitrary memory access when loading ONNX models with malicious in-memory external data references. The fix validates that any in-memory references (identified by the special tag */_ORT_MEM_ADDR_/*) point to valid OrtValue objects created through ModelEditor, rather than allowing arbitrary memory addresses to be dereferenced.
Key changes:
- Added validation logic in
Graph::ConvertInitializersIntoOrtValues()to verify in-memory external data references match existing OrtValue initializers - Added validation in
Graph::AddInitializedOrtValue()to ensure data pointer consistency between tensor proto and OrtValue - Created test artifacts to demonstrate the vulnerability and verify the fix
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| onnxruntime/test/testdata/test_evil_weights.py | Python script that generates a malicious ONNX model with arbitrary in-memory external data references for testing the security fix |
| onnxruntime/test/testdata/test_evil_weights.onnx | Binary ONNX model file generated by the Python script containing malicious external data references |
| onnxruntime/test/shared_lib/test_inference.cc | C++ test case that verifies models with malicious external data references fail to load with appropriate error messages |
| onnxruntime/core/graph/graph.cc | Core security fix that validates in-memory references during model loading and prevents arbitrary memory access |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Description
When loading the model verify that in-memory references point to an existing and valid OrtValue as if created my ModelEditor.
Motivation and Context
This prevents reading from arbitrary memory location when loading the model.