CVE-2021-29595: TensorFlow - Division by Zero in DepthToSpace TFLite Operator
Summary
CVE-2021-29595: Division by zero in TFLite's implementation of DepthToSpace. 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-29595 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 DepthToSpace TFLite operator is a part of TensorFlow and is used for rearranging data in a tensor. This operator is vulnerable to a division by zero error, which can be exploited by an attacker. The vulnerability exists in the implementation of the operator, specifically in the depth_to_space.cc file. The affected versions of TensorFlow include 2.1.4, 2.2.3, 2.3.3, and 2.4.2.
Vulnerability Detail
The vulnerability in the DepthToSpace TFLite operator arises from a division by zero error. An attacker can craft a malicious model in which the params->block_size parameter is set to 0. When this model is executed, the division operation in the operator's implementation will result in a division by zero error. This can lead to various consequences, including crashes, denial of service, or even potential remote code execution. 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, 2.3.3, 2.2.3, and 2.1.4 to address the vulnerability in the supported versions.
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 avoid the vulnerability by ensuring that the params->block_size parameter in the DepthToSpace TFLite operator is never set to 0. This can be achieved by validating and sanitizing the input values before executing the model. Here is an example code snippet that demonstrates the workaround:
import tensorflow as tf
# Validate and sanitize the block_size parameter
block_size = get_block_size()
if block_size == 0:
block_size = 1
# Create and execute the model
model = create_model()
output = model.predict(block_size=block_size)
Conclusion
In conclusion, the DepthToSpace TFLite operator in TensorFlow is vulnerable to a division by zero error. This can be exploited by an attacker by crafting a malicious model. The issue has been identified and a fix will be included in TensorFlow 2.5.0. Users of the affected versions can expect the fix to be backported and included in the respective patch releases. It is recommended to update TensorFlow to the latest version once the fix is available. 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 that provides a comprehensive ecosystem for building and deploying machine learning models.
The DepthToSpace TFLite operator is a part of TensorFlow and is used for rearranging data in a tensor.
The vulnerability can lead to various consequences, including crashes, denial of service, or potential remote code execution.
The vulnerability affects TensorFlow versions 2.1.4, 2.2.3, 2.3.3, and 2.4.2.
To fix the vulnerability, it is recommended to update TensorFlow to version 2.5.0 once it is released. For users of the affected versions, the fix will be backported and included in the respective patch releases.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow.