CVE-2021-37657
JSON

7.1high

Reference binding to nullptr in `MatrixDiagV*` ops in TensorFlow

Severity
7.1high CVSS:3.1 by GitHub_M
Exploit likelihood
0.17% (higher than 6% of CVEs; EPSS, by FIRST)
Published
Last changed
Assigned by
GitHub_M
Also known as
GHSA-5xwc-mrhx-5g3mBIT-TENSORFLOW-2021-37657PYSEC-2021-279PYSEC-2021-570PYSEC-2021-768

Description

TensorFlow is an end-to-end open source platform for machine learning. In affected versions an attacker can cause undefined behavior via binding a reference to null pointer in all operations of type `tf.raw_ops.MatrixDiagV*`. The [implementation](https://github.com/tensorflow/tensorflow/blob/84d053187cb80d975ef2b9684d4b61981bca0c41/tensorflow/core/kernels/linalg/matrix_diag_op.cc) has incomplete validation that the value of `k` is a valid tensor. We have check that this value is either a scalar or a vector, but there is no check for the number of elements. If this is an empty tensor, then code that accesses the first element of the tensor is wrong. We have patched the issue in GitHub commit f2a673bd34f0d64b8e40a551ac78989d16daad09. The fix will be included in TensorFlow 2.6.0. We will also cherrypick this commit on TensorFlow 2.5.1, TensorFlow 2.4.3, and TensorFlow 2.3.4, as these are also affected and still in supported range.

Affected

Product or packageVersionsReported by
tensorflow tensorflow>= 2.5.0, < 2.5.1, >= 2.4.0, < 2.4.3, < 2.3.4CVE List
tensorflow (PyPI)before 2.3.4, from 2.4.0 before 2.4.3, from 2.5.0 before 2.5.1, before f2a673bd34f0d64b8e40a551ac78989d16daad09, from 2.3.0 before 2.3.4GitHub Advisory Database, PyPA Advisory Database
tensorflow-cpu (PyPI)before 2.3.4, from 2.4.0 before 2.4.3, from 2.5.0 before 2.5.1, before f2a673bd34f0d64b8e40a551ac78989d16daad09, from 2.3.0 before 2.3.4GitHub Advisory Database, PyPA Advisory Database
tensorflow-gpu (PyPI)before 2.3.4, from 2.4.0 before 2.4.3, from 2.5.0 before 2.5.1, before f2a673bd34f0d64b8e40a551ac78989d16daad09, from 2.3.0 before 2.3.4GitHub Advisory Database, PyPA Advisory Database
google tensorflowfrom 2.3.0 before 2.3.4, from 2.4.0 before 2.4.3, 2.5.0, 2.6.0NVD
tensorflow (Bitnami)from 2.3.0 before 2.3.4, from 2.4.0 before 2.4.3, from 2.5.0 before 2.5.1Bitnami Vulnerability Database

All scores

GitHub_M7.1high CVSS:3.1CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:H
GitHub7.1medium CVSS:3.1CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:H
GitHubmedium CVSS:4.0CVSS:4.0/AV:L/AC:L/AT:N/PR:L/UI:N/VC:N/VI:H/VA:H/SC:N/SI:N/SA:N
NVD7.8high CVSS:3.1CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H
NVD4.6medium CVSS:2.0AV:L/AC:L/Au:N/C:P/I:P/A:P
Bitnami Vulnerability Databasehigh rating

Classification

What each source says

CVE List

TensorFlow is an end-to-end open source platform for machine learning. In affected versions an attacker can cause undefined behavior via binding a reference to null pointer in all operations of type `tf.raw_ops.MatrixDiagV*`. The [implementation](https://github.com/tensorflow/tensorflow/blob/84d053187cb80d975ef2b9684d4b61981bca0c41/tensorflow/core/kernels/linalg/matrix_diag_op.cc) has incomplete validation that the value of `k` is a valid tensor. We have check that this value is either a scalar or a vector, but there is no check for the number of elements. If this is an empty tensor, then code that accesses the first element of the tensor is wrong. We have patched the issue in GitHub commit f2a673bd34f0d64b8e40a551ac78989d16daad09. The fix will be included in TensorFlow 2.6.0. We will also cherrypick this commit on TensorFlow 2.5.1, TensorFlow 2.4.3, and TensorFlow 2.3.4, as these are also affected and still in supported range.

GitHub Advisory Database
Impact

An attacker can cause undefined behavior via binding a reference to null pointer in all operations of type tf.raw_ops.MatrixDiagV*:

import tensorflow as tf

tf.raw_ops.MatrixDiagV3(
  diagonal=[1,0],
  k=[],
  num_rows=[1,2,3],
  num_cols=[4,5],
  padding_value=[],
  align='RIGHT_RIGHT')

The implementation has incomplete validation that the value of k is a valid tensor. We have check that this value is either a scalar or a vector, but there is no check for the number of elements. If this is an empty tensor, then code that accesses the first element of the tensor is wrong:

  auto& diag_index = context->input(1);
  ...
  lower_diag_index = diag_index.flat<int32>()(0);
Patches

We have patched the issue in GitHub commit f2a673bd34f0d64b8e40a551ac78989d16daad09.

The fix will be included in TensorFlow 2.6.0. We will also cherrypick this commit on TensorFlow 2.5.1, TensorFlow 2.4.3, and TensorFlow 2.3.4, as these are also affected and still in supported range.

For more information

Please consult our security guide for more information regarding the security model and how to contact us with issues and questions.

Attribution

This vulnerability has been reported by members of the Aivul Team from Qihoo 360.

NVD (es)

TensorFlow es una plataforma de código abierto de extremo a extremo para el aprendizaje automático. En las versiones afectadas, un atacante puede causar un comportamiento indefinido por medio de la vinculación de una referencia a un puntero null en todas las operaciones de tipo "tf.raw_ops.MatrixDiagV*". La [implementación](https://github.com/tensorflow/tensorflow/blob/84d053187cb80d975ef2b9684d4b61981bca0c41/tensorflow/core/kernels/linalg/matrix_diag_op.cc) presenta una comprobación incompleta de que el valor de "k" es un tensor válido. Hemos comprobado que este valor es un escalar o un vector, pero no hay ninguna comprobación del número de elementos. Si se trata de un tensor vacío, el código que accede al primer elemento del tensor es erróneo. Hemos parcheado el problema en el commit f2a673bd34f0d64b8e40a551ac78989d16daad09 de GitHub. La corrección será incluida en TensorFlow versión 2.6.0. También seleccionaremos este commit en TensorFlow versión 2.5.1, TensorFlow versión 2.4.3, y TensorFlow versión 2.3.4, ya que estos también están afectados y todavía están en el rango de soporte.

References

Sources

SourceRecordLicence
CVE ListCVE-2021-37657 changed 2024-08-04CVE Terms of Use
GitHub Advisory DatabaseGHSA-5xwc-mrhx-5g3m changed 2026-07-08CC-BY-4.0
NVDCVE-2021-37657 changed 2026-06-17Public domain
PyPA Advisory DatabasePYSEC-2021-279 changed 2023-12-06CC-BY-4.0
PyPA Advisory DatabasePYSEC-2021-570 changed 2023-12-06CC-BY-4.0
PyPA Advisory DatabasePYSEC-2021-768 changed 2023-12-06CC-BY-4.0
Bitnami Vulnerability DatabaseBIT-TENSORFLOW-2021-37657 changed 2026-09-08Apache-2.0