CVE-2021-29521
JSON

2.5low

Segfault in SparseCountSparseOutput

Severity
2.5low CVSS:3.1 by GitHub_M
Exploit likelihood
0.19% (higher than 8% of CVEs; EPSS, by FIRST)
Published
Last changed
Assigned by
GitHub_M
Also known as
GHSA-hr84-fqvp-48mmBIT-TENSORFLOW-2021-29521PYSEC-2021-158PYSEC-2021-449PYSEC-2021-647

Description

TensorFlow is an end-to-end open source platform for machine learning. Specifying a negative dense shape in `tf.raw_ops.SparseCountSparseOutput` results in a segmentation fault being thrown out from the standard library as `std::vector` invariants are broken. This is because the implementation(https://github.com/tensorflow/tensorflow/blob/8f7b60ee8c0206a2c99802e3a4d1bb55d2bc0624/tensorflow/core/kernels/count_ops.cc#L199-L213) assumes the first element of the dense shape is always positive and uses it to initialize a `BatchedMap<T>` (i.e., `std::vector<absl::flat_hash_map<int64,T>>`(https://github.com/tensorflow/tensorflow/blob/8f7b60ee8c0206a2c99802e3a4d1bb55d2bc0624/tensorflow/core/kernels/count_ops.cc#L27)) data structure. If the `shape` tensor has more than one element, `num_batches` is the first value in `shape`. Ensuring that the `dense_shape` argument is a valid tensor shape (that is, all elements are non-negative) solves this issue. The fix will be included in TensorFlow 2.5.0. We will also cherrypick this commit on TensorFlow 2.4.2 and TensorFlow 2.3.3.

Affected

Product or packageVersionsReported by
tensorflow tensorflow< 2.3.3, >= 2.4.0, < 2.4.2CVE List
tensorflow (PyPI)from 2.3.0 before 2.3.3, from 2.4.0 before 2.4.2, before c57c0b9f3a4f8684f3489dd9a9ec627ad8b599f5GitHub Advisory Database, PyPA Advisory Database
tensorflow-cpu (PyPI)from 2.3.0 before 2.3.3, from 2.4.0 before 2.4.2, before c57c0b9f3a4f8684f3489dd9a9ec627ad8b599f5GitHub Advisory Database, PyPA Advisory Database
tensorflow-gpu (PyPI)from 2.3.0 before 2.3.3, from 2.4.0 before 2.4.2, before c57c0b9f3a4f8684f3489dd9a9ec627ad8b599f5GitHub Advisory Database, PyPA Advisory Database
google tensorflowfrom 2.3.0 before 2.3.3, from 2.4.0 before 2.4.2NVD
tensorflow (Bitnami)from 2.3.0 before 2.3.3, from 2.4.0 before 2.4.2Bitnami Vulnerability Database

All scores

GitHub_M2.5low CVSS:3.1CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:N/I:N/A:L
GitHub2.5low CVSS:3.1CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:N/I:N/A:L
GitHublow CVSS:4.0CVSS:4.0/AV:N/AC:L/AT:P/PR:L/UI:N/VC:N/VI:N/VA:L/SC:N/SI:N/SA:N
NVD5.5medium CVSS:3.1CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H
NVD2.1low CVSS:2.0AV:L/AC:L/Au:N/C:N/I:N/A:P
Bitnami Vulnerability Databasemedium rating

Classification

What each source says

CVE List

TensorFlow is an end-to-end open source platform for machine learning. Specifying a negative dense shape in `tf.raw_ops.SparseCountSparseOutput` results in a segmentation fault being thrown out from the standard library as `std::vector` invariants are broken. This is because the implementation(https://github.com/tensorflow/tensorflow/blob/8f7b60ee8c0206a2c99802e3a4d1bb55d2bc0624/tensorflow/core/kernels/count_ops.cc#L199-L213) assumes the first element of the dense shape is always positive and uses it to initialize a `BatchedMap<T>` (i.e., `std::vector<absl::flat_hash_map<int64,T>>`(https://github.com/tensorflow/tensorflow/blob/8f7b60ee8c0206a2c99802e3a4d1bb55d2bc0624/tensorflow/core/kernels/count_ops.cc#L27)) data structure. If the `shape` tensor has more than one element, `num_batches` is the first value in `shape`. Ensuring that the `dense_shape` argument is a valid tensor shape (that is, all elements are non-negative) solves this issue. The fix will be included in TensorFlow 2.5.0. We will also cherrypick this commit on TensorFlow 2.4.2 and TensorFlow 2.3.3.

GitHub Advisory Database
Impact

Specifying a negative dense shape in tf.raw_ops.SparseCountSparseOutput results in a segmentation fault being thrown out from the standard library as std::vector invariants are broken.

import tensorflow as tf

indices = tf.constant([], shape=[0, 0], dtype=tf.int64)
values = tf.constant([], shape=[0, 0], dtype=tf.int64)
dense_shape = tf.constant([-100, -100, -100], shape=[3], dtype=tf.int64)
weights = tf.constant([], shape=[0, 0], dtype=tf.int64)

tf.raw_ops.SparseCountSparseOutput(indices=indices, values=values, dense_shape=dense_shape, weights=weights, minlength=79, maxlength=96, binary_output=False)

This is because the implementation assumes the first element of the dense shape is always positive and uses it to initialize a BatchedMap<T> (i.e., std::vector<absl::flat_hash_map<int64,T>>) data structure.

  bool is_1d = shape.NumElements() == 1;
  int num_batches = is_1d ? 1 : shape.flat<int64>()(0);
  ...
  auto per_batch_counts = BatchedMap<W>(num_batches); 

If the shape tensor has more than one element, num_batches is the first value in shape.

Ensuring that the dense_shape argument is a valid tensor shape (that is, all elements are non-negative) solves this issue.

Patches

We have patched the issue in GitHub commit c57c0b9f3a4f8684f3489dd9a9ec627ad8b599f5.

The fix will be included in TensorFlow 2.5.0. We will also cherrypick this commit on TensorFlow 2.4.2 and TensorFlow 2.3.3.

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 Yakun Zhang and Ying Wang of Baidu X-Team.

NVD (es)

TensorFlow es una plataforma de código abierto de extremo a extremo para el aprendizaje automático.&#xa0;Especificar una forma densa negativa en "tf.raw_ops.SparseCountSparseOutput" resulta en un error de segmentación que es eliminado de la biblioteca estándar ya que los invariantes "std::vector" son rotos.&#xa0;Esto es debido a que la implementación (https://github.com/tensorflow/tensorflow/blob/8f7b60ee8c0206a2c99802e3a4d1bb55d2bc0624/tensorflow/core/kernels/count_ops.cc#L199-L213) asume que el primer elemento de la forma densa es siempre positivo y lo usa para inicializar un "BatchedMap(T)" (es decir, "std::vector (absl::flat_hash_map(int64, T))" (https://github.com/tensorflow/tensorflow/blob/8f7b60ee8c0206a2c99802e3a4d1bb55d2bc0624/tensorflow/core/kernels/count_ops.cc#L27)) estructura de datos.&#xa0;Si el tensor de "shape" presenta más de un elemento,"num_batches" es el primer valor en "shape".&#xa0;Asegurarse de que el argumento "dense_shape" sea una forma de tensor válida (es decir, que todos los elementos no sean negativos) resuelve este problema.&#xa0;La corrección será incluida en TensorFlow versión 2.5.0.&#xa0;También seleccionaremos este commit en TensorFlow versión 2.4.2 y TensorFlow versión 2.3.3

References

Sources

SourceRecordLicence
CVE ListCVE-2021-29521 changed 2024-08-03CVE Terms of Use
GitHub Advisory DatabaseGHSA-hr84-fqvp-48mm changed 2026-09-10CC-BY-4.0
NVDCVE-2021-29521 changed 2026-06-17Public domain
PyPA Advisory DatabasePYSEC-2021-158 changed 2023-12-06CC-BY-4.0
PyPA Advisory DatabasePYSEC-2021-449 changed 2023-12-06CC-BY-4.0
PyPA Advisory DatabasePYSEC-2021-647 changed 2023-12-06CC-BY-4.0
Bitnami Vulnerability DatabaseBIT-TENSORFLOW-2021-29521 changed 2026-09-08Apache-2.0