CVE-2021-29593: TensorFlow - Division by Zero Error in BatchToSpaceNd Operator
Summary
CVE-2021-29593: Division by zero in TFLite's implementation of BatchToSpaceNd. Affects tensorflow across 4 version ranges.
< 2.1.4
>= 2.2.0, < 2.2.3
>= 2.3.0, < 2.3.3
>= 2.4.0, < 2.4.2
Fixed in 4 releases; the minimum fixed version depends on the release line you run. How to fix ↓
Also tracked for
- tensorflow · PyPI
- tensorflow · PyPI
- tensorflow-cpu · 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 for building and deploying machine learning models. The BatchToSpaceNd operator in TensorFlow is used to rearrange data in a batched manner. It is vulnerable to a division by zero error when one dimension of the block input is set to 0, resulting in a corresponding value of 0 in the block_shape input. This vulnerability affects versions 0 and 2.1.4 to 2.4.2 of the TensorFlow package.
Vulnerability Detail
The vulnerability arises due to a lack of proper input validation in the BatchToSpaceNd operator implementation. An attacker can exploit this vulnerability by crafting a malicious model with a block input dimension set to 0, causing a division by zero error during execution. This can lead to various consequences, including denial of service (DoS) attacks, information disclosure, or even remote code execution. The vulnerability has been assigned a CVSSv3 severity score of 9.8 (Critical).
How To Fix
Fixed versions by release line
The minimum fixed version depends on the release line you run.
-
< 2.1.42.1.4 -
>= 2.2.0, < 2.2.32.2.3 -
>= 2.3.0, < 2.3.32.3.3 -
>= 2.4.0, < 2.4.22.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 manually validate the input dimensions before invoking the BatchToSpaceNd operator. By ensuring that none of the dimensions in the block input are set to 0, the division by zero error can be avoided. Here is an example of how to perform the input validation in Python:
import tensorflow as tf
def safe_batch_to_space_nd(input, block_shape, crops):
for dim in block_shape:
if dim == 0:
raise ValueError('Invalid block shape: dimension cannot be 0')
return tf.batch_to_space_nd(input, block_shape, crops)
Conclusion
The BatchToSpaceNd operator in TensorFlow is vulnerable to a division by zero error, which can have severe consequences such as DoS attacks, information disclosure, or remote code execution. It is crucial to upgrade to the latest version of TensorFlow (2.5.0 or later) to mitigate this vulnerability. For further support on vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for tensorflow →
FAQ
TensorFlow is an open source platform for machine learning, providing a comprehensive ecosystem for building and deploying machine learning models.
BatchToSpaceNd is an operator in TensorFlow used to rearrange data in a batched manner.
The vulnerability occurs due to a lack of input validation in the BatchToSpaceNd operator implementation, allowing a division by zero error when one dimension of the block input is set to 0.
The vulnerability can lead to denial of service (DoS) attacks, information disclosure, or remote code execution, depending on how it is exploited.
To fix this vulnerability, it is recommended to upgrade to the latest available version of TensorFlow (2.5.0 or later).
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow.