CVE-2022-21731: Tensorflow Type Confusion Leading To Segfault Vulnerability
HIGHCVE-2022-21731 is a HIGH (CVSS 6.5) type confusion leading to segfault vulnerability (CWE-843: Access of Resource Using Incompatible Type ('Type Confusion')) affecting Tensorflow libraries in the PyPI ecosystem. The issue involves type confusion leading to segfault in tensorflow. Remediation is available by upgrading affected packages to version 2.5.3, 2.6.3, 2.7.1.
CVE-2022-21731 at a Glance
Security Impact
CVSS: 6.5
The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H).
How to Fix CVE-2022-21731
To remediate this vulnerability, upgrade all affected Tensorflow 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 tensorflow>=2.5.3
pip install tensorflow>=2.6.3
pip install tensorflow>=2.7.1
pip install tensorflow-cpu>=2.5.3
pip install tensorflow-cpu>=2.6.3
pip install tensorflow-cpu>=2.7.1
pip install tensorflow-gpu>=2.5.3
pip install tensorflow-gpu>=2.6.3
pip install tensorflow-gpu>=2.7.1
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
pip show tensorflow
How to Check if You Are Affected
To determine whether your Python environment is affected by CVE-2022-21731, inspect your installed packages using pip:
pip show tensorflow
Analyze the terminal output to locate any version of Tensorflow in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 2.5.3), your application is affected.
Note: The pip show tensorflow command checks currently installed packages in your active Python environment.
Technical Details
Vulnerability Mechanism & Technical Analysis
This vulnerability is classified under CWE-843: Access of Resource Using Incompatible Type ('Type Confusion'), where the product allocates or initializes a resource such as a pointer, object, or variable using one type, but it later accesses that resource using a type that is incompatible with the original type. In Tensorflow, 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-2022-21731 Affected Tensorflow Versions
9 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
tensorflow
|
PyPI |
< 2.5.3
|
2.5.3
|
|
tensorflow
|
PyPI |
≥ 2.6.0
< 2.6.3
|
2.6.3
|
|
tensorflow
|
PyPI |
≥ 2.7.0
< 2.7.1
All 1 versions
2.7.0
|
2.7.1
|
|
tensorflow-cpu
|
PyPI |
< 2.5.3
|
2.5.3
|
|
tensorflow-cpu
|
PyPI |
≥ 2.6.0
< 2.6.3
|
2.6.3
|
|
tensorflow-cpu
|
PyPI |
≥ 2.7.0
< 2.7.1
All 1 versions
2.7.0
|
2.7.1
|
|
tensorflow-gpu
|
PyPI |
< 2.5.3
|
2.5.3
|
|
tensorflow-gpu
|
PyPI |
≥ 2.6.0
< 2.6.3
|
2.6.3
|
|
tensorflow-gpu
|
PyPI |
≥ 2.7.0
< 2.7.1
All 1 versions
2.7.0
|
2.7.1
|
References
Frequently Asked Questions
What is CVE-2022-21731?
Which Tensorflow versions are affected?
What version fixes CVE-2022-21731?
Is tensorflow affected?
Is tensorflow-cpu affected?
What is the CVSS score of CVE-2022-21731?
What CWE is associated with CVE-2022-21731?
How can I check PyPI dependencies for CVE-2022-21731?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-m4hf-j54p-p353",
"modified" : "2024-11-13T22:12:12Z",
"published" : "2022-02-10T00:19:50Z",
"aliases" : [ "CVE-2022-21731" ],
"summary" : "Type confusion leading to segfault in Tensorflow",
"details" : "### Impact \nThe [implementation of shape inference for `ConcatV2`](https://github.com/tensorflow/tensorflow/blob/5100e359aef5c8021f2e71c7b986420b85ce7b3d/tensorflow/core/framework/common_shape_fns.cc#L1961-L2059) can be used to trigger a denial of service attack via a segfault caused by a type confusion:\n\n```python\nimport tensorflow as tf\n\n@tf.function\ndef test():\n y = tf.raw_ops.ConcatV2(\n values=[[1,2,3],[4,5,6]],\n axis = 0xb500005b)\n return y\n\ntest()\n```\n\nThe `axis` argument is translated into `concat_dim` in the `ConcatShapeHelper` helper function. Then, a value for `min_rank` is computed based on `concat_dim`. This is then used to validate that the `values` tensor has at least the required rank:\n\n```cc\n int64_t concat_dim;\n if (concat_dim_t->dtype() == DT_INT32) {\n concat_dim = static_cast<int64_t>(concat_dim_t->flat<int32>()(0));\n } else {\n concat_dim = concat_dim_t->flat<int64_t>()(0);\n }\n\n // Minimum required number of dimensions.\n const int min_rank = concat_dim < 0 ? -concat_dim : concat_dim + 1;\n\n // ...\n ShapeHandle input = c->input(end_value_index - 1);\n TF_RETURN_IF_ERROR(c->WithRankAtLeast(input, min_rank, &input));\n```\n\nHowever, [`WithRankAtLeast`](https://github.com/tensorflow/tensorflow/blob/5100e359aef5c8021f2e71c7b986420b85ce7b3d/tensorflow/core/framework/shape_inference.cc#L345-L358) receives the lower bound as a 64-bits value and then compares it against the maximum 32-bits integer value that could be represented:\n\n```cc\nStatus InferenceContext::WithRankAtLeast(ShapeHandle shape, int64_t rank,\n ShapeHandle* out) {\n if (rank > kint32max) {\n return errors::InvalidArgument(\"Rank cannot exceed kint32max\");\n }\n // ...\n}\n```\n\nDue to the fact that `min_rank` is a 32-bits value and the value of `axis`, the `rank` argument is a [negative value](https://godbolt.org/z/Gcr5haMob), so the error check is bypassed.\n\n### Patches\nWe have patched the issue in GitHub commit [08d7b00c0a5a20926363849f611729f53f3ec022](https://github.com/tensorflow/tensorflow/commit/08d7b00c0a5a20926363849f611729f53f3ec022).\n\nThe fix will be included in TensorFlow 2.8.0. We will also cherrypick this commit on TensorFlow 2.7.1, TensorFlow 2.6.3, and TensorFlow 2.5.3, as these are also affected and still in supported range.\n\n### For more information\nPlease consult [our security guide](https://github.com/tensorflow/tensorflow/blob/master/SECURITY.md) for more information regarding the security model and how to contact us with issues and questions.\n\n### Attribution\nThis vulnerability has been reported by Yu Tian of Qihoo 360 AIVul Team.",
"severity" : [ {
"type" : "CVSS_V3",
"score" : "CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H"
}, {
"type" : "CVSS_V4",
"score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "PyPI",
"name" : "tensorflow"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "2.5.3"
} ]
} ]
}, {
"package" : {
"ecosystem" : "PyPI",
"name" : "tensorflow"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "2.6.0"
}, {
"fixed" : "2.6.3"
} ]
} ]
}, {
"package" : {
"ecosystem" : "PyPI",
"name" : "tensorflow"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "2.7.0"
}, {
"fixed" : "2.7.1"
} ]
} ],
"versions" : [ "2.7.0" ]
}, {
"package" : {
"ecosystem" : "PyPI",
"name" : "tensorflow-cpu"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "2.5.3"
} ]
} ]
}, {
"package" : {
"ecosystem" : "PyPI",
"name" : "tensorflow-cpu"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "2.6.0"
}, {
"fixed" : "2.6.3"
} ]
} ]
}, {
"package" : {
"ecosystem" : "PyPI",
"name" : "tensorflow-cpu"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "2.7.0"
}, {
"fixed" : "2.7.1"
} ]
} ],
"versions" : [ "2.7.0" ]
}, {
"package" : {
"ecosystem" : "PyPI",
"name" : "tensorflow-gpu"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "2.5.3"
} ]
} ]
}, {
"package" : {
"ecosystem" : "PyPI",
"name" : "tensorflow-gpu"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "2.6.0"
}, {
"fixed" : "2.6.3"
} ]
} ]
}, {
"package" : {
"ecosystem" : "PyPI",
"name" : "tensorflow-gpu"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "2.7.0"
}, {
"fixed" : "2.7.1"
} ]
} ],
"versions" : [ "2.7.0" ]
} ],
"references" : [ {
"type" : "WEB",
"url" : "https://github.com/tensorflow/tensorflow/security/advisories/GHSA-m4hf-j54p-p353"
}, {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2022-21731"
}, {
"type" : "WEB",
"url" : "https://github.com/tensorflow/tensorflow/commit/08d7b00c0a5a20926363849f611729f53f3ec022"
}, {
"type" : "WEB",
"url" : "https://github.com/pypa/advisory-database/tree/main/vulns/tensorflow-cpu/PYSEC-2022-55.yaml"
}, {
"type" : "WEB",
"url" : "https://github.com/pypa/advisory-database/tree/main/vulns/tensorflow-gpu/PYSEC-2022-110.yaml"
}, {
"type" : "WEB",
"url" : "https://github.com/tensorflow/tensorflow"
}, {
"type" : "WEB",
"url" : "https://github.com/tensorflow/tensorflow/blob/5100e359aef5c8021f2e71c7b986420b85ce7b3d/tensorflow/core/framework/common_shape_fns.cc#L1961-L2059"
}, {
"type" : "WEB",
"url" : "https://github.com/tensorflow/tensorflow/blob/5100e359aef5c8021f2e71c7b986420b85ce7b3d/tensorflow/core/framework/shape_inference.cc#L345-L358"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-754", "CWE-843" ],
"severity" : "HIGH",
"github_reviewed" : true,
"github_reviewed_at" : "2022-02-03T19:01:09Z",
"nvd_published_at" : "2022-02-03T12:15:00Z"
}
}