CVE-2021-29529: Heap buffer overflow caused by rounding

Published May 14, 2021
·
Updated

Impact An attacker can trigger a heap buffer overflow in tf.rawops.QuantizedResizeBilinear by manipulating input values so that float rounding results in off-by-one error in accessing image elements:

python import tensorflow as tf

l = [256, 328, 361, 17, 361, 361, 361, 361, 361, 361, 361, 361, 361, 361, 384] images = tf.constant(l, shape=[1, 1, 15, 1], dtype=tf.qint32) size = tf.constant([12, 6], shape=[2], dtype=tf.int32) min = tf.constant(80.22522735595703) max = tf.constant(80.39215850830078)

tf.rawops.QuantizedResizeBilinear(images=images, size=size, min=min, max=max, aligncorners=True, halfpixelcenters=True)

This is because the implementation computes two integers (representing the upper and lower bounds for interpolation) by ceiling and flooring a floating point value:

cc const float inf = std::floor(in); interpolation->lower[i] = std::max(staticcast<int64>(inf), staticcast<int64>(0)); interpolation->upper[i] = std::min(staticcast<int64>(std::ceil(in)), insize - 1); For some values of in, interpolation->upper[i] might be smaller than interpolation->lower[i]. This is an issue if interpolation->upper[i] is capped at insize-1 as it means that interpolation->lower[i] points outside of the image. Then, in the interpolation code, this would result in heap buffer overflow:

cc template <int RESOLUTION, typename T, typename TSCALE, typename TCALC> inline void OutputLerpForChannels(const InterpolationCache<TSCALE>& xs, const int64 x, const TSCALE ysilerp, const int channels, const float min, const float max, const T ysinputlowerptr, const T ysinputupperptr, T outputyptr) { const int64 xslower = xs.lower[x]; ... for (int c = 0; c < channels; ++c) { const T topleft = ysinputlowerptr[xslower + c]; ... } }

For the other cases where interpolation->upper[i] is smaller than interpolation->lower[i], we can set them to be equal without affecting the output.

Patches We have patched the issue in GitHub commit f851613f8f0fb0c838d160ced13c134f778e3ce7.

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. An attacker can trigger a heap buffer overflow in tf.rawops.QuantizedResizeBilinear by manipulating input values so that float rounding results in off-by-one error in accessing image elements. This is because the implementation(https://github.com/tensorflow/tensorflow/blob/44b7f486c0143f68b56c34e2d01e146ee445134a/tensorflow/core/kernels/quantizedresizebilinearop.cc#L62-L66) computes two integers (representing the upper and lower bounds for interpolation) by ceiling and flooring a floating point value. For some values of in, interpolation->upper[i] might be smaller than interpolation->lower[i]. This is an issue if interpolation->upper[i] is capped at insize-1 as it means that interpolation->lower[i] points outside of the image. Then, in the interpolation code(https://github.com/tensorflow/tensorflow/blob/44b7f486c0143f68b56c34e2d01e146ee445134a/tensorflow/core/kernels/quantizedresizebilinearop.cc#L245-L264), this would result in heap buffer overflow. 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:12 PM
Data Sourced
via MITRE·07:12 PM
DescriptionSeverityWeakness
May 21, 2021
Advisory Published
via GitHub·02:22 PM

Frequently Asked Questions

1

What is the severity of CVE-2021-29529?

CVE-2021-29529 is categorized as a critical severity vulnerability due to the potential for remote exploitation through heap buffer overflow.

2

How do I fix CVE-2021-29529?

To fix CVE-2021-29529, upgrade to TensorFlow version 2.4.2 or later, or apply patches available in the affected versions.

3

Which versions are affected by CVE-2021-29529?

CVE-2021-29529 affects TensorFlow versions prior to 2.1.4, between 2.2.0 to 2.2.3, between 2.3.0 to 2.3.3, and between 2.4.0 to 2.4.2.

4

What kind of attack is possible with CVE-2021-29529?

An attacker can exploit CVE-2021-29529 to execute arbitrary code via a heap buffer overflow in the TensorFlow library.

5

Is CVE-2021-29529 specific to certain platforms?

CVE-2021-29529 is not limited to specific platforms but affects all implementations of the vulnerable TensorFlow versions regardless of the operating environment.

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