CVE-2021-37654
📋 TL;DR
This vulnerability in TensorFlow allows attackers to trigger crashes or read data outside allocated memory bounds via the ResourceGather API. It affects TensorFlow users who process untrusted input with the vulnerable function, potentially leading to denial of service or information disclosure.
💻 Affected Systems
- TensorFlow
📦 What is this software?
⚠️ Risk & Real-World Impact
Worst Case
Remote code execution via memory corruption leading to full system compromise, though this requires specific memory layout conditions.
Likely Case
Denial of service through application crashes or information disclosure via out-of-bounds memory reads.
If Mitigated
No impact if proper input validation is implemented or vulnerable functions aren't exposed to untrusted users.
🎯 Exploit Status
Exploitation requires calling tf.raw_ops.ResourceGather with malicious batch_dims parameter. No authentication needed if API is exposed.
🛠️ 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-2r8p-fg3c-wcj4
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__)'.
🔧 Temporary Workarounds
Input Validation Wrapper
allAdd validation to ensure batch_dims < input tensor rank before calling ResourceGather
# Python code to wrap ResourceGather calls
import tensorflow as tf
def safe_resource_gather(resource, indices, batch_dims=0, name=None):
if batch_dims >= resource.shape.rank:
raise ValueError('batch_dims must be less than tensor rank')
return tf.raw_ops.ResourceGather(resource=resource, indices=indices, batch_dims=batch_dims, name=name)
🧯 If You Can't Patch
- Restrict access to TensorFlow services processing untrusted input
- Implement strict input validation for all ResourceGather API calls
🔍 How to Verify
Check if Vulnerable:
Check TensorFlow version: python -c 'import tensorflow as tf; print(tf.__version__)' - versions 2.3.0-2.5.0 are vulnerable.
Check Version:
python -c 'import tensorflow as tf; print(tf.__version__)'
Verify Fix Applied:
Verify version is 2.6.0, 2.5.1, 2.4.3, or 2.3.4. Test ResourceGather with invalid batch_dims to ensure proper error handling.
📡 Detection & Monitoring
Log Indicators:
- TensorFlow crash logs mentioning ResourceGather
- CHECK-fail errors in debug builds
- Memory access violation errors
Network Indicators:
- Unusual requests to TensorFlow-serving APIs with batch_dims parameters
SIEM Query:
source="tensorflow" AND ("ResourceGather" OR "CHECK-fail" OR "out of bounds")
🔗 References
- https://github.com/tensorflow/tensorflow/commit/bc9c546ce7015c57c2f15c168b3d9201de679a1d
- https://github.com/tensorflow/tensorflow/security/advisories/GHSA-2r8p-fg3c-wcj4
- https://github.com/tensorflow/tensorflow/commit/bc9c546ce7015c57c2f15c168b3d9201de679a1d
- https://github.com/tensorflow/tensorflow/security/advisories/GHSA-2r8p-fg3c-wcj4