Skip to content

LLaMA-Factory allows Code Injection through improper vhead_file safeguards

High severity GitHub Reviewed Published Jun 26, 2025 in hiyouga/LLaMA-Factory • Updated Jun 27, 2025

Package

pip llamafactory (pip)

Affected versions

<= 0.9.3

Patched versions

None

Description

Summary

A critical remote code execution vulnerability was discovered during the Llama Factory training process. This vulnerability arises because the vhead_file is loaded without proper safeguards, allowing malicious attackers to execute arbitrary malicious code on the host system simply by passing a malicious Checkpoint path parameter through the WebUI interface. The attack is stealthy, as the victim remains unaware of the exploitation. The root cause is that the vhead_file argument is loaded without the secure parameter weights_only=True.

Note: In torch versions <2.6, the default setting is weights_only=False, and Llama Factory's setup.py only requires torch>=2.0.0.

Affected Version

Llama Factory versions <=0.9.3 are affected by this vulnerability.

Details

  1. In LLaMA Factory's WebUI, when a user sets the Checkpoint path, it modifies the adapter_name_or_path parameter passed to the training process.
    code in src/llamafactory/webui/runner.py

image-1

  1. The adapter_name_or_path passed to the training process is then used in src/llamafactory/model/model_utils/valuehead.py to fetch the corresponding value_head.bin file from Hugging Face. This file is subsequently loaded via torch.load() without the security parameter weights_only=True being set, resulting in remote code execution.
    code in src/llamafactory/model/model_utils/valuehead.py

image-2

PoC

Steps to Reproduce

  1. Deploy llama factory.
  2. Remote attack through the WebUI interface
    1. Configure Model name and Model path correctly. For demonstration purposes, we'll use a small model llamafactory/tiny-random-Llama-3 to accelerate model loading.
    2. Set Finetuning method to LoRA and Train Stage to Reward Modeling. The vulnerability is specifically triggered during the Reward Modeling training stage.
    3. Input a malicious Hugging Face path in Checkpoint path – here we use paulinsider/llamafactory-hack. This repository(https://huggingface.co/paulinsider/llamafactory-hack/tree/main ) contains a malicious value_head.bin file. The generation method for this file is as follows (it can execute arbitrary attack commands; for demonstration, we configured it to create a HACKED! folder).
    4. Click Start to begin training. After a brief wait, a HACKED! folder will be created on the server. Note that arbitrary malicious code could be executed through this method.

The video demonstration of the vulnerability exploitation is available at the Google Drive Link

Impact

Exploitation of this vulnerability allows remote attackers to:

  • Execute arbitrary malicious code / OS commands on the server.
  • Potentially compromise sensitive data or escalate privileges.
  • Deploy malware or create persistent backdoors in the system.
    This significantly increases the risk of data breaches and operational disruption.

References

@hiyouga hiyouga published to hiyouga/LLaMA-Factory Jun 26, 2025
Published by the National Vulnerability Database Jun 26, 2025
Published to the GitHub Advisory Database Jun 27, 2025
Reviewed Jun 27, 2025
Last updated Jun 27, 2025

Severity

High

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
Low
User interaction
None
Scope
Unchanged
Confidentiality
High
Integrity
Low
Availability
High

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:L/A:H

EPSS score

Exploit Prediction Scoring System (EPSS)

This score estimates the probability of this vulnerability being exploited within the next 30 days. Data provided by FIRST.
(51st percentile)

Weaknesses

CVE ID

CVE-2025-53002

GHSA ID

GHSA-xj56-p8mm-qmxj

Source code

Credits

Loading Checking history
See something to contribute? Suggest improvements for this vulnerability.