Summary
The mamba language model framework through version 2.2.6 insecurely deserializes model weights when loading pre-trained models from HuggingFace Hub.
Because MambaLMHeadModel.from_pretrained() calls torch.load() without weights_only=True, a malicious model repository can trigger arbitrary code execution on the system loading the model.
Affected context
This vulnerability affects applications and workflows that use the mamba language model framework (through 2.2.6) and load models using MambaLMHeadModel.from_pretrained() from remote repositories, such as HuggingFace Hub.
The risk is highest in environments where:
- Models are pulled from public or third-party repositories without strict trust validation
- Loading occurs in automated pipelines (e.g., experimentation, CI, batch jobs) without human review
- The mamba process runs with broad system permissions or access to sensitive data, credentials, or internal networks
Exploit preconditions
- Attack surface: Any system that invokes
MambaLMHeadModel.from_pretrained()on an untrusted or compromised model repository (e.g., HuggingFace Hub). - Required access: Ability for an attacker to publish or control a model repository that the victim will load, or to tamper with the
pytorch_model.binfile in transit or at rest. - Trigger point: The moment
torch.load()is called onpytorch_model.binbyfrom_pretrained()withoutweights_only=True, causing untrusted pickle content to be deserialized. - Why exploitation is possible:
torch.load()defaults to full pickle deserialization, allowing arbitrary Python objects and code to execute during loading, rather than restricting loading to tensor weights only.
Why this happens
The core issue is reliance on a general-purpose, pickle-based deserialization mechanism for untrusted model artifacts.
MambaLMHeadModel.from_pretrained() uses torch.load() on pytorch_model.bin without enabling the weights_only=True safeguard, so the file is treated as a generic pickle stream rather than a constrained collection of tensor weights.
This pattern aligns with CWE-502: Unsafe Deserialization, where data that can be influenced by an attacker is deserialized into executable objects, allowing them to embed logic that runs automatically on load.
Conceptually, the model loading pipeline conflates "data" (numerical weights) with "code" (arbitrary objects and constructors), breaking the expectation that model weights are passive content.
Potential impact
- Execution of arbitrary Python code on the victim machine in the context of the mamba process
- Theft or exfiltration of API keys, access tokens, and other secrets available to the process
- Access to and modification of training data, evaluation datasets, or proprietary models
- Lateral movement within the network if the process has connectivity to internal services
- Installation of persistence mechanisms (backdoors, scheduled tasks, malicious dependencies)
- Data poisoning of downstream models or pipelines that rely on the compromised environment
General mitigation guidance
Mitigation generally focuses on treating model artifacts as untrusted input and constraining how they are loaded:
- Prefer deserialization modes that restrict behavior to data-only, such as enabling
weights_onlyor equivalent safe-loading options, so that only tensor weights are accepted. - Introduce explicit separation between "code" and "data" by loading model architecture from trusted local code and weights from external sources, rather than executing objects from model files.
- Enforce strict provenance and trust controls for model repositories, using allowlists, internal registries, or signed artifacts to control what can be loaded in production.
- Run model loading and inference with least privilege: minimize filesystem access, environment visibility, and network reachability of the mamba process.
- Apply sandboxing or containerization around model loading steps to limit damage if a malicious artifact is processed.
- Incorporate secure defaults in framework utilities so that unsafe deserialization is not the out-of-the-box behavior.
How teams detect issues like this
Detection typically combines code analysis, configuration review, and environment monitoring:
- Static analysis / code scanning: Search for
torch.load()(or similar deserialization functions) used on model artifacts without safety parameters such asweights_only=True. Flag any use that can ingest remote or user-controlled files. - Code review signals: In pull requests, scrutinize new or modified model-loading utilities for direct pickle usage, generic deserialization, or implicit trust in external model hubs and registries.
- Policy enforcement: Establish internal guidelines that prohibit unsafe deserialization of remote models and require explicit safe-loading wrappers for all model-loading code paths.
- Runtime monitoring: Observe model-loading hosts for unexpected outbound connections, anomalous process spawning, or file system changes during or immediately after model load operations.
- Automated tooling: Integrate SAST tools and secret-scanning/behavioral analytics into CI/CD pipelines to surface unsafe deserialization patterns and suspicious activity early.

