CVE-2021-37678
YAML deserialization in TensorFlow allows arbitrary code execution
- CVSS 8.8
- CWE-502 Deserialization of Untrusted Data
- Input Validation and Sanitization
- Local
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.
- CVSS base score
- 8.8
- Published
- 2021-08-12
- OWASP
- A08 Software and Data Integrity Failures
- Orthogonal defect classification
- Timing/Serialization
- Code defect classification
- Serialization Issues
- Category
- Input Validation and Sanitization
- Subcategory
- Insecure Parsing or Deserialization
- Accessibility scope
- Local
- Impact
- Arbitrary Code Execution
- Affected component
- TensorFlow
- Fixed by upgrading
- Yes
Solution
Update TensorFlow to version 2.6.0 or higher.
Vulnerable code sample
import yaml
def load_yaml_model(yaml_string):
"""Vulnerable function that demonstrates the security issue."""
# VULNERABLE: This code is susceptible to command injection
return yaml.unsafe_load(yaml_string)
yaml = """
!!python/object/apply:os.system ["cat /etc/passwd"]
"""
model_config = load_yaml_model(yaml)
print(model_config)Patched code sample
import yaml
def load_yaml_model(yaml_string):
"""Secure function that fixes the vulnerability."""
# SECURE: This version prevents command injection
return yaml.safe_load(yaml_string)
yaml = """
!!python/object/apply:os.system ["cat /etc/passwd"]
"""
model_config = load_yaml_model(yaml)
print(model_config)Cite this entry
@misc{vaitp:cve202137678,
title = {{YAML deserialization in TensorFlow allows arbitrary code execution}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2021},
note = {VAITP Python Vulnerability Dataset, entry CVE-2021-37678},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2021-37678/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.
The supreme art of war is to subdue the enemy without fighting.
Sun Tzu – “The Art of War”
:: Shaping the future through research and ingenuity ::
