CVE-2021-29546: TensorFlow - Integer Division by Zero in QuantizedBiasAdd
Summary
CVE-2021-29546: Division by 0 in QuantizedBiasAdd. 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-29546 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. TensorFlow is widely used in various industries and research domains due to its flexibility and scalability. However, a vulnerability has been discovered in TensorFlow that can lead to an integer division by zero undefined behavior in the tf.raw_ops.QuantizedBiasAdd function. This vulnerability affects multiple versions of TensorFlow, including 2.1.4, 2.2.3, 2.3.3, and 2.4.2.
Vulnerability Detail
The vulnerability arises from a division operation performed in the Eigen kernel implementation of QuantizedBiasAdd. The kernel divides the number of elements of the smaller input (based on shape) without checking if the divisor is zero. This can result in an integer division by zero, leading to undefined behavior. An attacker can exploit this vulnerability to cause a denial of service or potentially execute arbitrary code with the privileges of the TensorFlow process.
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, you can modify the affected code to include a check for zero divisor before performing the division operation. Here is an example of how you can add the check:
import tensorflow as tf
def safe_quantized_bias_add(x, y):
if tf.reduce_prod(tf.shape(x)) == 0 or tf.reduce_prod(tf.shape(y)) == 0:
raise ValueError('Input shape cannot be zero')
return tf.raw_ops.QuantizedBiasAdd(x, y)
By adding this check, you ensure that the division operation is only performed when the divisor is non-zero.
Conclusion
The identified vulnerability in TensorFlow can lead to an integer division by zero undefined behavior, which can be exploited by attackers. It is crucial to upgrade to the fixed version of TensorFlow (2.5.0) as soon as it becomes available. In the meantime, you can apply the provided workaround to mitigate the risk. For further assistance and support 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 ecosystem for building and deploying machine learning models.
This vulnerability can be exploited by an attacker to cause a denial of service or potentially execute arbitrary code with the privileges of the TensorFlow process.
The vulnerability affects TensorFlow versions 2.1.4, 2.2.3, 2.3.3, and 2.4.2.
The fix for this vulnerability will be included in TensorFlow 2.5.0. It is recommended to upgrade to the fixed version as soon as it becomes available.
Yes, you can modify the affected code to include a check for zero divisor before performing the division operation. Please refer to the 'workaround' section for more details.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow.