7.1high
Reference binding to nullptr in `MatrixSetDiagV*` ops in TensorFlow
- Severity
- 7.1high CVSS:3.1 by GitHub_M
- Exploit likelihood
- 0.17% (higher than 3% of CVEs)
- Published
- Last changed
- Assigned by
- GitHub_M
- Also known as
- GHSA-6p5r-g9mq-ggh2BIT-TENSORFLOW-2021-37658PYSEC-2021-280PYSEC-2021-571PYSEC-2021-769
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.MatrixSetDiagV*`. 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 ff8894044dfae5568ecbf2ed514c1a37dc394f1b. 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 package | Versions | Reported by |
|---|---|---|
| tensorflow tensorflow | >= 2.5.0, < 2.5.1, >= 2.4.0, < 2.4.3, < 2.3.4 | CVE List |
| tensorflow (PyPI) | before 2.3.4, from 2.4.0 before 2.4.3, from 2.5.0 before 2.5.1, before ff8894044dfae5568ecbf2ed514c1a37dc394f1b, from 2.3.0 before 2.3.4 | GitHub 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 ff8894044dfae5568ecbf2ed514c1a37dc394f1b, from 2.3.0 before 2.3.4 | GitHub 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 ff8894044dfae5568ecbf2ed514c1a37dc394f1b, from 2.3.0 before 2.3.4 | GitHub Advisory Database, PyPA Advisory Database |
| google tensorflow | from 2.3.0 before 2.3.4, from 2.4.0 before 2.4.3, 2.5.0, 2.6.0 | NVD |
| 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.1 | Bitnami Vulnerability Database |
All scores
| GitHub_M | 7.1high CVSS:3.1 | CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:H |
| GitHub | 7.1medium CVSS:3.1 | CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:H |
| GitHub | medium CVSS:4.0 | CVSS:4.0/AV:L/AC:L/AT:N/PR:L/UI:N/VC:N/VI:H/VA:H/SC:N/SI:N/SA:N |
| NVD | 7.8high CVSS:3.1 | CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H |
| NVD | 4.6medium CVSS:2.0 | AV:L/AC:L/Au:N/C:P/I:P/A:P |
| Bitnami Vulnerability Database | high 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.MatrixSetDiagV*`. 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 ff8894044dfae5568ecbf2ed514c1a37dc394f1b. 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.MatrixSetDiagV*:
import tensorflow as tf
tf.raw_ops.MatrixSetDiagV3(
input=[1,2,3],
diagonal=[1,1],
k=[],
align='RIGHT_LEFT')
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 ff8894044dfae5568ecbf2ed514c1a37dc394f1b.
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.MatrixSetDiagV*". 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. Se comprueba que este valor es un escalar o un vector, pero no se comprueba el 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 ff8894044dfae5568ecbf2ed514c1a37dc394f1b de GitHub. La corrección será incluida en TensorFlow versión 2.6.0. También seleccionaremos este commit en TensorFlow 2.5.1, TensorFlow 2.4.3 y TensorFlow 2.3.4, ya que estos también están afectados y todavía están en el rango de soporte.
References
Sources
| Source | Record | Licence |
|---|---|---|
| CVE List | CVE-2021-37658 changed 2024-08-04 | CVE Terms of Use |
| GitHub Advisory Database | GHSA-6p5r-g9mq-ggh2 changed 2026-07-08 | CC-BY-4.0 |
| NVD | CVE-2021-37658 changed 2026-06-17 | Public domain |
| PyPA Advisory Database | PYSEC-2021-280 changed 2023-12-06 | CC-BY-4.0 |
| PyPA Advisory Database | PYSEC-2021-571 changed 2023-12-06 | CC-BY-4.0 |
| PyPA Advisory Database | PYSEC-2021-769 changed 2023-12-06 | CC-BY-4.0 |
| Bitnami Vulnerability Database | BIT-TENSORFLOW-2021-37658 changed 2026-09-08 | Apache-2.0 |