CVE-2021-29536: Heap buffer overflow in `QuantizedReshape`
Impact An attacker can cause a heap buffer overflow in QuantizedReshape by passing in invalid thresholds for the quantization:
python import tensorflow as tf
tensor = tf.constant([], dtype=tf.qint32) shape = tf.constant([], dtype=tf.int32) inputmin = tf.constant([], dtype=tf.float32) inputmax = tf.constant([], dtype=tf.float32)
tf.rawops.QuantizedReshape(tensor=tensor, shape=shape, inputmin=inputmin, inputmax=inputmax)
This is because the implementation assumes that the 2 arguments are always valid scalars and tries to access the numeric value directly:
cc const auto& inputminfloattensor = ctx->input(2); ... const float inputminfloat = inputminfloattensor.flat<float>()(0); const auto& inputmaxfloattensor = ctx->input(3); ... const float inputmaxfloat = inputmaxfloattensor.flat<float>()(0);
However, if any of these tensors is empty, then .flat<T>() is an empty buffer and accessing the element at position 0 results in overflow.
Patches We have patched the issue in GitHub commit a324ac84e573fba362a5e53d4e74d5de6729933e.
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 cause a heap buffer overflow in QuantizedReshape by passing in invalid thresholds for the quantization. This is because the implementation(https://github.com/tensorflow/tensorflow/blob/a324ac84e573fba362a5e53d4e74d5de6729933e/tensorflow/core/kernels/quantizedreshapeop.cc#L38-L55) assumes that the 2 arguments are always valid scalars and tries to access the numeric value directly. However, if any of these tensors is empty, then .flat<T>() is an empty buffer and accessing the element at position 0 results in 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
Remediation
Event History
Frequently Asked Questions
What is the severity of CVE-2021-29536?
CVE-2021-29536 is considered a high severity vulnerability due to the potential for heap buffer overflow which can lead to arbitrary code execution.
How do I fix CVE-2021-29536?
To mitigate CVE-2021-29536, update TensorFlow to version 2.4.2 or higher, or to versions 2.3.3 and 2.2.3 depending on your current version.
What software is affected by CVE-2021-29536?
CVE-2021-29536 affects multiple versions of Google TensorFlow up to version 2.4.2, including versions 2.1.4, 2.2.0 to 2.2.3, and 2.3.0 to 2.3.3.
What type of attack can exploit CVE-2021-29536?
An attacker can exploit CVE-2021-29536 by passing invalid thresholds for quantization, leading to potential arbitrary code execution.
Is CVE-2021-29536 being actively exploited?
As of the latest information, there are no confirmed reports of active exploitation of CVE-2021-29536, but it is advisable to patch it promptly.