CVE-2021-37678
JSON

9.3critical

Arbitrary code execution due to YAML deserialization

Severity
9.3critical CVSS:3.1 by GitHub_M
Exploit likelihood
0.45% (higher than 40% of CVEs; EPSS, by FIRST)
Published
Last changed
Assigned by
GitHub_M
Also known as
GHSA-r6jx-9g48-2r5rBIT-TENSORFLOW-2021-37678PYSEC-2021-300PYSEC-2021-591PYSEC-2021-789

Description

TensorFlow is an end-to-end open source platform for machine learning. In affected versions TensorFlow and Keras can be tricked to perform arbitrary code execution when deserializing a Keras model from YAML format. The [implementation](https://github.com/tensorflow/tensorflow/blob/460e000de3a83278fb00b61a16d161b1964f15f4/tensorflow/python/keras/saving/model_config.py#L66-L104) uses `yaml.unsafe_load` which can perform arbitrary code execution on the input. Given that YAML format support requires a significant amount of work, we have removed it for now. We have patched the issue in GitHub commit 23d6383eb6c14084a8fc3bdf164043b974818012. 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 23d6383eb6c14084a8fc3bdf164043b974818012, 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 23d6383eb6c14084a8fc3bdf164043b974818012, 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 23d6383eb6c14084a8fc3bdf164043b974818012, 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_M9.3critical CVSS:3.1CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H
GitHub9.3high CVSS:3.1CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H
GitHubhigh CVSS:4.0CVSS:4.0/AV:L/AC:L/AT:N/PR:L/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N
NVD8.8high CVSS:3.1CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H
NVD4.6medium CVSS:2.0AV:L/AC:L/Au:N/C:P/I:P/A:P
Bitnami Vulnerability Databasecritical rating

Classification

What each source says

CVE List

TensorFlow is an end-to-end open source platform for machine learning. In affected versions TensorFlow and Keras can be tricked to perform arbitrary code execution when deserializing a Keras model from YAML format. The [implementation](https://github.com/tensorflow/tensorflow/blob/460e000de3a83278fb00b61a16d161b1964f15f4/tensorflow/python/keras/saving/model_config.py#L66-L104) uses `yaml.unsafe_load` which can perform arbitrary code execution on the input. Given that YAML format support requires a significant amount of work, we have removed it for now. We have patched the issue in GitHub commit 23d6383eb6c14084a8fc3bdf164043b974818012. 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

TensorFlow and Keras can be tricked to perform arbitrary code execution when deserializing a Keras model from YAML format.

from tensorflow.keras import models

payload = '''
!!python/object/new:type
args: ['z', !!python/tuple [], {'extend': !!python/name:exec }]
listitems: "__import__('os').system('cat /etc/passwd')"
'''
  
models.model_from_yaml(payload)

The implementation uses yaml.unsafe_load which can perform arbitrary code execution on the input.

Patches

Given that YAML format support requires a significant amount of work, we have removed it for now.

We have patched the issue in GitHub commit 23d6383eb6c14084a8fc3bdf164043b974818012.

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 Arjun Shibu.

NVD (es)

TensorFlow es una plataforma de código abierto de extremo a extremo para el aprendizaje automático.&#xa0;En las versiones afectadas, se puede engañar a TensorFlow y Keras para llevar a cabo una ejecución de código arbitrario al deserializar un modelo de Keras desde el formato YAML.&#xa0;La [implementación] (https://github.com/tensorflow/tensorflow/blob/460e000de3a83278fb00b61a16d161b1964f15f4/tensorflow/python/keras/saving/model_config.py#L66-L104) usa "yaml.unsafe_load" en la entrada.&#xa0;Dado que la compatibilidad con el formato YAML requiere una gran cantidad de trabajo, lo hemos eliminado por ahora.&#xa0;Hemos solucionado el problema en el commit de GitHub 23d6383eb6c14084a8fc3bdf164043b974818012.&#xa0;La corrección será incluida en TensorFlow versión 2.6.0.&#xa0;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 aún se encuentran en el rango admitido.

References

https://github.com/tensorflow/tensorflow/security/advisories/GHSA-r6jx-9g48-2r5radvisory, third-party-advisory, web
https://github.com/tensorflow/tensorflow/commit/23d6383eb6c14084a8fc3bdf164043b974818012advisory, fix, patch, third-party-advisory, web
https://nvd.nist.gov/vuln/detail/CVE-2021-37678advisory, web
https://github.com/tensorflow/tensorflow/commit/1df5a69e9f1a18a937e7907223066e606bf466b9web
https://github.com/tensorflow/tensorflow/commit/8e47a685785bef8f81bcb996048921dfde08a9abweb
https://github.com/tensorflow/tensorflow/commit/a09ab4e77afdcc6e1e045c9d41d5edab63aafc1aweb
https://github.com/pypa/advisory-database/tree/main/vulns/tensorflow-cpu/PYSEC-2021-591.yamlweb
https://github.com/pypa/advisory-database/tree/main/vulns/tensorflow-gpu/PYSEC-2021-789.yamlweb
https://github.com/pypa/advisory-database/tree/main/vulns/tensorflow/PYSEC-2021-300.yamlweb
https://github.com/tensorflow/tensorflowpackage

Sources

SourceRecordLicence
CVE ListCVE-2021-37678 changed 2024-08-04CVE Terms of Use
GitHub Advisory DatabaseGHSA-r6jx-9g48-2r5r changed 2026-07-08CC-BY-4.0
NVDCVE-2021-37678 changed 2026-06-17Public domain
PyPA Advisory DatabasePYSEC-2021-300 changed 2023-12-06CC-BY-4.0
PyPA Advisory DatabasePYSEC-2021-591 changed 2023-12-06CC-BY-4.0
PyPA Advisory DatabasePYSEC-2021-789 changed 2023-12-06CC-BY-4.0
Bitnami Vulnerability DatabaseBIT-TENSORFLOW-2021-37678 changed 2026-09-10Apache-2.0