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.
Llama Factory versions <=0.9.3 are affected by this vulnerability.
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
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
Model name and Model path correctly. For demonstration purposes, we'll use a small model llamafactory/tiny-random-Llama-3 to accelerate model loading.Finetuning method to LoRA and Train Stage to Reward Modeling....0.7.10.8.00.8.10.8.20.8.30.9.00.9.10.9.20.9.3Exploitability
AV:NAC:LPR:LUI:NScope
S:UImpact
C:HI:LA:HCVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:L/A:H