CVE-2021-37642: Division by 0 in tensorflow
Summary
CVE-2021-37642: Division by 0 in ResourceScatterDiv. Affects tensorflow across 3 version ranges.
< 2.3.4
>= 2.4.0, < 2.4.3
>= 2.5.0, < 2.5.1
Fixed in 2.3.4, 2.4.3 or 2.5.1, 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-37642 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 open-source machine learning framework widely used for building and training various models. It provides a comprehensive ecosystem for developing and deploying machine learning applications. TensorFlow includes a feature called ResourceScatterDiv which is used for dividing the values of a resource variable by a specified index. However, a vulnerability has been discovered in the implementation of ResourceScatterDiv that allows a division by zero error to occur.
Vulnerability Detail
The vulnerability in ResourceScatterDiv arises from the failure to handle the division by zero case separately. This means that if the updates parameter passed to ResourceScatterDiv contains a zero value, a division by zero error will occur. An attacker could potentially exploit this vulnerability to cause a denial of service (DoS) by providing a zero value as the update. The impact of this vulnerability is considered moderate with a CVSS score of 5.5.
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.42.3.4pip install --upgrade "tensorflow==2.3.4" -
>= 2.4.0, < 2.4.32.4.3pip install --upgrade "tensorflow==2.4.3" -
>= 2.5.0, < 2.5.12.5.1pip install --upgrade "tensorflow==2.5.1"
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 the updates parameter passed to ResourceScatterDiv does not contain a zero value. This can be achieved by validating the input values before calling the function. Here is an example of how to check for zero values in Python:
import tensorflow as tf
v = tf.Variable([1, 2, 3])
updates = [0]
if all(update != 0 for update in updates):
tf.raw_ops.ResourceScatterDiv(
resource=v.handle,
indices=[1],
updates=updates
)
Conclusion
In conclusion, the vulnerability in TensorFlow's ResourceScatterDiv function allows a division by zero error to occur. This vulnerability has been addressed in TensorFlow versions 2.3.4, 2.4.3, 2.5.1, and 2.6.0. Users are advised to update their TensorFlow installation to one of the patched versions to mitigate the risk. For further support on vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for tensorflow →
FAQ
The impact of this vulnerability is considered moderate with a CVSS score of 5.5. It could potentially allow an attacker to cause a denial of service (DoS) by providing a zero value as the update.
The vulnerability affects TensorFlow versions 2.3.4, 2.4.3, 2.5.1, and prior versions.
Yes, the vulnerability has been patched in TensorFlow versions 2.3.4, 2.4.3, 2.5.1, and 2.6.0.
To fix the vulnerability, update your TensorFlow installation to one of the patched versions: TensorFlow 2.3.4, 2.4.3, 2.5.1, or 2.6.0.
Yes, as a workaround, you can ensure that the updates parameter passed to ResourceScatterDiv does not contain a zero value.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow.