CVE-2021-37660: TensorFlow Division by Zero Vulnerability
Summary
CVE-2021-37660: TensorFlow is an end-to-end open source platform for machine learning. Affects tensorflow across 3 version ranges.
>= 2.3.0, < 2.3.4
>= 2.4.0, < 2.4.3
< e86605c0a336c088b638da02135ea6f9f6753618
Fixed in 2.3.4 or 2.4.3, depending on the release line you run. How to fix ↓
Also tracked for
- tensorflow · Bitnami
- tensorflow-cpu · PyPI
- tensorflow-gpu · PyPI
The same CVE-2021-37660 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 is widely used in various industries and research domains for tasks such as image recognition, natural language processing, and recommendation systems. However, a vulnerability has been discovered in TensorFlow that can lead to a division by zero error, potentially causing a floating point exception.
Vulnerability Detail
The vulnerability in TensorFlow arises from a logic error in the implementation of inplace operations. Specifically, when calling inplace operations with crafted arguments, the code fails to properly handle the case where both the input tensor (x) and the value tensor (v) are empty. Instead of using the logical AND operator (&&), the code mistakenly uses the logical OR operator (||). As a result, if both x and v are empty, the code proceeds with the division operation, leading to a division by zero error. An attacker can exploit this vulnerability by providing malicious input that triggers the division by zero error. This vulnerability can have various ramifications depending on the context in which TensorFlow is used, including crashes, unexpected behavior, or potential security vulnerabilities.
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.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 temporary workaround, if you are unable to immediately update to one of the patched versions, you can avoid triggering the division by zero error by ensuring that either the input tensor (x) or the value tensor (v) is non-empty when calling inplace operations. You can achieve this by checking the dimensions or size of the tensors before performing the operation. Here is an example of a workaround in Python:
import tensorflow as tf
x = tf.constant([])
v = tf.constant([])
if x.shape.num_elements() == 0 or v.shape.num_elements() == 0:
# Handle empty tensors
print('Empty tensor detected')
else:
# Perform inplace operation
x.assign_add(v)
Conclusion
In conclusion, the TensorFlow Division by Zero vulnerability (CVE-2021-37660) can lead to a division by zero error in TensorFlow, potentially causing crashes, unexpected behavior, or security vulnerabilities. It is crucial to update to one of the patched versions (TensorFlow 2.6.0, TensorFlow 2.5.1, TensorFlow 2.4.3, or TensorFlow 2.3.4) to mitigate this vulnerability. If immediate update is not possible, you can use the provided workaround to avoid triggering the division by zero error. For further support on vulnerability remediation, you can contact DevNack.com.
See every vulnerability recorded for tensorflow →
FAQ
TensorFlow is an open source platform for machine learning that provides a comprehensive set of tools and resources for developing and deploying machine learning models.
This vulnerability can lead to a division by zero error in TensorFlow, potentially causing crashes, unexpected behavior, or security vulnerabilities depending on the context.
To fix this vulnerability, it is recommended to update to one of the patched versions of TensorFlow: TensorFlow 2.6.0, TensorFlow 2.5.1, TensorFlow 2.4.3, or TensorFlow 2.3.4.
Yes, if you are unable to immediately update to a patched version, you can avoid triggering the division by zero error by ensuring that either the input tensor or the value tensor is non-empty when calling inplace operations.
You can find more information about this vulnerability in the official TensorFlow advisory: https://github.com/pypa/advisory-database/blob/main/vulns/tensorflow/PYSEC-2021-282.yaml
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow.