CVE-2021-29593: TensorFlow CPU - Division by Zero in BatchToSpaceNd Operator
Summary
CVE-2021-29593: TensorFlow is an end-to-end open source platform for machine learning. Affects tensorflow-cpu across 5 version ranges.
< 2.1.4
>= 2.2.0, < 2.2.3
>= 2.3.0, < 2.3.3
>= 2.4.0, < 2.4.2
< 2c74674348a4708ced58ad6eb1b23354df8ee044
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-29593 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. The TensorFlow CPU package, available on PyPI, is a CPU-only version of TensorFlow that allows users to run TensorFlow on systems without GPU support.
Vulnerability Detail
The vulnerability (CVE-2021-29593) exists in the implementation of the BatchToSpaceNd TFLite operator in TensorFlow CPU. The issue arises when a crafted model is created with a dimension of the block input set to 0, resulting in a division by zero error. This vulnerability can be exploited by an attacker to cause a denial-of-service condition or potentially execute arbitrary code on the affected system. The vulnerability was identified in the source code of the batch_to_space_nd.cc file. The fix for this vulnerability has been included in TensorFlow 2.5.0, and patches have been backported to TensorFlow 2.4.2, TensorFlow 2.3.3, TensorFlow 2.2.3, and TensorFlow 2.1.4.
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.1.42.1.4pip install --upgrade "tensorflow-cpu==2.1.4" -
>= 2.2.0, < 2.2.32.2.3pip install --upgrade "tensorflow-cpu==2.2.3" -
>= 2.3.0, < 2.3.32.3.3pip install --upgrade "tensorflow-cpu==2.3.3" -
>= 2.4.0, < 2.4.22.4.2pip install --upgrade "tensorflow-cpu==2.4.2"
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 avoid the vulnerability by ensuring that the block input of the BatchToSpaceNd operator does not have any dimensions set to 0. This can be achieved by validating the input dimensions before passing them to the operator. Here is an example code snippet demonstrating the workaround:
import tensorflow as tf
# Validate block dimensions
block = [2, 0]
if 0 in block:
raise ValueError('Invalid block dimensions')
# Perform BatchToSpaceNd operation
output = tf.nn.batch_to_space_nd(input, block, crops)
By validating the block dimensions, the vulnerability can be mitigated.
Conclusion
The vulnerability (CVE-2021-29593) in TensorFlow CPU's BatchToSpaceNd operator can be exploited by an attacker to cause a division by zero error. This can lead to a denial-of-service condition or potential execution of arbitrary code. Users are advised to upgrade to TensorFlow CPU version 2.5.0 or apply the respective patches for their installed versions. A temporary workaround is available by validating the block dimensions to avoid setting any dimensions to 0. For further assistance on vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for tensorflow-cpu →
FAQ
TensorFlow is an open source platform for machine learning that provides a comprehensive ecosystem of tools, libraries, and resources for developing and deploying machine learning models.
This vulnerability in TensorFlow CPU can lead to a division by zero error, which can result in a denial-of-service condition or potential execution of arbitrary code by an attacker.
The vulnerability affects TensorFlow CPU versions 2.1.4 and above, including versions 2.2.3, 2.3.3, and 2.4.2. TensorFlow 2.5.0 and later versions have been patched to address this vulnerability.
To fix this vulnerability, it is recommended to upgrade to the latest version of TensorFlow CPU (2.5.0) or apply the respective patches for your installed version (2.4.2, 2.3.3, 2.2.3, or 2.1.4).
Yes, a temporary workaround is to validate the block dimensions before passing them to the BatchToSpaceNd operator to ensure that no dimensions are set to 0. By doing so, the vulnerability can be mitigated.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow-cpu.