Summary
Malicious pickle files can exploit torch._dynamo.guards.GuardBuilder.get via custom reduce methods to bypass picklescan's detection logic.
When these crafted pickle files are loaded, embedded code may execute arbitrary commands on the host, especially in environments that rely on picklescan as a primary safety check.
Affected context
This vulnerability appears in workflows that:
- Use Python pickle files for model, data, or configuration serialization
- Rely on picklescan (before 0.0.28) to detect and block malicious pickle content
- Load pickle files that may originate from external, shared, or untrusted sources
The issue is tied to picklescan's limited awareness of payloads abusing torch._dynamo.guards.GuardBuilder.get in reduce methods.
Exploit preconditions
- Attack surface: Any application or pipeline that loads pickle files validated by vulnerable picklescan versions
- Required access: Ability to supply or influence pickle files consumed by the target environment
- Trigger point: Deserialization of the crafted pickle using Python's pickle loading APIs (e.g.,
pickle.load,torch.load) - Why exploitation is possible: picklescan's inspection logic does not correctly recognize payloads that leverage GuardBuilder.get in reduce methods, allowing arbitrary object construction and code execution to pass undetected.
Why this happens
The underlying issue is a form of unsafe deserialization where complex Python objects are reconstructed from untrusted pickle data.
picklescan's detection heuristics are incomplete: they fail to account for malicious use of torch._dynamo.guards.GuardBuilder.get invoked via custom reduce methods, a pathway that can perform arbitrary actions when objects are rehydrated.
This maps to CWE-502: Unsafe Deserialization, where serialized data is treated as trusted instructions for object creation without robust validation or sandboxing.
Potential impact
- Execution of arbitrary commands on systems that load attacker-controlled pickle files
- Compromise of ML training or inference environments, including GPU-enabled nodes
- Data exfiltration or tampering within analytic or model-serving pipelines
- Installation of backdoors or persistence mechanisms via deserialization hooks
- Lateral movement from compromised ML workloads into broader infrastructure
General mitigation guidance
Mitigation generally focuses on reducing trust in serialized data and narrowing deserialization capabilities:
- Avoid loading pickle files from untrusted or unauthenticated sources; prefer safer, data-only serialization formats (e.g., JSON, protobuf) where feasible.
- Limit the set of allowable object types and modules that can be reconstructed during deserialization, using controlled loaders or whitelists.
- Isolate deserialization into hardened, least-privileged processes or containers so that any code execution is confined.
- Enforce strong input validation and provenance checks for artifacts in ML pipelines, including models and datasets.
- Treat security scanners like picklescan as one layer of defense, complemented by architectural safeguards that assume deserialization may be hostile.
How teams detect issues like this
Effective detection typically combines code, configuration, and artifact inspection:
- Use static analysis or policy checks to flag reliance on generic pickle APIs with untrusted inputs, especially in ML and data pipelines.
- Review deserialization call sites for use of complex objects, custom reduce methods, or hooks that execute logic on load.
- Integrate artifact scanning into CI/CD and model registries, using tools that understand Python's serialization semantics and known abuse patterns.
- Establish security policies that restrict arbitrary pickle loading in production services, and monitor for unexpected deserialization behaviors or modules in use.
- Periodically audit ML workflows and shared artifact repositories for anonymously supplied or unverified pickle files.

