CVE-2022-41887
TensorFlow crash: dimensions overflow in tf.keras.losses.poisson
- CVSS 7.5
- CWE-131 Incorrect Calculation of Buffer Size
- Numeric Errors
- Local
TensorFlow is an open source platform for machine learning. `tf.keras.losses.poisson` receives a `y_pred` and `y_true` that are passed through `functor::mul` in `BinaryOp`. If the resulting dimensions overflow an `int32`, TensorFlow will crash due to a size mismatch during broadcast assignment. We have patched the issue in GitHub commit c5b30379ba87cbe774b08ac50c1f6d36df4ebb7c. The fix will be included in TensorFlow 2.11. We will also cherrypick this commit on TensorFlow 2.10.1 and 2.9.3, as these are also affected and still in supported range. However, we will not cherrypick this commit into TensorFlow 2.8.x, as it depends on Eigen behavior that changed between 2.8 and 2.9.
- CVSS base score
- 7.5
- Published
- 2022-11-18
- OWASP
- A06 Vulnerable and Outdated Components
- Orthogonal defect classification
- Function
- Code defect classification
- Incorrect Functionality
- Category
- Numeric Errors
- Subcategory
- Integer Overflows
- Accessibility scope
- Local
- Impact
- Denial of Service (DoS)
- Affected component
- TensorFlow
- Fixed by upgrading
- Yes
Solution
Update to TensorFlow version 2.11 or apply GitHub commit c5b30379ba87cbe774b08ac50c1f6d36df4ebb7c.
Vulnerable code sample
import tensorflow as tf
def poisson_loss(y_true, y_pred):
return tf.keras.losses.poisson(y_true, y_pred)
y_true = tf.random.uniform((100000, 100000), minval=0, maxval=10)
y_pred = tf.random.uniform((100000, 100000), minval=0, maxval=10)
try:
loss = poisson_loss(y_true, y_pred)
print("Loss:", loss.numpy())
except Exception as e:
print("Error:", e)Patched code sample
import tensorflow as tf
MAX_TENSOR_SIZE = 10000
def poisson_loss(y_true, y_pred):
return tf.keras.losses.poisson(y_true, y_pred)
def validate_tensor_size(tensor):
if tensor.shape[0] > MAX_TENSOR_SIZE or tensor.shape[1] > MAX_TENSOR_SIZE:
raise ValueError(f"Tensor size too large: {tensor.shape}")
return tensor
try:
y_true = tf.random.uniform((100000, 100000), minval=0, maxval=10)
y_pred = tf.random.uniform((100000, 100000), minval=0, maxval=10)
y_true = validate_tensor_size(y_true)
y_pred = validate_tensor_size(y_pred)
loss = poisson_loss(y_true, y_pred)
print("Loss:", loss.numpy())
except Exception as e:
print("Error:", e)Cite this entry
@misc{vaitp:cve202241887,
title = {{TensorFlow crash: dimensions overflow in tf.keras.losses.poisson}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2022},
note = {VAITP Python Vulnerability Dataset, entry CVE-2022-41887},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2022-41887/}}
}
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 ::
