CVE-2021-29583: TensorFlow FusedBatchNorm Heap Buffer Overflow

tensorflow Updated 02 Oct 2025

Summary

06/03/2024
Yes i
High
Not published

CVE-2021-29583: Heap buffer overflow and undefined behavior in FusedBatchNorm. 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-29583 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 end-to-end open source platform for machine learning. It provides a comprehensive ecosystem of tools, libraries, and resources for developing and deploying machine learning models. TensorFlow includes various operations and functions to perform common tasks in machine learning, such as data preprocessing, model training, and inference. One of these operations is tf.raw_ops.FusedBatchNorm, which is used for batch normalization in neural networks. Batch normalization is a technique that normalizes the inputs to a neural network layer, improving the stability and performance of the model. However, the implementation of tf.raw_ops.FusedBatchNorm in TensorFlow is vulnerable to a heap buffer overflow.

Vulnerability Detail

The vulnerability in TensorFlow's tf.raw_ops.FusedBatchNorm arises from a lack of validation for the scale, offset, mean, and variance tensors. When these tensors are provided to the operation, the implementation fails to check if they have the same number of elements as the number of channels in the input tensor (x). This oversight allows for heap out-of-bounds reads when accessing the tensors beyond their boundaries. Additionally, if the tensors are empty, the lack of validation triggers undefined behavior by dereferencing null pointers. These vulnerabilities can be exploited by an attacker to execute arbitrary code or crash the application, leading to a denial of service (DoS) condition. The impact of this vulnerability is classified as high severity.

How To Fix

Fixed versions by release line

The minimum fixed version depends on the release line you run.

  • < 2.1.4 2.1.4
  • >= 2.2.0, < 2.2.3 2.2.3
  • >= 2.3.0, < 2.3.3 2.3.3
  • >= 2.4.0, < 2.4.2 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 avoid using the tf.raw_ops.FusedBatchNorm operation or ensure that the scale, offset, mean, and variance tensors have the correct number of elements matching the number of channels in the input tensor (x). This can be achieved by carefully validating the input tensors before passing them to the operation. Here is an example of how to validate the tensors in Python:

import tensorflow as tf

def validate_tensors(scale, offset, mean, variance, x):
    num_channels = x.shape[-1]
    if scale.shape[-1] != num_channels or offset.shape[-1] != num_channels:
        raise ValueError('Scale and offset tensors must have the same number of elements as the number of channels in x.')
    if mean.shape[-1] != num_channels or variance.shape[-1] != num_channels:
        raise ValueError('Mean and variance tensors must have the same number of elements as the number of channels in x.')

# Usage example
scale = tf.constant([1.0, 2.0, 3.0])
offset = tf.constant([0.0, 0.0, 0.0])
mean = tf.constant([0.0, 0.0, 0.0])
variance = tf.constant([1.0, 1.0, 1.0])
x = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])

validate_tensors(scale, offset, mean, variance, x)

Conclusion

The vulnerability in TensorFlow's tf.raw_ops.FusedBatchNorm operation can lead to a heap buffer overflow and undefined behavior when empty tensors are used. This vulnerability has been addressed in TensorFlow 2.5.0 and backported to earlier versions within the supported range. Users are advised to upgrade their TensorFlow installation to the fixed versions or apply the provided workarounds. For further assistance or support in vulnerability remediation, please contact DevNack.com.

See every vulnerability recorded for tensorflow →

Share this vulnerability

FAQ

TensorFlow is an open source platform for machine learning that provides a comprehensive ecosystem of tools, libraries, and resources for developing and deploying machine learning models.

tf.raw_ops.FusedBatchNorm is an operation in TensorFlow that performs batch normalization, a technique used to normalize the inputs to a neural network layer.

A heap buffer overflow is a type of vulnerability where a program writes data beyond the boundaries of a buffer allocated in the heap, potentially overwriting important data or executing arbitrary code.

This vulnerability can be exploited by an attacker to execute arbitrary code or crash the application, leading to a denial of service (DoS) condition.

To fix this vulnerability, it is recommended to upgrade to TensorFlow 2.5.0 or any subsequent versions. Alternatively, you can update to one of the backported fixes in TensorFlow versions 2.4.2, 2.3.3, 2.2.3, or 2.1.4.

Related vulnerabilities

Recent vulnerabilities recorded for tensorflow.

How To Fix

Fixed versions by release line

The minimum fixed version depends on the release line you run.

  • < 2.1.4 2.1.4
  • >= 2.2.0, < 2.2.3 2.2.3
  • >= 2.3.0, < 2.3.3 2.3.3
  • >= 2.4.0, < 2.4.2 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