/

CVE-2026-31239

Severity:

CRITICAL RISK

(9.8)

Unsafe Deserialization in MambaLMHeadModel.from_pretrained

CVE-2026-31239

Deferred

Vulnerability type

Category:

Unsafe Deserialization

CWE:

CWE-502

Impact:

Remote Code Execution via Malicious Model Artifacts

Severity:

CRITICAL RISK

(9.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

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.bin file in transit or at rest.
  • Trigger point: The moment torch.load() is called on pytorch_model.bin by from_pretrained() without weights_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_only or 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 as weights_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.

Sources

SourceLink
github.comgithub.com/state-spaces/mamba
notion.sonotion.so/CVE-2026-31239-35d1e1393188810d9baedfbd8363f396

Frequently asked

questions

Yes, indirectly. An attacker can host a malicious model in a remote repository (e.g., on HuggingFace Hub). When a victim's code calls MambaLMHeadModel.from_pretrained() on that repository, the attacker-controlled pickle content is deserialized and can execute code on the victim's machine.

The attacker needs to control the model artifact being loaded or the repository from which it is fetched. They do not need local access to the victim system; they just need to ensure that the victim loads their malicious model, for example by publishing it publicly or getting it referenced by scripts or examples.

The safest pattern is to prevent general-purpose pickle deserialization for model weights: use data-only loading mechanisms (such as enabling weights_only or equivalent), ensure that only tensors are deserialized, and keep the executable model code separate and locally trusted. Additionally, restrict which repositories can be used for from_pretrained() through allowlists or internal registries.

Treat all externally sourced model files as untrusted input, enforce safe-loading APIs by default in frameworks, and document that remote models must never be deserialized with generic pickle mechanisms. Combine this with organizational policies on model provenance, thorough code review of loading utilities, and running ML workloads with least privilege and isolation to limit impact if a malicious artifact slips through.

Find out what's already
exploitable in your codebase.