CVE-2021-29541
JSON

2.5low

Null pointer dereference in `StringNGrams`

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-xqfj-35wv-m3crBIT-TENSORFLOW-2021-29541PYSEC-2021-178PYSEC-2021-469PYSEC-2021-667

Description

TensorFlow is an end-to-end open source platform for machine learning. An attacker can trigger a dereference of a null pointer in `tf.raw_ops.StringNGrams`. This is because the implementation(https://github.com/tensorflow/tensorflow/blob/1cdd4da14282210cc759e468d9781741ac7d01bf/tensorflow/core/kernels/string_ngrams_op.cc#L67-L74) does not fully validate the `data_splits` argument. This would result in `ngrams_data`(https://github.com/tensorflow/tensorflow/blob/1cdd4da14282210cc759e468d9781741ac7d01bf/tensorflow/core/kernels/string_ngrams_op.cc#L106-L110) to be a null pointer when the output would be computed to have 0 or negative size. Later writes to the output tensor would then cause a null pointer dereference. The fix will be included in TensorFlow 2.5.0. We will also cherrypick this commit on TensorFlow 2.4.2, TensorFlow 2.3.3, TensorFlow 2.2.3 and TensorFlow 2.1.4, as these are also affected and still in supported range.

Affected

Product or packageVersionsReported by
tensorflow tensorflow< 2.1.4, >= 2.2.0, < 2.2.3, >= 2.3.0, < 2.3.3, >= 2.4.0, < 2.4.2CVE List
tensorflow (PyPI)before 2.1.4, from 2.2.0 before 2.2.3, from 2.3.0 before 2.3.3, from 2.4.0 before 2.4.2, before ba424dd8f16f7110eea526a8086f1a155f14f22bGitHub Advisory Database, PyPA Advisory Database
tensorflow-cpu (PyPI)before 2.1.4, from 2.2.0 before 2.2.3, from 2.3.0 before 2.3.3, from 2.4.0 before 2.4.2, before ba424dd8f16f7110eea526a8086f1a155f14f22bGitHub Advisory Database, PyPA Advisory Database
tensorflow-gpu (PyPI)before 2.1.4, from 2.2.0 before 2.2.3, from 2.3.0 before 2.3.3, from 2.4.0 before 2.4.2, before ba424dd8f16f7110eea526a8086f1a155f14f22bGitHub Advisory Database, PyPA Advisory Database
google tensorflowbefore 2.1.4, from 2.2.0 before 2.2.3, from 2.3.0 before 2.3.3, from 2.4.0 before 2.4.2NVD
tensorflow (Bitnami)before 2.1.4, from 2.2.0 before 2.2.3, 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:L/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. An attacker can trigger a dereference of a null pointer in `tf.raw_ops.StringNGrams`. This is because the implementation(https://github.com/tensorflow/tensorflow/blob/1cdd4da14282210cc759e468d9781741ac7d01bf/tensorflow/core/kernels/string_ngrams_op.cc#L67-L74) does not fully validate the `data_splits` argument. This would result in `ngrams_data`(https://github.com/tensorflow/tensorflow/blob/1cdd4da14282210cc759e468d9781741ac7d01bf/tensorflow/core/kernels/string_ngrams_op.cc#L106-L110) to be a null pointer when the output would be computed to have 0 or negative size. Later writes to the output tensor would then cause a null pointer dereference. The fix will be included in TensorFlow 2.5.0. We will also cherrypick this commit on TensorFlow 2.4.2, TensorFlow 2.3.3, TensorFlow 2.2.3 and TensorFlow 2.1.4, as these are also affected and still in supported range.

GitHub Advisory Database
Impact

An attacker can trigger a dereference of a null pointer in tf.raw_ops.StringNGrams:

import tensorflow as tf

data=tf.constant([''] * 11, shape=[11], dtype=tf.string)

splits = [0]*115
splits.append(3)
data_splits=tf.constant(splits, shape=[116], dtype=tf.int64)

tf.raw_ops.StringNGrams(data=data, data_splits=data_splits, separator=b'Ss',
                        ngram_widths=[7,6,11],
                        left_pad='ABCDE', right_pad=b'ZYXWVU',
                        pad_width=50, preserve_short_sequences=True)

This is because the implementation does not fully validate the data_splits argument. This would result in ngrams_data to be a null pointer when the output would be computed to have 0 or negative size.

Later writes to the output tensor would then cause a null pointer dereference.

Patches

We have patched the issue in GitHub commit ba424dd8f16f7110eea526a8086f1a155f14f22b.

The fix will be included in TensorFlow 2.5.0. We will also cherrypick this commit on TensorFlow 2.4.2, TensorFlow 2.3.3, TensorFlow 2.2.3 and TensorFlow 2.1.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 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;Un atacante puede desencadenar una desreferenciación de un puntero null en "tf.raw_ops.StringNGrams".&#xa0;Esto es debido a que la implementación (https://github.com/tensorflow/tensorflow/blob/1cdd4da14282210cc759e468d9781741ac7d01bf/tensorflow/core/kernels/string_ngrams_op.cc#L67-L74) no comprueba completamente el argumento "data_splits".&#xa0;Esto daría como resultado que "ngrams_data" (https://github.com/tensorflow/tensorflow/blob/1cdd4da14282210cc759e468d9781741ac7d01bf/tensorflow/core/kernels/string_ngrams_op.cc#L106-L110) sea un puntero null cuando se calcularía la salida tener 0 o tamaño negativo.&#xa0;Las escrituras posteriores en el tensor de salida causarían una desreferencia del puntero null.&#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, TensorFlow versión 2.3.3, TensorFlow versión 2.2.3 y TensorFlow versión 2.1.4, ya que estos también están afectados y aún están en el rango compatible

References

Sources

SourceRecordLicence
CVE ListCVE-2021-29541 changed 2024-08-03CVE Terms of Use
GitHub Advisory DatabaseGHSA-xqfj-35wv-m3cr changed 2026-09-10CC-BY-4.0
NVDCVE-2021-29541 changed 2026-06-17Public domain
PyPA Advisory DatabasePYSEC-2021-178 changed 2023-12-06CC-BY-4.0
PyPA Advisory DatabasePYSEC-2021-469 changed 2023-12-06CC-BY-4.0
PyPA Advisory DatabasePYSEC-2021-667 changed 2023-12-06CC-BY-4.0
Bitnami Vulnerability DatabaseBIT-TENSORFLOW-2021-29541 changed 2026-09-08Apache-2.0