CVE-2021-37658

7.1 HIGH

📋 TL;DR

This vulnerability in TensorFlow allows an attacker to cause undefined behavior by binding a reference to a null pointer in MatrixSetDiagV* operations. Attackers can exploit incomplete validation of the 'k' tensor parameter to trigger memory corruption. All TensorFlow users running affected versions are potentially vulnerable.

💻 Affected Systems

Products:
  • TensorFlow
Versions: TensorFlow 2.3.0 to 2.3.3, 2.4.0 to 2.4.2, 2.5.0, and 2.6.0-rc versions
Operating Systems: All platforms running TensorFlow
Default Config Vulnerable: ⚠️ Yes
Notes: Only affects systems using tf.raw_ops.MatrixSetDiagV* operations. The vulnerability is present in default TensorFlow installations.

📦 What is this software?

⚠️ Risk & Real-World Impact

🔴

Worst Case

Remote code execution leading to complete system compromise, data theft, or denial of service through memory corruption.

🟠

Likely Case

Application crash or denial of service due to null pointer dereference, potentially leading to availability issues.

🟢

If Mitigated

No impact if patched or workarounds applied; otherwise, limited to denial of service in controlled environments.

🌐 Internet-Facing: MEDIUM - Requires specific API endpoints exposing vulnerable operations, but could be exploited remotely if present.
🏢 Internal Only: MEDIUM - Internal applications using TensorFlow with vulnerable operations could be exploited by authenticated users.

🎯 Exploit Status

Public PoC: ✅ No
Weaponized: UNKNOWN
Unauthenticated Exploit: ✅ No
Complexity: MEDIUM

Exploitation requires the ability to call vulnerable TensorFlow operations with crafted inputs. No public exploit code is known at this time.

🛠️ Fix & Mitigation

✅ Official Fix

Patch Version: TensorFlow 2.6.0, 2.5.1, 2.4.3, and 2.3.4

Vendor Advisory: https://github.com/tensorflow/tensorflow/security/advisories/GHSA-6p5r-g9mq-ggh2

Restart Required: No

Instructions:

1. Update TensorFlow to patched version: pip install --upgrade tensorflow==2.6.0 (or appropriate version). 2. Verify installation with: python -c 'import tensorflow as tf; print(tf.__version__)'. 3. Restart any running TensorFlow applications.

🔧 Temporary Workarounds

Input Validation

all

Add validation to ensure 'k' tensor parameter has at least one element before passing to MatrixSetDiagV* operations.

# Python code to validate 'k' tensor
if k is not None and k.shape.num_elements() == 0:
    raise ValueError('k tensor must not be empty')

🧯 If You Can't Patch

  • Disable or restrict access to MatrixSetDiagV* operations in your application.
  • Implement strict input validation for all TensorFlow operations to reject empty tensors.

🔍 How to Verify

Check if Vulnerable:

Check TensorFlow version: python -c 'import tensorflow as tf; print(tf.__version__)'. If version is between 2.3.0-2.3.3, 2.4.0-2.4.2, 2.5.0, or 2.6.0-rc, you are vulnerable.

Check Version:

python -c 'import tensorflow as tf; print(tf.__version__)'

Verify Fix Applied:

After patching, verify version is 2.6.0, 2.5.1, 2.4.3, or 2.3.4. Test MatrixSetDiagV* operations with empty 'k' tensor to ensure proper error handling.

📡 Detection & Monitoring

Log Indicators:

  • Application crashes or segmentation faults in TensorFlow processes
  • Error logs containing 'MatrixSetDiag' or null pointer references

Network Indicators:

  • Unusual API calls to TensorFlow endpoints with malformed tensor data

SIEM Query:

source="tensorflow" AND (error="segmentation fault" OR error="null pointer" OR "MatrixSetDiag")

🔗 References

📤 Share & Export