[ML] Fail closed on incomplete TorchScript pre-load state-hook scan - #3149
Open
edsavage wants to merge 2 commits into
Open
[ML] Fail closed on incomplete TorchScript pre-load state-hook scan#3149edsavage wants to merge 2 commits into
edsavage wants to merge 2 commits into
Conversation
Reject unreadable or oversized zip record names so path-length truncation cannot skip the __setstate__/__getstate__ scan before torch::jit::load. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Pinging @elastic/ml-core (Team:ML) |
|
Hi @edsavage, I've created a changelog YAML for you. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens the TorchScript pre-load custom state-hook (__setstate__/__getstate__) archive scan in bin/pytorch_inference by failing closed when the scan cannot be completed safely, closing a path-length truncation evasion where torch::jit::load could still resolve and execute hooks.
Changes:
- Make
scanArchiveForCustomStateHooksfail closed (return an explicit sentinel) when encountering unreadable records or suspiciously long record names that can be truncated by PyTorch/miniz. - Update pre-load validation to fatal with a dedicated “incomplete scan” message before invoking
torch::jit::load. - Add a long-path evasion fixture generator and unit test coverage for the new fail-closed behavior.
Reviewed changes
Copilot reviewed 2 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| docs/changelog/3149.yaml | Adds changelog entry documenting the fail-closed scan behavior. |
| dev-tools/generate_malicious_models.py | Adds generator for a long-path evasion malicious TorchScript fixture ZIP. |
| bin/pytorch_inference/unittest/CModelGraphValidatorTest.cc | Adds unit tests for long-path evasion/incomplete scan handling and related assertions. |
| bin/pytorch_inference/Main.cc | Treats incomplete scan sentinel as fatal before model load. |
| bin/pytorch_inference/CModelGraphValidator.h | Documents fail-closed semantics and introduces sentinel + safe name-length constant. |
| bin/pytorch_inference/CModelGraphValidator.cc | Implements fail-closed behavior for unreadable records and oversized record names. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Summary
__setstate__/__getstate__scan: PyTorch/minizcan truncate long zip entry names sogetRecordfails; the previous fail-open skip allowedtorch::jit::loadto still run hooks.Follow-up to #3078. Related to elastic/security#12621.
Test plan
ml_test_pytorch_inference --run_test=CModelGraphValidatorTest/testPreLoadScan*pytorch_inferenceunit tests on PR builds