VAITP Dataset

← Back to the dataset

CVE-2021-29548

TensorFlow QuantizedBatchNormWithGlobalNormalization runtime division by zero vulnerability

  • CVSS 5.5
  • CWE-369 Divide By Zero
  • Design Defects
  • Remote

TensorFlow is an end-to-end open source platform for machine learning. An attacker can cause a runtime division by zero error and denial of service in `tf.raw_ops.QuantizedBatchNormWithGlobalNormalization`. This is because the implementation(https://github.com/tensorflow/tensorflow/blob/55a97caa9e99c7f37a0bbbeb414dc55553d3ae7f/tensorflow/core/kernels/quantized_batch_norm_op.cc) does not validate all constraints specified in the op's contract(https://www.tensorflow.org/api_docs/python/tf/raw_ops/QuantizedBatchNormWithGlobalNormalization). The fix will be included in TensorFlow 2.5.0. We will also cherrypick this commit on TensorFlow 2.4.2, TensorFlow 2.3.3, TensorFlow 2.2.3 and TensorFlow 2.1.4, as these are also affected and still in supported range.

CVSS base score
5.5
Published
2021-05-14
OWASP
A08 Software and Data Integrity Failures
Orthogonal defect classification
Function
Code defect classification
Incorrect Functionality
Category
Design Defects
Subcategory
Inadequate Error Handling
Accessibility scope
Remote
Impact
Denial of Service (DoS)
Affected component
TensorFlow
Fixed by upgrading
Yes

Solution

Update TensorFlow to version 2.5.0 or higher.

Vulnerable code sample

import tensorflow as tf

input_tensor = tf.constant([1, 2, 3], dtype=tf.qint8)
scale = tf.constant([1.0], dtype=tf.float32)
offset = tf.constant([0.0], dtype=tf.float32)
mean = tf.constant([1.0], dtype=tf.float32)
variance = tf.constant([0.0], dtype=tf.float32)

result = tf.raw_ops.QuantizedBatchNormWithGlobalNormalization(
    input=input_tensor,
    scale=scale,
    offset=offset,
    mean=mean,
    variance=variance,
    epsilon=1e-5
)

print(result)

Patched code sample

import tensorflow as tf

def quantized_batch_norm_with_global_normalization(input_tensor, scale, offset, mean, variance, epsilon=1e-5):
    if tf.reduce_any(variance <= 0):
        raise ValueError("Variance must be greater than zero to avoid division by zero.")

    return tf.raw_ops.QuantizedBatchNormWithGlobalNormalization(
        input=input_tensor,
        scale=scale,
        offset=offset,
        mean=mean,
        variance=variance,
        epsilon=epsilon
    )

try:
    input_tensor = tf.constant([1, 2, 3], dtype=tf.qint8)
    scale = tf.constant([1.0], dtype=tf.float32)
    offset = tf.constant([0.0], dtype=tf.float32)
    mean = tf.constant([1.0], dtype=tf.float32)
    variance = tf.constant([0.0], dtype=tf.float32)

    result = quantized_batch_norm_with_global_normalization(input_tensor, scale, offset, mean, variance)
except ValueError as e:
    print(e)

Cite this entry

@misc{vaitp:cve202129548,
  title        = {{TensorFlow QuantizedBatchNormWithGlobalNormalization runtime division by zero vulnerability}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2021},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2021-29548},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2021-29548/}}
}
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 ::