CVE-2021-29517: Tensorflow Division By Zero Vulnerability
LOWCVE-2021-29517 is a LOW (CVSS 2.5) division by zero vulnerability (CWE-369: Divide By Zero) affecting Tensorflow libraries in the PyPI ecosystem. The issue involves division by zero in `conv3d`. Remediation is available by upgrading affected packages to version 2.1.4, 2.2.3, 2.3.3, 2.4.2.
CVE-2021-29517 at a Glance
Security Impact
CVSS: 2.5
The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:N/I:N/A:L).
How to Fix CVE-2021-29517
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.1.4
pip install tensorflow>=2.2.3
pip install tensorflow>=2.3.3
pip install tensorflow>=2.4.2
pip install tensorflow-cpu>=2.1.4
pip install tensorflow-cpu>=2.2.3
pip install tensorflow-cpu>=2.3.3
pip install tensorflow-cpu>=2.4.2
pip install tensorflow-gpu>=2.1.4
pip install tensorflow-gpu>=2.2.3
pip install tensorflow-gpu>=2.3.3
pip install tensorflow-gpu>=2.4.2
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-2021-29517, 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.1.4), 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-369: Divide By Zero, where the product divides a value by zero. 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-2021-29517 Affected Tensorflow Versions
12 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
tensorflow
|
PyPI |
< 2.1.4
|
2.1.4
|
|
tensorflow
|
PyPI |
≥ 2.2.0
< 2.2.3
|
2.2.3
|
|
tensorflow
|
PyPI |
≥ 2.3.0
< 2.3.3
|
2.3.3
|
|
tensorflow
|
PyPI |
≥ 2.4.0
< 2.4.2
|
2.4.2
|
|
tensorflow-cpu
|
PyPI |
< 2.1.4
|
2.1.4
|
|
tensorflow-cpu
|
PyPI |
≥ 2.2.0
< 2.2.3
|
2.2.3
|
|
tensorflow-cpu
|
PyPI |
≥ 2.3.0
< 2.3.3
|
2.3.3
|
|
tensorflow-cpu
|
PyPI |
≥ 2.4.0
< 2.4.2
|
2.4.2
|
|
tensorflow-gpu
|
PyPI |
< 2.1.4
|
2.1.4
|
|
tensorflow-gpu
|
PyPI |
≥ 2.2.0
< 2.2.3
|
2.2.3
|
|
tensorflow-gpu
|
PyPI |
≥ 2.3.0
< 2.3.3
|
2.3.3
|
|
tensorflow-gpu
|
PyPI |
≥ 2.4.0
< 2.4.2
|
2.4.2
|
References
Frequently Asked Questions
What is CVE-2021-29517?
Which Tensorflow versions are affected?
What version fixes CVE-2021-29517?
Is tensorflow affected?
Is tensorflow-cpu affected?
What is the CVSS score of CVE-2021-29517?
What CWE is associated with CVE-2021-29517?
How can I check PyPI dependencies for CVE-2021-29517?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-772p-x54p-hjrv",
"modified" : "2024-10-28T21:26:22Z",
"published" : "2021-05-21T14:21:01Z",
"aliases" : [ "CVE-2021-29517" ],
"summary" : "Division by zero in `Conv3D`",
"details" : "### Impact\nA malicious user could trigger a division by 0 in `Conv3D` implementation:\n\n```python\nimport tensorflow as tf\n\ninput_tensor = tf.constant([], shape=[0, 0, 0, 0, 0], dtype=tf.float32)\nfilter_tensor = tf.constant([], shape=[0, 0, 0, 0, 0], dtype=tf.float32)\n\ntf.raw_ops.Conv3D(input=input_tensor, filter=filter_tensor, strides=[1, 56, 56, 56, 1], padding='VALID', data_format='NDHWC', dilations=[1, 1, 1, 23, 1])\n```\n\nThe [implementation](https://github.com/tensorflow/tensorflow/blob/42033603003965bffac51ae171b51801565e002d/tensorflow/core/kernels/conv_ops_3d.cc#L143-L145) does a modulo operation based on user controlled input:\n\n```cc\n const int64 out_depth = filter.dim_size(4);\n OP_REQUIRES(context, in_depth % filter_depth == 0, ...);\n```\n\nThus, when `filter` has a 0 as the fifth element, this results in a division by 0.\n\nAdditionally, if the shape of the two tensors is not valid, an Eigen assertion can be triggered, resulting in a program crash:\n\n```python\nimport tensorflow as tf\n\ninput_tensor = tf.constant([], shape=[2, 2, 2, 2, 0], dtype=tf.float32)\nfilter_tensor = tf.constant([], shape=[0, 0, 2, 6, 2], dtype=tf.float32)\n\ntf.raw_ops.Conv3D(input=input_tensor, filter=filter_tensor, strides=[1, 56, 39, 34, 1], padding='VALID', data_format='NDHWC', dilations=[1, 1, 1, 1, 1])\n```\n\nThe shape of the two tensors must follow the constraints specified in the [op description](https://www.tensorflow.org/api_docs/python/tf/raw_ops/Conv3D).\n\n### Patches\nWe have patched the issue in GitHub commit [799f835a3dfa00a4d852defa29b15841eea9d64f](https://github.com/tensorflow/tensorflow/commit/799f835a3dfa00a4d852defa29b15841eea9d64f).\n\nThe fix will be included in TensorFlow 2.5.0. We will also cherrypick this commit on TensorFlow 2.4.2, TensorFlow 2.3.3, TensorFlow 2.2.3 and TensorFlow 2.1.4, 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 Yakun Zhang and Ying Wang of Baidu X-Team.",
"severity" : [ {
"type" : "CVSS_V3",
"score" : "CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:N/I:N/A:L"
}, {
"type" : "CVSS_V4",
"score" : "CVSS:4.0/AV:L/AC:L/AT:P/PR:L/UI:N/VC:N/VI:N/VA:L/SC:N/SI:N/SA:N"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "PyPI",
"name" : "tensorflow"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "2.1.4"
} ]
} ]
}, {
"package" : {
"ecosystem" : "PyPI",
"name" : "tensorflow"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "2.2.0"
}, {
"fixed" : "2.2.3"
} ]
} ]
}, {
"package" : {
"ecosystem" : "PyPI",
"name" : "tensorflow"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "2.3.0"
}, {
"fixed" : "2.3.3"
} ]
} ]
}, {
"package" : {
"ecosystem" : "PyPI",
"name" : "tensorflow"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "2.4.0"
}, {
"fixed" : "2.4.2"
} ]
} ]
}, {
"package" : {
"ecosystem" : "PyPI",
"name" : "tensorflow-cpu"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "2.1.4"
} ]
} ]
}, {
"package" : {
"ecosystem" : "PyPI",
"name" : "tensorflow-cpu"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "2.2.0"
}, {
"fixed" : "2.2.3"
} ]
} ]
}, {
"package" : {
"ecosystem" : "PyPI",
"name" : "tensorflow-cpu"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "2.3.0"
}, {
"fixed" : "2.3.3"
} ]
} ]
}, {
"package" : {
"ecosystem" : "PyPI",
"name" : "tensorflow-cpu"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "2.4.0"
}, {
"fixed" : "2.4.2"
} ]
} ]
}, {
"package" : {
"ecosystem" : "PyPI",
"name" : "tensorflow-gpu"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "2.1.4"
} ]
} ]
}, {
"package" : {
"ecosystem" : "PyPI",
"name" : "tensorflow-gpu"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "2.2.0"
}, {
"fixed" : "2.2.3"
} ]
} ]
}, {
"package" : {
"ecosystem" : "PyPI",
"name" : "tensorflow-gpu"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "2.3.0"
}, {
"fixed" : "2.3.3"
} ]
} ]
}, {
"package" : {
"ecosystem" : "PyPI",
"name" : "tensorflow-gpu"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "2.4.0"
}, {
"fixed" : "2.4.2"
} ]
} ]
} ],
"references" : [ {
"type" : "WEB",
"url" : "https://github.com/tensorflow/tensorflow/security/advisories/GHSA-772p-x54p-hjrv"
}, {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-29517"
}, {
"type" : "WEB",
"url" : "https://github.com/tensorflow/tensorflow/commit/799f835a3dfa00a4d852defa29b15841eea9d64f"
}, {
"type" : "WEB",
"url" : "https://github.com/pypa/advisory-database/tree/main/vulns/tensorflow-cpu/PYSEC-2021-445.yaml"
}, {
"type" : "WEB",
"url" : "https://github.com/pypa/advisory-database/tree/main/vulns/tensorflow-gpu/PYSEC-2021-643.yaml"
}, {
"type" : "WEB",
"url" : "https://github.com/pypa/advisory-database/tree/main/vulns/tensorflow/PYSEC-2021-154.yaml"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-369" ],
"severity" : "LOW",
"github_reviewed" : true,
"github_reviewed_at" : "2021-05-18T23:32:11Z",
"nvd_published_at" : "2021-05-14T20:15:00Z"
}
}