Abstract
PickleBall is a security framework designed to mitigate the risks of arbitrary code execution inherent in Python's pickle format, which remains a dominant standard for distributing machine learning models. By performing static analysis on trusted loading libraries rather than untrusted models, PickleBall generates fine-grained security policies that allow for safe model instantiation. Evaluation on a dataset of 336 models demonstrates that PickleBall achieves 100% detection of malicious payloads while maintaining 79.8% compatibility with benign models—significantly outperforming existing "weights-only" restrictive loaders.
Introduction: The "Pickle Bomb" Threat
In the machine learning ecosystem, the Python pickle format is a double-edged sword. Its ability to serialize almost any Python object makes it the de facto standard for sharing complex models. However, pickle is essentially a domain-specific language for a stack-based virtual machine; unpickling a file is equivalent to executing arbitrary code. Attackers can exploit this by crafting "pickle bombs"—malicious files that execute payloads, such as reverse shells or credential stealers, the moment a user calls model.load().
While safer alternatives like SafeTensors have been introduced, the transition has been slow. Existing defenses generally fall into two categories: model scanners, which use easily bypassed denylists, and restrictive loaders (like PyTorch’s "weights-only" mode), which are often too brittle to load legitimate models that use non-tensor metadata.
The Persistence of the Pickle Format
A longitudinal study of the Hugging Face ecosystem reveals that the pickle format is remarkably "sticky." Despite the push for safer formats, approximately 44.9% of popular models still utilize pickle. Furthermore, as shown in the longitudinal analysis, download rates for pickle-based models are actually increasing, highlighting a critical and growing security gap in the ML supply chain.
The PickleBall Framework
PickleBall addresses this challenge through a two-phase approach: Policy Generation and Policy Enforcement.
Static Policy Generation
Rather than attempting to identify malicious patterns in untrusted models, PickleBall identifies "benign" behavior by analyzing the trusted library (e.g., flair, yolov5) intended to load the model. Using static analysis, it traverses the library's abstract syntax tree (AST) to identify every class and function required to instantiate a model, producing a tailored allow-list of "Allowed Imports" and "Allowed Invocations."
Dynamic Enforcement and Lazy Loading
PickleBall acts as a drop-in replacement for the standard pickle module. During the loading process, it validates every operation against the generated policy. A key innovation is the use of Stub Objects for lazy enforcement. If a model attempts to import an object not found in the policy, PickleBall creates a "stub" rather than crashing. If the model never actually utilizes that object, the load succeeds. This significantly improves compatibility with benign models that may contain "junk" metadata or legacy references that are never executed.
Evaluation and Results
The authors evaluated PickleBall using a dataset of 252 benign models from 16 popular libraries and 84 malicious models, including real-world malware and synthetic exploits.
- Security: PickleBall achieved a 100% detection rate, successfully blocking all malicious payloads, including those specifically designed to bypass commercial scanners.
- Usability: It correctly loaded 79.8% of benign models. In contrast, PyTorch’s state-of-the-art "weights-only" unpickler only managed a 62.3% success rate on the same dataset.
- Performance: The runtime overhead for loading models is negligible, averaging approximately 2.62%, while the one-time policy generation cost for a library is typically under 15 seconds.
Conclusion
PickleBall demonstrates that the "Library as Truth" principle—defining safety based on the loading code rather than the model data—is a robust strategy for securing the ML supply chain. By combining static analysis with lazy dynamic enforcement, PickleBall provides a high-security, high-usability solution for the millions of models that continue to rely on the pickle format.
Summary updated