CVE-2021-29589: TensorFlow-CPU - Division by Zero Vulnerability
Summary
CVE-2021-29589: TensorFlow is an end-to-end open source platform for machine learning. Affects tensorflow-cpu 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
< 8e45822aa0b9f5df4b4c64f221e64dc930a70a9d
Fixed in 4 releases; the minimum fixed version depends on the release line you run. How to fix ↓
Also tracked for
- tensorflow · Bitnami
- tensorflow · PyPI
- tensorflow · PyPI
- tensorflow-gpu · PyPI
The same CVE-2021-29589 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-CPU is a specific package that focuses on running TensorFlow on CPUs. It is widely used in various industries for machine learning tasks.
Vulnerability Detail
The reference implementation of the GatherNd TFLite operator in TensorFlow-CPU is vulnerable to a division by zero error. This vulnerability can be exploited by an attacker by crafting a model with an empty tensor as the params input. When params_shape.Dims(.) is zero in at least one dimension, a division by zero occurs. This vulnerability can lead to a crash or unexpected behavior of the TensorFlow-CPU application. The issue has been identified and a fix will be included in TensorFlow 2.5.0. Additionally, the fix will be backported to TensorFlow 2.4.2, TensorFlow 2.3.3, TensorFlow 2.2.3, and TensorFlow 2.1.4, as these versions are also affected and still within the supported range.
How To Fix
Latest published version: 2.21.0 as of 22 Oct 2026
pip install --upgrade "tensorflow-cpu==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-cpu==2.2.0rc0" -
>= 2.2.0, < 2.3.0rc02.3.0rc0pip install --upgrade "tensorflow-cpu==2.3.0rc0" -
>= 2.3.0, < 2.3.42.3.4pip install --upgrade "tensorflow-cpu==2.3.4" -
>= 2.4.0, < 2.4.32.4.3pip install --upgrade "tensorflow-cpu==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 temporary workaround, users can check if their input tensor is empty before passing it to the GatherNd TFLite operator. By ensuring that the params input is not empty, the division by zero error can be avoided. Here is an example code snippet demonstrating the workaround:
import tensorflow as tf
params = tf.constant([]) # Check if params is empty
if tf.size(params) > 0:
# Perform the TFLite operation
result = tf.raw_ops.GatherNd(params)
else:
# Handle the empty case
result = tf.constant([])
Conclusion
The division by zero vulnerability in TensorFlow-CPU's GatherNd TFLite operator can be mitigated by updating to the patched versions or by applying the temporary workaround. It is crucial for users to promptly update their TensorFlow-CPU installations to ensure the security and stability of their machine learning applications. For further support and assistance in vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for tensorflow-cpu →
FAQ
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-CPU is a specific package that focuses on running TensorFlow on CPUs. It is widely used in various industries for machine learning tasks.
GatherNd is a TensorFlow Lite (TFLite) operator that performs a gather operation on N-dimensional tensors. It is commonly used in machine learning models for indexing and gathering values from tensors.
An attacker can exploit this vulnerability by crafting a model with an empty tensor as the params input. When params_shape.Dims(.) is zero in at least one dimension, a division by zero occurs, leading to a crash or unexpected behavior of the TensorFlow-CPU application.
To fix this vulnerability, it is recommended to update TensorFlow-CPU to version 2.5.0 once it is released. For users on affected versions, the fix can be obtained by updating to the respective patched versions: TensorFlow 2.4.2, TensorFlow 2.3.3, TensorFlow 2.2.3, or TensorFlow 2.1.4.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow-cpu.