CVE-2024-31583: Torch Pytorch Use-after-free Vulnerability Vulnerability
HIGHCVE-2024-31583 is a HIGH (CVSS 7.8) pytorch use-after-free vulnerability vulnerability (CWE-416: Use After Free) affecting Torch libraries in the PyPI ecosystem. The issue involves pytorch use-after-free vulnerability. Remediation is available by upgrading affected packages to version 2.2.0.
CVE-2024-31583 at a Glance
Security Impact
CVSS: 7.8
The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H).
How to Fix CVE-2024-31583
To remediate this vulnerability, upgrade all affected Torch 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 torch>=2.2.0
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
pip show torch
How to Check if You Are Affected
To determine whether your Python environment is affected by CVE-2024-31583, inspect your installed packages using pip:
pip show torch
Analyze the terminal output to locate any version of Torch in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 2.2.0), your application is affected.
Note: The pip show torch command checks currently installed packages in your active Python environment.
Technical Details
Vulnerability Mechanism & Technical Analysis
This vulnerability is classified under CWE-416: Use After Free, where the product reuses or references memory after it has been freed. at some point afterward, the memory may be allocated again and saved in another pointer, while the original pointer references a location somewhere within the new allocation. any operations using the original pointer are no longer valid because the memory "belongs" to the code that operates on the new pointer. In Torch, 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
CVE-2024-31583 Affected Torch Versions
1 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
torch
|
PyPI |
< 2.2.0
|
2.2.0
|
References
Frequently Asked Questions
What is CVE-2024-31583?
Which Torch versions are affected?
What version fixes CVE-2024-31583?
Is torch affected?
What is the CVSS score of CVE-2024-31583?
What CWE is associated with CVE-2024-31583?
How can I check PyPI dependencies for CVE-2024-31583?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-pg7h-5qx3-wjr3",
"modified" : "2025-06-10T14:52:02Z",
"published" : "2024-04-17T21:30:48Z",
"aliases" : [ "CVE-2024-31583" ],
"summary" : "Pytorch use-after-free vulnerability",
"details" : "Pytorch before version v2.2.0 was discovered to contain a use-after-free vulnerability in torch/csrc/jit/mobile/interpreter.cpp.",
"severity" : [ {
"type" : "CVSS_V3",
"score" : "CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "PyPI",
"name" : "torch"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "2.2.0"
} ]
} ]
} ],
"references" : [ {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-31583"
}, {
"type" : "WEB",
"url" : "https://github.com/pytorch/pytorch/commit/9c7071b0e324f9fb68ab881283d6b8d388a4bcd2"
}, {
"type" : "WEB",
"url" : "https://gist.github.com/1047524396/43e19a41f2b36503a4a228c32cdbc176"
}, {
"type" : "WEB",
"url" : "https://github.com/pypa/advisory-database/tree/main/vulns/torch/PYSEC-2024-251.yaml"
}, {
"type" : "PACKAGE",
"url" : "https://github.com/pytorch/pytorch"
}, {
"type" : "WEB",
"url" : "https://github.com/pytorch/pytorch/blob/v2.1.2/torch/csrc/jit/mobile/interpreter.cpp#L132"
}, {
"type" : "WEB",
"url" : "https://security.snyk.io/vuln/SNYK-PYTHON-TORCH-6619806"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-416" ],
"severity" : "HIGH",
"github_reviewed" : true,
"github_reviewed_at" : "2024-07-25T10:11:09Z",
"nvd_published_at" : "2024-04-17T19:15:07Z"
}
}