# Model Deserialization Attacks > Remote code execution through the serialized formats used to distribute and load machine-learning models — overwhelmingly Python pickle under `torch.load`/`joblib`, but also checkpoint, cache and IPC formats — where loading a model is loading code. ## Why this is its own problem Pickle's RCE risk is old (see [[Python Pickle Deserialization]]); what is new is scale and threat-model blindness. PyTorch standardised pickle as the model format in 2018, so `torch.load`, `joblib.load`, HuggingFace hubs and countless pipelines unpickle by default. The reviewer who approves `joblib.load("classifier_v2.pkl")` checks API usage and paths but never asks where the file came from, because "it's a model file" was never in the threat model (Afine). The blast radius: code runs with the inference process's privileges — often root in containers, with cloud instance-metadata credentials reachable, feeding directly into [[AI Infrastructure Vulnerabilities]]. ## Attack surfaces - **Supply-chain poisoning.** A malicious model uploaded to a sharing platform executes on download/load. Academic work ("The Art of Hide and Seek") systematised the poisoning surface: **22 model loading paths** across five frameworks (19 missed by scanners) and **133 exploitable gadgets** with near-100% scanner bypass, plus Exception-Oriented Programming (EOP) to evade detection; it earned a $6000 bounty. - **Network-exposed deserialization.** Model-serving infrastructure unpickling off sockets/queues: vLLM (CVE-2025-32444, CVSS 10.0 over ZeroMQ), LightLLM, LMCache (CVE-2026-105192), LMDeploy (CVE-2026-119706), Xoscar (CVE-2026-49950, cloudpickle). - **Untrusted file / cache loads.** FAISS `index.pkl` upload in DocsGPT (`allow_dangerous_deserialization=True`); `torch.load(weights_only=False)` on `.th`/`.pt` files (audio-separator CVE-2026-134172, Stanza lemmatizer CVE-2026-115878 where attacker bytes reach `pickle.loads` even under `weights_only=True`); dataset cache files (Ultralytics ZDI-26-816); HuggingFace `datasets` pandas builder (CVE-2026-57845); LSP symbol-cache poisoning in the Serena coding agent (≤1.7.1). - **Beyond pickle.** Qiskit QPY `qiskit.qpy.load()` embedding Python (CVE-2026-116499); numcodecs pickle codec on Zarr chunk decode; NVIDIA Megatron-LM / Model Optimizer checkpoint loads; Meta FAIRChem / Detectron2 / fairseq and Microsoft Qlib MLflowRecorder (ZDI series); MLflow PickleEvaluationArtifact / SHAP / statsmodels loaders. ## Scanner limitations `picklescan` and `modelscan` parse bytecode against a denylist and must interpret files exactly as the loader does — any divergence is a bypass. JFrog found three zero-days (CVE-2025-10155/10156/10157: file-extension trust, ZIP CRC, subclass imports); Sonatype found four more (CVE-2025-1716/1889/1944/1945: static-analysis bypass, hidden files, ZIP filename/flag tampering). Denylists cannot anticipate new gadgets; PickleBall (static-analysis-driven load-time policies) and allowlist unpicklers are the research direction, though NLTK's `AllowlistUnpickler` still missed numpy file-I/O sinks. ## Prevention - Prefer `safetensors` (no code execution) for weights; use data-only formats for config/cache. HuggingFace made safetensors the `transformers` default. - Treat every model/checkpoint/cache/dataset file as untrusted input; verify provenance and integrity, not just the extension. - Isolate model loading (least privilege, no ambient cloud creds, network egress controls) so an RCE is contained; bind serving IPC/sockets to localhost and authenticate peers before deserializing. - Don't rely on a single scanner; combine provenance, allowlist loaders, and sandboxing. ## Related - [[Python Pickle Deserialization]] - [[Insecure Deserialization]] - [[Python AI and ML Framework Vulnerabilities]] - [[AI Infrastructure Vulnerabilities]] - [[Software Supply Chain Security]] - [[Remote Code Execution]] ## Sources - [[raw/afine.com/pickle-deserialization-in-ml-pipelines-the-rce-that-won-t-go-away-3815|Pickle Deserialization in ML Pipelines]] - [[raw/arxiv.org/the-art-of-hide-and-seek-pickle-based-model-supply-chain-poisoning-4356|The Art of Hide and Seek: Model Supply Chain Poisoning]] - [[raw/arxiv.org/pickleball-secure-deserialization-of-pickle-based-ml-models-3788|PickleBall: Secure Deserialization of Pickle-based ML Models]] - [[raw/jfrog.com/pytorch-users-at-risk-3-zero-day-picklescan-vulnerabilities-jfrog-2855|PyTorch Users at Risk: 3 Zero-Day PickleScan Vulnerabilities]] - [[raw/sonatype.com/exposing-4-critical-vulnerabilities-in-python-picklescan-sonatype-2851|Exposing 4 Critical Vulnerabilities in Python PickleScan]] - [[raw/github.com/docsgpt-unauthenticated-rce-via-faiss-pickle-deserialization-13228|DocsGPT unauthenticated RCE via FAISS pickle]] - [[raw/github.com/audio-separator-insecure-deserialization-15511|audio-separator insecure deserialization]] - [[raw/github.com/stanza-rce-via-pickle-deserialization-in-the-lemmatizer-13585|Stanza RCE via pickle deserialization in the lemmatizer]] - [[raw/zerodayinitiative.com/zdi-26-816-ultralytics-load-dataset-cache-file-deserialization-rce-12480|ZDI-26-816: Ultralytics cache file deserialization RCE]] - [[raw/dailysecurityreview.com/public-poc-for-hugging-face-datasets-pickle-deserialization-rce-cve-20-13913|Hugging Face datasets pickle deserialization RCE]] - [[raw/ibm.com/ibm-arbitrary-code-execution-in-qiskit-sdk-qpy-deserialization-13580|Qiskit SDK QPY deserialization RCE]] - [[raw/github.com/serena-rce-via-insecure-pickle-deserialization-of-lsp-symbol-cache-12477|Serena RCE via LSP symbol cache pickle]] - [[raw/github.com/nvidia-model-optimizer-unsafe-deserialization-15246|NVIDIA Model Optimizer unsafe deserialization]]