CVE-2021-29602: TensorFlow DepthwiseConv Operator Division by Zero Vulnerability
Summary
CVE-2021-29602: Division by zero in TFLite's implementation of DepthwiseConv. 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-29602 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 set of tools, libraries, and resources for developing and deploying machine learning models. The DepthwiseConv operator is a part of TensorFlow Lite, which is a lightweight version of TensorFlow designed for mobile and embedded devices. This operator performs depthwise convolution, a common operation in convolutional neural networks. It is used to apply a set of filters to input data, preserving the spatial dimensions while varying the number of channels. The vulnerability in the DepthwiseConv operator allows an attacker to craft a malicious model that triggers a division by zero error when the fourth dimension of the input is set to zero.
Vulnerability Detail
The vulnerability arises from a division by zero error in the implementation of the DepthwiseConv TFLite operator in TensorFlow. By providing a model with a fourth dimension of zero for the input, an attacker can trigger this error. The impact of this vulnerability can be severe, leading to crashes, denial of service, or potential exploitation of other vulnerabilities in the system. The vulnerability has been assigned the identifier CVE-2021-29602 and has a CVSSv3 score of 7.5 (CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H).
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 workaround, users can ensure that the fourth dimension of the input in their models is always set to a non-zero value. This can be achieved by validating the input dimensions before passing them to the DepthwiseConv operator. Here is an example code snippet in Python that demonstrates this workaround:
import tensorflow as tf
# Validate input dimensions
input_shape = (batch_size, height, width, channels)
if input_shape[3] == 0:
raise ValueError('Invalid input dimensions: fourth dimension cannot be zero')
# Perform depthwise convolution
output = tf.nn.depthwise_conv2d(input, filter, strides, padding)
By performing this validation, the division by zero error can be avoided.
Conclusion
The TensorFlow DepthwiseConv operator division by zero vulnerability (CVE-2021-29602) can be mitigated by upgrading to the latest patched version of TensorFlow. It is important to promptly apply the fix to ensure the security and stability of machine learning models. For further support and assistance in 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 set of tools and libraries for developing and deploying machine learning models.
The DepthwiseConv operator is a part of TensorFlow Lite, which is a lightweight version of TensorFlow designed for mobile and embedded devices. It performs depthwise convolution, a common operation in convolutional neural networks.
The vulnerability arises from a division by zero error in the implementation of the DepthwiseConv operator. By providing a model with a fourth dimension of zero for the input, an attacker can trigger this error.
The vulnerability can lead to crashes, denial of service, or potential exploitation of other vulnerabilities in the system.
The vulnerability has been fixed in TensorFlow 2.5.0. Users are advised to upgrade to the latest patched version of TensorFlow to mitigate the vulnerability.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow.