Downloads · 30 days
0
yibai777/pytorch-audit
pytorch-audit is a machine learning model from yibai777. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
Format: Torch Export (.pt2) – PyTorch Project: PyTorch (pytorch/pytorch) Version: 2.12.0 Severity: Critical – RCE on model load
Downloads · 30 days
0
Access
Public
Updated May 15, 2026
Repo size
227 KB
Likes
0
Public
Click a slice to open those files.
.png227 KB · 94%
From the Hugging Face model README
Format: Torch Export (.pt2) – PyTorch
Project: PyTorch (pytorch/pytorch)
Version: 2.12.0
Severity: Critical – RCE on model load
torch.load() attempt to use weights_only=True, but the except fallback still uses weights_only=False.weights_only=True attempt (e.g., using blocked globals) and the fallback loads it unsafely.deserialize_torch_artifact() in torch/_export/serde/serialize.py:422-445 first tries weights_only=True, and on any exception falls back to weights_only=False:
try:
artifact = torch.load(buffer, weights_only=True) # line 437
except Exception as e:
buffer.seek(0)
artifact = torch.load(buffer, weights_only=False) # line 440 – FALLBACK!
An attacker crafts data/sample_inputs/model.pt in a .pt2 archive that references os.system (blocklisted). The weights_only=True path fails → falls back to weights_only=False → standard pickle.load() executes the payload.
When weights_only=False, torch.load() calls _legacy_load() which does pickle_module.load(f) at serialization.py:1887 — this is a full unpickling operation that executes the malicious pickle before checking the magic number.
Any user calling torch.export.load("malicious.pt2") gets RCE. This is a separate code path from the weights loading RCE in _package.py:877.
python poc_serialize_fallback.py --cmd "echo PWNED" --test-load
Output:
[!] weights_only=True → Exception → weights_only=False
[!] Post-exploitation error: RuntimeError: ...
But the command already executed (check PWNED output).
data/sample_inputs/model.pt with pickle using GLOBAL os systemtorch.export.load() → deserialize_torch_artifact() → try weights_only=True → blockedweights_only=False → _legacy_load → pickle.load() → RCE| File | Purpose |
|---|---|
poc_serialize_fallback.py | Exploit PoC – generate & test malicious .pt2 |
torch/_export/serde/serialize.py:437-440 – Fallback to weights_only=Falsetorch/serialization.py:1887 – pickle_module.load() executes before magic check