GHSA-r54c-2xmf-2cf3: Ms swift Remote Code Execution Vulnerability
MODERATEGHSA-r54c-2xmf-2cf3 is a MODERATE remote code execution vulnerability (CWE-502: Deserialization of Untrusted Data) affecting Ms swift libraries in the PyPI ecosystem. The issue involves ms swift deserialization rce vulnerability. Remediation is available in the latest vendor maintenance releases.
GHSA-r54c-2xmf-2cf3 at a Glance
How to Fix GHSA-r54c-2xmf-2cf3
To remediate this vulnerability, upgrade all affected Ms swift dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
pip install ms-swift>=Latest secure release
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
pip show ms-swift
How to Check if You Are Affected
To determine whether your Python environment is affected by GHSA-r54c-2xmf-2cf3, inspect your installed packages using pip:
pip show ms-swift
Analyze the terminal output to locate any version of Ms swift in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than the patched release), your application is affected.
Note: The pip show ms-swift command checks currently installed packages in your active Python environment.
Technical Details
Vulnerability Mechanism & Technical Analysis
This vulnerability is classified under CWE-502: Deserialization of Untrusted Data, where the product deserializes untrusted data without sufficiently ensuring that the resulting data will be valid. In Ms swift, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.
Source Advisory Statement
GHSA-r54c-2xmf-2cf3 Affected Ms swift Versions
1 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
ms-swift
|
PyPI |
≤ 3.6.3
|
|
References
Frequently Asked Questions
What is GHSA-r54c-2xmf-2cf3?
Which Ms swift versions are affected?
What version fixes GHSA-r54c-2xmf-2cf3?
Is ms-swift affected?
What CWE is associated with GHSA-r54c-2xmf-2cf3?
How can I check PyPI dependencies for GHSA-r54c-2xmf-2cf3?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-r54c-2xmf-2cf3",
"modified" : "2025-07-31T14:06:13Z",
"published" : "2025-07-31T14:05:13Z",
"aliases" : [ ],
"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.\n\nThis occurs when using machine torch version < 2.6.0, while ms-swift accepts torch version >= 2.0\n\n**I. Detailed Description:**\n1. Install ms-swift\n```\npip install ms-swift -U\n```\n\n2. Start web-ui\n```\nswift web-ui --lang en\n```\n\n3. After startup, you can access [http://localhost:7860/](http://localhost:7860/) through your browser to see the launched fine-tuning framework program\n\n4. Upload an adapter model repository (cyjhhh/lora_adapter_4_llama3) on ModelScope, where the lora/adapter_model.bin file is generated through the following code:\n```python\nimport torch, pickle, os\n\nclass MaliciousPayload:\n def __reduce__(self):\n return (os.system, (\"touch /tmp/malicious.txt\",)) # Arbitrary command\n\nmalicious_data = {\n \"v_head.summary.weight\": MaliciousPayload(),\n \"v_head.summary.bias\": torch.randn(10)\n}\n\nif __name__ == \"__main__\":\n with open(\"adapter_model.bin\", \"wb\") as f:\n pickle.dump(malicious_data, f)\n```\n\n5. 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\n\n6. Click Begin to submit. You can see the backend command running as follows\n\n7. By reading the ms-swift source code, swift.llm.model.utils#safe_snapshot_download() and modelscope.hub.utils.utils#get_cache_dir(), 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:\n```\n~/.cache/modelscope/hub/models/cyjhhh/lora_adapter_4_llama3\n```\nWait 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\n\n8. Second training submission, configure the page parameters as follows\n\nClick submit to see the backend command running as follows\n\n9. After waiting for a while, you can see that torch.load() loaded the malicious adapter_model.bin file and successfully executed the command. Related execution information can also be seen in the log file corresponding to --logging_dir\n\n10. Note (Prerequisites)\nRequires machine torch version < 2.6.0, while ms-swift accepts torch version >= 2.0\n\n**II. Vulnerability Proof:**\n1. Remote downloaded adapter malicious model: [[lora_adapter_4_llama3](https://www.modelscope.cn/models/cyjhhh/lora_adapter_4_llama3/files)](https://www.modelscope.cn/models/cyjhhh/lora_adapter_4_llama3/files)\n2. 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\n3. 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\n\n**III. Fix Solution:**\n```\nSWIFT has disabled torch.load operations from 3.7 or later.\n```\n\n## Author\n\n* Discovered by: [TencentAISec](https://github.com/TencentAISec)\n* Contact: *[security@tencent.com](mailto:security@tencent.com)*",
"severity" : [ {
"type" : "CVSS_V4",
"score" : "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"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "PyPI",
"name" : "ms-swift"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"last_affected" : "3.6.3"
} ]
} ]
} ],
"references" : [ {
"type" : "WEB",
"url" : "https://github.com/modelscope/ms-swift/security/advisories/GHSA-r54c-2xmf-2cf3"
}, {
"type" : "WEB",
"url" : "https://github.com/modelscope/ms-swift/commit/cc47463bcd25a8720437cf945130f43052eec5e4"
}, {
"type" : "PACKAGE",
"url" : "https://github.com/modelscope/ms-swift"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-502" ],
"severity" : "MODERATE",
"github_reviewed" : true,
"github_reviewed_at" : "2025-07-31T14:05:13Z",
"nvd_published_at" : null
}
}