CVE-2021-41219: Vulnerability in TensorFlow - Undefined behavior via nullptr reference binding in sparse matrix multiplication

tensorflow Updated 02 Oct 2025

Summary

10/11/2021
Yes i
High
7.8

CVE-2021-41219: Undefined behavior via nullptr reference binding in sparse matrix multiplication. 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-41219 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 building and training neural networks. It provides a comprehensive set of tools and libraries for numerical computation and data flow graphs. TensorFlow supports various platforms and is available for Python, C++, and other programming languages. However, a vulnerability has been discovered in TensorFlow that can lead to undefined behavior in sparse matrix multiplication.

Vulnerability Detail

The vulnerability in TensorFlow arises from the code for sparse matrix multiplication. When the dimensions of the input matrices are 0 or less, a reference is bound to a nullptr, resulting in undefined behavior. This can lead to heap out-of-bounds access and potential security risks. The issue has been assigned a CVSS score of 7.8, indicating a high severity level. The vulnerability affects versions 2.4.4, 2.5.2, 2.6.1, and 2.7.0 of 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 →

Workaround

As a workaround, users can ensure that the dimensions of the input matrices are not 0 or less. By validating the dimensions before performing sparse matrix multiplication, the vulnerability can be avoided. Here is an example code snippet in Python that demonstrates the workaround:

import tensorflow as tf

a = [[1.0, 1.0, 1.0]]
b = [[], [], []]

if len(a) > 0 and len(b) > 0:
    tf.raw_ops.SparseMatMul(
        a=a,
        b=b,
        transpose_a=False,
        transpose_b=False,
        a_is_sparse=False,
        b_is_sparse=True
    )

By checking the dimensions of a and b before calling SparseMatMul, the vulnerability can be mitigated.

Conclusion

In conclusion, the vulnerability in TensorFlow related to undefined behavior in sparse matrix multiplication can lead to heap out-of-bounds access and potential security risks. It is crucial to update TensorFlow to the latest patched version (2.6.1 or later) to mitigate this vulnerability. For further support on vulnerability remediation, you can 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. It provides tools and libraries for numerical computation and data flow graphs.

Sparse matrix multiplication is a mathematical operation that involves multiplying two matrices where one or both matrices have a large number of zero elements. It is commonly used in various machine learning algorithms.

The vulnerability occurs when the dimensions of the input matrices are 0 or less. This leads to a reference being bound to a nullptr, resulting in undefined behavior and potential security risks.

The vulnerability can lead to heap out-of-bounds access, which can be exploited by attackers to gain unauthorized access or execute arbitrary code. It is important to patch the vulnerability to prevent potential security breaches.

To fix the vulnerability, it is recommended to update TensorFlow to version 2.6.1 or later. The TensorFlow team has released patches for the affected versions, and the fix will be included in TensorFlow 2.7.0.

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