CVE-2021-37678

9.3 CRITICAL

📋 TL;DR

This vulnerability allows arbitrary code execution when TensorFlow or Keras deserializes a malicious YAML model file. Attackers can exploit unsafe YAML loading to run arbitrary commands on affected systems. Users of TensorFlow who load Keras models from YAML format are affected.

💻 Affected Systems

Products:
  • TensorFlow
  • Keras
Versions: TensorFlow 2.3.0 to 2.5.0, and potentially earlier versions using YAML model loading
Operating Systems: All operating systems running affected TensorFlow versions
Default Config Vulnerable: ⚠️ Yes
Notes: Vulnerability exists when using keras.models.model_from_yaml() or related YAML deserialization functions. JSON and H5 model formats are not affected.

📦 What is this software?

⚠️ Risk & Real-World Impact

🔴

Worst Case

Full system compromise with attacker gaining remote code execution, potentially leading to data theft, ransomware deployment, or lateral movement within the network.

🟠

Likely Case

Local privilege escalation or remote code execution in ML pipelines that process untrusted YAML model files, compromising the hosting server.

🟢

If Mitigated

Limited impact if systems only load trusted YAML files from secure sources and have proper network segmentation.

🌐 Internet-Facing: HIGH if systems accept YAML model uploads from untrusted sources via web interfaces or APIs.
🏢 Internal Only: MEDIUM if internal users can upload YAML models, but LOW if YAML model loading is restricted to trusted pipelines.

🎯 Exploit Status

Public PoC: ⚠️ Yes
Weaponized: LIKELY
Unauthenticated Exploit: ⚠️ Yes
Complexity: LOW

Exploitation requires the victim to load a malicious YAML file. Public proof-of-concept demonstrates code execution via crafted YAML payloads.

🛠️ Fix & Mitigation

✅ Official Fix

Patch Version: TensorFlow 2.6.0, 2.5.1, 2.4.3, 2.3.4

Vendor Advisory: https://github.com/tensorflow/tensorflow/security/advisories/GHSA-r6jx-9g48-2r5r

Restart Required: No

Instructions:

1. Upgrade TensorFlow to patched version: pip install --upgrade tensorflow==2.6.0 (or appropriate version). 2. Verify YAML model loading is disabled or removed in your codebase. 3. Test ML pipelines after upgrade.

🔧 Temporary Workarounds

Disable YAML model loading

all

Remove or disable all usage of keras.models.model_from_yaml() and related YAML deserialization functions in your code.

# Search for YAML model loading in Python code
grep -r "model_from_yaml\|yaml\.load" /path/to/code/
# Replace with safe alternatives like model_from_json()

Use safe YAML loader

all

If YAML loading is required, replace yaml.unsafe_load with yaml.safe_load in custom code (note: TensorFlow's implementation cannot be safely patched this way).

# In custom Python code:
import yaml
# Replace: data = yaml.unsafe_load(file)
# With: data = yaml.safe_load(file)

🧯 If You Can't Patch

  • Restrict YAML file uploads to trusted sources only
  • Implement strict input validation and sandboxing for ML model processing pipelines

🔍 How to Verify

Check if Vulnerable:

Check TensorFlow version and usage of YAML model loading: python -c "import tensorflow as tf; print(tf.__version__)" and review code for model_from_yaml() calls.

Check Version:

python -c "import tensorflow as tf; print('TensorFlow version:', tf.__version__)"

Verify Fix Applied:

After patching, verify TensorFlow version >=2.6.0, 2.5.1, 2.4.3, or 2.3.4, and test that YAML model loading fails or is disabled.

📡 Detection & Monitoring

Log Indicators:

  • Unusual process execution from TensorFlow/Python processes
  • Errors related to YAML parsing or model loading failures
  • Large or malformed YAML file uploads to ML endpoints

Network Indicators:

  • Unexpected outbound connections from ML servers after YAML file processing
  • HTTP requests with YAML payloads to model loading endpoints

SIEM Query:

source="*tensorflow*" AND ("yaml" OR "model_from_yaml") AND (process_execution OR error)

🔗 References

📤 Share & Export