CVE-2021-29577: Heap buffer overflow in tensorflow

tensorflow Updated 02 Oct 2025

Summary

21/05/2021
Yes i
Low
2.5

CVE-2021-29577: Heap buffer overflow in AvgPool3DGrad. 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

The same CVE-2021-29577 is tracked separately for each ecosystem and vendor. Its fix information is the same; the package and affected versions differ.

Free scan

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.

Check my app free

No signup required · Results in about 60 seconds

Sponsored MarkAI Find prospects already talking about the problem you solve AI watches the communities your customers use to find qualified prospects, then alerts you when a conversation is worth joining. See MarkAI

Background

TensorFlow is an open-source machine learning framework developed by Google. It provides a comprehensive ecosystem of tools, libraries, and community resources that enable researchers and developers to build and deploy machine learning models. TensorFlow is widely used in various domains, including computer vision, natural language processing, and deep learning. However, a vulnerability has been discovered in TensorFlow that could lead to a heap buffer overflow.

Vulnerability Detail

The vulnerability, identified as CVE-2021-29577, is a heap buffer overflow in the AvgPool3DGrad function of TensorFlow. This function is used for calculating the gradient of the average pooling operation in 3D convolutional neural networks. The vulnerability arises from an assumption made in the implementation of AvgPool3DGrad that the orig_input_shape and grad tensors have similar first and last dimensions. However, this assumption is not validated, leading to a potential heap buffer overflow. An attacker could exploit this vulnerability to execute arbitrary code or cause a denial-of-service 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.4 2.1.4
    pip install --upgrade "tensorflow==2.1.4"
  • >= 2.2.0, < 2.2.3 2.2.3
    pip install --upgrade "tensorflow==2.2.3"
  • >= 2.3.0, < 2.3.3 2.3.3
    pip install --upgrade "tensorflow==2.3.3"
  • >= 2.4.0, < 2.4.2 2.4.2
    pip 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

If updating TensorFlow is not immediately feasible, users can mitigate the risk by avoiding the use of the AvgPool3DGrad function or ensuring that the orig_input_shape and grad tensors have compatible dimensions. Here is an example of how to use compatible tensors:

import tensorflow as tf

orig_input_shape = tf.constant([10, 6, 3, 7, 7], shape=[5], dtype=tf.int32)
grad = tf.constant([0.01, 0, 0], shape=[3, 1, 1, 1, 1], dtype=tf.float32)
ksize = [1, 1, 1, 1, 1]
strides = [1, 1, 1, 1, 1]
padding = "SAME"

if orig_input_shape.shape[0] == grad.shape[0] and orig_input_shape.shape[-1] == grad.shape[-1]:
  tf.raw_ops.AvgPool3DGrad(
    orig_input_shape=orig_input_shape, grad=grad, ksize=ksize, strides=strides,
    padding=padding)
else:
  print("Incompatible tensor dimensions")

By checking the dimensions of the tensors before calling AvgPool3DGrad, the risk of a heap buffer overflow can be mitigated.

Conclusion

The vulnerability in TensorFlow has been addressed by the TensorFlow team in the latest patched versions. Users are advised to update their installations to mitigate the risk of a heap buffer overflow. For further support on vulnerability remediation, please contact DevNack.com.

See every vulnerability recorded for tensorflow →

Share this vulnerability

FAQ

TensorFlow is an open-source machine learning framework developed by Google. It provides tools and libraries for building and deploying machine learning models.

AvgPool3DGrad is a function in TensorFlow used for calculating the gradient of the average pooling operation in 3D convolutional neural networks.

A heap buffer overflow occurs when a program writes data beyond the bounds of a dynamically allocated buffer in the heap, potentially overwriting adjacent memory and leading to crashes or arbitrary code execution.

This vulnerability could allow an attacker to execute arbitrary code or cause a denial-of-service condition in systems using TensorFlow.

To fix this vulnerability, update your TensorFlow installation to one of the patched versions: TensorFlow 2.1.4, TensorFlow 2.2.3, TensorFlow 2.3.3, or TensorFlow 2.4.2.

Related vulnerabilities

Recent vulnerabilities recorded for tensorflow.

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.4 2.1.4
    pip install --upgrade "tensorflow==2.1.4"
  • >= 2.2.0, < 2.2.3 2.2.3
    pip install --upgrade "tensorflow==2.2.3"
  • >= 2.3.0, < 2.3.3 2.3.3
    pip install --upgrade "tensorflow==2.3.3"
  • >= 2.4.0, < 2.4.2 2.4.2
    pip 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 →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback