The vulnerability stems from unsafe deserialization using torch.load. The advisory highlights that the LLaMA-Factory application loads a vhead_file without the necessary weights_only=True safeguard in the torch.load function. This allows an attacker to craft a malicious model file (value_head.bin) that, when loaded by the application, executes arbitrary code on the server.
The investigation of the provided patch commit, bb7bf51554d4ba8432333c35a5e3b52705955ede, confirms this root cause. The commit applies the same fix—adding weights_only=True to torch.load calls—in two different locations:
-
load_valuehead_params: This function, located in src/llamafactory/model/model_utils/valuehead.py, is the primary function identified in the vulnerability description. It is called during the Reward Modeling training stage and takes a user-controlled 'Checkpoint path' from the WebUI to load model parameters. The lack of the weights_only=True flag makes it the direct entry point for the described remote code execution attack.
-
fix_valuehead_checkpoint: This function, found in src/llamafactory/train/callbacks.py, also contained a vulnerable torch.load call that was patched. It handles loading checkpoint files during the training process. While not the main attack vector described, it represents the same fundamental flaw and could be another potential avenue for exploitation.
Both functions would appear in a runtime profile during the exploitation of this vulnerability, as they are directly involved in loading the malicious file that triggers the code execution. The fix applied in the patch effectively mitigates the vulnerability by ensuring that torch.load only deserializes model weights and not arbitrary Python objects.