CVE-2021-41216: TensorFlow - Heap Buffer Overflow in Transpose Shape Inference Function

tensorflow Updated 02 Oct 2025

Summary

06/03/2024
Yes i
High
Not published

CVE-2021-41216: Heap buffer overflow in Transpose. Affects tensorflow across 3 version ranges.

>= 2.4.0, < 2.4.4 >= 2.5.0, < 2.5.2 >= 2.6.0, < 2.6.1

Fixed in 2.4.4, 2.5.2 or 2.6.1, depending on the release line you run. How to fix ↓

Also tracked for

The same CVE-2021-41216 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 Devnack Penetration testing for web, API and mobile Manual testing by engineers who build software, not an auditor's checklist. Trusted by teams at Swift and Google Talk to Devnack

Background

TensorFlow is an open source platform for machine learning. It provides a comprehensive ecosystem of tools, libraries, and resources for developing and deploying machine learning models. TensorFlow is widely used in various domains, including research, industry, and academia. This vulnerability affects versions 2.4.0 and above of the TensorFlow package.

Vulnerability Detail

The shape inference function for the Transpose operation in TensorFlow is vulnerable to a heap buffer overflow. This vulnerability occurs when the perm parameter contains negative elements. The shape inference function does not validate the indices in perm, allowing for the possibility of accessing memory outside the bounds of the allocated buffer. An attacker could exploit this vulnerability to execute arbitrary code or cause a denial of service. The severity of this vulnerability is rated as high.

How To Fix

Fixed versions by release line

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

  • >= 2.4.0, < 2.4.4 2.4.4
  • >= 2.5.0, < 2.5.2 2.5.2
  • >= 2.6.0, < 2.6.1 2.6.1

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 ensure that the perm parameter passed to the Transpose operation does not contain any negative elements. This can be achieved by validating the input and rejecting any invalid values. Here is an example code snippet that demonstrates the workaround:

import tensorflow as tf

def safe_transpose(input_tensor, perm):
    if any(i < 0 for i in perm):
        raise ValueError('Invalid permutation indices')
    return tf.transpose(input_tensor, perm)

Conclusion

In conclusion, the TensorFlow package is vulnerable to a heap buffer overflow in the shape inference function for the Transpose operation. This vulnerability can be mitigated by updating to the latest patched version of TensorFlow. Users are advised to follow the recommended steps to fix the vulnerability and ensure the security of their TensorFlow installations. 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 platform for machine learning that provides tools and resources for developing and deploying machine learning models.

This vulnerability allows for a heap buffer overflow, which can be exploited by an attacker to execute arbitrary code or cause a denial of service.

Versions 2.4.0 and above of the TensorFlow package are affected by this vulnerability.

To fix this vulnerability, it is recommended to update TensorFlow to version 2.7.0 or later. Patches for earlier versions, including TensorFlow 2.4.4, TensorFlow 2.5.2, and TensorFlow 2.6.1, will also be released.

Yes, a temporary workaround is to ensure that the perm parameter passed to the Transpose operation does not contain any negative elements. This can be achieved by validating the input and rejecting any invalid values.

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.4.0, < 2.4.4 2.4.4
  • >= 2.5.0, < 2.5.2 2.5.2
  • >= 2.6.0, < 2.6.1 2.6.1

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