GHSA-r54c-2xmf-2cf3

Suggest an improvement
Source
https://github.com/advisories/GHSA-r54c-2xmf-2cf3
Import Source
https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2025/07/GHSA-r54c-2xmf-2cf3/GHSA-r54c-2xmf-2cf3.json
JSON Data
https://api.osv.dev/v1/vulns/GHSA-r54c-2xmf-2cf3
Published
2025-07-31T14:05:13Z
Modified
2025-08-12T05:50:23.537488Z
Severity
  • 6.6 (Medium) CVSS_V4 - CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:A/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N/E:P CVSS Calculator
Summary
MS SWIFT Deserialization RCE Vulnerability
Details

This appears to be a security vulnerability report describing a remote code execution (RCE) exploit in the ms-swift framework through malicious pickle deserialization in adapter model files. The vulnerability allows arbitrary command execution when loading specially crafted adapter models from ModelScope.

This occurs when using machine torch version < 2.6.0, while ms-swift accepts torch version >= 2.0

I. Detailed Description: 1. Install ms-swift

pip install ms-swift -U
  1. Start web-ui

    swift web-ui --lang en
    
  2. After startup, you can access http://localhost:7860/ through your browser to see the launched fine-tuning framework program

  3. Upload an adapter model repository (cyjhhh/loraadapter4llama3) on ModelScope, where the lora/adaptermodel.bin file is generated through the following code:

    import torch, pickle, os
    
    class MaliciousPayload:
       def __reduce__(self):
           return (os.system, ("touch /tmp/malicious.txt",))  # Arbitrary command
    
    malicious_data = {
       "v_head.summary.weight": MaliciousPayload(),
       "v_head.summary.bias": torch.randn(10)
    }
    
    if __name__ == "__main__":
       with open("adapter_model.bin", "wb") as f:
           pickle.dump(malicious_data, f)
    
  4. First training submission: First, fill in the required parameters in the LLM Training interface, including Model id and Dataset Code, and configure the following in the Other params section of Advanced settings

  5. Click Begin to submit. You can see the backend command running as follows

  6. By reading the ms-swift source code, swift.llm.model.utils#safesnapshotdownload() and modelscope.hub.utils.utils#getcachedir(), we can see that adapters are downloaded locally to the path ~/.cache/modelscope. Therefore, the complete local path for the specified remote adapters after download is:

    ~/.cache/modelscope/hub/models/cyjhhh/lora_adapter_4_llama3
    

    Wait for the first submission program until the adapters download is complete, then you can click "kill running task" on the page to terminate the first training

  7. Second training submission, configure the page parameters as follows

Click submit to see the backend command running as follows

  1. After waiting for a while, you can see that torch.load() loaded the malicious adaptermodel.bin file and successfully executed the command. Related execution information can also be seen in the log file corresponding to --loggingdir

  2. Note (Prerequisites) Requires machine torch version < 2.6.0, while ms-swift accepts torch version >= 2.0

II. Vulnerability Proof: 1. Remote downloaded adapter malicious model: [loraadapter4llama3](https://www.modelscope.cn/models/cyjhhh/loraadapter4llama3/files) 2. For the second training submission, it's recommended to follow the parameters shown in the screenshots above for reproduction, as it will validate the target modules specified in the base model and adapter config. If they don't match, the program will terminate early. It's also recommended to select the same dataset content as shown in the screenshots 3. This report only reproduces RCE for one entry point (single path). In reality, there are more than one path in the code that can cause deserialization RCE

III. Fix Solution:

SWIFT has disabled torch.load operations from 3.7 or later.

Author

Database specific
{
    "github_reviewed": true,
    "github_reviewed_at": "2025-07-31T14:05:13Z",
    "severity": "MODERATE",
    "nvd_published_at": null,
    "cwe_ids": [
        "CWE-502"
    ]
}
References

Affected packages

PyPI / ms-swift

Package

Affected ranges

Type
ECOSYSTEM
Events
Introduced
0Unknown introduced version / All previous versions are affected
Last affected
3.6.3

Affected versions

1.*
1.0.0
1.1.0
1.2.0
1.2.1
1.3.0
1.4.0
1.5.0
1.5.1
1.5.2
1.5.3
1.5.4
1.6.0
1.6.1
1.6.2
1.6.3
1.7.0
1.7.1
1.7.2
1.7.3
2.*
2.0.0
2.0.1
2.0.2
2.0.3
2.0.3.post1
2.0.4
2.0.5
2.0.5.post1
2.1.0
2.1.1
2.1.1.post1
2.1.1.post2
2.2.0
2.2.1
2.2.2
2.2.3
2.2.4
2.2.5
2.3.0
2.3.0.post1
2.3.1
2.3.2
2.3.2.post1
2.4.0
2.4.0.post1
2.4.1
2.4.2
2.4.2.post1
2.4.2.post2
2.5.0.post1
2.5.1
2.5.1.post1
2.5.2
2.5.2.post1
2.6.0
2.6.0.post1
2.6.0.post2
2.6.1
3.*
3.0.0
3.0.1
3.0.1.post1
3.0.2
3.0.2.post1
3.0.3
3.1.0
3.1.1
3.1.1.post1
3.2.0
3.2.0.post2
3.2.1
3.2.2
3.3.0
3.3.0.post1
3.3.1
3.4.0
3.4.1
3.4.1.post1
3.5.0
3.5.1
3.5.2
3.5.3
3.6.0
3.6.1
3.6.2
3.6.3

Database specific

source
"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2025/07/GHSA-r54c-2xmf-2cf3/GHSA-r54c-2xmf-2cf3.json"