Headline
CVE-2022-23576: Prevent integer overflow in `OpLevelCostEstimator::CalculateOutputSize`. · tensorflow/tensorflow@b9bd6cf
Tensorflow is an Open Source Machine Learning Framework. The implementation of OpLevelCostEstimator::CalculateOutputSize
is vulnerable to an integer overflow if an attacker can create an operation which would involve tensors with large enough number of elements. We can have a large enough number of dimensions in output_shape.dim()
or just a small number of dimensions being large enough to cause an overflow in the multiplication. The fix will be included in TensorFlow 2.8.0. We will also cherrypick this commit on TensorFlow 2.7.1, TensorFlow 2.6.3, and TensorFlow 2.5.3, as these are also affected and still in supported range.
@@ -27,6 +27,7 @@ limitations under the License. #include “tensorflow/core/grappler/costs/op_context.h” #include “tensorflow/core/grappler/costs/utils.h” #include “tensorflow/core/platform/errors.h” #include “tensorflow/core/util/overflow.h”
namespace tensorflow { namespace grappler { @@ -1607,7 +1608,14 @@ int64_t OpLevelCostEstimator::CalculateOutputSize(const OpInfo& op_info, auto output_shape = MaybeGetMinimumShape(original_output_shape, num_dims, found_unknown_shapes); for (const auto& dim : output_shape.dim()) { output_size *= dim.size(); int64_t new_output_size = MultiplyWithoutOverflow(output_size, dim.size()); if (new_output_size < 0) { VLOG(1) << "Overflow encountered when estimating cost, multiplying " << output_size << " with " << dim.size(); return -1; } output_size = new_output_size; } total_output_size += output_size; VLOG(1) << "Output Size: " << output_size