CVE-2021-41227: Arbitrary Memory Read in TensorFlow

tensorflow Updated 02 Oct 2025

Summary

10/11/2021
Yes i
Moderate
6.6

CVE-2021-41227: Arbitrary memory read in ImmutableConst. Affects tensorflow across 3 version ranges.

< 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-41227 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 widely used for developing and deploying machine learning models. It provides a comprehensive ecosystem of tools, libraries, and resources for building and training various types of neural networks. TensorFlow supports multiple programming languages and platforms, making it a popular choice among researchers and developers. However, a vulnerability has been discovered in TensorFlow that allows for arbitrary memory read, potentially leading to unauthorized access to sensitive information.

Vulnerability Detail

The vulnerability, identified as CVE-2021-41227, affects the ImmutableConst operation in TensorFlow. By exploiting this vulnerability, an attacker can trick the operation into reading arbitrary memory contents. This can be achieved by providing a specially crafted input to the operation. The issue arises due to a lack of proper handling of memory mapped strings in the tstring TensorFlow string class. Although the class has support for memory mapped strings, the ImmutableConst operation does not provide any support for this data type. As a result, an attacker can abuse this inconsistency to read arbitrary memory, potentially exposing sensitive data.

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.4.4 2.4.4
    pip install --upgrade "tensorflow==2.4.4"
  • >= 2.5.0, < 2.5.2 2.5.2
    pip install --upgrade "tensorflow==2.5.2"
  • >= 2.6.0, < 2.6.1 2.6.1
    pip install --upgrade "tensorflow==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 avoid using the ImmutableConst operation with memory mapped strings. Instead, alternative data types or operations can be used to achieve the desired functionality. Here is an example of how to avoid the vulnerable operation:

import tensorflow as tf

with open('/tmp/test', 'wb') as f:
    f.write(b'\xe2' * 128)
    data = tf.constant(b'\xe2' * 128)

print(data)

In this example, the constant operation is used as a substitute for ImmutableConst to create a tensor with the desired data. This ensures that the vulnerability is not triggered.

Conclusion

The vulnerability in TensorFlow (CVE-2021-41227) allows for arbitrary memory read, potentially leading to unauthorized access to sensitive information. It is crucial to update to the latest patched version of TensorFlow (2.7.0 or the backported versions) to mitigate the vulnerability. In the meantime, users can follow the provided workaround to avoid using the vulnerable operation. 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 used for building and training neural networks.

The vulnerability allows for arbitrary memory read, which can potentially lead to unauthorized access to sensitive information.

To fix the vulnerability, update TensorFlow to the latest patched version (2.7.0 or the backported versions).

No, the vulnerability affects TensorFlow versions 2.4.4, 2.5.2, 2.6.1, and 2.7.0.

Yes, users can avoid using the vulnerable ImmutableConst operation with memory mapped strings and use alternative data types or operations instead.

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.4.4 2.4.4
    pip install --upgrade "tensorflow==2.4.4"
  • >= 2.5.0, < 2.5.2 2.5.2
    pip install --upgrade "tensorflow==2.5.2"
  • >= 2.6.0, < 2.6.1 2.6.1
    pip install --upgrade "tensorflow==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