CVE-2022-21728

8.1 HIGH

📋 TL;DR

This vulnerability in TensorFlow's ReverseSequence operation allows heap out-of-bounds reads when processing negative batch_dim values. Attackers could potentially read sensitive memory contents or cause crashes. Users of affected TensorFlow versions are vulnerable when processing untrusted input data.

💻 Affected Systems

Products:
  • TensorFlow
Versions: TensorFlow 2.5.0 to 2.7.0, and earlier versions if using ReverseSequence operation
Operating Systems: All platforms running TensorFlow
Default Config Vulnerable: ⚠️ Yes
Notes: Vulnerability exists in the core framework and affects all deployments using the ReverseSequence operation.

📦 What is this software?

⚠️ Risk & Real-World Impact

🔴

Worst Case

Information disclosure through memory leakage, potential remote code execution via memory corruption, or denial of service through application crashes.

🟠

Likely Case

Application crashes or instability when processing maliciously crafted input tensors with negative batch_dim values.

🟢

If Mitigated

Minimal impact if input validation is performed externally or if the vulnerable function isn't used with untrusted data.

🌐 Internet-Facing: MEDIUM - Exploitation requires feeding malicious data to TensorFlow models, which could occur through API endpoints serving ML models.
🏢 Internal Only: LOW - Requires internal users to process malicious data, less likely in controlled environments.

🎯 Exploit Status

Public PoC: ✅ No
Weaponized: UNKNOWN
Unauthenticated Exploit: ⚠️ Yes
Complexity: MEDIUM

Exploitation requires crafting specific tensor inputs with negative batch_dim values that trigger the OOB read.

🛠️ Fix & Mitigation

✅ Official Fix

Patch Version: TensorFlow 2.8.0, 2.7.1, 2.6.3, 2.5.3

Vendor Advisory: https://github.com/tensorflow/tensorflow/security/advisories/GHSA-6gmv-pjp9-p8w8

Restart Required: No

Instructions:

1. Update TensorFlow to patched version using pip: pip install --upgrade tensorflow==2.8.0 2. For specific versions: pip install tensorflow==2.7.1, tensorflow==2.6.3, or tensorflow==2.5.3 3. Verify installation with: python -c 'import tensorflow as tf; print(tf.__version__)'

🔧 Temporary Workarounds

Input Validation Wrapper

all

Wrap ReverseSequence calls with validation to ensure batch_dim is non-negative and within valid range

# Python code to validate batch_dim before ReverseSequence
import tensorflow as tf

def safe_reverse_sequence(input, seq_lengths, batch_dim):
    if batch_dim < 0:
        batch_dim = input.shape.ndims + batch_dim
    if batch_dim < 0 or batch_dim >= input.shape.ndims:
        raise ValueError('Invalid batch_dim value')
    return tf.reverse_sequence(input, seq_lengths, batch_dim)

🧯 If You Can't Patch

  • Disable or restrict use of ReverseSequence operation in production models
  • Implement strict input validation for all tensor operations, especially for user-supplied data

🔍 How to Verify

Check if Vulnerable:

Check TensorFlow version: python -c 'import tensorflow as tf; print(tf.__version__)' - if version is between 2.5.0 and 2.7.0 (excluding patched versions), you are vulnerable.

Check Version:

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

Verify Fix Applied:

After updating, verify version is 2.8.0, 2.7.1, 2.6.3, or 2.5.3 using same command.

📡 Detection & Monitoring

Log Indicators:

  • Segmentation faults in TensorFlow processes
  • Memory access violation errors
  • Unexpected application crashes during tensor operations

Network Indicators:

  • Unusual patterns in ML model API requests with tensor data

SIEM Query:

source="tensorflow" AND ("segmentation fault" OR "memory violation" OR "out of bounds")

🔗 References

📤 Share & Export