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.

Sources