CVE-2021-29579: Heap buffer overflow in tensorflow
Summary
CVE-2021-29579: Heap buffer overflow in MaxPoolGrad. 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 · Bitnami
- tensorflow-cpu · PyPI
- tensorflow-gpu · PyPI
The same CVE-2021-29579 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 open-source machine learning framework developed by Google. It provides a comprehensive ecosystem of tools, libraries, and resources for building and deploying machine learning models. TensorFlow is widely used in various domains, including research, industry, and academia. However, a vulnerability has been discovered in TensorFlow that could potentially lead to a heap buffer overflow.
Vulnerability Detail
The vulnerability, identified as CVE-2021-29579, affects the MaxPoolGrad function in TensorFlow. This function is used for gradient computation in max pooling operations. The implementation of MaxPoolGrad fails to validate indices used to access elements of input/output arrays, potentially resulting in out-of-bounds (OOB) access. An attacker could exploit this vulnerability to execute arbitrary code or cause a denial-of-service (DoS) condition.
How To Fix
Latest published version: 2.21.0 as of 22 Oct 2026
pip install --upgrade "tensorflow==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==2.1.4" -
>= 2.2.0, < 2.2.32.2.3pip install --upgrade "tensorflow==2.2.3" -
>= 2.3.0, < 2.3.32.3.3pip install --upgrade "tensorflow==2.3.3" -
>= 2.4.0, < 2.4.22.4.2pip install --upgrade "tensorflow==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 apply input validation checks in their own code before calling the MaxPoolGrad function. By ensuring that the indices used for accessing input/output arrays are within valid bounds, the risk of a heap buffer overflow can be mitigated. Here is an example of how to perform input validation:
import tensorflow as tf
orig_input = tf.constant([0.0], shape=[1, 1, 1, 1], dtype=tf.float32)
orig_output = tf.constant([0.0], shape=[1, 1, 1, 1], dtype=tf.float32)
grad = tf.constant([], shape=[0, 0, 0, 0], dtype=tf.float32)
ksize = [1, 1, 1, 1]
strides = [1, 1, 1, 1]
padding = "SAME"
# Perform input validation
if (orig_input.shape != orig_output.shape) or (orig_input.shape != grad.shape):
raise ValueError("Invalid input shapes")
# Call MaxPoolGrad function
output = tf.raw_ops.MaxPoolGrad(
orig_input=orig_input, orig_output=orig_output, grad=grad, ksize=ksize,
strides=strides, padding=padding, explicit_paddings=[])
Conclusion
The vulnerability in TensorFlow can lead to a heap buffer overflow, potentially enabling arbitrary code execution or causing a denial-of-service (DoS) condition. It is crucial to update TensorFlow to the latest version once the fix is available. Additionally, applying input validation checks in your code can serve as a temporary workaround. For further support on vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for tensorflow →
FAQ
TensorFlow is an open-source machine learning framework developed by Google. It provides tools and resources for building and deploying machine learning models.
The vulnerability in TensorFlow could allow an attacker to execute arbitrary code or cause a denial-of-service (DoS) condition.
The vulnerability has been fixed in TensorFlow 2.5.0. It is recommended to update to the latest version once the fix is available.
As a temporary workaround, users can apply input validation checks in their own code before calling the vulnerable function.
You can use Vulert, a tool that provides real-time monitoring and alerts for open-source vulnerabilities, to monitor your applications for this vulnerability.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow.