CVE-2021-29513: TensorFlow - Type Confusion Vulnerability
Summary
CVE-2021-29513: TensorFlow is an end-to-end open source platform for machine learning. Affects tensorflow across 5 version ranges.
>= 2.2.0, < 2.3.0rc0
< 2.2.0rc0
>= 2.3.0, < 2.3.4
>= 2.4.0, < 2.4.3
< 030af767d357d1b4088c4a25c72cb3906abac489
Fixed in 4 releases; the minimum fixed version depends on the release line you run. How to fix ↓
Also tracked for
- tensorflow · Bitnami
- tensorflow-cpu · PyPI
- tensorflow-gpu · PyPI
The same CVE-2021-29513 is tracked separately for each ecosystem and vendor. Its fix information is the same; the package and affected versions differ.
Check if this vulnerability affects your application
Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.
No signup required · Results in about 60 seconds
Background
TensorFlow is an end-to-end open source platform for machine learning. It provides a comprehensive ecosystem of tools, libraries, and resources for developing and deploying machine learning models. TensorFlow allows users to perform various operations on tensors, which are multi-dimensional arrays. These operations are typically performed on numeric tensors. However, calling TensorFlow operations with tensors of non-numeric types can lead to null pointer dereferences. This vulnerability arises due to a type confusion in the conversion from Python arrays to C++ arrays within TensorFlow.
Vulnerability Detail
The type confusion vulnerability in TensorFlow can be exploited when non-numeric tensors are passed to operations that expect numeric tensors. This can result in null pointer dereferences, leading to crashes or potential code execution vulnerabilities. An attacker could potentially craft malicious inputs to trigger this vulnerability and compromise the integrity or availability of the TensorFlow application. The vulnerability affects versions of TensorFlow up to 2.4.3.
How To Fix
Latest published version: 2.21.0 as of 22 Oct 2026
pip install --upgrade "tensorflow==2.21.0"
Upgrading to it may include breaking changes; the versions below are the minimum fixed release for this vulnerability.
If you can't move to the latest
The minimum fixed version depends on the release line you run.
-
< 2.2.0rc02.2.0rc0pip install --upgrade "tensorflow==2.2.0rc0" -
>= 2.2.0, < 2.3.0rc02.3.0rc0pip install --upgrade "tensorflow==2.3.0rc0" -
>= 2.3.0, < 2.3.42.3.4pip install --upgrade "tensorflow==2.3.4" -
>= 2.4.0, < 2.4.32.4.3pip install --upgrade "tensorflow==2.4.3"
Tip — Not sure which release line you're on? Vulert can find the fix for the version you are using. Scan free →
Workaround
As a workaround, users can ensure that only numeric tensors are passed to TensorFlow operations that expect numeric inputs. This can be achieved by validating the input tensors before passing them to the operations. Here is an example of how to validate and convert a Python array to a numeric tensor in TensorFlow:
import tensorflow as tf
def validate_and_convert_array(array):
if not isinstance(array, (list, tuple)):
raise ValueError('Input must be a list or tuple')
if not all(isinstance(element, (int, float)) for element in array):
raise ValueError('Input must contain only numeric elements')
return tf.convert_to_tensor(array)
# Example usage
array = [1, 2, 3]
numeric_tensor = validate_and_convert_array(array)
Conclusion
The type confusion vulnerability in TensorFlow can be mitigated by upgrading to one of the fixed versions. It is important to keep software dependencies up to date to ensure the security and stability of machine learning applications. For further support on vulnerability remediation, you can reach out to DevNack.com.
See every vulnerability recorded for tensorflow →
FAQ
TensorFlow is an open source platform for machine learning that provides a comprehensive ecosystem of tools and resources for developing and deploying machine learning models.
A tensor in TensorFlow is a multi-dimensional array that represents data used in machine learning operations. Tensors can have any number of dimensions and can contain numeric or non-numeric values.
The type confusion vulnerability in TensorFlow occurs when non-numeric tensors are passed to operations that expect numeric tensors. This can lead to null pointer dereferences and potential crashes or code execution vulnerabilities.
The type confusion vulnerability in TensorFlow can potentially be exploited by an attacker to compromise the integrity or availability of the TensorFlow application. This could lead to crashes, data corruption, or unauthorized code execution.
To fix the vulnerability, it is recommended to upgrade to one of the fixed versions of TensorFlow (2.5.0, 2.4.2, 2.3.3, 2.2.3, or 2.1.4). Users can update their TensorFlow installation using the package manager or by manually downloading and installing the updated version from the TensorFlow GitHub repository.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow.