Heavy Weights: Crushing PyTorch's 'Secure' Loader via Heap Corruption
Vulnerability ID: CVE-2026-24747
CVSS Score: 8.8
Published: 2026-01-27
A critical heap corruption vulnerability in PyTorch's restricted unpickler allows attackers to bypass the weights_only=True security flag, turning safe model loading into arbitrary code execution.
TL;DR
The weights_only=True flag in PyTorch was supposed to be the silver bullet against Pickle RCE. However, a logic flaw in the underlying C++ unpickler allows attackers to use the SETITEM opcode on non-container objects. This causes Type Confusion on the heap, allowing a malicious model file to corrupt memory and execute arbitrary code, even when the user explicitly requests 'safe' loading.
⚠️ Exploit Status: POC
Technical Details
- CWE ID: CWE-843 (Type Confusion)
- Attack Vector: Network / File (Context Dependent)
- CVSS: 8.8 (Critical)
- Impact: Remote Code Execution (RCE)
- Trigger: Opcode 'SETITEM' on non-container
- Component: torch/csrc/jit/serialization/unpickler.cpp
Affected Systems
- PyTorch < 2.10.0
- Systems loading untrusted .pt/.pth files
- Model training pipelines using SWALR
-
PyTorch: < 2.10.0 (Fixed in:
2.10.0)
Code Analysis
Commit: 954dc51
Fix SWALR serialization to prevent anneal_func pickling
@@ -1,5 +1,9 @@
- return {key: value for key, value in self.__dict__.items()}
+ state = self.__dict__.copy()
+ state.pop('anneal_func', None)
+ state['_anneal_strategy'] = self._anneal_strategy
+ return state
Exploit Details
- GitHub Issue: Initial report identifying the crash and opcode failure in SWALR serialization.
Mitigation Strategies
- Enforce strict type validation in C++ unpickler opcodes
- Sanitize
SWALRand other scheduler serializations - Migrate to SafeTensors format where possible
Remediation Steps:
- Upgrade PyTorch to version 2.10.0 or later immediately.
- Regenerate any checkpoints created with the vulnerable
SWALRimplementation. - Audit codebases for
torch.loadcalls and ensure they handle exceptions gracefully.
References
Read the full report for CVE-2026-24747 on our website for more details including interactive diagrams and full exploit analysis.
Top comments (0)