CVE-2021-29515: TensorFlow MatrixDiag* Operations Validation Vulnerability

tensorflow Updated 02 Oct 2025

Summary

06/03/2024
Yes i
High
Not published

CVE-2021-29515: Reference binding to null pointer in MatrixDiag* ops. 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-29515 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 Lume, the Habilume companion Habilume Habit tracker with a companion that grows with you Complete habits, earn Lume Points, and watch your Lume grow as you stay consistent. App Store Google Play

Background

TensorFlow is an end-to-end open source platform for machine learning. 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 industries for tasks such as image recognition, natural language processing, and recommendation systems. However, a vulnerability has been discovered in the implementation of the MatrixDiag* operations, which could potentially lead to security breaches and data integrity issues.

Vulnerability Detail

The vulnerability in TensorFlow's MatrixDiag* operations arises from the lack of validation for non-empty tensor arguments. This oversight allows an attacker to manipulate the tensor inputs, potentially leading to unexpected behavior, data corruption, or even remote code execution. The vulnerability affects versions 0 and above, as well as versions 2.1.4, 2.2.3, 2.3.3, and 2.4.2. The severity of this vulnerability is rated as High (CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H).

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 workaround, users can manually validate the tensor arguments before passing them to the MatrixDiag* operations. Here is an example of how to perform the validation in Python:

import tensorflow as tf

def matrix_diag_workaround(tensor):
    if tensor.shape[0] == 0 or tensor.shape[1] == 0:
        raise ValueError('Tensor arguments must be non-empty')
    return tf.linalg.matrix_diag(tensor)

Conclusion

The vulnerability in TensorFlow's MatrixDiag* operations can have serious security and data integrity implications. It is crucial to promptly update to the latest patched version of TensorFlow or apply the backported fixes to mitigate the risk. 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 a comprehensive ecosystem of tools and libraries.

This vulnerability allows an attacker to manipulate tensor inputs, potentially leading to unexpected behavior, data corruption, or remote code execution.

The vulnerability affects versions 0 and above, as well as versions 2.1.4, 2.2.3, 2.3.3, and 2.4.2.

To fix this vulnerability, it is recommended to update TensorFlow to version 2.5.0 or apply the backported fixes for versions 2.4.2, 2.3.3, 2.2.3, and 2.1.4.

Yes, a workaround is available. Users can manually validate the tensor arguments before using the MatrixDiag* operations.

Related vulnerabilities

Recent vulnerabilities recorded for tensorflow.

Sponsored Lume, the Habilume companion Habilume Habit tracker with a companion that grows with you Complete habits, earn Lume Points, and watch your Lume grow as you stay consistent. App Store Google Play

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